Ejemplo n.º 1
0
 public EnumReference(Token token, EnumDefinition enumDefinition, TopLevelConstruct owner)
     : base(token, owner)
 {
     this.EnumDefinition = enumDefinition;
 }
Ejemplo n.º 2
0
        internal override Expression Resolve(ParserContext parser)
        {
            this.Root = this.Root.Resolve(parser);

            string step = this.StepToken.Value;

            if (this.Root is EnumReference)
            {
                EnumDefinition enumDef = ((EnumReference)this.Root).EnumDefinition;

                ConstantResolutionState resolutionState = parser.ConstantAndEnumResolutionState[enumDef];
                if (resolutionState != ConstantResolutionState.RESOLVED)
                {
                    enumDef.Resolve(parser);
                }

                if (step == parser.Keywords.FIELD_ENUM_LENGTH)
                {
                    return(new IntegerConstant(this.FirstToken, enumDef.IntValue.Count, this.Owner));
                }
                if (step == parser.Keywords.FIELD_ENUM_MAX)
                {
                    return(new SpecialEntity.EnumMaxFunction(this.FirstToken, enumDef, this.Owner));
                }
                if (step == parser.Keywords.FIELD_ENUM_VALUES)
                {
                    return(new SpecialEntity.EnumValuesFunction(this.FirstToken, enumDef, this.Owner));
                }

                if (enumDef.IntValue.ContainsKey(step))
                {
                    return(new IntegerConstant(this.FirstToken, enumDef.IntValue[step], this.Owner));
                }
                else
                {
                    throw new ParserException(this.StepToken, "The enum '" + enumDef.Name + "' does not contain a definition for '" + step + "'");
                }
            }

            if (this.Root is BaseKeyword)
            {
                return(new BaseMethodReference(this.Root.FirstToken, this.DotToken, this.StepToken, this.Owner).Resolve(parser));
            }

            if (this.Root is StringConstant)
            {
                if (step == "join")
                {
                    throw new ParserException(this.StepToken,
                                              "There is no join method on strings. Did you mean to do list.join(string) instead?");
                }
                else if (step == "size")
                {
                    throw new ParserException(this.StepToken, "String size is indicated by string.length.");
                }
                else if (step == "length")
                {
                    int length = ((StringConstant)this.Root).Value.Length;
                    return(new IntegerConstant(this.FirstToken, length, this.Owner));
                }
            }

            return(this);
        }