Ejemplo n.º 1
0
        public void Execute(Repl repl, ReplParser.CdContext tree, bool piped)
        {
            var expr = repl.GetArg(tree.arg());
            var list = new Globbing().GetDirectory(expr);

            if (list.Count == 0)
            {
                throw new Exception("directory does not exist.");
            }
            else if (list.Count >= 2)
            {
                throw new Exception("ambigous");
            }
            Directory.SetCurrentDirectory(list.First().FullName);
        }
Ejemplo n.º 2
0
        public void Execute(Repl repl, ReplParser.ReadContext tree, bool piped)
        {
            var    f    = repl.GetArg(tree.arg());
            string here = null;

            if (!f.Contains("."))
            {
                here = f;
            }
            if (f != null)
            {
                var files = new Globbing().Contents(f);
                if (files.Count() != 1)
                {
                    throw new Exception("Ambiguous match for '" + f + "'.");
                }
                var doc = repl._docs.ReadDoc(files.First().FullName);
                repl.stack.Push(doc);
            }
            else if (here != null)
            {
                StringBuilder sb = new StringBuilder();
                for (; ;)
                {
                    string cl;
                    if (repl.script_file != null)
                    {
                        cl = repl.lines[repl.current_line_index++];
                    }
                    else
                    {
                        cl = Console.ReadLine();
                    }
                    if (cl == here)
                    {
                        break;
                    }
                    sb.AppendLine(cl);
                }
                var s   = sb.ToString();
                var doc = repl._docs.CreateDoc("temp" + repl.current_line_index + ".g4", s);
                repl.stack.Push(doc);
            }
            else
            {
                throw new Exception("not sure what to read.");
            }
        }