Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        public void TestSimpleTokens()
        {
            var lexer = new PiLexer("1 2 3");

            Assert.IsTrue(lexer.Process());
            var parser = new PiParser(lexer);

            Assert.IsTrue(parser.Process(lexer));
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }