Skip to content

Commit

Permalink
fix: rewrite text, eol, and comment
Browse files Browse the repository at this point in the history
Trevor: resolve conflicts, reformat C with existing style. This change
includes a new XFAIL test, but fixes several others.
  • Loading branch information
amaanq authored and tgross35 committed Feb 19, 2024
1 parent 7e2e8c5 commit 75a5535
Show file tree
Hide file tree
Showing 7 changed files with 5,011 additions and 4,567 deletions.
63 changes: 33 additions & 30 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ function array(item) {

module.exports = grammar({
name: "just",
externals: ($) => [$._indent, $._dedent, $._newline],

externals: ($) => [
$._indent,
$._dedent,
$._newline,
$.text,
$.error_recovery,
],

extras: ($) => [$.comment, /\s/],

inline: ($) => [
$._string,
$._string_indented,
Expand All @@ -56,7 +66,6 @@ module.exports = grammar({
// | import
// | module
// | setting
// | eol
item: ($) =>
choice(
$.recipe,
Expand All @@ -66,13 +75,8 @@ module.exports = grammar({
$.import,
$.module,
$.setting,
$._eol,
),

// eol : NEWLINE
// | COMMENT NEWLINE
_eol: ($) => choice($._newline, $.comment),

// alias : 'alias' NAME ':=' NAME
alias: ($) =>
seq(
Expand All @@ -81,14 +85,13 @@ module.exports = grammar({
":=",
field("right", $.identifier),
),

// assignment : NAME ':=' expression eol
// assignment : NAME ':=' expression _eol
assignment: ($) =>
seq(
field("left", $.identifier),
":=",
field("right", $.expression),
$._eol,
$._newline,
),

// export : 'export' assignment
Expand Down Expand Up @@ -124,14 +127,14 @@ module.exports = grammar({
),
),
),
$._eol,
$._newline,
),
seq(
"set",
"shell",
":=",
field("right", array($.string_literal)),
$._eol,
$._newline,
),
),

Expand Down Expand Up @@ -216,7 +219,7 @@ module.exports = grammar({
"[",
field("contents", comma_sep1(field("attr_item", $.identifier))),
"]",
$._eol,
$._newline,
),

// A complete recipe
Expand All @@ -232,7 +235,7 @@ module.exports = grammar({
recipe_header: ($) =>
seq(
optional("@"),
field("recipe_name", $.identifier),
field("name", $.identifier),
optional($.parameters),
":",
optional($.dependencies),
Expand Down Expand Up @@ -276,32 +279,27 @@ module.exports = grammar({
recipe_body: ($) =>
seq(
$._indent,
field("contents", seq(optional($.shebang), repeat($.recipe_line))),
field(
"content",
seq(
optional($.shebang),
repeat(seq($.recipe_line, $._newline)),
$._newline,
),
),
$._dedent,
),

recipe_line: ($) =>
seq(
optional($.recipe_line_prefix),
repeat(choice($.text, $.interpolation)),
$._newline,
repeat1(choice($.text, $.interpolation)),
),

recipe_line_prefix: (_) => choice("@-", "-@", "@", "-"),

shebang: ($) => seq(/\s*#!.*/, $._newline),

// `# ...` comment
comment: ($) => seq(/#.*/, $._newline),

// notinterpolation: ($) => /[^{][^{]\S*/,
notinterpolation: (_) => /[^\s{][^\s{]\S*/,

// interpolation : '{{' expression '}}'
interpolation: ($) => seq("{{", $.expression, "}}"),

identifier: (_) => /[a-zA-Z_][a-zA-Z0-9_-]*/,

// string : STRING
// | INDENTED_STRING
// | RAW_STRING
Expand All @@ -325,7 +323,12 @@ module.exports = grammar({
_backticked: (_) => seq("`", repeat(/./), "`"),
_indented_backticked: (_) => seq("```", repeat(/./), "```"),

text: (_) => /.+/, // recipe TEXT, only matches in a recipe body
// text: (_) => /\S+/, // recipe TEXT, only matches in a recipe body
// interpolation : '{{' expression '}}'
interpolation: ($) => seq("{{", $.expression, "}}"),

identifier: (_) => /[a-zA-Z_][a-zA-Z0-9_-]*/,

// `# ...` comment
comment: (_) => token(prec(-1, /#.*/)),
},
});
135 changes: 65 additions & 70 deletions src/grammar.json

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

Loading

0 comments on commit 75a5535

Please sign in to comment.