Beispiel #1
0
 /// <summary>
 /// Add built-in debug functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.repl", new Repl());
     scope.SetValue("l3.debug.break", new Break());
     scope.SetValue("l3.debug.getTicks", new GetTicks());
     scope.SetValue("l3.throw", new Throw());
 }
Beispiel #2
0
 /// <summary>
 /// Add built-in array functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.mapToMap", new MapToMap());
     scope.SetValue("l3.mapToArray", new MapToArray());
     scope.SetValue("l3.getMapKeys", new GetMapKeys());
     scope.SetValue("l3.getMapValues", new GetMapValues());
 }
Beispiel #3
0
 /// <summary>
 /// Add built-in array functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.combine", new Combine());
     scope.SetValue("l3.addToArray", new AddToArray());
     scope.SetValue("l3.arrayToArray", new ArrayToArray());
     scope.SetValue("l3.foldLeft", new FoldLeft());
     scope.SetValue("l3.foldRight", new FoldRight());
 }
Beispiel #4
0
 /// <summary>
 /// Add built-in Value functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.getScope", new GetScope());
     scope.SetValue("l3.popScope", new PopScope());
     scope.SetValue("l3.callWithScope", new CallWithScope());
     scope.SetValue("l3.evalWithScope", new EvalWithScope());
     scope.SetValue("l3.onScopeExit", new OnScopeExit());
 }
Beispiel #5
0
 /// <summary>
 /// Add built-in Value functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.equal?", new IsEqual());
     scope.SetValue("l3.anyEqual?", new IsAnyEqual());
     scope.SetValue("l3.and?", new LogicalAnd());
     scope.SetValue("l3.or?", new LogicalOr());
     scope.SetValue("l3.not?", new LogicalNot());
 }
Beispiel #6
0
 /// <summary>Add values from one scope onto another</summary>
 internal static void AddToScope(IScope from, IScope to)
 {
     Dictionary<string, Value> dict = from.AsMap.Raw;
     if (dict != null)
         foreach (string key in dict.Keys)
             to.SetValue(key, dict[key]);
 }
Beispiel #7
0
 /// <summary>
 /// Add built-in functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.toString", new ConvertToString());
     scope.SetValue("l3.intToChar", new IntToChar());
     scope.SetValue("l3.stringConcat", new StringConcat());
     scope.SetValue("l3.formatTable", new FormatTable());
     scope.SetValue("l3.formatTable2", new FormatTable2());
     scope.SetValue("l3.stringToArray", new StringToArray());
 }
Beispiel #8
0
 /// <summary>
 /// Add built-in math functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.add", new Add());
     scope.SetValue("l3.addArray", new AddArray());
     scope.SetValue("l3.subtract", new Subtract());
     scope.SetValue("l3.multiply", new Multiply());
     scope.SetValue("l3.multiplyArray", new MultiplyArray());
     scope.SetValue("l3.divide", new Divide());
     scope.SetValue("l3.modulo", new Modulo());
     scope.SetValue("l3.sqrt", new SquareRoot());
     scope.SetValue("l3.power", new Power());
     scope.SetValue("l3.lt", new LessThan());
     scope.SetValue("l3.gt", new GreaterThan());
     scope.SetValue("l3.floor", new Floor());
     scope.SetValue("l3.ceiling", new Ceiling());
     scope.SetValue("l3.bitAnd", new BitAnd());
     scope.SetValue("l3.bitOr", new BitOr());
 }
Beispiel #9
0
 /// <summary>
 /// Add built-in IO functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.print", new Print());
 }
Beispiel #10
0
        /// <summary>
        /// Add a new function (prefix, postfix or infix), to the scope
        /// </summary>
        /// <param name="scope">scope to add function definition to</param>
        /// <param name="name">name of the new function</param>
        /// <param name="pattern1">null, variable name, or pattern to match for previous token</param>
        /// <param name="pattern2">null, variable name, or pattern to match for next token</param>
        /// <param name="rawLines">lines to parse and run when function is invoked</param>
        /// <param name="precedence">the order in which function should be evaled</param>
        internal static void Do(IScope scope, string name,
			Value pattern1, Value pattern2, List<Value> rawLines, Order precedence)
        {
            ValueFunction func = new UserFunction(pattern1, pattern2, rawLines, precedence);
            scope.SetValue(name, func);
        }
Beispiel #11
0
 /// <summary>
 /// Add built-in module functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.loadModule", new LoadModule());
 }
Beispiel #12
0
            internal override Value Eval(Value arg, IScope scope)
            {
                // extract the delimiter strings
                string delims = arg.AsString;
                string start = delims.Substring(0, delims.Length / 2);
                string end = delims.Substring(delims.Length / 2, delims.Length - delims.Length / 2);

                // create the delimiter & store it on the current scope
                ValueDelimiter value = new ValueDelimiter(end, DelimiterType);
                scope.SetValue(start, value);
                return value;
            }
Beispiel #13
0
 /// <summary>
 /// Add built-in Value functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.setValue", new SetValue());
     scope.SetValue("l3.getValue", new GetValue());
     scope.SetValue("l3.copy", new Copy());
     scope.SetValue("l3.createMap", new CreateMap());
     scope.SetValue("l3.createRange", new CreateRange());
     scope.SetValue("l3.createFunction", new CreateFunction());
     scope.SetValue("l3.createDelimiter", new CreateDelimiter());
     scope.SetValue("l3.createEvalDelimiter", new CreateEvalDelimiter());
     scope.SetValue("l3.createArrayDelimiter", new CreateArrayDelimiter());
     scope.SetValue("l3.getCount", new GetCount());
     scope.SetValue("l3.getMetadata", new GetMetadata());
     scope.SetValue("l3.getType", new GetTypeFunction());
     scope.SetValue("l3.getFunctionBody", new GetFunctionBody());
     scope.SetValue("l3.eval", new EvalValue());
     scope.SetValue("l3.bindFunction", new BindFunction());
 }
Beispiel #14
0
 /// <summary>
 /// Add built-in If functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.loop", new BasicLoop());
     scope.SetValue("l3.forEach", new ForEach());
 }
Beispiel #15
0
 /// <summary>
 /// Add built-in If functions to the scope
 /// </summary>
 internal static void Register(IScope scope)
 {
     scope.SetValue("l3.ifBody", new IfBody());
     scope.SetValue("l3.ifValue", new IfValue());
 }
Beispiel #16
0
        /// <summary>
        /// Start a read-eval-print loop at the console
        /// </summary>
        /// <param name="scope">scope for parse-eval</param>
        internal static void Do(IScope scope, string prompt)
        {
            prompt += " ";
            string s = "";
            do
            {
                Console.Write(prompt);

                // keep reading lines as long as they end with \
                List<string> lines = new List<string>();
                bool bMore = false;
                do
                {
                    s = Console.ReadLine();
                    bMore = (s.Length > 2 && s[s.Length - 1] == '\\' && s[s.Length - 2] == ' ');
                    if (bMore)
                        s = s.Substring(0, s.Length - 2);
                    lines.Add(s);
                } while (bMore);
                LineConsumer consumer = new LineConsumer(lines);

                // eval the line(s)
                try
                {
                    Value v = EvalLines.Do(consumer, scope);
                    Console.WriteLine(v.ToString());
                }
                catch (Loki3Exception error)
                {
                    // if we're at the root scope, remove it to avoid infinite
                    // recursion in Map.ToString
                    if (error.Errors.ContainsKey("l3.error.scope"))
                        if (error.Errors["l3.error.scope"].AsMap == scope.AsMap)
                            error.Errors.Raw.Remove("l3.error.scope");

                    if (scope.Exists("prettify") != null)
                    {
                        scope.SetValue("lastError", new ValueMap(error.Errors));
                        Value v = loki3.builtin.test.TestSupport.ToValue("prettify lastError", scope);
                        Console.WriteLine("LOKI3 ERROR:\n" + v.AsString);
                        if (error.Errors.ContainsKey(Loki3Exception.keyScope))
                        {
                            scope.SetValue("lastScope", error.Errors[Loki3Exception.keyScope]);
                            try
                            {
                                v = loki3.builtin.test.TestSupport.ToValue("dumpStack lastScope", scope);
                                Console.WriteLine("STACK:\n" + v.AsString);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("ERROR PRINTING STACK:\n" + e.ToString());
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine(error.ToString());
                    }
                }
                catch (Exception error)
                {
                    Console.WriteLine("INTERNAL ERROR: " + error.ToString());
                }
            } while (s != "");
        }