Exemplo n.º 1
0
 public static object ReadVectorHandler2(LispReader stream, string ch, int arg)
 {
     if (stream.ReadChar() != '(')
     {
         throw stream.MakeScannerException("Invalid #() expression");
     }
     var list = stream.ReadDelimitedList(")");
     var obj = new Vector();
     obj.AddRange(list);
     if (arg == -1)
     {
         // default no action
     }
     else if (arg < obj.Count)
     {
         throw new LispException("Vector {0} contains more than {1} items", ToPrintString(obj), arg);
     }
     else if (arg > obj.Count)
     {
         var filler = obj.Count == 0 ? (object)null : obj[obj.Count - 1];
         while (obj.Count < arg)
         {
             obj.Add(filler);
         }
     }
     return obj;
 }
Exemplo n.º 2
0
        public static object ParseInterpolateString(string s)
        {
            var pos = 0;
            var code = new Vector();

            for (var match = InterpolationStringPatterns.Match(s, pos); match.Success; match = match.NextMatch())
            {
                var left = match.Index;
                var sideEffect = false;
                var script = "";

                if (left != pos)
                {
                    code.Add(s.Substring(pos, left - pos));
                }

                pos = match.Index + match.Length;

                if (match.Groups[1].Success)
                {
                    // <%...%> or <%=...%>
                    script = match.Groups[1].Value.Trim();
                    if (script.StartsWith("="))
                    {
                        script = script.Substring(1);
                        sideEffect = false;
                    }
                    else
                    {
                        sideEffect = true;
                    }
                }
                else if (match.Groups[2].Success)
                {
                    // <!...!> or <!=...!>
                    script = match.Groups[2].Value.Trim();
                    if (script.StartsWith("="))
                    {
                        script = script.Substring(1);
                        sideEffect = false;
                    }
                    else
                    {
                        sideEffect = true;
                    }
                }
                else if (match.Groups[3].Success)
                {
                    // ${...}
                    script = match.Groups[3].Value;
                    sideEffect = false;
                }

                script = script.Trim();

                if (script.Length > 0)
                {
                    if (sideEffect)
                    {
                        if (script[0] != '(')
                        {
                            // must have function call to have side effect
                            script = "(with-output-to-string ($stdout) (" + script + "))";
                        }
                        else
                        {
                            script = "(with-output-to-string ($stdout) " + script + ")";
                        }
                    }
                    var statements = ReadAllFromString(script);

                    if (statements.Count > 1)
                    {
                        code.Add(new Cons(Symbols.Do, AsList(statements)));
                    }
                    else
                    {
                        code.AddRange(statements);
                    }
                }
            }

            if (code.Count == 0)
            {
                return s;
            }
            else
            {
                if (pos < s.Length)
                {
                    code.Add(s.Substring(pos, s.Length - pos));
                }

                return new Cons(Symbols.Str, AsList(code));
            }
        }
Exemplo n.º 3
0
 public static object ReadVectorHandler(LispReader stream, char ch)
 {
     var list = stream.ReadDelimitedList("]");
     var obj = new Vector();
     obj.AddRange(list);
     return obj;
 }