private void Compile() { using (StreamWriter sw = new StreamWriter("temp.as")) { sw.WriteLine(fastColoredTextBox1.Text); } var lexed = Pygmentize.File("temp.as").WithLexer(new ASLexer()); TokenStream ts = new TokenStream(lexed.GetTokens().ToList()); ts.ProgressChanged += ProgressChanged; CompilationUnit file = null; try { file = new Parser(ts).Parse(); JObject obj = JObject.Parse(file.ToJSON()); TreeNode parent = Json2Tree(obj); parent.Text = "Root"; treeView1.Nodes.Add(parent); } catch (CompilerException e) { treeView1.Nodes.Add(Exception2Tree(e)); fastColoredTextBox1.AddHint(new Range(fastColoredTextBox1, CharnoToPlace(this.fastColoredTextBox1, ts.charno), CharnoToPlace(this.fastColoredTextBox1, ts.charno)), e.ToString()); } catch (Exception e) { treeView1.Nodes.Add(Exception2Tree(e)); } ProgressChanged(1, 1); ProgressChanged(0, 1); }
public static void Main(string[] args) { //////////////Utils.DEBUG_PARSING = false; //new System.Threading.Thread(() => //new AS2CS().ShowDialog()).Start(); //Console.WindowWidth = (Console.LargestWindowWidth / 4) * 3; var lexed = Pygmentize.File(@"rotmgsrc\com\company\assembleegameclient\appengine\SavedCharactersList.as").WithLexer(new ASLexer()); TokenStream ts = new TokenStream(lexed.GetTokens().ToList()); //foreach (Token t in lexed.GetTokens().ToList()) //{ // Console.WriteLine(t.ToString()); //} lexed.WithFormatter(new HtmlFormatter(new HtmlFormatterOptions() { })).ToFile("output.html"); File.WriteAllText("output.html", File.ReadAllText("output.html").Insert(0, "<style>html{background-color:#272822}.c{color:#75715e}.err{color:#960050;background-color:#1e0010}.k{color:#66d9ef}.l{color:#ae81ff}.n{color:#f8f8f2}.o{color:#f92672}.p{color:#f8f8f2}.cm{color:#75715e}.cp{color:#75715e}.c1{color:#75715e}.cs{color:#75715e}.ge{font-style:italic}.gs{font-weight:700}.kc{color:#66d9ef}.kd{color:#66d9ef}.kn{color:#f92672}.kp{color:#66d9ef}.kr{color:#66d9ef}.kt{color:#66d9ef}.ld{color:#e6db74}.m{color:#ae81ff}.s{color:#e6db74}.na{color:#a6e22e}.nb{color:#f8f8f2}.nc{color:#a6e22e}.no{color:#66d9ef}.nd{color:#a6e22e}.ni{color:#f8f8f2}.ne{color:#a6e22e}.nf{color:#a6e22e}.nl{color:#f8f8f2}.nn{color:#f8f8f2}.nx{color:#a6e22e}.py{color:#f8f8f2}.nt{color:#f92672}.nv{color:#f8f8f2}.ow{color:#f92672}.w{color:#f8f8f2}.mf{color:#ae81ff}.mh{color:#ae81ff}.mi{color:#ae81ff}.mo{color:#ae81ff}.sb{color:#e6db74}.sc{color:#e6db74}.sd{color:#e6db74}.s2{color:#e6db74}.se{color:#ae81ff}.sh{color:#e6db74}.si{color:#e6db74}.sx{color:#e6db74}.sr{color:#e6db74}.s1{color:#e6db74}.ss{color:#e6db74}.bp{color:#f8f8f2}.vc{color:#f8f8f2}.vg{color:#f8f8f2}.vi{color:#f8f8f2}.il{color:#ae81ff}.gu{color:#75715e}.gd{color:#f92672}.gi{color:#a6e22e}</style>" )); Process.Start("output.html"); CompilationUnit file = null; file = new Parser(ts).Parse(); new TreeDebug(file.ToJSON()).ShowDialog(); //BugScan("rotmgsrc"); }
public void ToHtml() { var result = Pygmentize.Content("class Foo { }") .WithLexer(new CSharpLexer()) .ToHtml() .AsString(); Check.That(result).StartsWith("<div class=\"highlight\" >"); }
public void BaseCase() { var result = Pygmentize.Content("") .WithLexer(new PlainLexer()) .WithFormatter(new NullFormatter()) .AsString(); Check.That(result).IsEqualTo(""); }
public void FromFile() { var filename = Path.GetTempFileName() + ".cs"; // autodetects lexer from filename File.WriteAllText(filename, "class Foo { }"); var result = Pygmentize.File(filename) .WithFormatter(new NullFormatter()) .AsString(); Check.That(result).IsEqualTo("class Foo { }"); }
public void ToFile() { var file = Path.GetTempFileName() + ".html"; //autodetects output formatter from filename Pygmentize.Content("class Foo { }") .WithLexer(new CSharpLexer()) .ToFile(file); var result = File.ReadAllText(file); Check.That(result).StartsWith("<div class=\"highlight\" >"); }
public static void BugScan(string path) { int no = 0; using (StreamWriter sw = new StreamWriter("bugs.txt")) { //List<string> r = new List<string>(); foreach (string f in Directory.GetFiles(path, "*.as", SearchOption.AllDirectories)) { try { var lexed = Pygmentize.File(f).WithLexer(new ASLexer()); TokenStream ts = new TokenStream(lexed.GetTokens().ToList()); //ts.ProgressUpdate = 500; ts.dontPrUpdt = true; //ts.ProgressChanged += PrintProgress; CompilationUnit file = null; file = new Parser(ts).Parse(); //PrintProgress(100, 100); } catch { Console.ForegroundColor = ConsoleColor.Red; //r.Add(f); sw.WriteLine(f); sw.Flush(); no++; } Console.WriteLine(new FileInfo(f).Name); Console.ResetColor(); } sw.WriteLine(no); //using (StreamWriter sw = new StreamWriter("bugs.txt")) //{ // foreach (string str in r) // { // sw.WriteLine(str); // } //} } }