refactor($parse): move duplicate $parse interpreter/compiler logic into Parser
- the construction of the AST is now in the Parser - the assigning of the literal and constant flags is now in the Parser - remove unused references to the lexer, $filter and options on the Parser
This commit is contained in:
+13
-20
@@ -769,15 +769,13 @@ function isConstant(ast) {
|
||||
return ast.constant;
|
||||
}
|
||||
|
||||
function ASTCompiler(astBuilder, $filter) {
|
||||
this.astBuilder = astBuilder;
|
||||
function ASTCompiler($filter) {
|
||||
this.$filter = $filter;
|
||||
}
|
||||
|
||||
ASTCompiler.prototype = {
|
||||
compile: function(expression) {
|
||||
compile: function(ast) {
|
||||
var self = this;
|
||||
var ast = this.astBuilder.ast(expression);
|
||||
this.state = {
|
||||
nextId: 0,
|
||||
filters: {},
|
||||
@@ -832,8 +830,6 @@ ASTCompiler.prototype = {
|
||||
ifDefined,
|
||||
plusFn);
|
||||
this.state = this.stage = undefined;
|
||||
fn.literal = isLiteral(ast);
|
||||
fn.constant = isConstant(ast);
|
||||
return fn;
|
||||
},
|
||||
|
||||
@@ -1236,15 +1232,13 @@ ASTCompiler.prototype = {
|
||||
};
|
||||
|
||||
|
||||
function ASTInterpreter(astBuilder, $filter) {
|
||||
this.astBuilder = astBuilder;
|
||||
function ASTInterpreter($filter) {
|
||||
this.$filter = $filter;
|
||||
}
|
||||
|
||||
ASTInterpreter.prototype = {
|
||||
compile: function(expression) {
|
||||
compile: function(ast) {
|
||||
var self = this;
|
||||
var ast = this.astBuilder.ast(expression);
|
||||
findConstantAndWatchExpressions(ast, self.$filter);
|
||||
var assignable;
|
||||
var assign;
|
||||
@@ -1283,8 +1277,6 @@ ASTInterpreter.prototype = {
|
||||
if (inputs) {
|
||||
fn.inputs = inputs;
|
||||
}
|
||||
fn.literal = isLiteral(ast);
|
||||
fn.constant = isConstant(ast);
|
||||
return fn;
|
||||
},
|
||||
|
||||
@@ -1613,20 +1605,21 @@ ASTInterpreter.prototype = {
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
var Parser = function Parser(lexer, $filter, options) {
|
||||
this.lexer = lexer;
|
||||
this.$filter = $filter;
|
||||
this.options = options;
|
||||
function Parser(lexer, $filter, options) {
|
||||
this.ast = new AST(lexer, options);
|
||||
this.astCompiler = options.csp ? new ASTInterpreter(this.ast, $filter) :
|
||||
new ASTCompiler(this.ast, $filter);
|
||||
};
|
||||
this.astCompiler = options.csp ? new ASTInterpreter($filter) :
|
||||
new ASTCompiler($filter);
|
||||
}
|
||||
|
||||
Parser.prototype = {
|
||||
constructor: Parser,
|
||||
|
||||
parse: function(text) {
|
||||
return this.astCompiler.compile(text);
|
||||
var ast = this.ast.ast(text);
|
||||
var fn = this.astCompiler.compile(ast);
|
||||
fn.literal = isLiteral(ast);
|
||||
fn.constant = isConstant(ast);
|
||||
return fn;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user