improve highlighting

This commit is contained in:
Daniella / Tove 2024-11-15 21:01:47 +01:00
parent 02baa62702
commit e62088ee87
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
5 changed files with 2971 additions and 2784 deletions

View file

@ -6,6 +6,7 @@ module.exports = grammar({
_unspaced_statement: $ => seq( _unspaced_statement: $ => seq(
choice( choice(
$.string, $.string,
$.number,
$.function_definition, $.function_definition,
$.type_definition, $.type_definition,
$.with_expr, $.with_expr,
@ -16,7 +17,6 @@ module.exports = grammar({
$.use, $.use,
$.include, $.include,
$.def, $.def,
$.number,
$.call_expr, $.call_expr,
seq( seq(
repeat('&'), repeat('&'),
@ -41,7 +41,7 @@ module.exports = grammar({
repeat($._statement), repeat($._statement),
'}', '}',
), ),
identifier: $ => /[^ \n\r\t<>:;&{}"'\[\]]+/, identifier: $ => /[^ \n\r\t<>:;&{}"'\[\],]+/,
call: $ => choice( call: $ => choice(
seq( seq(
optional($.call), optional($.call),
@ -52,20 +52,20 @@ module.exports = grammar({
$.operation, $.operation,
$.identifier, $.identifier,
), ),
number: $ => /\d+(\.\d+)?/, number: $ => token(prec(10, /\d+(\.\d+)?/)),
string: $ => seq('"', repeat(choice(/\\./, /./)), '"'), string: $ => choice(
token(prec(10, seq('^', /[^ \n\r\t<>:;&{}"'\[\],]+/))),
seq('"', repeat(choice(/\\./, /./)), '"'),
),
call_expr: $ => seq('<', optional($._spacing), repeat($._statement), $._unspaced_statement, '>'), call_expr: $ => seq('<', optional($._spacing), repeat($._statement), $._unspaced_statement, '>'),
with_expr: $ => seq( with_expr: $ => seq(
'with', $._spacing, 'with', $._spacing,
repeat($.identifier), repeat(seq($.identifier, $._spacing)),
';', ';',
), ),
array: $ => seq('[', $._spacing, optional(repeat($._statement)), ']'), array: $ => seq('[', $._spacing, optional(repeat($._statement)), ']'),
operation: $ => choice(/[+\-*\/%&]/, "=>!", "=>?", "=>?!", "=>"), operation: $ => choice(/[+\-*\/%&]/, "=>!", "=>?", "=>?!", "=>"),
variable: $ => choice( set_variable: $ => seq('=', $.identifier),
seq('def', $._spacing, $.identifier),
seq('=', $.identifier),
),
type_definition: $ => seq( type_definition: $ => seq(
'construct', $._spacing, 'construct', $._spacing,
$.call, $._spacing, $.call, $._spacing,
@ -115,6 +115,7 @@ module.exports = grammar({
def: $ => seq( def: $ => seq(
'def', $._spacing, 'def', $._spacing,
$.identifier, $.identifier,
optional(repeat(seq(',', $._spacing, $.identifier)))
), ),
}, },
}); });

View file

@ -12,4 +12,7 @@
(number) @number (number) @number
(string) @string (string) @string
(call (call) @function (identifier) @property) (call (identifier) @function)
(call (call) @function (identifier) @property)
(def (identifier) @local.definition)
(with_expr (identifier) @local.definition)

View file

@ -24,6 +24,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "string" "name": "string"
}, },
{
"type": "SYMBOL",
"name": "number"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "function_definition" "name": "function_definition"
@ -64,10 +68,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "def" "name": "def"
}, },
{
"type": "SYMBOL",
"name": "number"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "call_expr" "name": "call_expr"
@ -272,7 +272,7 @@
}, },
"identifier": { "identifier": {
"type": "PATTERN", "type": "PATTERN",
"value": "[^ \\n\\r\\t<>:;&{}\"'\\[\\]]+" "value": "[^ \\n\\r\\t<>:;&{}\"'\\[\\],]+"
}, },
"call": { "call": {
"type": "CHOICE", "type": "CHOICE",
@ -328,35 +328,67 @@
] ]
}, },
"number": { "number": {
"type": "PATTERN", "type": "TOKEN",
"value": "\\d+(\\.\\d+)?" "content": {
"type": "PREC",
"value": 10,
"content": {
"type": "PATTERN",
"value": "\\d+(\\.\\d+)?"
}
}
}, },
"string": { "string": {
"type": "SEQ", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "STRING", "type": "TOKEN",
"value": "\""
},
{
"type": "REPEAT",
"content": { "content": {
"type": "CHOICE", "type": "PREC",
"members": [ "value": 10,
{ "content": {
"type": "PATTERN", "type": "SEQ",
"value": "\\\\." "members": [
}, {
{ "type": "STRING",
"type": "PATTERN", "value": "^"
"value": "." },
} {
] "type": "PATTERN",
"value": "[^ \\n\\r\\t<>:;&{}\"'\\[\\],]+"
}
]
}
} }
}, },
{ {
"type": "STRING", "type": "SEQ",
"value": "\"" "members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "\\\\."
},
{
"type": "PATTERN",
"value": "."
}
]
}
},
{
"type": "STRING",
"value": "\""
}
]
} }
] ]
}, },
@ -410,8 +442,17 @@
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL", "type": "SEQ",
"name": "identifier" "members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_spacing"
}
]
} }
}, },
{ {
@ -477,38 +518,16 @@
} }
] ]
}, },
"variable": { "set_variable": {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SEQ", "type": "STRING",
"members": [ "value": "="
{
"type": "STRING",
"value": "def"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}, },
{ {
"type": "SEQ", "type": "SYMBOL",
"members": [ "name": "identifier"
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
} }
] ]
}, },
@ -845,6 +864,34 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
},
{
"type": "BLANK"
}
]
} }
] ]
} }

View file

@ -314,7 +314,7 @@
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": false, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{ {
@ -658,6 +658,10 @@
"type": "&", "type": "&",
"named": false "named": false
}, },
{
"type": ",",
"named": false
},
{ {
"type": ":", "type": ":",
"named": false "named": false

File diff suppressed because it is too large Load diff