Removing some cruft in the grammar

This commit is contained in:
Jeff Avallone 2014-12-19 20:35:20 -05:00
parent 70789258ab
commit 43eaf493e6
2 changed files with 6 additions and 16 deletions

View File

@ -1,20 +1,17 @@
grammar JavascriptRegexp grammar JavascriptRegexp
root <- ( ( "/" regexp "/" flags:[igm]* ) / regexp ""? ) <Root> root <- ( ( "/" regexp "/" flags:[igm]* ) / regexp flags:""? ) <Root>
regexp <- match:match alternates:( "|" match )* <Regexp> regexp <- match:match alternates:( "|" match )* <Regexp>
match <- anchor_start:anchor_start? match <- anchor_start:"^"?
(!repeat) parts:match_fragment* (!repeat) parts:match_fragment*
anchor_end:anchor_end? <Match> anchor_end:"$"? <Match>
match_fragment <- content:( subexp / charset / terminal ) repeat:repeat? <MatchFragment> match_fragment <- content:( subexp / charset / terminal ) repeat:repeat? <MatchFragment>
anchor_start <- "^" repeat <- spec:( repeat_any / repeat_required / repeat_optional / repeat_spec ) greedy:"?"? <Repeat>
anchor_end <- "$"
repeat <- spec:( repeat_any / repeat_required / repeat_optional / repeat_spec ) greedy:repeat_greedy? <Repeat>
repeat_any <- "*" <RepeatAny> repeat_any <- "*" <RepeatAny>
repeat_required <- "+" <RepeatRequired> repeat_required <- "+" <RepeatRequired>
repeat_optional <- "?" <RepeatOptional> repeat_optional <- "?" <RepeatOptional>
repeat_spec <- ( "{" min:[0-9]+ "," max:[0-9]+ "}" repeat_spec <- ( "{" min:[0-9]+ "," max:[0-9]+ "}"
/ "{" min:[0-9]+ ",}" / "{" min:[0-9]+ ",}"
/ "{" exact:[0-9]+ "}" ) <RepeatSpec> / "{" exact:[0-9]+ "}" ) <RepeatSpec>
repeat_greedy <- "?"
subexp <- "(" capture:( subexp_no_capture / subexp_positive_lookahead / subexp_negative_lookahead )? regexp ")" <Subexp> subexp <- "(" capture:( subexp_no_capture / subexp_positive_lookahead / subexp_negative_lookahead )? regexp ")" <Subexp>
subexp_no_capture <- "?:" subexp_no_capture <- "?:"
subexp_positive_lookahead <- "?=" subexp_positive_lookahead <- "?="
@ -29,10 +26,9 @@ grammar JavascriptRegexp
/ code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] ) / 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:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] ) )
charset_literal <- ( ""? literal:[^\\\]] ) / ( "\\" literal:. ) charset_literal <- ( ""? literal:[^\\\]] ) / ( "\\" literal:. )
terminal <- any_character <AnyCharacter> terminal <- "." <AnyCharacter>
/ escape <Escape> / escape <Escape>
/ literal <Literal> / literal <Literal>
any_character <- "."
escape <- "\\" esc:( escape <- "\\" esc:(
code:[bBdDfnrsStvwW1-9] arg:""? code:[bBdDfnrsStvwW1-9] arg:""?
/ code:"c" arg:. / code:"c" arg:.

View File

@ -52,13 +52,7 @@ export default {
}, },
setup() { setup() {
var flagsStr; var flagsStr = this.properties.flags.textValue;
if (this.properties.flags) {
flagsStr = this.properties.flags.textValue;
} else {
flagsStr = '';
}
this.flags = { this.flags = {
global: /g/.test(flagsStr), global: /g/.test(flagsStr),