Adding tests for CharsetEscape nodes

This commit is contained in:
Jeff Avallone 2014-12-19 21:56:56 -05:00
parent 24e21834f6
commit d27831a265
2 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,35 @@
import javascript from 'src/js/parser/javascript/parser.js';
import _ from 'lodash';
import Snap from 'snapsvg';
describe('parser/javascript/any_character.js', function() {
_.forIn({
'\\b': 'backspace',
'\\d': 'digit',
'\\D': 'non-digit',
'\\f': 'form feed',
'\\n': 'line feed',
'\\r': 'carriage return',
'\\s': 'white space',
'\\S': 'non-white space',
'\\t': 'tab',
'\\v': 'vertical tab',
'\\w': 'word',
'\\W': 'non-word',
'\\0': 'null',
'\\012': 'octal: 12',
'\\cx': 'ctrl-x',
'\\xab': '0xAB',
'\\uabcd': 'U+ABCD'
}, (label, str) => {
it(`parses "${str}" as a CharsetEscape`, function() {
var parser = new javascript.Parser(str);
expect(parser.__consume__charset_terminal()).toEqual(jasmine.objectContaining({
type: 'charset-escape',
label
}));
});
});
});

View File

@ -22,9 +22,11 @@ grammar JavascriptRegexp
/ charset_literal <Literal> / charset_literal <Literal>
charset_escape <- "\\" esc:( charset_escape <- "\\" esc:(
code:[bdDfnrsStvwW] arg:""? code:[bdDfnrsStvwW] arg:""?
/ code:"c" arg:.
/ code:"0" arg:[0-7]+ / code:"0" arg:[0-7]+
/ 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] )
/ code:"0" arg:""? )
charset_literal <- ( ""? literal:[^\\\]] ) / ( "\\" literal:. ) charset_literal <- ( ""? literal:[^\\\]] ) / ( "\\" literal:. )
terminal <- "." <AnyCharacter> terminal <- "." <AnyCharacter>
/ escape <Escape> / escape <Escape>