Skip to content

Commit

Permalink
Adjust string rules to flatten parser tree to one node per string lit…
Browse files Browse the repository at this point in the history
…eral instance and enforce suffix _literal for all string literal rules
  • Loading branch information
nordlow committed Oct 1, 2024
1 parent 4227cc5 commit 5d5016b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = grammar({
_token_no_braces: ($) =>
choice(
$.identifier,
$._string_literal,
$._any_string_literal,
$.char_literal,
$.int_literal,
$.float_literal,
Expand Down Expand Up @@ -265,6 +265,7 @@ module.exports = grammar({
$.foreach_reverse,
$.function,
$.goto,
$.if,
$.import,
$.in,
$.interface,
Expand All @@ -286,6 +287,7 @@ module.exports = grammar({
$.ref,
$.return,
$.scope,
$.static,
$.struct,
$.super,
$.switch,
Expand Down Expand Up @@ -392,6 +394,7 @@ module.exports = grammar({
foreach_reverse: (_$) => token("foreach_reverse"),
function: (_$) => token("function"),
goto: (_$) => token("goto"),
if: (_$) => token("if"),
immutable: (_$) => token("immutable"),
import: (_$) => token("import"),
in: (_$) => token("in"),
Expand All @@ -416,6 +419,7 @@ module.exports = grammar({
return: (_$) => token("return"),
scope: (_$) => token("scope"),
shared: (_$) => token("shared"),
static: (_$) => token("static"),
struct: (_$) => token("struct"),
switch: (_$) => token("switch"),
synchronized: (_$) => token("synchronized"),
Expand Down Expand Up @@ -595,7 +599,7 @@ module.exports = grammar({
$.at_attribute,
$.type_ctor,
$.deprecated,
"static",
$.static,
$.extern,
$.abstract,
$.final,
Expand Down Expand Up @@ -858,7 +862,7 @@ module.exports = grammar({
$.protected,
$.public,
$.export,
"static",
$.static,
$.extern,
$.abstract,
$.final,
Expand Down Expand Up @@ -1034,7 +1038,7 @@ module.exports = grammar({
$.int_literal,
$.float_literal,
$.char_literal,
$._string_literal,
$._any_string_literal,
),

// also covers slicing (we renamed from slice,
Expand Down Expand Up @@ -1345,7 +1349,7 @@ module.exports = grammar({
),

// string literal stuff
_string_literal: ($) =>
_any_string_literal: ($) =>
choice(
$.regular_string_literal,
$.raw_string_literal,
Expand Down Expand Up @@ -1513,7 +1517,7 @@ module.exports = grammar({
if_statement: ($) =>
prec.right(
seq(
"if",
$.if,
$.if_condition,
$.consequence,
optional(seq($.else, $.alternative)),
Expand Down Expand Up @@ -1874,7 +1878,7 @@ module.exports = grammar({
),
seq(
optional($.shared),
"static",
$.static,
$.this,
"(",
")",
Expand All @@ -1887,7 +1891,7 @@ module.exports = grammar({
destructor: ($) =>
seq(
repeat($._attribute),
optional(seq(optional($.shared), "static")),
optional(seq(optional($.shared), $.static)),
"~",
$.this,
"(",
Expand Down Expand Up @@ -2243,7 +2247,7 @@ module.exports = grammar({
$.void,
$._builtin_type,
$.char_literal,
$._string_literal,
$._any_string_literal,
$.int_literal,
$.float_literal,
$.true,
Expand Down Expand Up @@ -2308,7 +2312,7 @@ module.exports = grammar({
//
// Constraint
//
constraint: ($) => seq("if", "(", $.expression, ")"),
constraint: ($) => seq($.if, "(", $.expression, ")"),

/**************************************************
*
Expand Down Expand Up @@ -2425,14 +2429,14 @@ module.exports = grammar({
debug_specification: ($) =>
seq($.debug, "=", choice($.int_literal, $.identifier), ";"),

static_if_condition: ($) => seq("static", "if", "(", $.expression, ")"),
static_if_condition: ($) => seq($.static, $.if, "(", $.expression, ")"),

static_foreach_statement: ($) => seq("static", $.foreach_statement),
static_foreach_statement: ($) => seq($.static, $.foreach_statement),

static_foreach_declaration: ($) =>
choice(
seq(
"static",
$.static,
$._foreach,
"(",
commaSep1($.foreach_type),
Expand All @@ -2444,7 +2448,7 @@ module.exports = grammar({
"}",
),
seq(
"static",
$.static,
$._foreach,
"(",
commaSep1($.foreach_type),
Expand All @@ -2454,7 +2458,7 @@ module.exports = grammar({
$._declaration,
),
seq(
"static",
$.static,
$._foreach,
"(",
$.foreach_type,
Expand All @@ -2468,7 +2472,7 @@ module.exports = grammar({
"}",
),
seq(
"static",
$.static,
$._foreach,
"(",
$.foreach_type,
Expand All @@ -2481,7 +2485,7 @@ module.exports = grammar({
),
),

static_assert: ($) => seq("static", $.assert_expression, ";"),
static_assert: ($) => seq($.static, $.assert_expression, ";"),

/**************************************************
*
Expand Down

0 comments on commit 5d5016b

Please sign in to comment.