Continue syntax overhaul

This commit is contained in:
Jeff 2023-10-06 06:18:02 -04:00
parent 4ddc656455
commit dbe7991fc6
10 changed files with 7727 additions and 10966 deletions

View File

@ -1,5 +1,5 @@
==================
If/Then
If
==================
if true then "True"
@ -9,7 +9,7 @@ if true then "True"
(root
(item
(statement
(control_flow
(if_else
(expression
(value
(boolean)))
@ -19,7 +19,7 @@ if true then "True"
(string))))))))
==================
If/Then Assignment
If Assignment
==================
x = if true then 1
@ -31,25 +31,18 @@ x = if true then 1
(statement
(assignment
(identifier)
(statement
(if_else
(expression
(identifier)))))
(item
(value
(boolean)))
(statement
(expression
(value
(boolean)))))
(item
(statement
(expression
(identifier))))
(item
(statement
(expression
(value
(integer))))))
(integer))))))))))
==================
If/Else
If Else
==================
if false then "True" else "False"
@ -59,7 +52,7 @@ if false then "True" else "False"
(root
(item
(statement
(control_flow
(if_else
(expression
(value
(boolean)))
@ -73,7 +66,7 @@ if false then "True" else "False"
(string))))))))
==================
If/Else If
If Else If
==================
if 1 == 1
@ -86,7 +79,7 @@ else if 4 == 9
(root
(item
(statement
(control_flow
(if_else
(expression
(logic
(expression
@ -113,3 +106,60 @@ else if 4 == 9
(expression
(value
(string))))))))
==================
If Else Else If Else
==================
if false
then "no"
else if false
then "no"
else if 1 + 1 == 9
then "not the answer"
else "42"
---
(root
(item
(statement
(if_else
(expression
(value
(boolean)))
(statement
(expression
(value
(string))))
(expression
(value
(boolean)))
(statement
(expression
(value
(string))))
(expression
(logic
(expression
(math
(expression
(value
(integer)))
(math_operator)
(expression
(value
(integer)))))
(logic_operator)
(expression
(value
(integer)))))
(statement
(expression
(value
(string))))
(statement
(expression
(value
(string))))))))

View File

@ -2,7 +2,7 @@
Simple Function
==================
function <> { "Hiya" }
function { "Hiya" }
---
@ -22,7 +22,7 @@ function <> { "Hiya" }
Function Call
==================
foobar {"Hiya"}
(foobar "Hiya")
---
@ -40,7 +40,7 @@ foobar {"Hiya"}
Complex Function
==================
function <message, number> {
function <message number> {
output message
output number
}

View File

@ -30,13 +30,14 @@ foobar = ['answer', 42]
(statement
(assignment
(identifier)
(statement
(expression
(value
(list
(value
(string))
(value
(integer)))))))))
(integer))))))))))
==================
List Nesting

34
corpus/match.txt Normal file
View File

@ -0,0 +1,34 @@
==================
Match
==================
match 21 + 21
42 => true
catch false
---
(root
(item
(statement
(match
(expression
(math
(expression
(value
(integer)))
(math_operator)
(expression
(value
(integer)))))
(expression
(value
(integer)))
(statement
(expression
(value
(boolean))))
(statement
(expression
(value
(boolean))))))))

View File

@ -38,16 +38,18 @@ y = "one"
(statement
(assignment
(identifier)
(statement
(expression
(value
(integer))))))
(integer)))))))
(item
(statement
(assignment
(identifier)
(statement
(expression
(value
(string)))))))
(string))))))))
==================
Complex Assignment

View File

@ -37,6 +37,7 @@ foobar = table <text, number> {
(statement
(assignment
(identifier)
(statement
(expression
(value
(table
@ -46,7 +47,7 @@ foobar = table <text, number> {
(value
(string))
(value
(integer))))))))))
(integer)))))))))))
==================
Table Access

View File

@ -13,33 +13,31 @@ module.exports = grammar({
comment: $ => seq('#', /.*/),
statement: $ => prec.right(1, choice(
statement: $ => choice(
$.assignment,
$.expression,
$.control_flow,
$.if_else,
$.yield,
$.insert,
$.select,
$.loop,
$.match,
)),
),
yield: $ => prec.right(2,
seq(
yield: $ => seq(
$.expression,
'->',
$.expression,
repeat(prec.left(seq('->', $.expression)))
)
),
expression: $ => prec.right(choice(
expression: $ => choice(
$.value,
$.identifier,
$.function_call,
$.math,
$.logic,
)),
),
identifier: $ => /[a-z|_|.]+[0-9]?/,
@ -54,9 +52,9 @@ module.exports = grammar({
$.map,
),
integer: $ => /[-]*[0-9]+[.]{0}/,
integer: $ => /[-]?[0-9]+/,
float: $ => /[-]*[0-9]*[.]{1}[0-9]+/,
float: $ => /[-]?[0-9]+[.]{1}[0-9]*/,
string: $ => /("[^"]*?")|('[^']*?')|(`[^`]*?`)/,
@ -125,7 +123,7 @@ module.exports = grammar({
assignment: $ => prec.right(seq(
$.identifier,
choice("=", "+=", "-="),
$.expression,
$.statement,
)),
select: $ => prec.right(seq(
@ -148,17 +146,17 @@ module.exports = grammar({
),
)),
control_flow: $ => prec.right(seq(
if_else: $ => prec.left(1, seq(
'if',
$.expression,
'then',
$.statement,
prec.left(repeat(seq(
repeat(seq(
'else if',
$.expression,
'then',
$.statement,
))),
)),
optional(seq(
'else',
$.statement,
@ -166,18 +164,13 @@ module.exports = grammar({
)),
function_call: $ => prec.right(seq(
'(',
$.identifier,
'{',
repeat(seq($.expression)),
'}',
')',
)),
loop: $ => choice(
$.break_loop,
$.while_loop,
),
while_loop: $ => seq(
while: $ => seq(
'while',
$.expression,
'{',
@ -185,7 +178,7 @@ module.exports = grammar({
'}',
),
break_loop: $ => seq(
loop: $ => seq(
'loop',
'{',
repeat($.statement),
@ -194,12 +187,12 @@ module.exports = grammar({
'}',
),
match: $ => seq(
match: $ => prec.right(seq(
'match',
$.expression,
'{',
repeat1(seq($.expression, '=>', $.statement)),
'}',
),
'catch',
$.statement
)),
}
});

View File

@ -36,9 +36,6 @@
]
},
"statement": {
"type": "PREC_RIGHT",
"value": 1,
"content": {
"type": "CHOICE",
"members": [
{
@ -51,7 +48,7 @@
},
{
"type": "SYMBOL",
"name": "control_flow"
"name": "if_else"
},
{
"type": "SYMBOL",
@ -74,12 +71,8 @@
"name": "match"
}
]
}
},
"yield": {
"type": "PREC_RIGHT",
"value": 2,
"content": {
"type": "SEQ",
"members": [
{
@ -115,12 +108,8 @@
}
}
]
}
},
"expression": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
@ -144,7 +133,6 @@
"name": "logic"
}
]
}
},
"identifier": {
"type": "PATTERN",
@ -189,11 +177,11 @@
},
"integer": {
"type": "PATTERN",
"value": "[-]*[0-9]+[.]{0}"
"value": "[-]?[0-9]+"
},
"float": {
"type": "PATTERN",
"value": "[-]*[0-9]*[.]{1}[0-9]+"
"value": "[-]?[0-9]+[.]{1}[0-9]*"
},
"string": {
"type": "PATTERN",
@ -537,7 +525,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "statement"
}
]
}
@ -637,9 +625,9 @@
]
}
},
"control_flow": {
"type": "PREC_RIGHT",
"value": 0,
"if_else": {
"type": "PREC_LEFT",
"value": 1,
"content": {
"type": "SEQ",
"members": [
@ -660,9 +648,6 @@
"name": "statement"
},
{
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "REPEAT",
"content": {
"type": "SEQ",
@ -685,7 +670,6 @@
}
]
}
}
},
{
"type": "CHOICE",
@ -718,12 +702,12 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"type": "STRING",
"value": "("
},
{
"type": "STRING",
"value": "{"
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "REPEAT",
@ -739,25 +723,12 @@
},
{
"type": "STRING",
"value": "}"
"value": ")"
}
]
}
},
"loop": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "break_loop"
},
{
"type": "SYMBOL",
"name": "while_loop"
}
]
},
"while_loop": {
"while": {
"type": "SEQ",
"members": [
{
@ -782,7 +753,7 @@
}
]
},
"break_loop": {
"loop": {
"type": "SEQ",
"members": [
{
@ -823,6 +794,9 @@
]
},
"match": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
@ -833,10 +807,6 @@
"type": "SYMBOL",
"name": "expression"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT1",
"content": {
@ -859,10 +829,15 @@
},
{
"type": "STRING",
"value": "}"
"value": "catch"
},
{
"type": "SYMBOL",
"name": "statement"
}
]
}
}
},
"extras": [
{

View File

@ -8,11 +8,11 @@
"required": true,
"types": [
{
"type": "expression",
"type": "identifier",
"named": true
},
{
"type": "identifier",
"type": "statement",
"named": true
}
]
@ -23,49 +23,11 @@
"named": true,
"fields": {}
},
{
"type": "break_loop",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "statement",
"named": true
},
{
"type": "value",
"named": true
}
]
}
},
{
"type": "comment",
"named": true,
"fields": {}
},
{
"type": "control_flow",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "statement",
"named": true
}
]
}
},
{
"type": "expression",
"named": true,
@ -135,6 +97,25 @@
]
}
},
{
"type": "if_else",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "statement",
"named": true
}
]
}
},
{
"type": "insert",
"named": true,
@ -221,15 +202,15 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"multiple": true,
"required": false,
"types": [
{
"type": "break_loop",
"type": "statement",
"named": true
},
{
"type": "while_loop",
"type": "value",
"named": true
}
]
@ -344,11 +325,11 @@
"named": true
},
{
"type": "control_flow",
"type": "expression",
"named": true
},
{
"type": "expression",
"type": "if_else",
"named": true
},
{
@ -436,25 +417,6 @@
]
}
},
{
"type": "while_loop",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "statement",
"named": true
}
]
}
},
{
"type": "yield",
"named": true,
@ -486,6 +448,14 @@
"type": "&&",
"named": false
},
{
"type": "(",
"named": false
},
{
"type": ")",
"named": false
},
{
"type": "*",
"named": false
@ -554,6 +524,10 @@
"type": "break",
"named": false
},
{
"type": "catch",
"named": false
},
{
"type": "else",
"named": false

17987
src/parser.c

File diff suppressed because it is too large Load Diff