Skip to content

Commit

Permalink
Add support for regex injections
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 7, 2024
1 parent 37ae0e3 commit 18eb696
Show file tree
Hide file tree
Showing 8 changed files with 3,065 additions and 2,933 deletions.
5 changes: 4 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,14 @@ module.exports = grammar({
choice(
seq($.expression, "==", $.expression),
seq($.expression, "!=", $.expression),
seq($.expression, "=~", $.expression),
seq($.expression, "=~", choice($.regex_literal, $.expression)),
// verify whether this is valid
$.expression,
),

// Capture this special for injections
regex_literal: ($) => prec(4, $._string),

// value : NAME '(' sequence? ')'
// | BACKTICK
// | INDENTED_BACKTICK
Expand Down
16 changes: 7 additions & 9 deletions queries-src/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(#set! injection.language "comment"))


; FIXME: read default from shebang
(recipe_line
(text) @injection.content
(#set! injection.language "bash"))
Expand All @@ -12,12 +13,9 @@
(command_body) @injection.content
(#set! injection.language "bash"))

; ; FIXME: read default from shebang
; ([
; (recipe_body
; (recipe_line (text)))
; (external_command
; body: (_)*)
; ] @injection.content
; (#set! injection.language "bash")
; )
((regex_literal
[
(string_literal)
(raw_string_literal)
] @injection.content)
(#set! injection.language "regex"))
5 changes: 5 additions & 0 deletions queries/just/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
(command_body) @injection.content
(#set! injection.language "bash"))

((regex_literal
[(string_literal)
(raw_string_literal)] @injection.content)
(#set! injection.language "regex"))

; ; FIXME: read default from shebang
; ([
; (recipe_body
Expand Down
21 changes: 19 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,17 @@
"value": "=~"
},
{
"type": "SYMBOL",
"name": "expression"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "regex_literal"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
]
},
Expand All @@ -705,6 +714,14 @@
}
]
},
"regex_literal": {
"type": "PREC",
"value": 4,
"content": {
"type": "SYMBOL",
"name": "_string"
}
},
"value": {
"type": "PREC_LEFT",
"value": 0,
Expand Down
23 changes: 23 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
{
"type": "expression",
"named": true
},
{
"type": "regex_literal",
"named": true
}
]
}
Expand Down Expand Up @@ -622,6 +626,25 @@
"named": true,
"fields": {}
},
{
"type": "regex_literal",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "raw_string_literal",
"named": true
},
{
"type": "string_literal",
"named": true
}
]
}
},
{
"type": "sequence",
"named": true,
Expand Down
Loading

0 comments on commit 18eb696

Please sign in to comment.