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
47
48
49
//! JavaScript Parser
//!
//! Support JavaScript and TypeScript.
item = _{ SOI ~ line* ~ EOI }
line = _{ expr | html }
other = ${ !(string | open_html) ~ ANY }
WHITESPACE = { " " | "\t" | NEWLINE }
/// Comment
COMMENT = ${ line_comment | block_comment }
line_comment = _{ "//" ~ (!(NEWLINE) ~ ANY)* }
block_comment = _{ "/*" ~ (!("*/") ~ ANY)* ~ "*/" }
/// HTML tags
html = _{ html_node | html_void | text }
expr = _{ pair | string | regexp | other }
/// other text
text = ${ (!("<") ~ ANY)+ }
/// HTML void
html_void = @{ "<" ~ (!("/>" | ">") ~ ANY)* ~ (">" | "/>") }
/// HTML node
html_node = ${ open_html ~ (!(close_html) ~ (html_node | text))+ ~ close_html }
inner_html = @{ (!(">") ~ ANY)* }
open_html = @{ "<" ~ inner_html ~ chevron_right }
close_html = @{ "</" ~ inner_html ~ ">" }
chevron_right = @{
">"
| "/>"
| "?>"
}
/// String
string = ${ inner_string }
inner_string = _{
("'" ~ (!("'") ~ ANY)* ~ "'")
| ("\"" ~ (!(NEWLINE | "\"") ~ ANY)* ~ "\"")
| ("`" ~ (!("`") ~ ANY)* ~ "`"+)
}
key = ${ inner_string ~ (" ")* ~ ":" ~ (" ")* }
pair = _{ key ~ string }
/// Regexp
regexp = ${
("/" ~ (!(NEWLINE | "/") ~ ANY)* ~ "/")
| ("RegExp" ~ "(" ~ " "* ~ inner_string ~ (!")" ~ ANY)* ~ ")")
}