private bool ColorisePi() { CheckFonts(); var rtb = piInput; BeginUpdate(rtb); var input = piInput.Text + " \n"; var lex = new PiLexer(input); try { // start by setting everything to default color and font SetPiSliceColor(new Slice(lex, 0, input.Length - 1), Color.Black, _defaultFont); lex.Process(); foreach (var tok in lex.Tokens) { ColorisePiToken(tok, tok.Slice); } } catch (Exception e) { output.Text = $"{e.Message}: {lex.Error}"; } finally { EndUpdate(rtb); } return(true); }
private void Parse(string text, bool verbose = false) { var lexer = new PiLexer(text); Assert.IsTrue(lexer.Process()); if (verbose) { WriteLine(lexer.ToString()); } if (lexer.Failed) { WriteLine(lexer.Error); } PiParser = new PiParser(lexer); PiParser.Process(lexer, EStructure.None); if (verbose) { WriteLine(PiParser.PrintTree()); } if (PiParser.Failed) { Debug.WriteLine(PiParser.Error); } Assert.IsFalse(PiParser.Failed); Assert.IsNotNull(PiParser.Root); }
public void TestSimpleTokens() { var lexer = new PiLexer("1 2 3"); Assert.IsTrue(lexer.Process()); var parser = new PiParser(lexer); Assert.IsTrue(parser.Process(lexer)); }
protected static PiLexer PiLex(string input) { var lex = new PiLexer(input); if (lex.Failed) { WriteLine("LexerFailed: {0}", lex.Error); } Assert.IsTrue(lex.Process(), lex.Error); return(lex); }
private bool Pi() { var input = Current().Text; var lexer = new PiLexer(input); if (!lexer.Process()) { return(FailLocation(lexer.Error)); } var parser = new PiParser(lexer); if (!parser.Process(lexer)) { return(FailLocation(parser.Error)); } var pi = NewNode(Consume()); pi.Value = parser.Root; Push(pi); return(true); }