Added functions and ensured the context was being passed around correctly
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import ParseNode from '/imports/parser/parseTree/ParseNode.js';
|
||||
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
|
||||
import ErrorNode from '/imports/parser/parseTree/ErrorNode.js';
|
||||
|
||||
export default class SymbolNode extends ParseNode {
|
||||
constructor({name}){
|
||||
@@ -19,23 +18,25 @@ export default class SymbolNode extends ParseNode {
|
||||
type = typeof value;
|
||||
}
|
||||
if (type === 'string' || type === 'number' || type === 'boolean'){
|
||||
return new ConstantNode({value, type, previousNodes: [this]});
|
||||
return new ConstantNode({value, type});
|
||||
} else if (type === 'undefined'){
|
||||
return new SymbolNode({
|
||||
name: this.name,
|
||||
previousNodes: [this],
|
||||
});
|
||||
} else {
|
||||
throw new Meteor.Error(`Unexpected case: ${this.name} resolved to ${value}`);
|
||||
}
|
||||
}
|
||||
reduce(scope){
|
||||
reduce(scope, context){
|
||||
let result = this.compile(scope);
|
||||
if (result instanceof SymbolNode){
|
||||
return new ErrorNode({
|
||||
node: result,
|
||||
error: `${this.toString()} could not be resolved`,
|
||||
previousNodes: [result],
|
||||
if (context) context.storeError({
|
||||
type: 'info',
|
||||
message: `${result.toString()} not found, set to 0`
|
||||
});
|
||||
return new ConstantNode({
|
||||
type: 'number',
|
||||
value: 0,
|
||||
});
|
||||
} else {
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user