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

View File

@ -1,5 +1,5 @@
==================
Remove Loop
Simple Remove
==================
remove i from [1, 2, 3] {
@ -9,7 +9,6 @@ remove i from [1, 2, 3] {
---
(root
(item
(statement
(remove
(identifier)
@ -25,7 +24,6 @@ remove i from [1, 2, 3] {
(expression
(value
(integer))))))
(item
(statement
(expression
(logic
@ -34,20 +32,21 @@ remove i from [1, 2, 3] {
(logic_operator)
(expression
(value
(integer)))))))))))
(integer)))))))))
==================
Remove Loop Assignment
Nested Remove
==================
removed = remove i from ["one", "two", "three"] {
i == "two"
removed = remove i from big_list {
remove j from i {
j != 42
}
}
---
(root
(item
(statement
(assignment
(identifier)
@ -56,18 +55,12 @@ removed = remove i from ["one", "two", "three"] {
(remove
(identifier)
(expression
(value
(list
(identifier))
(statement
(remove
(identifier)
(expression
(value
(string)))
(expression
(value
(string)))
(expression
(value
(string))))))
(item
(identifier))
(statement
(expression
(logic
@ -76,4 +69,4 @@ removed = remove i from ["one", "two", "three"] {
(logic_operator)
(expression
(value
(string)))))))))))))
(integer)))))))))))))

View File

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

View File

@ -9,6 +9,10 @@
"name": "statement"
}
},
"comment": {
"type": "PATTERN",
"value": "[#][^#\\n]*[#|\\n]"
},
"statement": {
"type": "PREC_LEFT",
"value": 0,
@ -16,11 +20,8 @@
"type": "CHOICE",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_statement_kind"
}
},
{
"type": "SEQ",
@ -56,10 +57,6 @@
"type": "SYMBOL",
"name": "async"
},
{
"type": "SYMBOL",
"name": "comment"
},
{
"type": "SYMBOL",
"name": "expression"
@ -111,15 +108,6 @@
]
}
},
"comment": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[#]+.*"
}
]
},
"expression": {
"type": "CHOICE",
"members": [
@ -147,6 +135,9 @@
]
},
"_expression_kind": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
@ -178,6 +169,7 @@
"name": "value"
}
]
}
},
"identifier": {
"type": "PATTERN",
@ -221,200 +213,12 @@
]
},
"integer": {
"type": "PREC_LEFT",
"value": 0,
"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": "PATTERN",
"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])*"
},
"float": {
"type": "PREC_LEFT",
"value": 0,
"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"
}
]
}
}
]
}
}
"type": "PATTERN",
"value": "\\d(_?\\d)*(\\.\\d)?(_?\\d)*([eE][\\+-]?\\d(_?\\d)*)?"
},
"string": {
"type": "PATTERN",
@ -900,9 +704,6 @@
]
},
"function_call": {
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
@ -942,7 +743,6 @@
"value": ")"
}
]
}
},
"match": {
"type": "SEQ",
@ -1550,6 +1350,10 @@
{
"type": "PATTERN",
"value": "\\s"
},
{
"type": "SYMBOL",
"name": "comment"
}
],
"conflicts": [],

View File

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

File diff suppressed because it is too large Load Diff