From 580af045d66c6aab2ce07a6e094222bb504d54cc Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Mon, 22 Dec 2014 15:00:38 -0500 Subject: [PATCH] Adjusting grammar to match \c escape "correctly" \c followed by something other than a-z leads to inconsistent behavior across browsers. Most will treat it as a series of literals (/\c#/ will match the string "\\c#" for example) --- src/js/parser/javascript/grammar.peg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/parser/javascript/grammar.peg b/src/js/parser/javascript/grammar.peg index b77ece4..a4c739a 100644 --- a/src/js/parser/javascript/grammar.peg +++ b/src/js/parser/javascript/grammar.peg @@ -22,20 +22,20 @@ grammar JavascriptRegexp / charset_literal charset_escape <- "\\" esc:( code:[bdDfnrsStvwW] arg:""? - / code:"c" arg:. + / code:"c" arg:[a-zA-Z] / 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:""? ) - charset_literal <- ( ""? literal:[^\\\]] ) / ( "\\" literal:. ) + charset_literal <- ( ""? literal:[^\\\]] ) / ( literal:"\\" &"c" ) / ( "\\" literal:. ) terminal <- "." / escape / literal escape <- "\\" esc:( code:[bBdDfnrsStvwW1-9] arg:""? - / code:"c" arg:. + / code:"c" arg:[a-zA-Z] / 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:""? ) - literal <- ( ""? literal:[^|\\/.\[\(\)?+*$^] ) / ( "\\" literal:. ) + literal <- ( ""? literal:[^|\\/.\[\(\)?+*$^] ) / ( literal:"\\" &"c" ) / ( "\\" literal:. )