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('#', /.*/),