2014-11-26 00:37:54 +00:00
|
|
|
grammar JavascriptRegexp
|
2014-12-03 00:59:10 +00:00
|
|
|
root <- ( ( "/" regexp "/" _flags:[igm]* ) / regexp ""? ) <Root>
|
|
|
|
regexp <- _match:match _alternates:( "|" match )* <Regexp>
|
|
|
|
match <- _anchor_start:anchor_start?
|
2014-12-06 17:34:00 +00:00
|
|
|
(!repeat) _parts:match_fragment*
|
2014-12-03 00:59:10 +00:00
|
|
|
_anchor_end:anchor_end? <Match>
|
2014-12-06 17:34:00 +00:00
|
|
|
match_fragment <- _content:( subexp / charset / terminal ) _repeat:repeat? <MatchFragment>
|
2014-11-26 00:37:54 +00:00
|
|
|
anchor_start <- "^"
|
|
|
|
anchor_end <- "$"
|
2014-12-06 17:34:00 +00:00
|
|
|
repeat <- _spec:( repeat_any / repeat_required / repeat_optional / repeat_spec ) _greedy:repeat_greedy? <Repeat>
|
|
|
|
repeat_any <- "*" <RepeatAny>
|
|
|
|
repeat_required <- "+" <RepeatRequired>
|
|
|
|
repeat_optional <- "?" <RepeatOptional>
|
|
|
|
repeat_spec <- ( "{" _min:[0-9]+ "," _max:[0-9]+ "}"
|
|
|
|
/ "{" _min:[0-9]+ ",}"
|
|
|
|
/ "{" _exact:[0-9]+ "}" ) <RepeatSpec>
|
2014-11-26 00:37:54 +00:00
|
|
|
repeat_greedy <- "?"
|
2014-12-08 02:16:23 +00:00
|
|
|
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-07 22:38:24 +00:00
|
|
|
charset <- "[" _invert:"^"? parts:( charset_range / charset_terminal )* "]" <Charset>
|
|
|
|
charset_range <- first:charset_terminal "-" last:charset_terminal <CharsetRange>
|
|
|
|
charset_terminal <- charset_escape <CharsetEscape>
|
|
|
|
/ charset_literal <CharsetLiteral>
|
2014-12-07 20:26:45 +00:00
|
|
|
charset_escape <- "\\" esc:(
|
|
|
|
code:[bdDfnrsStvwW] arg:""?
|
|
|
|
/ code:"0" arg:[0-7]+
|
|
|
|
/ code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] )
|
|
|
|
/ code:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] ) )
|
2014-12-07 22:38:24 +00:00
|
|
|
charset_literal <- ( ""? literal:[^\\\]] ) / ( "\\" literal:. )
|
2014-12-06 21:03:58 +00:00
|
|
|
terminal <- any_character <AnyCharacter>
|
|
|
|
/ escape <Escape>
|
|
|
|
/ literal <Literal>
|
2014-11-26 00:37:54 +00:00
|
|
|
any_character <- "."
|
2014-12-07 20:26:45 +00:00
|
|
|
escape <- "\\" esc:(
|
|
|
|
code:[bBdDfnrsStvwW1-9] arg:""?
|
|
|
|
/ code:"c" arg:.
|
|
|
|
/ code:"0" arg:[0-7]+
|
|
|
|
/ code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] )
|
|
|
|
/ code:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] )
|
|
|
|
/ code:"0" arg:""? )
|
2014-12-06 21:03:58 +00:00
|
|
|
literal <- ( ""? literal:[^|\\/.\[\(\)?+*$^] ) / ( "\\" literal:. )
|