예제 #1
0
        public PreprocessorLine ParseNextLine(TextBuffer text, IDictionary defines) {
            PreprocessorLine line = null;

            do {
                lexer.SkipWhiteSpace();
                if (lexer.EOF) {
                    line = new PreprocessorLine(PreprocessorTokenType.EndOfLine);
                }
                else if (text.PeekChar() != '#') {
                    lexer.IgnoreRestOfLine();
                }
                else {
                    line = Parse(text, defines);
                }
            } while (line == null);

            return line;
        }
예제 #2
0
        public PreprocessorLine ParseNextLine(TextBuffer text, IDictionary defines)
        {
            PreprocessorLine line = null;

            do
            {
                lexer.SkipWhiteSpace();
                if (lexer.EOF)
                {
                    line = new PreprocessorLine(PreprocessorTokenType.EndOfLine);
                }
                else if (text.PeekChar() != '#')
                {
                    lexer.IgnoreRestOfLine();
                }
                else
                {
                    line = Parse(text, defines);
                }
            } while (line == null);

            return(line);
        }
예제 #3
0
        public PreprocessorLine Parse(TextBuffer text, IDictionary defines)
        {
            this.text    = text;
            this.defines = defines;

            Debug.Assert(text.PeekChar() == '#');
            text.NextChar();

            PreprocessorToken     token = NextToken();
            PreprocessorTokenType type  = token.Type;

            switch (type)
            {
            case PreprocessorTokenType.Define:
            case PreprocessorTokenType.Undef:
                token = Eat(PreprocessorTokenType.Identifier);
                EatEndOfLine();
                if (token != null)
                {
                    return(new PreprocessorDeclarationLine(type, ((PreprocessorIdentifierToken)token).Value));
                }
                else
                {
                    return(null);
                }

            case PreprocessorTokenType.Warning:
            case PreprocessorTokenType.Error:
                return(new PreprocessorControlLine(type, lexer.GetRestOfLine()));

            case PreprocessorTokenType.Line:
                // hidden, default
                type = PeekType();
                if (type == PreprocessorTokenType.Default || type == PreprocessorTokenType.Hidden)
                {
                    NextToken();
                    EatEndOfLine();
                    return(new PreprocessorLine(type));
                }

                token = Eat(PreprocessorTokenType.Int);
                if (token != null)
                {
                    int    line = ((PreprocessorIntToken)token).Value;
                    string file = null;
                    if (PeekType() == PreprocessorTokenType.String)
                    {
                        file = ((PreprocessorStringToken)NextToken()).Value;
                    }
                    EatEndOfLine();

                    return(new PreprocessorLineNumberLine(line, file));
                }
                else
                {
                    lexer.IgnoreRestOfLine();
                    return(null);
                }

            case PreprocessorTokenType.If:
            case PreprocessorTokenType.Elif:
                return(new PreprocessorIfLine(type, EvalExpression()));

            case PreprocessorTokenType.Else:
            case PreprocessorTokenType.Endif:
                return(new PreprocessorLine(type));

            case PreprocessorTokenType.Region:
            case PreprocessorTokenType.EndRegion:
                lexer.IgnoreRestOfLine();
                return(new PreprocessorLine(type));

            case PreprocessorTokenType.Pragma:
                lexer.IgnoreRestOfLine();
                return(new PreprocessorLine(type));

            default:
                ReportError(PreprocessorError.UnexpectedDirective, token.Position);
                return(null);
            }
        }
예제 #4
0
 private char PeekChar()
 {
     return(_text.PeekChar());
 }
        public PreprocessorLine Parse(TextBuffer text, IDictionary defines)
        {
            this.text = text;
            this.defines = defines;

            Debug.Assert(text.PeekChar() == '#');
            text.NextChar();

            PreprocessorToken token = NextToken();
            PreprocessorTokenType type = token.Type;
            switch (type) {
                case PreprocessorTokenType.Define:
                case PreprocessorTokenType.Undef:
                    token = Eat(PreprocessorTokenType.Identifier);
                    EatEndOfLine();
                    if (token != null) {
                        return new PreprocessorDeclarationLine(type, ((PreprocessorIdentifierToken)token).Value);
                    }
                    else {
                        return null;
                    }

                case PreprocessorTokenType.Warning:
                case PreprocessorTokenType.Error:
                    return new PreprocessorControlLine(type, lexer.GetRestOfLine());

                case PreprocessorTokenType.Line:
                    // hidden, default
                    type = PeekType();
                    if (type == PreprocessorTokenType.Default || type == PreprocessorTokenType.Hidden) {
                        NextToken();
                        EatEndOfLine();
                        return new PreprocessorLine(type);
                    }

                    token = Eat(PreprocessorTokenType.Int);
                    if (token != null) {
                        int line = ((PreprocessorIntToken)token).Value;
                        string file = null;
                        if (PeekType() == PreprocessorTokenType.String) {
                            file = ((PreprocessorStringToken)NextToken()).Value;
                        }
                        EatEndOfLine();

                        return new PreprocessorLineNumberLine(line, file);
                    }
                    else {
                        lexer.IgnoreRestOfLine();
                        return null;
                    }

                case PreprocessorTokenType.If:
                case PreprocessorTokenType.Elif:
                    return new PreprocessorIfLine(type, EvalExpression());

                case PreprocessorTokenType.Else:
                case PreprocessorTokenType.Endif:
                    return new PreprocessorLine(type);

                case PreprocessorTokenType.Region:
                case PreprocessorTokenType.EndRegion:
                    lexer.IgnoreRestOfLine();
                    return new PreprocessorLine(type);

                case PreprocessorTokenType.Pragma:
                    lexer.IgnoreRestOfLine();
                    return new PreprocessorLine(type);
                default:
                    ReportError(PreprocessorError.UnexpectedDirective, token.Position);
                    return null;
            }
        }
예제 #6
0
 private char PeekChar(int index)
 {
     return(_text.PeekChar(index));
 }