~rockorager/tree-sitter-hare

690c3e9d067cd7a0d08d8244a72985d9dcfe5120 — Tim Culverhouse 1 year, 5 months ago 4983ba5
format-seq: add format field modifiers

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
3 files changed, 54 insertions(+), 3 deletions(-)

M corpus/types.txt
M grammar.js
M queries/highlights.scm
M corpus/types.txt => corpus/types.txt +46 -1
@@ 1,5 1,5 @@
================================================================================
Struct
Struct: simple declaration
================================================================================

type foo = struct { x: int, y: int };


@@ 33,3 33,48 @@ type foo = struct @packed { x: int, y: int };
        (struct_union_field
          (identifier)
          (integer_type))))))

================================================================================
Strings: simple declaration
================================================================================

let a: str = "foo";
--------------------------------------------------------------------------------
(unit
  (global_declaration
    (identifier)
    (string_type)
    (string_literal)))

================================================================================
Strings: escape sequence
================================================================================

let a: str = "foo\n";
--------------------------------------------------------------------------------
(unit
  (global_declaration
    (identifier)
    (string_type)
    (string_literal
      (escape_sequence))))

================================================================================
Strings: format sequence
================================================================================

let a: str = "foo{0:10}";
let a: str = "foo{}";
--------------------------------------------------------------------------------
(unit
  (global_declaration
    (identifier)
    (string_type)
    (string_literal
      (format_sequence)))
  (global_declaration
    (identifier)
    (string_type)
    (string_literal
      (format_sequence))))


M grammar.js => grammar.js +7 -1
@@ 383,9 383,15 @@ module.exports = grammar({
        ),
      )),

    format_sequence: ($) => seq("{", optional(repeat(/[^"\\]/)), "}"),

    string_literal: ($) =>
      choice(
        seq('"', repeat(choice(/[^"\\]/, $.escape_sequence)), '"'),
        seq(
          '"',
          repeat(choice(/[^"\\]/, $.escape_sequence, $.format_sequence)),
          '"',
        ),
        seq("'", repeat(choice(/[^']/)), "'"),
      ),


M queries/highlights.scm => queries/highlights.scm +1 -1
@@ 115,7 115,7 @@
 ] @punctuation.bracket

(string_literal) @string

(format_sequence) @string.special
(escape_sequence) @string.escape
(comment) @comment @spell