Skip to content

Commit

Permalink
POC #28, #34, #33
Browse files Browse the repository at this point in the history
  • Loading branch information
EmranMR committed Jan 8, 2024
1 parent 01e5550 commit 76078c7
Show file tree
Hide file tree
Showing 5 changed files with 135,515 additions and 127,758 deletions.
18 changes: 14 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ module.exports = grammar({
$._nested_directive,
$.loop_operator,
$.comment,
$.text
$.text,
$.alpine_js
),

// https://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
comment: $ => token(seq('{{--', /[^-]*-+([^}-][^-]*-+)*/, '}}')),
comment: ($) =>
token(seq('{{--', /[^-]*-+([^}-][^-]*-+)*/, '}}')),

// !keywords
keyword: ($) =>
Expand Down Expand Up @@ -488,6 +490,14 @@ module.exports = grammar({
alias('@endvolt', $.directive_end)
),

alpine_js: ($) =>
seq(
token(prec(1, /x-[a-zA-Z1-9]+=/)),
token(prec(1, /[\"\']/)),
$.text,
token(prec(1, /[\"\']/))
),

/*------------------------------------
/ Do NOT change below this line  /
/ without running tests  /
Expand Down Expand Up @@ -544,11 +554,11 @@ module.exports = grammar({
_text: ($) =>
choice(
token(prec(-1, /@[a-zA-Z\d]*[^\(-]/)), // custom directive conflict resolution
token(prec(-2, /[{}!@()?,-]/)), // orphan tags
token(prec(-2, /[\"\'x{}!@()?,-]/)), // orphan tags
token(
prec(
-1,
/[^\s(){!}@-]([^(){!}@,?]*[^{!}()@?,-])?/ //general text
/[^\"\'\sx(){!}@-]([^\"\'x(){!}@,?]*[^\"\'x{!}()@?,-])?/ //general text
)
)
),
Expand Down
10 changes: 6 additions & 4 deletions queries/injections.scm
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
((text) @injection.content
(#not-has-ancestor? @injection.content "envoy")
(#not-has-ancestor? @injection.content "envoy" "alpine_js")
(#set! injection.combined)
(#set! injection.language php))

; could be bash or zsh
; or whatever tree-sitter grammar you have.
((text) @injection.content
(#has-ancestor? @injection.content "envoy")
(#set! injection.combined)
(#set! injection.language bash))
(#set! injection.language shell))

((text) @injection.content
(#has-ancestor? @injection.content "alpine_js")
(#set! injection.combined)
(#set! injection.language js))

((php_only) @injection.content
(#set! injection.language php_only))
Expand Down
50 changes: 48 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
{
"type": "SYMBOL",
"name": "text"
},
{
"type": "SYMBOL",
"name": "alpine_js"
}
]
},
Expand Down Expand Up @@ -2047,6 +2051,48 @@
}
]
},
"alpine_js": {
"type": "SEQ",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "x-[a-zA-Z1-9]+="
}
}
},
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[\\\"\\']"
}
}
},
{
"type": "SYMBOL",
"name": "text"
},
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[\\\"\\']"
}
}
}
]
},
"_directive_body": {
"type": "REPEAT1",
"content": {
Expand Down Expand Up @@ -2351,7 +2397,7 @@
"value": -2,
"content": {
"type": "PATTERN",
"value": "[{}!@()?,-]"
"value": "[\\\"\\'x{}!@()?,-]"
}
}
},
Expand All @@ -2362,7 +2408,7 @@
"value": -1,
"content": {
"type": "PATTERN",
"value": "[^\\s(){!}@-]([^(){!}@,?]*[^{!}()@?,-])?"
"value": "[^\\\"\\'\\sx(){!}@-]([^\\\"\\'x(){!}@,?]*[^\\\"\\'x{!}()@?,-])?"
}
}
}
Expand Down
67 changes: 67 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
[
{
"type": "alpine_js",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "text",
"named": true
}
]
}
},
{
"type": "attribute",
"named": true,
Expand Down Expand Up @@ -34,6 +49,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -141,6 +160,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -236,6 +259,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -378,6 +405,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -481,6 +512,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -626,6 +661,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -729,6 +768,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -859,6 +902,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -981,6 +1028,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -1132,6 +1183,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -1235,6 +1290,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -1338,6 +1397,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down Expand Up @@ -1446,6 +1509,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "alpine_js",
"named": true
},
{
"type": "attribute",
"named": true
Expand Down
Loading

0 comments on commit 76078c7

Please sign in to comment.