Ejemplo n.º 1
0
        public void Execute(Repl repl, ReplParser.CatContext tree, bool piped)
        {
            var args = tree.arg();

            if (args.Length == 0)
            {
                args = null;
            }
            var           list = new Globbing().Contents(args?.Select(t => repl.GetArg(t)).ToList());
            StringBuilder sb   = new StringBuilder();

            foreach (var f in list)
            {
                if (f is DirectoryInfo d)
                {
                    throw new Exception("Cannot cat a directory.");
                }
                else
                {
                    string input = System.IO.File.ReadAllText(f.FullName);
                    sb.Append(input);
                }
            }
            repl.input_output_stack.Push(sb.ToString());
        }
Ejemplo n.º 2
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.º 3
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.");
            }
        }
Ejemplo n.º 4
0
        public void Execute(Repl repl, ReplParser.LsContext tree, bool piped)
        {
            var args = tree.arg();

            if (args.Length == 0)
            {
                args = null;
            }
            var list = new Globbing().Contents(args?.Select(t => repl.GetArg(t)).ToList());

            foreach (var f in list)
            {
                if (f is DirectoryInfo d)
                {
                    Console.WriteLine($"{d.Name}/");
                }
                else
                {
                    Console.WriteLine($"{f.Name}");
                }
            }
        }
Ejemplo n.º 5
0
 public static Filter HaveDependencyOn(string name)
 {
     return(HaveDependencyOn(Globbing.New(name)));
 }
Ejemplo n.º 6
0
        public void Execute(Repl repl, ReplParser.DiffContext tree, bool piped)
        {
            var args             = tree.arg();
            var expr             = args.Select(t => repl.GetArg(t)).ToList();
            var list             = new Globbing().Contents(args?.Select(t => repl.GetArg(t)).ToList());
            var lines            = list.Select(f => System.IO.File.ReadAllText(f.FullName)).ToList();
            var serializeOptions = new JsonSerializerOptions();

            serializeOptions.Converters.Add(new AntlrJson.ParseTreeConverter());
            serializeOptions.WriteIndented = false;
            var tuples = lines.Select(t => JsonSerializer.Deserialize <AntlrJson.ParsingResultSet>(t, serializeOptions)).ToList();
            var lexer  = tuples[0].Lexer;
            var parser = tuples[0].Parser;
            var trees  = tuples.Select(t => new Tree(t.Nodes[0], parser, lexer)).ToList();
            var result = ZhangShashaCSharp.Tree.ZhangShasha(trees[0], trees[1]);

            foreach (var o in result.Item2)
            {
                //System.Console.Write(o.O.ToString() + " " + o.N1 + " => " + o.N2 + " ");
                if (o.O == Operation.Op.Insert)
                {
                    var zs_node = trees[1].all_nodes[o.N2];
                    //System.Console.Write(zs_node.label);
                    var a_node = trees[1].antlr_nodes[zs_node];
                    if (a_node is TerminalNodeImpl term)
                    {
                        var name = term.Symbol.Text;
                        var line = term.Symbol.Line;
                        var col  = term.Symbol.Column;
                        System.Console.WriteLine("+++ (" + line + "," + col + ") " + name);
                    }
                }
                else if (o.O == Operation.Op.Delete)
                {
                    var zs_node = trees[0].all_nodes[o.N1];
                    //System.Console.Write(zs_node.label);
                    var a_node = trees[0].antlr_nodes[zs_node];
                    if (a_node is TerminalNodeImpl term)
                    {
                        var name = term.Symbol.Text;
                        var line = term.Symbol.Line;
                        var col  = term.Symbol.Column;
                        System.Console.WriteLine("--- (" + line + "," + col + ") " + name);
                    }
                }
                else if (o.O == Operation.Op.Change)
                {
                    var zs_node  = trees[0].all_nodes[o.N1];
                    var a_node   = trees[0].antlr_nodes[zs_node];
                    var zs_node2 = trees[1].all_nodes[o.N2];
                    var a_node2  = trees[1].antlr_nodes[zs_node2];
                    if (a_node is TerminalNodeImpl term)
                    {
                        var name = term.Symbol.Text;
                        var line = term.Symbol.Line;
                        var col  = term.Symbol.Column;
                        System.Console.WriteLine("--- (" + line + "," + col + ") " + name);
                    }
                    if (a_node2 is TerminalNodeImpl term2)
                    {
                        var name = term2.Symbol.Text;
                        var line = term2.Symbol.Line;
                        var col  = term2.Symbol.Column;
                        System.Console.WriteLine("+++ (" + line + "," + col + ") " + name);
                    }
                }
            }
            //System.Console.WriteLine("======");
            //foreach (var o in trees[0].all_nodes)
            //{
            //    System.Console.WriteLine(o.Key + " " + o.Value.label + " " + trees[0].antlr_nodes[o.Value]);
            //}
            //System.Console.WriteLine("======");
            //foreach (var o in trees[1].all_nodes)
            //{
            //    System.Console.WriteLine(o.Key + " " + o.Value.label + " " + trees[1].antlr_nodes[o.Value]);
            //}
        }