Skip to content

Commit

Permalink
chore: rename escapes
Browse files Browse the repository at this point in the history
Trevor: applied query fixes
  • Loading branch information
amaanq authored and tgross35 committed Feb 18, 2024
1 parent 5a1e57b commit ece99ae
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 40 deletions.
18 changes: 15 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check

const ESCAPE_SEQUENCE = token(/\\[nrt"\\]/);

/** Comma separated list with at least one item */
function comma_sep1(item) {
return seq(item, repeat(seq(",", item)));
Expand Down Expand Up @@ -314,10 +316,20 @@ module.exports = grammar({
),

_raw_string_indented: (_) => seq("'''", repeat(/./), "'''"),
_string: ($) => seq('"', repeat(choice($.string_escape, /[^\\"]+/)), '"'),
_string: ($) =>
seq(
'"',
repeat(choice($.escape_sequence, /[^\\"]+/)),
'"',
),
_string_indented: ($) =>
seq('"""', repeat(choice($.string_escape, /[^\\"]+/)), '"""'),
string_escape: (_) => /\\[nrt"\\]/,
seq(
'"""',
repeat(choice($.escape_sequence, /[^\\"]+/)),
'"""',
),

escape_sequence: (_) => ESCAPE_SEQUENCE,

_backticked: (_) => seq("`", repeat(/./), "`"),
_indented_backticked: (_) => seq("```", repeat(/./), "```"),
Expand Down
2 changes: 1 addition & 1 deletion queries-src/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
(dependency_expression recipe: (identifier) @function)

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

(comment) @comment.line
Expand Down
2 changes: 1 addition & 1 deletion queries/just/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
(dependency_expression recipe: (identifier) @function)

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

(comment) @comment
Expand Down
14 changes: 9 additions & 5 deletions src/grammar.json

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

12 changes: 6 additions & 6 deletions src/node-types.json

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

40 changes: 20 additions & 20 deletions src/parser.c

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

8 changes: 4 additions & 4 deletions test/corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ baz := "a\"\t"
(expression
(value
(string_literal
(string_escape)
(string_escape))))
(escape_sequence)
(escape_sequence))))
(eol)))
(item
(eol)))
Expand Down Expand Up @@ -175,8 +175,8 @@ def \"
(expression
(value
(string_literal
(string_escape)
(string_escape))))
(escape_sequence)
(escape_sequence))))
(eol)))
(item
(eol)))
Expand Down

0 comments on commit ece99ae

Please sign in to comment.