Skip to content

Commit

Permalink
feat: add highlight & injection queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Mar 4, 2024
1 parent f9cc060 commit 222397a
Show file tree
Hide file tree
Showing 6 changed files with 496 additions and 435 deletions.
30 changes: 12 additions & 18 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,27 @@ module.exports = grammar({
alias($._equals_end, $.separator),
),

attributes: $ => repeat1(
field("attribute", choice(
$.skip,
$.error,
$.fail_fast,
$.language,
$.platform,
))
attributes: $ => repeat1($.attribute),

attribute: $ => choice(
":skip",
":error",
":fail-fast",
$._language,
$._platform,
),

skip: _ => ":skip",

error: _ => ":error",

fail_fast: _ => ":fail-fast",

language: $ => seq(
_language: $ => seq(
":language",
token.immediate("("),
alias($._lang, $.parameter),
field("language", alias($._lang, $.parameter)),
token.immediate(")")
),

platform: $ => seq(
_platform: $ => seq(
":platform",
token.immediate("("),
alias($._os, $.parameter),
field("platform", alias($._os, $.parameter)),
token.immediate(")")
),

Expand Down
25 changes: 24 additions & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
; TODO: add highlight queries here
(name) @markup.heading

[
(input)
(output)
] @markup.raw.block

[
":skip"
":error"
":fail-fast"
":language"
":platform"
] @attribute

(attribute
language: (parameter) @string)

(attribute
platform: (parameter) @constant.builtin)

(separator) @punctuation.delimiter

[ "(" ")" ] @punctuation.bracket
30 changes: 29 additions & 1 deletion queries/injections.scm
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
; TODO: add injection queries here
(test
(header
(name)
(attributes
. ; skip over non-language attributes
(attribute
!language)*
. ; select only the first language attribute
(attribute
language: (parameter) @injection.language)))
(input) @injection.input)

((test
(output) @injection.content)
(#set! injection.language "query"))

; NOTE: dynamic injection
; ((test
; (header
; [
; (attributes
; (attribute
; !language))
; ((name)
; .
; (separator))
; ])
; (input) @injection.content)
; (#set! injection.language "{}"))
100 changes: 48 additions & 52 deletions src/grammar.json

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

95 changes: 37 additions & 58 deletions src/node-types.json

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

Loading

0 comments on commit 222397a

Please sign in to comment.