feat: add base parser

Signed-off-by: kjuulh <contact@kjuulh.io>

feat: with basic assignment

Signed-off-by: kjuulh <contact@kjuulh.io>

feat: remove target

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-07-03 20:16:09 +02:00
commit 67e3f73ab4
18 changed files with 4113 additions and 0 deletions

328
src/grammar.json Normal file
View File

@@ -0,0 +1,328 @@
{
"name": "rhai",
"word": "identifier",
"rules": {
"source_file": {
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
"_statement": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "expression_statement"
},
{
"type": "SYMBOL",
"name": "_declaration_statement"
}
]
},
"expression_statement": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ";"
}
]
}
]
},
"_declaration_statement": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "let_declaration"
}
]
},
"let_declaration": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "let"
},
{
"type": "FIELD",
"name": "pattern",
"content": {
"type": "SYMBOL",
"name": "_pattern"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ";"
}
]
},
"_pattern": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_literal_pattern"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "_"
}
]
},
"_expression": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "assignment_expression"
},
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
]
},
"assignment_expression": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "left",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "right",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
}
]
}
},
"_literal": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string_literal"
},
{
"type": "SYMBOL",
"name": "raw_string_literal"
},
{
"type": "SYMBOL",
"name": "integer_literal"
}
]
},
"_literal_pattern": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string_literal"
},
{
"type": "SYMBOL",
"name": "raw_string_literal"
},
{
"type": "SYMBOL",
"name": "integer_literal"
}
]
},
"integer_literal": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[0-9][0-9_]*"
}
]
}
]
}
},
"string_literal": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "b?\""
},
"named": false,
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "escape_sequence"
},
{
"type": "SYMBOL",
"name": "_string_content"
}
]
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "\""
}
}
]
},
"escape_sequence": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^xu]"
},
{
"type": "PATTERN",
"value": "u[0-9a-fA-F]{4}"
},
{
"type": "PATTERN",
"value": "u{[0-9a-fA-F]+}"
},
{
"type": "PATTERN",
"value": "x[0-9a-fA-F]{2}"
}
]
}
]
}
},
"identifier": {
"type": "PATTERN",
"value": "(r#)?[_\\p{XID_Start}][_\\p{XID_Continue}]*"
}
},
"extras": [
{
"type": "PATTERN",
"value": "\\s"
}
],
"conflicts": [],
"precedences": [],
"externals": [
{
"type": "SYMBOL",
"name": "_string_content"
},
{
"type": "SYMBOL",
"name": "raw_string_literal"
},
{
"type": "SYMBOL",
"name": "float_literal"
},
{
"type": "SYMBOL",
"name": "block_comment"
}
],
"inline": [
"_declaration_statement"
],
"supertypes": [
"_expression",
"_literal",
"_literal_pattern",
"_declaration_statement",
"_pattern"
]
}