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?
|
|
|
|
_parts:( ( subexp / charset / terminal ) repeat? )*
|
|
|
|
_anchor_end:anchor_end? <Match>
|
2014-11-26 00:37:54 +00:00
|
|
|
anchor_start <- "^"
|
|
|
|
anchor_end <- "$"
|
|
|
|
repeat <- ( repeat_any / repeat_required / repeat_optional / repeat_spec ) repeat_greedy?
|
|
|
|
repeat_any <- "*"
|
|
|
|
repeat_required <- "+"
|
|
|
|
repeat_optional <- "?"
|
|
|
|
repeat_spec <- "{" [0-9]+ "," [0-9]+ "}"
|
|
|
|
/ "{," [0-9]+ "}"
|
|
|
|
/ "{" [0-9]+ ",}"
|
|
|
|
/ "{" [0-9]+ "}"
|
|
|
|
repeat_greedy <- "?"
|
|
|
|
subexp <- "(" ( subexp_no_capture / subexp_positive_lookahead / subexp_negative_lookahead )? regexp ")"
|
|
|
|
subexp_no_capture <- "?:"
|
|
|
|
subexp_positive_lookahead <- "?="
|
|
|
|
subexp_negative_lookahead <- "?!"
|
|
|
|
charset <- "[" "^"? ( charset_range / charset_terminal )* "]"
|
|
|
|
charset_range <- charset_terminal "-" charset_terminal
|
|
|
|
charset_terminal <- charset_escape / charset_literal
|
|
|
|
charset_escape <- ( backspace_esc
|
|
|
|
/ control_esc
|
|
|
|
/ digit_esc
|
|
|
|
/ non_digit_esc
|
|
|
|
/ form_feed_esc
|
|
|
|
/ line_feed_esc
|
|
|
|
/ carriage_return_esc
|
|
|
|
/ white_space_esc
|
|
|
|
/ non_white_space_esc
|
|
|
|
/ tab_esc
|
|
|
|
/ vertical_tab_esc
|
|
|
|
/ word_esc
|
|
|
|
/ non_word_esc
|
|
|
|
/ octal_esc
|
|
|
|
/ hex_esc
|
|
|
|
/ unicode_esc
|
|
|
|
/ null_esc
|
|
|
|
/ literal_esc )
|
|
|
|
charset_literal <- [^\\\]]
|
|
|
|
terminal <- any_character / escape / literal
|
|
|
|
any_character <- "."
|
|
|
|
escape <- ( word_boundary_esc
|
|
|
|
/ non_word_boundary_esc
|
|
|
|
/ control_esc
|
|
|
|
/ digit_esc
|
|
|
|
/ non_digit_esc
|
|
|
|
/ form_feed_esc
|
|
|
|
/ line_feed_esc
|
|
|
|
/ carriage_return_esc
|
|
|
|
/ white_space_esc
|
|
|
|
/ non_white_space_esc
|
|
|
|
/ tab_esc
|
|
|
|
/ vertical_tab_esc
|
|
|
|
/ word_esc
|
|
|
|
/ non_word_esc
|
|
|
|
/ back_reference
|
|
|
|
/ octal_esc
|
|
|
|
/ hex_esc
|
|
|
|
/ unicode_esc
|
|
|
|
/ null_esc
|
|
|
|
/ literal_esc )
|
|
|
|
literal <- [^|\\/.\[\(\)?+*$^]
|
|
|
|
back_reference <- "\\" [1-9]
|
|
|
|
word_boundary_esc <- "\\b"
|
|
|
|
non_word_boundary_esc <- "\\B"
|
|
|
|
backspace_esc <- "\\b"
|
|
|
|
control_esc <- "\\b" .
|
|
|
|
digit_esc <- "\\d"
|
|
|
|
non_digit_esc <- "\\D"
|
|
|
|
form_feed_esc <- "\\f"
|
|
|
|
line_feed_esc <- "\\n"
|
|
|
|
carriage_return_esc <- "\\r"
|
|
|
|
white_space_esc <- "\\s"
|
|
|
|
non_white_space_esc <- "\\S"
|
|
|
|
tab_esc <- "\\t"
|
|
|
|
vertical_tab_esc <- "\\v"
|
|
|
|
word_esc <- "\\w"
|
|
|
|
non_word_esc <- "\\W"
|
|
|
|
octal_esc <- "\\0" [0-7]+
|
|
|
|
hex_esc <- "\\x" [0-9a-fA-F] [0-9a-fA-F]
|
|
|
|
unicode_esc <- "\\u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]
|
|
|
|
null_esc <- "\\0"
|
|
|
|
literal_esc <- "\\" .
|