feat(compiler): pass compilation unit to the parser

This commit is contained in:
vsavkin
2014-12-10 19:21:15 -08:00
parent d985045983
commit d5fcac4d7a
17 changed files with 109 additions and 72 deletions

View File

@ -385,8 +385,10 @@ export class FunctionCall extends AST {
export class ASTWithSource extends AST {
ast:AST;
source:string;
constructor(ast:AST, source:string) {
location:string;
constructor(ast:AST, source:string, location:string) {
this.source = source;
this.location = location;
this.ast = ast;
}
@ -407,7 +409,7 @@ export class ASTWithSource extends AST {
}
toString():string {
return this.source;
return `${this.source} in ${this.location}`;
}
}

View File

@ -36,32 +36,34 @@ export class Parser {
this._reflector = isPresent(providedReflector) ? providedReflector : reflector;
}
parseAction(input:string):ASTWithSource {
parseAction(input:string, location:any):ASTWithSource {
var tokens = this._lexer.tokenize(input);
var ast = new _ParseAST(input, tokens, this._reflector, true).parseChain();
return new ASTWithSource(ast, input);
var ast = new _ParseAST(input, location, tokens, this._reflector, true).parseChain();
return new ASTWithSource(ast, input, location);
}
parseBinding(input:string):ASTWithSource {
parseBinding(input:string, location:any):ASTWithSource {
var tokens = this._lexer.tokenize(input);
var ast = new _ParseAST(input, tokens, this._reflector, false).parseChain();
return new ASTWithSource(ast, input);
var ast = new _ParseAST(input, location, tokens, this._reflector, false).parseChain();
return new ASTWithSource(ast, input, location);
}
parseTemplateBindings(input:string):List<TemplateBinding> {
parseTemplateBindings(input:string, location:any):List<TemplateBinding> {
var tokens = this._lexer.tokenize(input);
return new _ParseAST(input, tokens, this._reflector, false).parseTemplateBindings();
return new _ParseAST(input, location, tokens, this._reflector, false).parseTemplateBindings();
}
}
class _ParseAST {
input:string;
location:any;
tokens:List<Token>;
reflector:Reflector;
parseAction:boolean;
index:int;
constructor(input:string, tokens:List, reflector:Reflector, parseAction:boolean) {
constructor(input:string, location:any, tokens:List, reflector:Reflector, parseAction:boolean) {
this.input = input;
this.location = location;
this.tokens = tokens;
this.index = 0;
this.reflector = reflector;
@ -451,7 +453,7 @@ class _ParseAST {
var start = this.inputIndex;
var ast = this.parseExpression();
var source = this.input.substring(start, this.inputIndex);
expression = new ASTWithSource(ast, source);
expression = new ASTWithSource(ast, source, this.location);
}
}
ListWrapper.push(bindings, new TemplateBinding(key, name, expression));
@ -469,6 +471,6 @@ class _ParseAST {
? `at column ${this.tokens[index].index + 1} in`
: `at the end of the expression`;
throw new BaseException(`Parser Error: ${message} ${location} [${this.input}]`);
throw new BaseException(`Parser Error: ${message} ${location} [${this.input}] in ${this.location}`);
}
}