-
Notifications
You must be signed in to change notification settings - Fork 1
/
grammar.js
46 lines (37 loc) · 1.23 KB
/
grammar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module.exports = grammar({
name: "embedded_php",
extras: ($) => [/\r?\n/],
externals: ($) => [$._eof],
rules: {
template: ($) => repeat(choice($.php, $.content)),
php: ($) =>
seq(
// regex copied from tree-sitter-php
/<\?([pP][hH][pP]|=)?/,
repeat(
choice(
// swallow anything w/i php tags
/./,
// swallow anything w/i strings
// This prevents end tag w/i a string (eg `echo "?>"`) from
// prematurely ending the php node
// FIXME this will match unbalanced quotes, eg: "my string'
// FIXME this does not handle heredoc or nowdoc
/['"].*['"]/,
// swallow anything w/i comments
// This prevents end tags and string chars from affecting parsing
/(\/\/|#).*\n/,
/\/\*(.|\r?\n)*\*\//
)
),
choice(
// Specifying the end tag as a regex means that it will be included
// in the main `(php)` node. If we instead specified it as a string,
// it would be added as an anonymous child node of `(php)`.
/\?>/,
$._eof
)
),
content: ($) => prec.right(repeat1(/./)),
},
});