Add string literals
Once again, taking the rules more or less straight from tree-sitter-go.
This commit is contained in:
parent
57b38c01c0
commit
f548b1d5ad
5 changed files with 712 additions and 181 deletions
34
grammar.js
34
grammar.js
|
|
@ -31,6 +31,7 @@ module.exports = grammar({
|
|||
// Literals
|
||||
$.identifier,
|
||||
$.integer_literal,
|
||||
$._string_literal,
|
||||
),
|
||||
|
||||
// The Blueprint scanner makes use of Go's lexer, so copy their rule
|
||||
|
|
@ -38,6 +39,39 @@ module.exports = grammar({
|
|||
|
||||
integer_literal: (_) => seq(optional("-"), /[0-9]+/),
|
||||
|
||||
// The Blueprint scanner makes use of Go's lexer, so copy their rule
|
||||
_string_literal: ($) => choice(
|
||||
$.raw_string_literal,
|
||||
$.interpreted_string_literal,
|
||||
),
|
||||
|
||||
raw_string_literal: (_) => token(seq(
|
||||
"`",
|
||||
/[^`]+/,
|
||||
"`",
|
||||
)),
|
||||
|
||||
interpreted_string_literal: $ => seq(
|
||||
'"',
|
||||
repeat(choice(
|
||||
// Allow all characters without special meaning, disallow newlines
|
||||
/[^"\n\\]+/,
|
||||
$.escape_sequence,
|
||||
)),
|
||||
token.immediate('"'),
|
||||
),
|
||||
|
||||
escape_sequence: (_) => token.immediate(seq(
|
||||
'\\',
|
||||
choice(
|
||||
/[^xuU]/,
|
||||
/\d{2,3}/,
|
||||
/x[0-9a-fA-F]{2,}/,
|
||||
/u[0-9a-fA-F]{4}/,
|
||||
/U[0-9a-fA-F]{8}/,
|
||||
),
|
||||
)),
|
||||
|
||||
// }}}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue