From 43eaf493e631b6bee4cfa8eaa234c9ec87c14a5b Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Fri, 19 Dec 2014 20:35:20 -0500 Subject: [PATCH] Removing some cruft in the grammar --- src/js/parser/javascript/grammar.peg | 14 +++++--------- src/js/parser/javascript/root.js | 8 +------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/js/parser/javascript/grammar.peg b/src/js/parser/javascript/grammar.peg index d9c0f6d..67096e6 100644 --- a/src/js/parser/javascript/grammar.peg +++ b/src/js/parser/javascript/grammar.peg @@ -1,20 +1,17 @@ grammar JavascriptRegexp - root <- ( ( "/" regexp "/" flags:[igm]* ) / regexp ""? ) + root <- ( ( "/" regexp "/" flags:[igm]* ) / regexp flags:""? ) regexp <- match:match alternates:( "|" match )* - match <- anchor_start:anchor_start? + match <- anchor_start:"^"? (!repeat) parts:match_fragment* - anchor_end:anchor_end? + anchor_end:"$"? match_fragment <- content:( subexp / charset / terminal ) repeat:repeat? - anchor_start <- "^" - anchor_end <- "$" - repeat <- spec:( repeat_any / repeat_required / repeat_optional / repeat_spec ) greedy:repeat_greedy? + repeat <- spec:( repeat_any / repeat_required / repeat_optional / repeat_spec ) greedy:"?"? repeat_any <- "*" repeat_required <- "+" repeat_optional <- "?" repeat_spec <- ( "{" min:[0-9]+ "," max:[0-9]+ "}" / "{" min:[0-9]+ ",}" / "{" exact:[0-9]+ "}" ) - repeat_greedy <- "?" subexp <- "(" capture:( subexp_no_capture / subexp_positive_lookahead / subexp_negative_lookahead )? regexp ")" subexp_no_capture <- "?:" subexp_positive_lookahead <- "?=" @@ -29,10 +26,9 @@ grammar JavascriptRegexp / 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] ) ) charset_literal <- ( ""? literal:[^\\\]] ) / ( "\\" literal:. ) - terminal <- any_character + terminal <- "." / escape / literal - any_character <- "." escape <- "\\" esc:( code:[bBdDfnrsStvwW1-9] arg:""? / code:"c" arg:. diff --git a/src/js/parser/javascript/root.js b/src/js/parser/javascript/root.js index fb68336..7dfe56e 100644 --- a/src/js/parser/javascript/root.js +++ b/src/js/parser/javascript/root.js @@ -52,13 +52,7 @@ export default { }, setup() { - var flagsStr; - - if (this.properties.flags) { - flagsStr = this.properties.flags.textValue; - } else { - flagsStr = ''; - } + var flagsStr = this.properties.flags.textValue; this.flags = { global: /g/.test(flagsStr),