private static void BuildCC() { var projectDir = DirRef.ProjectDir(); var linguCC = projectDir.Up.Dir("LinguCC"); var genDir = linguCC.Dir("Gen"); Environment.CurrentDirectory = genDir; var file = FileRef.From("./Lingu.Grammar"); var dumps = FileRef.From("./Lingu").Add(".Out"); var context = Timer.Time("context", () => new LinguContext()); var source = Timer.Time("source", () => Source.FromFile(file)); var lexer = Timer.Time("lexer", () => new Lexer(context, source)); var parser = Timer.Time("parser", () => new Parser(context, lexer)); var parseTree = Timer.Time("parse", () => parser.Parse()); Timer.Time("tree-dump", () => new TreeDumper(dumps.Add(".Tree")).Dump(parseTree)); var ast = Timer.Time("ast", () => new TreeBuilder().Visit(parseTree)); var grammar = Timer.Time("build", () => new GrammarBuilder(ast).Build()); Timer.Time("dump", () => new Dumper(grammar).Dump(dumps)); Timer.Time("write", () => new CSharpWriter(grammar, file, genDir).Write()); }
public void Build() { var lingu = new LinguContext(); var projectDir = DirRef.ProjectDir(); var ponyDir = projectDir.Dir("Ponies"); Environment.CurrentDirectory = ponyDir; var file = FileRef.From("./Pony.Grammar"); var dumps = FileRef.From("./Pony").Add(".Out"); var source = Source.FromFile(file); var parseTree = lingu.Try(source); if (parseTree != null) { new TreeDumper(dumps.Add(".Tree")).Dump(parseTree); var ast = new TreeBuilder().Visit(parseTree); if (ast != null) { var grammar = new GrammarBuilder(ast).Build(); if (grammar != null) { new Dumper(grammar).Dump(dumps); new CSharpWriter(grammar, file, ponyDir).Write(); } } } }
private void Build() { var options = new HimeTaskOptions { Public = true, Namespace = "Lingu.Boot.Hime", //RNGLR = true, Debug = true, Grammar = "Lingu", }; Environment.CurrentDirectory = $"{ProjectDir}"; var source = FileRef.From($"{ProjectDir}Lingu.Grammar"); var parser = FileRef.From($"{ProjectDir}LinguParser.cs"); var lexer = FileRef.From($"{ProjectDir}LinguLexer.cs"); var visitor = FileRef.From($"{ProjectDir}LinguVisitor.cs"); Generate(options, source); var tweaker = new Tweaker(parser, visitor); Console.WriteLine($"[Info] Tweaking new Visitor at {visitor.FileName} ..."); tweaker.TweakVisitor(); tweaker.TweakLexer(lexer); tweaker.TweakParser(parser); }
private void BuildTree(string stem, string content) { Environment.CurrentDirectory = DirRef.ProjectDir().Dir("Grammar"); var grammarSource = FileRef.From($"./{stem}.Grammar"); var dests = FileRef.From(grammarSource.Directory + "/Out/" + grammarSource.BaseName).With(".Out"); var raw = Parser.Parse(grammarSource); if (raw != null) { var builder = new Build.GrammarBuilder(raw); var grammar = builder.Build(); new Dumper(grammar).Dump(dests); var ccOut = DirRef.ProjectDir().Dir("..").Dir("Lingu.CC").Dir("Gen"); var csharp = new CSharpWriter(grammar, grammarSource, ccOut); csharp.Write(); Debug.Assert(grammar.Eof != null); var dfaSet = new CompactDfaReader(new BinReader(new CompactDfaWriter(grammar).Write())).Read(); //var dfaSet = new DfaSet(grammar.Dfas.Select(dfa => dfa.Convert()).ToArray(), grammar.StateToDfa, grammar.SpacingDfa.Convert()); var context = new LinguContext( grammar.Symbols, grammar.Productions, grammar.ParseTable, dfaSet); Source source; if (File.Exists(content)) { source = Source.FromFile(content); } else { source = Source.FromString(content); } var tree = context.Try(source); new TreeDumper(dests.Add(".Tree")).Dump(tree); } }
private static IEnumerable <FileRef> EnumeratePonies(params DirRef[] roots) { foreach (var root in roots) { foreach (var pony in Directory.EnumerateFiles(root, "*.pony", SearchOption.AllDirectories)) { if (pony.Contains(@"\ponycc\test\fixtures\") || pony.Contains(@"\adv5.pony") || pony.Contains(@"\bench\bench_pg.pony") || pony.Contains(@"\examples\clisample.pony") || pony.Contains(@"\pony-stats\stats\test.pony") || pony.Contains(@"\pony-queue\queue.pony")) { continue; } yield return(FileRef.From(pony)); } } }
private void BuildCC0() { var projectDir = DirRef.ProjectDir(); var cc0 = projectDir.Dir("..").Dir("LinguCC0"); var genDir = cc0.Dir("Gen"); Environment.CurrentDirectory = genDir; var grammarSource = FileRef.From($"./Lingu.Grammar"); var outs = FileRef.From("./Lingu").Add(".Out"); var raw = Parser.Parse(grammarSource); if (raw != null) { var builder = new GrammarBuilder(raw); var grammar = builder.Build(); new Dumper(grammar).Dump(outs); var csharp = new CSharpWriter(grammar, grammarSource, genDir); csharp.Write(); } }