Skip to content

Commit

Permalink
fix: update escape sequences & related queries (Wilfred#18)
Browse files Browse the repository at this point in the history
* fix: Make Tree-sitter queries conform to standard

* feat: escape_sequence in highlighting queries of Helix and Neovim

* fix: Narrow the available escape options to match Ohm grammar
  • Loading branch information
novusnota authored Apr 6, 2024
1 parent bcb2ae5 commit 776796a
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 29 deletions.
5 changes: 5 additions & 0 deletions editor_queries/helix/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
(constant
name: (identifier) @constant)

; constant.character.escape
; -------------------------

(escape_sequence) @constant.character.escape

; constant.numeric.integer
; ------------------------

Expand Down
5 changes: 5 additions & 0 deletions editor_queries/neovim/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@

(string) @string

; string.escape
; -------------

(escape_sequence) @string.escape

; string.special.path
; -------------------

Expand Down
8 changes: 4 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,10 @@ module.exports = grammar({
escape_sequence: () => token.immediate(seq(
'\\',
choice(
/[^xu]/, // anything, except for [xu], which are:
/x[0-9a-fA-F]{2}/, // \x00 through \xFF
/u[0-9a-fA-F]{4}/, // \u0000 through \uFFFF
/u\{[0-9a-fA-F]{1,6}\}/, // \u{0} through \u{FFFFFF}
/[\\"nrtvbf]/, // \\ \" \n \r \t \v \b \f
/x[0-9a-fA-F]{2}/, // hexEscape, \x00 through \xFF
/u[0-9a-fA-F]{4}/, // unicodeEscape, \u0000 through \uFFFF
/u\{[0-9a-fA-F]{1,6}\}/, // unicodeCodePoint, \u{0} through \u{FFFFFF}
),
)),

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"src/**"
],
"scripts": {
"ts": "tree-sitter",
"gen": "tree-sitter generate",
"test": "tree-sitter test",
"gentest": "tree-sitter generate && tree-sitter test",
Expand Down
23 changes: 11 additions & 12 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@

(string) @string

; string.special.path
; -------------------
; string.special
; --------------

(import_statement
library: (string) @string.special.path)
library: (string) @string.special)

(escape_sequence) @string.special

; constant
; --------
Expand Down Expand Up @@ -169,7 +171,7 @@
; --------

(function
name: (identifier) @function.method)
name: (identifier) @function)

(native_function
name: (identifier) @function)
Expand All @@ -181,24 +183,21 @@
name: (identifier) @function)

(init_function
"init" @function.method)
"init" @function)

(receive_function
"receive" @function.method)
"receive" @function)

(bounced_function
"bounced" @function.method)
"bounced" @function)

(external_function
"external" @function.method)
"external" @function)

(func_identifier) @function

; function.method
; ---------------

(method_call_expression
name: (identifier) @function.method)
name: (identifier) @function)

; function.builtin
; ----------------
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.json

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

8 changes: 7 additions & 1 deletion 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/highlight/contract.tact
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ contract Empty {}

contract Filled {
init() {}
// <- function.method
// <- function
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket

receive() {}
// <- function.method
// <- function

external() {}
// <- function.method
// <- function

bounced(msg: Slice) {}
// <- function.method
// <- function
// ^ variable.parameter
// ^ punctuation.delimiter
// ^ type.builtin
Expand Down
4 changes: 2 additions & 2 deletions test/highlight/import.tact
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "@stdlib/deploy";
// <- keyword
// ^ string.special.path
// ^ string.special
// ^ punctuation.delimiter

// comment
// <- comment

/* multi-line comment/doc-string */
// <- comment
// <- comment
4 changes: 2 additions & 2 deletions test/highlight/trait.tact
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ trait Filled with Deployable, Ownable {
get fun c(arg1: String): Int {
// <- keyword
// ^ keyword
// ^ function.method
// ^ function
// ^ punctuation.bracket
// ^ variable.parameter
// ^ punctuation.delimiter
Expand Down Expand Up @@ -64,7 +64,7 @@ trait Filled with Deployable, Ownable {
// ^ keyword
// ^ keyword
// ^ keyword
// ^ function.method
// ^ function
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
Expand Down
7 changes: 4 additions & 3 deletions test/highlight/value_expression.tact
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extends fun c(self: Int) {

/* call_expression */
95.toString();
// ^ function.method
// ^ function

/* field_expression */
context().sender;
Expand Down Expand Up @@ -71,11 +71,12 @@ extends fun c(self: Int) {
// ^ constructor

/* string */
"Tact is awesome!";
"// \\ \" \n\r \t\v \b\f \u{0} \u{FFFFFF} \u0000 \xFF";
// <- string
// ^ string.special

/* self, not as a builtin, but as a parameter */
self.toString();
// <- variable.parameter
// ^ function.method
// ^ function
}

0 comments on commit 776796a

Please sign in to comment.