示例#1
0
        public void ConsumeIfndef(LookAheadLangParser parser)
        {
            Debug.Assert(Preprocessor.NextIsIfndef(parser));

            while (true)
            {
                if (parser.PeekNextKeyword().Equals("ifndef"))
                {
                    break;
                }

                ConumseNextKeyWordSpaceOutput();
            }

            ConumseNextKeyWordSpaceOutput();
        }
示例#2
0
        public StreamReader Process()
        {
            try
            {
                Stack <bool> blockInclusion = new Stack <bool>();

                blockInclusion.Push(true); // start by including next block of text

                do
                {
                    if (Preprocessor.NextIsIfdef(this.parser))
                    {
                        ConsumeIfDef(this.parser);

                        // if we are currently excluding a block, i.e nested #if's, just push 0 onto the inclusion
                        if (!blockInclusion.Peek())
                        {
                            blockInclusion.Push(false);
                        }
                        else
                        {
                            blockInclusion.Push(EvaluateExpression());
                        }

                        MoveToNextLineSpaceOutput();
                    }
                    else if (Preprocessor.NextIsElse(this.parser) && blockInclusion.Count > 1)
                    {
                        // just reverse the inclusion book-keeping

                        bool blockShouldInclude = blockInclusion.Pop();

                        // check if parent inclusing says no
                        if (!blockInclusion.Peek())
                        {
                            blockInclusion.Push(false);
                        }
                        else
                        {
                            blockInclusion.Push(!blockShouldInclude);
                        }

                        MoveToNextLineSpaceOutput();
                    }
                    else if (Preprocessor.NextIsEndif(this.parser) && blockInclusion.Count > 1)
                    {
                        blockInclusion.Pop();
                        MoveToNextLineSpaceOutput();
                    }
                    else if (Preprocessor.NextIsIfndef(this.parser))
                    {
                        ConsumeIfndef(this.parser);

                        if (!blockInclusion.Peek())
                        {
                            blockInclusion.Push(false);
                        }
                        else
                        {
                            blockInclusion.Push(!EvaluateExpression());
                        }

                        MoveToNextLineSpaceOutput();
                    }
                    else if (Preprocessor.NextIsCommentBlock(this.parser))
                    {
                        ConsumeComments();
                    }
                    else if (this.parser.PeekNextKeyword().Equals("#"))
                    {
                        ConsumeDirectiveMultiLine();
                    }
                    else
                    {
                        if (blockInclusion.Peek())
                        {
                            this.sb.Append(this.parser.NextKeyword());
                        }
                        else
                        {
                            ConumseNextKeyWordSpaceOutput(); // move the stream ahead without including its data...
                        }
                    }
                }while (true);
            }
            catch (EndOfStreamException)
            {
            }
            catch (Exception)
            {
                throw new PreprocessorException();
            }

            return(Preprocessor.GetTextStream(this.sb.ToString()));
        }