internal override Expression Resolve(Parser parser) { this.Root = this.Root.Resolve(parser); this.Index = this.Index.Resolve(parser); if (this.Root is CompileTimeDictionary) { // Swap out this bracketed expression with a fixed constant. CompileTimeDictionary root = (CompileTimeDictionary)this.Root; if (root.Type == "var") { if (this.Index is StringConstant) { string index = ((StringConstant)this.Index).Value; if (parser.BuildContext.BuildVariableLookup.ContainsKey(index)) { Crayon.BuildContext.BuildVarCanonicalized buildVar = parser.BuildContext.BuildVariableLookup[index]; switch (buildVar.Type) { case Crayon.BuildContext.VarType.INT: return(new IntegerConstant(this.FirstToken, buildVar.IntValue, this.FunctionOrClassOwner)); case Crayon.BuildContext.VarType.FLOAT: return(new FloatConstant(this.FirstToken, buildVar.FloatValue, this.FunctionOrClassOwner)); case Crayon.BuildContext.VarType.STRING: return(new StringConstant(this.FirstToken, buildVar.StringValue, this.FunctionOrClassOwner)); case Crayon.BuildContext.VarType.BOOLEAN: return(new BooleanConstant(this.FirstToken, buildVar.BoolValue, this.FunctionOrClassOwner)); default: throw new System.Exception("This should not happen."); // invalid types filtered during build context construction. } } else { return(new NullConstant(this.FirstToken, this.FunctionOrClassOwner)); // TODO: strict mode that enforces this. There are two ways this could be done: // 1) $var['foo'] vs $optional['foo'] // 2) <strictvars>true</strictvars> // I kind of prefer #1. // throw new ParserException(this.Index.FirstToken, "The build variable with id '" + index + "' is not defined for this target."); } } } else { throw new System.Exception("Unknown compile time dictionary type."); } } return(this); }
private void CompileCompileTimeDictionary(CompileTimeDictionary compileTimeDictionary) { if (compileTimeDictionary.Type == "var") { throw new ParserException(compileTimeDictionary.FirstToken, "$var is a compile-time dictionary and must be dereferenced with a hardcoded string constant."); } throw new Exception(); // should not happen. }