@ -145,7 +145,7 @@ export const $BACKSLASH = 92;
|
||||
export const $RBRACKET = 93;
|
||||
const $CARET = 94;
|
||||
const $_ = 95;
|
||||
|
||||
export const $BT = 96;
|
||||
const $a = 97, $e = 101, $f = 102, $n = 110, $r = 114, $t = 116, $u = 117, $v = 118, $z = 122;
|
||||
|
||||
export const $LBRACE = 123;
|
||||
@ -415,6 +415,10 @@ function isExponentSign(code: number): boolean {
|
||||
return code == $MINUS || code == $PLUS;
|
||||
}
|
||||
|
||||
export function isQuote(code: number): boolean {
|
||||
return code === $SQ || code === $DQ || code === $BT;
|
||||
}
|
||||
|
||||
function unescape(code: number): number {
|
||||
switch (code) {
|
||||
case $n:
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
Lexer,
|
||||
EOF,
|
||||
isIdentifier,
|
||||
isQuote,
|
||||
Token,
|
||||
$PERIOD,
|
||||
$COLON,
|
||||
@ -16,7 +17,8 @@ import {
|
||||
$LBRACE,
|
||||
$RBRACE,
|
||||
$LPAREN,
|
||||
$RPAREN
|
||||
$RPAREN,
|
||||
$SLASH
|
||||
} from './lexer';
|
||||
import {
|
||||
AST,
|
||||
@ -67,7 +69,7 @@ export class Parser {
|
||||
|
||||
parseAction(input: string, location: any): ASTWithSource {
|
||||
this._checkNoInterpolation(input, location);
|
||||
var tokens = this._lexer.tokenize(input);
|
||||
var tokens = this._lexer.tokenize(this._stripComments(input));
|
||||
var ast = new _ParseAST(input, location, tokens, true).parseChain();
|
||||
return new ASTWithSource(ast, input, location);
|
||||
}
|
||||
@ -96,7 +98,7 @@ export class Parser {
|
||||
}
|
||||
|
||||
this._checkNoInterpolation(input, location);
|
||||
var tokens = this._lexer.tokenize(input);
|
||||
var tokens = this._lexer.tokenize(this._stripComments(input));
|
||||
return new _ParseAST(input, location, tokens, false).parseChain();
|
||||
}
|
||||
|
||||
@ -122,7 +124,7 @@ export class Parser {
|
||||
let expressions = [];
|
||||
|
||||
for (let i = 0; i < split.expressions.length; ++i) {
|
||||
var tokens = this._lexer.tokenize(split.expressions[i]);
|
||||
var tokens = this._lexer.tokenize(this._stripComments(split.expressions[i]));
|
||||
var ast = new _ParseAST(input, location, tokens, false).parseChain();
|
||||
expressions.push(ast);
|
||||
}
|
||||
@ -158,6 +160,28 @@ export class Parser {
|
||||
return new ASTWithSource(new LiteralPrimitive(input), input, location);
|
||||
}
|
||||
|
||||
private _stripComments(input: string): string {
|
||||
let i = this._commentStart(input);
|
||||
return isPresent(i) ? input.substring(0, i).trim() : input;
|
||||
}
|
||||
|
||||
private _commentStart(input: string): number {
|
||||
var outerQuote = null;
|
||||
for (var i = 0; i < input.length - 1; i++) {
|
||||
let char = StringWrapper.charCodeAt(input, i);
|
||||
let nextChar = StringWrapper.charCodeAt(input, i + 1);
|
||||
|
||||
if (char === $SLASH && nextChar == $SLASH && isBlank(outerQuote)) return i;
|
||||
|
||||
if (outerQuote === char) {
|
||||
outerQuote = null;
|
||||
} else if (isBlank(outerQuote) && isQuote(char)) {
|
||||
outerQuote = char;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private _checkNoInterpolation(input: string, location: any): void {
|
||||
var parts = StringWrapper.split(input, INTERPOLATION_REGEXP);
|
||||
if (parts.length > 1) {
|
||||
|
Reference in New Issue
Block a user