1
0

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)))
(item (comment))
(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)))
(item (comment))
==================
Multiline Comments
==================
# comment #
not_a_comment #
# comment # "not a comment"
---
(root
(comment)
(statement (statement
(comment)))) (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,7 +9,6 @@ reduce i to acc in [1, 2, 3] {
--- ---
(root (root
(item
(statement (statement
(reduce (reduce
(identifier) (identifier)
@ -26,31 +25,25 @@ reduce i to acc in [1, 2, 3] {
(expression (expression
(value (value
(integer)))))) (integer))))))
(item
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator) (assignment_operator)
(statement (statement
(expression (expression
(identifier)))))))))) (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
(assignment
(identifier)
(assignment_operator)
(statement (statement
(reduce (reduce
(identifier) (identifier)
@ -67,11 +60,10 @@ together = reduce i to acc in ["one", "two", "three"] {
(expression (expression
(value (value
(string)))))) (string))))))
(item
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator) (assignment_operator)
(statement (statement
(expression (expression
(identifier)))))))))))) (identifier))))))))

View File

@ -1,5 +1,5 @@
================== ==================
Remove Loop Simple Remove
================== ==================
remove i from [1, 2, 3] { remove i from [1, 2, 3] {
@ -9,7 +9,6 @@ remove i from [1, 2, 3] {
--- ---
(root (root
(item
(statement (statement
(remove (remove
(identifier) (identifier)
@ -25,7 +24,6 @@ remove i from [1, 2, 3] {
(expression (expression
(value (value
(integer)))))) (integer))))))
(item
(statement (statement
(expression (expression
(logic (logic
@ -34,20 +32,21 @@ remove i from [1, 2, 3] {
(logic_operator) (logic_operator)
(expression (expression
(value (value
(integer))))))))))) (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)
@ -56,18 +55,12 @@ removed = remove i from ["one", "two", "three"] {
(remove (remove
(identifier) (identifier)
(expression (expression
(value (identifier))
(list (statement
(remove
(identifier)
(expression (expression
(value (identifier))
(string)))
(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",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statement_kind" "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,6 +135,9 @@
] ]
}, },
"_expression_kind": { "_expression_kind": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -178,6 +169,7 @@
"name": "value" "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,9 +704,6 @@
] ]
}, },
"function_call": { "function_call": {
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@ -942,7 +743,6 @@
"value": ")" "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