Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: line compiler directive #71

Merged
merged 8 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module.exports = grammar({
$._triple_quoted_content,
$.block_comment_content,
$._inside_string_marker,
$._newline_not_aligned,

$._error_sentinel, // unused token to detect parser errors in external parser.
],
Expand Down Expand Up @@ -177,9 +178,9 @@ module.exports = grammar({
// Make sure to parse a module node before a sequential expression
// NOTE: This removes all sequential expressions from module bodies
PREC.SEQ_EXPR + 1,
seq(alias($._newline, ";"), $._module_elem)
)
)
seq(alias($._newline, ";"), $._module_elem),
),
),
),

import_decl: ($) => seq("open", $.long_identifier),
Expand Down Expand Up @@ -383,7 +384,9 @@ module.exports = grammar({
list_pattern: ($) => seq("[", optional($._list_pattern_content), "]"),
array_pattern: ($) => seq("[|", optional($._list_pattern_content), "|]"),
record_pattern: ($) =>
prec.left(seq("{", $.field_pattern, repeat(seq(";", $.field_pattern)), "}")),
prec.left(
seq("{", $.field_pattern, repeat(seq(";", $.field_pattern)), "}"),
),

identifier_pattern: ($) =>
prec.left(
Expand Down Expand Up @@ -1602,7 +1605,7 @@ module.exports = grammar({

bool: (_) => token(choice("true", "false")),

unit: (_) => "()",
unit: (_) => token(prec(100000, "()")),

const: ($) =>
choice(
Expand Down Expand Up @@ -1760,9 +1763,13 @@ module.exports = grammar({
compiler_directive_decl: ($) =>
prec(
100000,
seq(
choice(seq("#nowarn", alias($._string_literal, $.string)), "#light"),
/\n/,
choice(
seq(
"#nowarn",
alias($._string_literal, $.string),
$._newline_not_aligned,
),
"#light",
),
),

Expand All @@ -1771,10 +1778,10 @@ module.exports = grammar({

preproc_line: ($) =>
seq(
alias(/#(line)? /, "#line"),
alias(/#(line)?/, "#line"),
$.int,
optional(choice(alias($._string_literal, $.string), $.verbatim_string)),
/\n/,
$._newline_not_aligned,
),

...preprocIf("", ($) => $._module_elem),
Expand Down Expand Up @@ -1836,7 +1843,7 @@ function preprocIf(suffix, content, precedence = 0) {
seq(
"#if",
field("condition", $.identifier),
/\n/,
$._newline_not_aligned,
content($),
field("alternative", optional(alternativeBlock($))),
"#endif",
Expand Down
72 changes: 39 additions & 33 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading