Allowed effects and calculations to target nearest ancestors of #type

This commit is contained in:
Stefan Zermatten
2021-02-02 16:11:59 +02:00
parent 69c72e0987
commit aaa5d0b63b
13 changed files with 69 additions and 17 deletions

View File

@@ -24,7 +24,7 @@ function id(x) { return x[0]; }
value: s => s.slice(1, -1),
},
name: {
match: /[a-zA-Z_]*[a-ce-zA-Z_][a-zA-Z0-9_]*/,
match: /[a-zA-Z_#]*[a-ce-zA-Z_#][a-zA-Z0-9_#]*/,
type: moo.keywords({
'keywords': ['true', 'false'],
}),

View File

@@ -22,7 +22,7 @@
value: s => s.slice(1, -1),
},
name: {
match: /[a-zA-Z_]*[a-ce-zA-Z_][a-zA-Z0-9_]*/,
match: /[a-zA-Z_#]*[a-ce-zA-Z_#][a-zA-Z0-9_#]*/,
type: moo.keywords({
'keywords': ['true', 'false'],
}),

View File

@@ -7,7 +7,7 @@ export default class AccessorNode extends ParseNode {
this.name = name;
this.path = path;
}
compile(scope){
compile(scope, context){
let value = scope && scope[this.name];
// For objects, get their value
this.path.forEach(name => {
@@ -16,14 +16,21 @@ export default class AccessorNode extends ParseNode {
});
let 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 AccessorNode({
name: this.name,
path: this.path,
});
} else {
throw new Meteor.Error(`Unexpected case: ${this.name} resolved to ${value}`);
if (context) context.storeError({
type: 'error',
message: `${this.name} returned an unexpected type`
});
return new AccessorNode({
name: this.name,
path: this.path,
});
}
}
reduce(scope, context){