Continue syntax revisions

This commit is contained in:
Jeff 2023-10-31 03:17:58 -04:00
parent 42339e1171
commit 0c37e5e3a6
7 changed files with 6448 additions and 9407 deletions

View File

@ -8,13 +8,10 @@ not_a_comment
--- ---
(root (root
(item (statement
(statement (expression
(expression (identifier)))
(identifier)))) (comment))
(item
(statement
(comment))))
================== ==================
Partial Line Comments Partial Line Comments
@ -25,10 +22,29 @@ not_a_comment # comment
--- ---
(root (root
(item (statement
(statement (expression
(expression (identifier)))
(identifier)))) (comment))
(item
(statement ==================
(comment)))) Multiline Comments
==================
# comment #
not_a_comment #
# comment # "not a comment"
---
(root
(comment)
(statement
(expression
(identifier)))
(comment)
(comment)
(statement
(expression
(value
(string)))))

View File

@ -1,5 +1,5 @@
================== ==================
Reduce Loop Simple Reduce Loop
================== ==================
reduce i to acc in [1, 2, 3] { reduce i to acc in [1, 2, 3] {
@ -9,69 +9,61 @@ reduce i to acc in [1, 2, 3] {
--- ---
(root (root
(item (statement
(statement (reduce
(reduce (identifier)
(identifier) (identifier)
(identifier) (expression
(expression (value
(value (list
(list (expression
(expression (value
(value (integer)))
(integer))) (expression
(expression (value
(value (integer)))
(integer))) (expression
(expression (value
(value (integer))))))
(integer)))))) (statement
(item (assignment
(identifier)
(assignment_operator)
(statement (statement
(assignment (expression
(identifier) (identifier))))))))
(assignment_operator)
(statement
(expression
(identifier))))))))))
================== ==================
Reduce Loop Assignment Nested Reduce Loop
================== ==================
together = reduce i to acc in ["one", "two", "three"] { reduce i to acc in ["one", "two", "three"] {
acc += i acc += i
} }
--- ---
(root (root
(item (statement
(statement (reduce
(assignment (identifier)
(identifier) (identifier)
(assignment_operator) (expression
(statement (value
(reduce (list
(identifier)
(identifier)
(expression (expression
(value (value
(list (string)))
(expression (expression
(value (value
(string))) (string)))
(expression (expression
(value (value
(string))) (string))))))
(expression (statement
(value (assignment
(string)))))) (identifier)
(item (assignment_operator)
(statement (statement
(assignment (expression
(identifier) (identifier))))))))
(assignment_operator)
(statement
(expression
(identifier))))))))))))

View File

@ -1,5 +1,5 @@
================== ==================
Remove Loop Simple Remove
================== ==================
remove i from [1, 2, 3] { remove i from [1, 2, 3] {
@ -9,65 +9,58 @@ remove i from [1, 2, 3] {
--- ---
(root (root
(item (statement
(statement (remove
(remove (identifier)
(identifier) (expression
(expression (value
(value (list
(list
(expression
(value
(integer)))
(expression
(value
(integer)))
(expression
(value
(integer))))))
(item
(statement
(expression (expression
(logic (value
(expression (integer)))
(identifier)) (expression
(logic_operator) (value
(expression (integer)))
(value (expression
(integer))))))))))) (value
(integer))))))
(statement
(expression
(logic
(expression
(identifier))
(logic_operator)
(expression
(value
(integer)))))))))
================== ==================
Remove Loop Assignment Nested Remove
================== ==================
removed = remove i from ["one", "two", "three"] { removed = remove i from big_list {
i == "two" remove j from i {
j != 42
}
} }
--- ---
(root (root
(item (statement
(statement (assignment
(assignment (identifier)
(identifier) (assignment_operator)
(assignment_operator) (statement
(statement (remove
(remove (identifier)
(identifier) (expression
(expression (identifier))
(value (statement
(list (remove
(expression (identifier)
(value (expression
(string))) (identifier))
(expression
(value
(string)))
(expression
(value
(string))))))
(item
(statement (statement
(expression (expression
(logic (logic
@ -76,4 +69,4 @@ removed = remove i from ["one", "two", "three"] {
(logic_operator) (logic_operator)
(expression (expression
(value (value
(string))))))))))))) (integer)))))))))))))

View File

@ -3,18 +3,21 @@ module.exports = grammar({
word: $ => $.identifier, word: $ => $.identifier,
extras: $ => [ /\s/, $.comment ],
rules: { rules: {
root: $ => repeat1($.statement), root: $ => repeat1($.statement),
comment: $ => /[#][^#\n]*[#|\n]/,
statement: $ => prec.left(choice( statement: $ => prec.left(choice(
repeat1($._statement_kind), $._statement_kind,
seq('{', $._statement_kind, '}'), seq('{', $._statement_kind, '}'),
// )) )),
_statement_kind: $ => prec.left(choice( _statement_kind: $ => prec.left(choice(
$.assignment, $.assignment,
$.async, $.async,
$.comment,
$.expression, $.expression,
$.filter, $.filter,
$.find, $.find,
@ -29,14 +32,12 @@ module.exports = grammar({
$.while, $.while,
)), )),
comment: $ => seq(/[#]+.*/),
expression: $ => choice( expression: $ => choice(
$._expression_kind, $._expression_kind,
seq('(', $._expression_kind, ')'), seq('(', $._expression_kind, ')'),
), ),
_expression_kind: $ => choice( _expression_kind: $ => prec.left(choice(
$.function_call, $.function_call,
$.identifier, $.identifier,
$.index, $.index,
@ -44,7 +45,7 @@ module.exports = grammar({
$.math, $.math,
$.tool, $.tool,
$.value, $.value,
), )),
identifier: $ => /[_a-zA-Z]+[_a-zA-Z0-9]?/, identifier: $ => /[_a-zA-Z]+[_a-zA-Z0-9]?/,
@ -59,19 +60,9 @@ module.exports = grammar({
$.map, $.map,
), ),
integer: $ => prec.left(token(seq( integer: $ => /0[bB][01](_?[01])*|0[oO]?[0-7](_?[0-7])*|(0[dD])?\d(_?\d)*|0[xX][0-9a-fA-F](_?[0-9a-fA-F])*/,
optional('-'),
repeat1(
choice('1', '2', '3', '4', '5', '6', '7', '8', '9', '0')
),
))),
float: $ => prec.left(token(seq( float: $ => /\d(_?\d)*(\.\d)?(_?\d)*([eE][\+-]?\d(_?\d)*)?/,
optional('-'),
repeat1(choice('1', '2', '3', '4', '5', '6', '7', '8', '9', '0')),
'.',
repeat1(choice('1', '2', '3', '4', '5', '6', '7', '8', '9', '0')),
))),
string: $ => /("[^"]*?")|('[^']*?')|(`[^`]*?`)/, string: $ => /("[^"]*?")|('[^']*?')|(`[^`]*?`)/,
@ -188,12 +179,12 @@ module.exports = grammar({
'}', '}',
), ),
function_call: $ => prec(1, seq( function_call: $ => seq(
'(', '(',
$.identifier, $.identifier,
repeat(seq($.expression, optional(','))), repeat(seq($.expression, optional(','))),
')', ')',
)), ),
match: $ => seq( match: $ => seq(
'match', 'match',

View File

@ -9,6 +9,10 @@
"name": "statement" "name": "statement"
} }
}, },
"comment": {
"type": "PATTERN",
"value": "[#][^#\\n]*[#|\\n]"
},
"statement": { "statement": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 0, "value": 0,
@ -16,11 +20,8 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "REPEAT1", "type": "SYMBOL",
"content": { "name": "_statement_kind"
"type": "SYMBOL",
"name": "_statement_kind"
}
}, },
{ {
"type": "SEQ", "type": "SEQ",
@ -56,10 +57,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "async" "name": "async"
}, },
{
"type": "SYMBOL",
"name": "comment"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
@ -111,15 +108,6 @@
] ]
} }
}, },
"comment": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[#]+.*"
}
]
},
"expression": { "expression": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -147,37 +135,41 @@
] ]
}, },
"_expression_kind": { "_expression_kind": {
"type": "CHOICE", "type": "PREC_LEFT",
"members": [ "value": 0,
{ "content": {
"type": "SYMBOL", "type": "CHOICE",
"name": "function_call" "members": [
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "function_call"
"name": "identifier" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "identifier"
"name": "index" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "index"
"name": "logic" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "logic"
"name": "math" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "math"
"name": "tool" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "tool"
"name": "value" },
} {
] "type": "SYMBOL",
"name": "value"
}
]
}
}, },
"identifier": { "identifier": {
"type": "PATTERN", "type": "PATTERN",
@ -221,200 +213,12 @@
] ]
}, },
"integer": { "integer": {
"type": "PREC_LEFT", "type": "PATTERN",
"value": 0, "value": "0[bB][01](_?[01])*|0[oO]?[0-7](_?[0-7])*|(0[dD])?\\d(_?\\d)*|0[xX][0-9a-fA-F](_?[0-9a-fA-F])*"
"content": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "-"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "1"
},
{
"type": "STRING",
"value": "2"
},
{
"type": "STRING",
"value": "3"
},
{
"type": "STRING",
"value": "4"
},
{
"type": "STRING",
"value": "5"
},
{
"type": "STRING",
"value": "6"
},
{
"type": "STRING",
"value": "7"
},
{
"type": "STRING",
"value": "8"
},
{
"type": "STRING",
"value": "9"
},
{
"type": "STRING",
"value": "0"
}
]
}
}
]
}
}
}, },
"float": { "float": {
"type": "PREC_LEFT", "type": "PATTERN",
"value": 0, "value": "\\d(_?\\d)*(\\.\\d)?(_?\\d)*([eE][\\+-]?\\d(_?\\d)*)?"
"content": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "-"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "1"
},
{
"type": "STRING",
"value": "2"
},
{
"type": "STRING",
"value": "3"
},
{
"type": "STRING",
"value": "4"
},
{
"type": "STRING",
"value": "5"
},
{
"type": "STRING",
"value": "6"
},
{
"type": "STRING",
"value": "7"
},
{
"type": "STRING",
"value": "8"
},
{
"type": "STRING",
"value": "9"
},
{
"type": "STRING",
"value": "0"
}
]
}
},
{
"type": "STRING",
"value": "."
},
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "1"
},
{
"type": "STRING",
"value": "2"
},
{
"type": "STRING",
"value": "3"
},
{
"type": "STRING",
"value": "4"
},
{
"type": "STRING",
"value": "5"
},
{
"type": "STRING",
"value": "6"
},
{
"type": "STRING",
"value": "7"
},
{
"type": "STRING",
"value": "8"
},
{
"type": "STRING",
"value": "9"
},
{
"type": "STRING",
"value": "0"
}
]
}
}
]
}
}
}, },
"string": { "string": {
"type": "PATTERN", "type": "PATTERN",
@ -900,49 +704,45 @@
] ]
}, },
"function_call": { "function_call": {
"type": "PREC", "type": "SEQ",
"value": 1, "members": [
"content": { {
"type": "SEQ", "type": "STRING",
"members": [ "value": "("
{ },
"type": "STRING", {
"value": "(" "type": "SYMBOL",
}, "name": "identifier"
{ },
"type": "SYMBOL", {
"name": "identifier" "type": "REPEAT",
}, "content": {
{ "type": "SEQ",
"type": "REPEAT", "members": [
"content": { {
"type": "SEQ", "type": "SYMBOL",
"members": [ "name": "expression"
{ },
"type": "SYMBOL", {
"name": "expression" "type": "CHOICE",
}, "members": [
{ {
"type": "CHOICE", "type": "STRING",
"members": [ "value": ","
{ },
"type": "STRING", {
"value": "," "type": "BLANK"
}, }
{ ]
"type": "BLANK" }
} ]
]
}
]
}
},
{
"type": "STRING",
"value": ")"
} }
] },
} {
"type": "STRING",
"value": ")"
}
]
}, },
"match": { "match": {
"type": "SEQ", "type": "SEQ",
@ -1550,6 +1350,10 @@
{ {
"type": "PATTERN", "type": "PATTERN",
"value": "\\s" "value": "\\s"
},
{
"type": "SYMBOL",
"name": "comment"
} }
], ],
"conflicts": [], "conflicts": [],

View File

@ -47,11 +47,6 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "comment",
"named": true,
"fields": {}
},
{ {
"type": "else", "type": "else",
"named": true, "named": true,
@ -194,11 +189,6 @@
] ]
} }
}, },
{
"type": "float",
"named": true,
"fields": {}
},
{ {
"type": "for", "type": "for",
"named": true, "named": true,
@ -336,11 +326,6 @@
] ]
} }
}, },
{
"type": "integer",
"named": true,
"fields": {}
},
{ {
"type": "list", "type": "list",
"named": true, "named": true,
@ -527,7 +512,7 @@
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{ {
@ -538,10 +523,6 @@
"type": "async", "type": "async",
"named": true "named": true
}, },
{
"type": "comment",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -828,6 +809,10 @@
"type": "columns", "type": "columns",
"named": false "named": false
}, },
{
"type": "comment",
"named": true
},
{ {
"type": "download", "type": "download",
"named": false "named": false
@ -856,6 +841,10 @@
"type": "fish", "type": "fish",
"named": false "named": false
}, },
{
"type": "float",
"named": true
},
{ {
"type": "for", "type": "for",
"named": false "named": false
@ -892,6 +881,10 @@
"type": "insert", "type": "insert",
"named": false "named": false
}, },
{
"type": "integer",
"named": true
},
{ {
"type": "into", "type": "into",
"named": false "named": false

File diff suppressed because it is too large Load Diff