Change syntax

This commit is contained in:
Jeff 2023-09-30 21:12:35 -04:00
parent 14c294a1db
commit 69fda534a3
8 changed files with 9201 additions and 6770 deletions

@ -1 +1 @@
Subproject commit 327a2d044b4416ffe27d70c6c3485e6dea2b573c
Subproject commit f596c6b5811cabc9b1b8ef87b9c6ce627b567c93

View File

@ -20,6 +20,24 @@ function { "Hiya" }
(value
(string))))))))))))
==================
Function Call
==================
foobar <"Hiya">
---
(root
(item
(statement
(open_statement
(expression
(function_call
(identifier)
(value
(string))))))))
==================
Complex Function
==================
@ -43,7 +61,7 @@ function <message, number> {
(statement
(open_statement
(expression
(tool))))
(identifier))))
(statement
(open_statement
(expression
@ -51,7 +69,7 @@ function <message, number> {
(statement
(open_statement
(expression
(tool))))
(identifier))))
(statement
(open_statement
(expression

49
corpus/operators.txt Normal file
View File

@ -0,0 +1,49 @@
==================
Simple Equality
==================
1 == 1
---
(root
(item
(statement
(open_statement
(expression
(operation
(expression
(value
(integer)))
(operator)
(expression
(value
(integer)))))))))
==================
Complex Equality
==================
(1 + 1) == 2
---
(root
(item
(statement
(open_statement
(expression
(operation
(expression
(operation
(expression
(value
(integer)))
(operator)
(expression
(value
(integer)))))
(operator)
(expression
(value
(integer)))))))))

View File

@ -7,7 +7,6 @@ Simple Statements
x
---
(root
(item
(statement

View File

@ -11,7 +11,7 @@ module.exports = grammar({
$.statement,
),
comment: $ => prec.left(seq(token('#'), /.*/)),
comment: $ => seq(token('#'), /.*/),
statement: $ => prec.right(choice(
$.open_statement,
@ -23,18 +23,25 @@ module.exports = grammar({
yield_statement: $ => seq($.open_statement, '->', $.open_statement),
expression: $ => choice(
$._expression_kind,
seq('(', $._expression_kind, ')')
),
_expression_kind: $ => prec.right(choice(
$.value,
$.identifier,
$.operation,
$.control_flow,
$.tool,
$.select,
$.insert,
),
$.function_call,
$.assignment,
$.math,
$.logic,
)),
identifier: $ => /[a-z|_|.]+[0-9]?/,
value: $ => choice(
value: $ => prec.left(1, choice(
$.integer,
$.float,
$.string,
@ -44,13 +51,17 @@ module.exports = grammar({
$.function,
$.table,
$.map,
),
)),
float: $ => /\d+\.\d*/,
integer: $ => /\d+/,
string: $ => /("|'|`)(.*?)("|'|`)/,
string: $ => choice(
/'([^"]+)'/,
/"([^"]+)"/,
/`([^"]+)`/
),
empty: $ => '()',
@ -88,25 +99,37 @@ module.exports = grammar({
'}',
),
operator: $ => choice(
'=',
math: $ => prec.right(seq(
$.expression,
$.math_operator,
$.expression,
)),
math_operator: $ => choice(
'+',
'-',
'*',
'/',
'%',
),
logic: $ => prec.right(seq(
$.expression,
$.logic_operator,
$.expression,
)),
logic_operator: $ => choice(
'==',
'+=',
'-=',
'&&',
'||',
'and',
'or',
),
operation: $ => prec.right(seq(
$.expression,
$.operator,
assignment: $ => prec.right(seq(
$.identifier,
choice("=", "+=", "-="),
$.expression,
)),
@ -138,8 +161,13 @@ module.exports = grammar({
optional(seq('else', $.statement))
)),
tool: $ => choice(
"output",
),
function_call: $ => prec.right(seq(
$.identifier,
'<',
repeat(
choice($.identifier, $.value),
),
'>',
)),
}
});

View File

@ -23,24 +23,20 @@
]
},
"comment": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "TOKEN",
"content": {
"type": "STRING",
"value": "#"
}
},
{
"type": "PATTERN",
"value": ".*"
"type": "SEQ",
"members": [
{
"type": "TOKEN",
"content": {
"type": "STRING",
"value": "#"
}
]
}
},
{
"type": "PATTERN",
"value": ".*"
}
]
},
"statement": {
"type": "PREC_RIGHT",
@ -89,78 +85,120 @@
"members": [
{
"type": "SYMBOL",
"name": "value"
"name": "_expression_kind"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "operation"
},
{
"type": "SYMBOL",
"name": "control_flow"
},
{
"type": "SYMBOL",
"name": "tool"
},
{
"type": "SYMBOL",
"name": "select"
},
{
"type": "SYMBOL",
"name": "insert"
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_expression_kind"
},
{
"type": "STRING",
"value": ")"
}
]
}
]
},
"_expression_kind": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "value"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "control_flow"
},
{
"type": "SYMBOL",
"name": "select"
},
{
"type": "SYMBOL",
"name": "insert"
},
{
"type": "SYMBOL",
"name": "function_call"
},
{
"type": "SYMBOL",
"name": "assignment"
},
{
"type": "SYMBOL",
"name": "math"
},
{
"type": "SYMBOL",
"name": "logic"
}
]
}
},
"identifier": {
"type": "PATTERN",
"value": "[a-z|_|.]+[0-9]?"
},
"value": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "empty"
},
{
"type": "SYMBOL",
"name": "boolean"
},
{
"type": "SYMBOL",
"name": "function"
},
{
"type": "SYMBOL",
"name": "table"
},
{
"type": "SYMBOL",
"name": "map"
}
]
"type": "PREC_LEFT",
"value": 1,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "empty"
},
{
"type": "SYMBOL",
"name": "boolean"
},
{
"type": "SYMBOL",
"name": "function"
},
{
"type": "SYMBOL",
"name": "table"
},
{
"type": "SYMBOL",
"name": "map"
}
]
}
},
"float": {
"type": "PATTERN",
@ -171,8 +209,21 @@
"value": "\\d+"
},
"string": {
"type": "PATTERN",
"value": "(\"|'|`)(.*?)(\"|'|`)"
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "'([^\"]+)'"
},
{
"type": "PATTERN",
"value": "\"([^\"]+)\""
},
{
"type": "PATTERN",
"value": "`([^\"]+)`"
}
]
},
"empty": {
"type": "STRING",
@ -395,13 +446,30 @@
}
]
},
"operator": {
"math": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "math_operator"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
},
"math_operator": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": "+"
@ -421,19 +489,37 @@
{
"type": "STRING",
"value": "%"
},
}
]
},
"logic": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "logic_operator"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
},
"logic_operator": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "=="
},
{
"type": "STRING",
"value": "+="
},
{
"type": "STRING",
"value": "-="
},
{
"type": "STRING",
"value": "&&"
@ -452,7 +538,7 @@
}
]
},
"operation": {
"assignment": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
@ -460,11 +546,24 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "operator"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": "+="
},
{
"type": "STRING",
"value": "-="
}
]
},
{
"type": "SYMBOL",
@ -614,14 +713,42 @@
]
}
},
"tool": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "output"
}
]
"function_call": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "<"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "value"
}
]
}
},
{
"type": "STRING",
"value": ">"
}
]
}
}
},
"extras": [

View File

@ -1,4 +1,23 @@
[
{
"type": "assignment",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "boolean",
"named": true,
@ -36,10 +55,18 @@
"multiple": false,
"required": true,
"types": [
{
"type": "assignment",
"named": true
},
{
"type": "control_flow",
"named": true
},
{
"type": "function_call",
"named": true
},
{
"type": "identifier",
"named": true
@ -49,17 +76,17 @@
"named": true
},
{
"type": "operation",
"type": "logic",
"named": true
},
{
"type": "math",
"named": true
},
{
"type": "select",
"named": true
},
{
"type": "tool",
"named": true
},
{
"type": "value",
"named": true
@ -86,6 +113,25 @@
]
}
},
{
"type": "function_call",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "value",
"named": true
}
]
}
},
{
"type": "insert",
"named": true,
@ -143,6 +189,30 @@
]
}
},
{
"type": "logic",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "logic_operator",
"named": true
}
]
}
},
{
"type": "logic_operator",
"named": true,
"fields": {}
},
{
"type": "map",
"named": true,
@ -162,6 +232,30 @@
]
}
},
{
"type": "math",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "math_operator",
"named": true
}
]
}
},
{
"type": "math_operator",
"named": true,
"fields": {}
},
{
"type": "open_statement",
"named": true,
@ -177,30 +271,6 @@
]
}
},
{
"type": "operation",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "operator",
"named": true
}
]
}
},
{
"type": "operator",
"named": true,
"fields": {}
},
{
"type": "root",
"named": true,
@ -254,6 +324,11 @@
]
}
},
{
"type": "string",
"named": true,
"fields": {}
},
{
"type": "table",
"named": true,
@ -273,11 +348,6 @@
]
}
},
{
"type": "tool",
"named": true,
"fields": {}
},
{
"type": "value",
"named": true,
@ -352,6 +422,14 @@
"type": "&&",
"named": false
},
{
"type": "(",
"named": false
},
{
"type": ")",
"named": false
},
{
"type": "*",
"named": false
@ -464,18 +542,10 @@
"type": "or",
"named": false
},
{
"type": "output",
"named": false
},
{
"type": "select",
"named": false
},
{
"type": "string",
"named": true
},
{
"type": "table",
"named": false

15340
src/parser.c

File diff suppressed because it is too large Load Diff