Esempio n. 1
0
 public InputVar GetVar(string name, bool originator = true)
 {
     if (originator)
     {
         name = name.ToLower();
     }
     if (!Vars.TryGetValue(name, out InputVar var))
     {
         if (ParentScope != null)
         {
             InputVar pvar = ParentScope.GetVar(name, false);
             if (pvar != null)
             {
                 return(pvar);
             }
         }
         if (originator)                             // not found, return an undefined var (the reason we do this is so that
         {
             return(DefineAndReturnVar(name, null)); // new var will work properly, otherwise it finds no name)
         }
         // ^ I will probably regret this design decision when people have errors from undefined
         // variables and can't figure out what's going on
         return(null);
     }
     return(var);
 }
Esempio n. 2
0
        private static InputVar GetVarAtRuntime(InputContext context, object o, string errtype)
        {
            InputVar var = null;

            if (o is InputVar)
            {
                var = o as InputVar;
            }
            else if (o is AccessorResult)
            {
                AccessorResult a = o as AccessorResult;
                if (!a.IsVar)
                {
                    throw new Exception(errtype + " not supported for non-var types.");
                }
                var = a.Var;
            }
            else if (o is string)
            {
                var = context.GetVar(o as string);
                if (var == null)
                {
                    throw new Exception("Var " + o.ToString() + " not found at runtime.");
                }
            }
            if (var == null)
            {
                throw new Exception("Could not parse '" + o.ToString() + "' as var for " + errtype + ".");
            }
            return(var);
        }
Esempio n. 3
0
        public static InputVar LookupVar(string varname, InputContext context)
        {
            InputVar var = context.GetVar(varname);

            //if (var == null)
            //    context.DefineVar(varname, "UNDEFINED");
            return(var);
        }