fix: increase precedence of escape chars

pull/625/head^2
Nikolaj Sidorenco 2024-04-18 19:34:02 +07:00
parent 9b6903a9f4
commit 385792d371
No known key found for this signature in database
5 changed files with 14577 additions and 14564 deletions

@ -1,10 +1 @@
[<AutoOpen>]
module Constants =
[<Literal>]
let A = "A"
[<Literal>]
let B = "B"
module Mod =
let x = A + B
let x = "\""

@ -217,7 +217,7 @@ module.exports = grammar({
choice(
prec(PREC.LET_DECL, $.function_or_value_defn),
prec(PREC.DO_DECL, $.do),
)
),
),
do: $ => prec(PREC.DO_EXPR,
@ -1561,8 +1561,8 @@ module.exports = grammar({
//
// Constants (BEGIN)
//
_escape_char: _ => token.immediate(/\\["\'ntbrafv]/),
_non_escape_char: _ => token.immediate(/\\[^"\'ntbrafv]/),
_escape_char: _ => token.immediate(prec(100, /\\["\'ntbrafv]/)),
_non_escape_char: _ => token.immediate(prec(100, /\\[^"\'ntbrafv]/)),
// using \u0008 to model \b
_simple_char_char: _ => token.immediate(/[^\n\t\r\u0008\a\f\v'\\]/),
_hex_digit_imm: _ => token.immediate(/[0-9a-fA-F]/),
@ -1610,7 +1610,7 @@ module.exports = grammar({
seq('\\', $._string_elem),
),
char: $ => seq('\'', $._char_char, token.immediate('\'')),
string: $ => seq('"', repeat($._string_char), token.immediate('"')),
string: $ => seq('"', repeat($._string_char), '"'),
_verbatim_string_char: $ => choice(
$._simple_string_char,
$._non_escape_char,

23
src/grammar.json generated

@ -6261,15 +6261,23 @@
"_escape_char": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\\\[\"\\'ntbrafv]"
"type": "PREC",
"value": 100,
"content": {
"type": "PATTERN",
"value": "\\\\[\"\\'ntbrafv]"
}
}
},
"_non_escape_char": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\\\[^\"\\'ntbrafv]"
"type": "PREC",
"value": 100,
"content": {
"type": "PATTERN",
"value": "\\\\[^\"\\'ntbrafv]"
}
}
},
"_simple_char_char": {
@ -6507,11 +6515,8 @@
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "\""
}
"type": "STRING",
"value": "\""
}
]
},

29081
src/parser.c generated

File diff suppressed because it is too large Load Diff

@ -422,3 +422,21 @@ do
(const
(decimal
(int)))))))))))
================================================================================
string with escaped quote
================================================================================
let str = "name: \"name\""
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(string)))))