use of org.kie.dmn.feel.lang.types.VariableSymbol in project drools by kiegroup.
the class ParserHelper method recoverScope.
public void recoverScope(String name) {
LOG.trace("[{}] recoverScope( name: {}) with currentScope: {}", this.currentScope.getName(), name, currentScope);
Scope s = this.currentScope.getChildScopes().get(name);
if (s != null) {
currentScope = s;
if (currentScope.getType() != null && currentScope.getType().equals(BuiltInType.UNKNOWN)) {
enableDynamicResolution();
}
} else {
Symbol resolved = this.currentScope.resolve(name);
if (resolved != null && resolved.getType() instanceof CompositeType) {
pushName(name);
pushScope(resolved.getType());
CompositeType type = (CompositeType) resolved.getType();
for (Map.Entry<String, Type> f : type.getFields().entrySet()) {
this.currentScope.define(new VariableSymbol(f.getKey(), f.getValue()));
}
LOG.trace(".. PUSHED, scope name {} with symbols {}", this.currentName.peek(), this.currentScope.getSymbols());
} else if (resolved != null && resolved.getType() instanceof BuiltInType) {
BuiltInType resolvedBIType = (BuiltInType) resolved.getType();
pushName(name);
pushScope(resolvedBIType);
switch(resolvedBIType) {
// FEEL spec table 53
case DATE:
this.currentScope.define(new VariableSymbol("year", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("month", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("day", BuiltInType.NUMBER));
break;
case TIME:
this.currentScope.define(new VariableSymbol("hour", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("minute", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("second", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("time offset", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("timezone", BuiltInType.NUMBER));
break;
case DATE_TIME:
this.currentScope.define(new VariableSymbol("year", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("month", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("day", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("hour", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("minute", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("second", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("time offset", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("timezone", BuiltInType.NUMBER));
break;
case DURATION:
// TODO might need to distinguish between `years and months duration` and `days and time duration`
this.currentScope.define(new VariableSymbol("years", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("months", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("days", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("hours", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("minutes", BuiltInType.NUMBER));
this.currentScope.define(new VariableSymbol("seconds", BuiltInType.NUMBER));
break;
// table 53 applies only to type(e) is a date/time/duration
case UNKNOWN:
enableDynamicResolution();
break;
default:
break;
}
} else {
pushScope();
}
}
}
use of org.kie.dmn.feel.lang.types.VariableSymbol in project drools by kiegroup.
the class ParserHelper method defineVariable.
public void defineVariable(String variable) {
VariableSymbol var = new VariableSymbol(variable);
this.currentScope.define(var);
}
use of org.kie.dmn.feel.lang.types.VariableSymbol in project drools by kiegroup.
the class ParserHelper method defineVariable.
public void defineVariable(String variable, Type type) {
LOG.trace("defining custom type symbol.");
VariableSymbol var = new VariableSymbol(variable, type);
this.currentScope.define(var);
}
Aggregations