Search in sources :

Example 1 with SimpleType

use of org.kie.dmn.feel.lang.SimpleType 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);
        Type scopeType = resolved != null ? resolved.getType() : null;
        if (scopeType instanceof GenListType) {
            scopeType = ((GenListType) scopeType).getGen();
        }
        if (resolved != null && scopeType instanceof CompositeType) {
            pushScope(scopeType);
            CompositeType type = (CompositeType) scopeType;
            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 && scopeType instanceof SimpleType) {
            BuiltInType resolvedBIType = null;
            if (scopeType instanceof BuiltInType) {
                resolvedBIType = (BuiltInType) scopeType;
            } else if (scopeType instanceof AliasFEELType) {
                resolvedBIType = ((AliasFEELType) scopeType).getBuiltInType();
            } else {
                throw new UnsupportedOperationException("Unsupported BIType " + scopeType + "!");
            }
            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));
                    if (isFeatDMN12weekday()) {
                        // Table 60 spec DMN v1.2
                        this.currentScope.define(new VariableSymbol("weekday", 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.DURATION));
                    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));
                    if (isFeatDMN12weekday()) {
                        // Table 60 spec DMN v1.2
                        this.currentScope.define(new VariableSymbol("weekday", 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.DURATION));
                    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;
                case RANGE:
                    this.currentScope.define(new VariableSymbol("start included", BuiltInType.BOOLEAN));
                    this.currentScope.define(new VariableSymbol("start", BuiltInType.UNKNOWN));
                    this.currentScope.define(new VariableSymbol("end", BuiltInType.UNKNOWN));
                    this.currentScope.define(new VariableSymbol("end included", BuiltInType.BOOLEAN));
                    break;
                // table 53 applies only to type(e) is a date/time/duration
                case UNKNOWN:
                    enableDynamicResolution();
                    break;
                default:
                    break;
            }
        } else {
            pushScope();
        }
    }
}
Also used : Symbol(org.kie.dmn.feel.lang.Symbol) VariableSymbol(org.kie.dmn.feel.lang.types.VariableSymbol) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) SimpleType(org.kie.dmn.feel.lang.SimpleType) SimpleType(org.kie.dmn.feel.lang.SimpleType) CompositeType(org.kie.dmn.feel.lang.CompositeType) Type(org.kie.dmn.feel.lang.Type) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) AliasFEELType(org.kie.dmn.feel.lang.types.AliasFEELType) GenListType(org.kie.dmn.feel.lang.types.GenListType) Scope(org.kie.dmn.feel.lang.Scope) GenListType(org.kie.dmn.feel.lang.types.GenListType) AliasFEELType(org.kie.dmn.feel.lang.types.AliasFEELType) Map(java.util.Map) VariableSymbol(org.kie.dmn.feel.lang.types.VariableSymbol) CompositeType(org.kie.dmn.feel.lang.CompositeType)

Aggregations

Map (java.util.Map)1 CompositeType (org.kie.dmn.feel.lang.CompositeType)1 Scope (org.kie.dmn.feel.lang.Scope)1 SimpleType (org.kie.dmn.feel.lang.SimpleType)1 Symbol (org.kie.dmn.feel.lang.Symbol)1 Type (org.kie.dmn.feel.lang.Type)1 AliasFEELType (org.kie.dmn.feel.lang.types.AliasFEELType)1 BuiltInType (org.kie.dmn.feel.lang.types.BuiltInType)1 GenListType (org.kie.dmn.feel.lang.types.GenListType)1 VariableSymbol (org.kie.dmn.feel.lang.types.VariableSymbol)1