This commit is contained in:
mhoffm
2021-06-08 00:45:23 +02:00
parent 06cff26e7a
commit c4bfe1228f
5 changed files with 687 additions and 569 deletions

View File

@@ -1,5 +1,4 @@
const
//TODO figure out how to subtact regex sets
unicodeLetter = /\p{L}/
unicodePunctuation = /\p{Pc}/
unicodeDigit = /[0-9]/
@@ -41,7 +40,7 @@ module.exports = grammar({
'}',
),
// TODO: not to spec, but maybe good enough
// TODO: not to spec but good enough for now
identifier: $ => token(seq(
unicodeLetter,
repeat(choice(unicodeLetter, unicodeDigit, unicodePunctuation))
@@ -70,13 +69,18 @@ module.exports = grammar({
literal_value: $ => choice(
$.numeric_lit,
$.string_lit,
'true',
'false',
'null',
$.bool_lit,
$.null_lit,
),
numeric_lit: $ => /[0-9]+(\.[0-9]+([eE][-+]?[0-9]+)?)?/,
string_lit: $ => seq('"', repeat(/./), '"'),
bool_lit: $ => choice('true', 'false'),
null_lit: $ => 'null',
collection_value: $ => choice(
$.tuple,
$.object,
@@ -108,17 +112,6 @@ module.exports = grammar({
variable_expr: $ => $.identifier,
// TODO: template expressions
//template_expr: $ => choice(
//$.quoted_template,
//$.heredoc_template,
//),
//quoted_template: $ => seq('"', /\w+/, '"'),
//heredoc_template: $ => '',
// TODO: string_literals are special template literals
string_lit: $ => seq('"', /\w+/, '"'),
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
comment: $ => token(choice(
seq('#', /.*/),

View File

@@ -1,6 +1,9 @@
; highlights.scm
(string_lit) @keyword
(identifier) @type
(identifier) @string.special
(string_lit) @string
(numeric_lit) @number
(bool_lit) @boolean
(null_lit) @null
(comment) @comment

View File

@@ -175,16 +175,12 @@
"name": "string_lit"
},
{
"type": "STRING",
"value": "true"
"type": "SYMBOL",
"name": "bool_lit"
},
{
"type": "STRING",
"value": "false"
},
{
"type": "STRING",
"value": "null"
"type": "SYMBOL",
"name": "null_lit"
}
]
},
@@ -192,6 +188,43 @@
"type": "PATTERN",
"value": "[0-9]+(\\.[0-9]+([eE][-+]?[0-9]+)?)?"
},
"string_lit": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "."
}
},
{
"type": "STRING",
"value": "\""
}
]
},
"bool_lit": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "true"
},
{
"type": "STRING",
"value": "false"
}
]
},
"null_lit": {
"type": "STRING",
"value": "null"
},
"collection_value": {
"type": "CHOICE",
"members": [
@@ -336,23 +369,6 @@
"type": "SYMBOL",
"name": "identifier"
},
"string_lit": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "PATTERN",
"value": "\\w+"
},
{
"type": "STRING",
"value": "\""
}
]
},
"comment": {
"type": "TOKEN",
"content": {

View File

@@ -60,6 +60,11 @@
]
}
},
{
"type": "bool_lit",
"named": true,
"fields": {}
},
{
"type": "collection_value",
"named": true,
@@ -142,8 +147,16 @@
"fields": {},
"children": {
"multiple": false,
"required": false,
"required": true,
"types": [
{
"type": "bool_lit",
"named": true
},
{
"type": "null_lit",
"named": true
},
{
"type": "numeric_lit",
"named": true
@@ -269,8 +282,8 @@
"named": true
},
{
"type": "null",
"named": false
"type": "null_lit",
"named": true
},
{
"type": "numeric_lit",

File diff suppressed because it is too large Load Diff