2014-11-26 00:37:54 +00:00
|
|
|
grammar JavascriptRegexp
|
2014-12-20 01:35:20 +00:00
|
|
|
root <- ( ( "/" regexp "/" flags:[igm]* ) / regexp flags:""? ) <Root>
|
2014-12-17 19:44:48 +00:00
|
|
|
regexp <- match:match alternates:( "|" match )* <Regexp>
|
2014-12-20 01:35:20 +00:00
|
|
|
match <- anchor_start:"^"?
|
2014-12-17 19:44:48 +00:00
|
|
|
(!repeat) parts:match_fragment*
|
2014-12-20 01:35:20 +00:00
|
|
|
anchor_end:"$"? <Match>
|
2014-12-17 19:44:48 +00:00
|
|
|
match_fragment <- content:( subexp / charset / terminal ) repeat:repeat? <MatchFragment>
|
2014-12-20 01:35:20 +00:00
|
|
|
repeat <- spec:( repeat_any / repeat_required / repeat_optional / repeat_spec ) greedy:"?"? <Repeat>
|
2014-12-06 17:34:00 +00:00
|
|
|
repeat_any <- "*" <RepeatAny>
|
|
|
|
repeat_required <- "+" <RepeatRequired>
|
|
|
|
repeat_optional <- "?" <RepeatOptional>
|
2014-12-17 19:44:48 +00:00
|
|
|
repeat_spec <- ( "{" min:[0-9]+ "," max:[0-9]+ "}"
|
|
|
|
/ "{" min:[0-9]+ ",}"
|
|
|
|
/ "{" exact:[0-9]+ "}" ) <RepeatSpec>
|
|
|
|
subexp <- "(" capture:( subexp_no_capture / subexp_positive_lookahead / subexp_negative_lookahead )? regexp ")" <Subexp>
|
2014-11-26 00:37:54 +00:00
|
|
|
subexp_no_capture <- "?:"
|
|
|
|
subexp_positive_lookahead <- "?="
|
|
|
|
subexp_negative_lookahead <- "?!"
|
2014-12-17 19:44:48 +00:00
|
|
|
charset <- "[" invert:"^"? parts:( charset_range / charset_terminal )* "]" <Charset>
|
2014-12-22 21:09:27 +00:00
|
|
|
charset_range <- first:charset_range_terminal "-" last:charset_range_terminal <CharsetRange>
|
2014-12-07 22:38:24 +00:00
|
|
|
charset_terminal <- charset_escape <CharsetEscape>
|
2014-12-20 01:23:32 +00:00
|
|
|
/ charset_literal <Literal>
|
2014-12-22 21:09:27 +00:00
|
|
|
charset_range_terminal <- charset_range_escape <CharsetEscape>
|
|
|
|
/ charset_literal <Literal>
|
2014-12-07 20:26:45 +00:00
|
|
|
charset_escape <- "\\" esc:(
|
|
|
|
code:[bdDfnrsStvwW] arg:""?
|
2014-12-22 21:26:08 +00:00
|
|
|
/ control_escape
|
|
|
|
/ octal_escape
|
|
|
|
/ hex_escape
|
|
|
|
/ unicode_escape
|
|
|
|
/ null_escape )
|
2014-12-22 21:09:27 +00:00
|
|
|
charset_range_escape <- "\\" esc:(
|
|
|
|
code:[bfnrtv] arg:""?
|
2014-12-22 21:26:08 +00:00
|
|
|
/ control_escape
|
|
|
|
/ octal_escape
|
|
|
|
/ hex_escape
|
|
|
|
/ unicode_escape
|
|
|
|
/ null_escape )
|
2014-12-22 21:09:27 +00:00
|
|
|
charset_literal <- ( ""? literal:[^\\\]] )
|
|
|
|
/ ( literal:"\\" &"c" )
|
|
|
|
/ ( "\\" literal:[^bdDfnrsStvwW] )
|
2014-12-20 01:35:20 +00:00
|
|
|
terminal <- "." <AnyCharacter>
|
2014-12-06 21:03:58 +00:00
|
|
|
/ escape <Escape>
|
|
|
|
/ literal <Literal>
|
2014-12-07 20:26:45 +00:00
|
|
|
escape <- "\\" esc:(
|
|
|
|
code:[bBdDfnrsStvwW1-9] arg:""?
|
2014-12-22 21:26:08 +00:00
|
|
|
/ control_escape
|
|
|
|
/ octal_escape
|
|
|
|
/ hex_escape
|
|
|
|
/ unicode_escape
|
|
|
|
/ null_escape )
|
2014-12-22 21:09:27 +00:00
|
|
|
literal <- ( ""? literal:[^|\\/.\[\(\)?+*$^] )
|
|
|
|
/ ( literal:"\\" &"c" )
|
|
|
|
/ ( "\\" literal:. )
|
2014-12-22 21:26:08 +00:00
|
|
|
|
|
|
|
control_escape <- code:"c" arg:[a-zA-Z]
|
|
|
|
octal_escape <- code:"0" arg:[0-7]+
|
|
|
|
hex_escape <- code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] )
|
|
|
|
unicode_escape <- code:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] )
|
|
|
|
null_escape <- code:"0" arg:""?
|