Skip to content

Commit

Permalink
tmp work
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 5, 2024
1 parent f3b88d9 commit a959c70
Show file tree
Hide file tree
Showing 9 changed files with 4,929 additions and 4,992 deletions.
63 changes: 29 additions & 34 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@ module.exports = grammar({
$._indent,
$._dedent,
$._newline,
$._string_start,
$._string_end,
$._raw_string_start,
$._raw_string_end,
$._command_start,
$._command_end,
$.string_start,
$.string_end,
$.string_body,
$.raw_string_start,
$.raw_string_end,
$.command_start,
$.command_end,
],
inline: (
$,
) => [
$._string,
$._string_indented,
$._raw_string_indented,
$._expression_braced,
$._expression_recurse,
],
Expand Down Expand Up @@ -99,15 +97,15 @@ module.exports = grammar({
export: ($) => seq("export", $.assignment),

// import : 'import' '?'? string?
import: ($) => seq("import", optional("?"), $.string),
import: ($) => seq("import", optional("?"), $._string),

// module : 'mod' '?'? string?
module: ($) =>
seq(
"mod",
optional("?"),
field("mod_name", $.identifier),
optional($.string),
optional($._string),
),

// setting : 'set' 'dotenv-load' boolean?
Expand All @@ -122,7 +120,7 @@ module.exports = grammar({
field(
"right",
optional(
seq(":=", choice($.boolean, $.string, array($.string))),
seq(":=", choice($.boolean, $._string, array($._string))),
),
),
$.eol,
Expand All @@ -133,7 +131,7 @@ module.exports = grammar({
":=",
field(
"right",
array($.string),
array($._string),
),
$.eol,
),
Expand Down Expand Up @@ -195,7 +193,7 @@ module.exports = grammar({
$.function_call,
$.external_command,
$.identifier,
$.string,
$._string,
seq("(", $.expression, ")"),
),
),
Expand All @@ -208,9 +206,6 @@ module.exports = grammar({
")",
),

external_command: ($) =>
choice(seq($._backticked), seq($._indented_backticked)),

// sequence : expression ',' sequence
// | expression ','?
sequence: ($) => comma_sep1($.expression),
Expand Down Expand Up @@ -302,9 +297,6 @@ module.exports = grammar({
// `# ...` comment
comment: ($) => seq(/#.*/, $._newline),

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

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

Expand All @@ -314,23 +306,26 @@ module.exports = grammar({
// | INDENTED_STRING
// | RAW_STRING
// | INDENTED_RAW_STRING
string: ($) =>
choice(
$._string_indented,
$._raw_string_indented,
$._string,
// _raw_string, can't be written as a separate inline for osm reason
/'[^']*'/,
_string: ($) => choice($.raw_string_literal, $.string_literal),

string_literal: ($) =>
seq(
$.string_start,
repeat(choice($.string_body, $.escape_sequence)),
$.string_end,
),

_raw_string_indented: (_) => seq("'''", repeat(/./), "'''"),
_string: ($) => seq('"', repeat(choice($.string_escape, /[^\\"]+/)), '"'),
_string_indented: ($) =>
seq('"""', repeat(choice($.string_escape, /[^\\"]+/)), '"""'),
string_escape: (_) => ESCAPE_SEQUENCE,
raw_string_literal: ($) =>
seq($.raw_string_start, repeat($.string_body), $.raw_string_end),

external_command: ($) =>
seq(
$.command_start,
repeat(choice($.string_body, $.interpolation)),
$.command_end,
),

_backticked: (_) => seq("`", repeat(/./), "`"),
_indented_backticked: (_) => seq("```", repeat(/./), "```"),
escape_sequence: (_) => ESCAPE_SEQUENCE,

text: (_) => /.+/, //recipe TEXT, only matches in a recipe body
// text: (_) => /\S+/, //recipe TEXT, only matches in a recipe body
Expand Down
7 changes: 5 additions & 2 deletions queries-src/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@
(dependency_expression recipe: (identifier) @function)

; handle escape sequences
(string (string_escape) @constant.character.escape)
(string) @string
(string_literal (escape_sequence) @constant.character.escape)
[
(string_literal)
(raw_string_literal)
] @string

(comment) @comment.line

Expand Down
7 changes: 5 additions & 2 deletions queries/just/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@
(dependency_expression recipe: (identifier) @function)

; handle escape sequences
(string (string_escape) @string.escape)
(string) @string
(string_literal (escape_sequence) @string.escape)
[
(string_literal)
(raw_string_literal)
] @string

(comment) @comment

Expand Down
Loading

0 comments on commit a959c70

Please sign in to comment.