tree-sitter-mage
Version:
Mage grammar for tree-sitter
801 lines • 17.8 kB
JSON
{
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
"name": "mage",
"rules": {
"source_file": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ";"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "BLANK"
}
]
}
]
},
"source": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ";"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
}
]
},
"parenthesize": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ")"
}
]
},
"_expression": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "source"
},
{
"type": "SYMBOL",
"name": "parenthesize"
},
{
"type": "SYMBOL",
"name": "member"
},
{
"type": "SYMBOL",
"name": "call"
},
{
"type": "SYMBOL",
"name": "multiplicative"
},
{
"type": "SYMBOL",
"name": "additive"
},
{
"type": "SYMBOL",
"name": "comparison"
},
{
"type": "SYMBOL",
"name": "logical"
},
{
"type": "SYMBOL",
"name": "assign"
},
{
"type": "SYMBOL",
"name": "_number"
},
{
"type": "SYMBOL",
"name": "_string"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
"member": {
"type": "PREC_LEFT",
"value": 7,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_extract"
},
"named": true,
"value": "extract"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"operator_extract": {
"type": "STRING",
"value": "."
},
"multiplicative": {
"type": "PREC_LEFT",
"value": 6,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_multiply"
},
"named": true,
"value": "multiply"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_divide"
},
"named": true,
"value": "divide"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_modulo"
},
"named": true,
"value": "modulo"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"operator_multiply": {
"type": "STRING",
"value": "*"
},
"operator_divide": {
"type": "STRING",
"value": "/"
},
"operator_modulo": {
"type": "STRING",
"value": "%"
},
"additive": {
"type": "PREC_LEFT",
"value": 5,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_add"
},
"named": true,
"value": "add"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_subtract"
},
"named": true,
"value": "subtract"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"operator_add": {
"type": "STRING",
"value": "+"
},
"operator_subtract": {
"type": "STRING",
"value": "-"
},
"comparison": {
"type": "PREC_LEFT",
"value": 4,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_equal"
},
"named": true,
"value": "equal"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_not_equal"
},
"named": true,
"value": "not_equal"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_less_than"
},
"named": true,
"value": "less_than"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_greater_than"
},
"named": true,
"value": "greater_than"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_less_equal"
},
"named": true,
"value": "less_equal"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_greater_equal"
},
"named": true,
"value": "greater_equal"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"operator_equal": {
"type": "STRING",
"value": "=="
},
"operator_not_equal": {
"type": "STRING",
"value": "!="
},
"operator_less_than": {
"type": "STRING",
"value": "<"
},
"operator_greater_than": {
"type": "STRING",
"value": ">"
},
"operator_less_equal": {
"type": "STRING",
"value": "<="
},
"operator_greater_equal": {
"type": "STRING",
"value": ">="
},
"logical": {
"type": "CHOICE",
"members": [
{
"type": "PREC_LEFT",
"value": 3,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_and"
},
"named": true,
"value": "and"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
{
"type": "PREC_LEFT",
"value": 2,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_or"
},
"named": true,
"value": "or"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
}
]
},
"operator_and": {
"type": "STRING",
"value": "&&"
},
"operator_or": {
"type": "STRING",
"value": "||"
},
"call": {
"type": "PREC_LEFT",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_pipe"
},
"named": true,
"value": "pipe"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"operator_pipe": {
"type": "STRING",
"value": "=>"
},
"assign": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_constant"
},
"named": true,
"value": "constant"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_variable"
},
"named": true,
"value": "variable"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"operator_constant": {
"type": "STRING",
"value": ":"
},
"operator_variable": {
"type": "STRING",
"value": "="
},
"_number": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "number_binary"
},
"named": true,
"value": "binary"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "number_octal"
},
"named": true,
"value": "octal"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "number_decimal"
},
"named": true,
"value": "decimal"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "number_hex"
},
"named": true,
"value": "hex"
}
]
},
"number_binary": {
"type": "PATTERN",
"value": "0[Bb][0-1]+"
},
"number_octal": {
"type": "PATTERN",
"value": "0[Oo][0-7]+"
},
"number_decimal": {
"type": "PATTERN",
"value": "0[Dd][0-9]+"
},
"number_hex": {
"type": "PATTERN",
"value": "0[Xx][0-9A-Fa-f]+"
},
"string_escape": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^xu0-7]"
},
{
"type": "PATTERN",
"value": "[0-7]{1,3}"
},
{
"type": "PATTERN",
"value": "x[0-9a-fA-F]{2}"
},
{
"type": "PATTERN",
"value": "u[0-9a-fA-F]{4}"
},
{
"type": "PATTERN",
"value": "u\\{[0-9a-fA-F]+\\}"
},
{
"type": "PATTERN",
"value": "[\\r?][\\n\\u2028\\u2029]"
}
]
}
]
}
},
"string_single_quoted_unescaped_raw": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[^'\\\\\\r\\n]+"
}
}
},
"string_double_quoted_unescaped_raw": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[^\"\\\\\\r\\n]+"
}
}
},
"string_single_quoted": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "string_single_quoted_unescaped_raw"
},
"named": true,
"value": "raw"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "string_escape"
},
"named": true,
"value": "escape"
}
]
}
},
{
"type": "STRING",
"value": "'"
}
]
},
"string_double_quoted": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "string_double_quoted_unescaped_raw"
},
"named": true,
"value": "raw"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "string_escape"
},
"named": true,
"value": "escape"
}
]
}
},
{
"type": "STRING",
"value": "\""
}
]
},
"_string": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "string_single_quoted"
},
"named": true,
"value": "single_quoted"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "string_double_quoted"
},
"named": true,
"value": "double_quoted"
}
]
},
"identifier": {
"type": "PATTERN",
"value": "\\w+"
}
},
"extras": [
{
"type": "PATTERN",
"value": "\\s"
}
],
"conflicts": [],
"precedences": [],
"externals": [],
"inline": [],
"supertypes": [],
"reserved": {}
}