コード例 #1
0
        public bool Next()
        {
            int matched = LookAhead(out TokenEnum token, out string content, out int position, out LintType lint);

            if (Lint != lint)
            {
                Linter.Add(new LintElement(LineNumber, Position, lint)); Lint = lint;
            }

            return(DoNext(matched, token, content, position));
        }
コード例 #2
0
        private int LookAhead(out TokenEnum token, out string content, out int position, out LintType lint)
        {
            if (lineRemaining == null)
            {
                token    = 0;
                content  = "";
                position = Position;
                lint     = LintType.NONE;
                return(0);
            }
            foreach (var def in m_tokenDefinitions)
            {
                var matched = def.Matcher.Match(lineRemaining);
                if (matched > 0)
                {
                    position = Position + matched;
                    token    = def.Token;
                    lint     = def.Lint;
                    content  = lineRemaining.Substring(0, matched);

                    // special case for linting for type
                    if (lint == LintType.VARIABLE_OR_TYPE && token == TokenEnum.VARIABLE)
                    {
                        if (Parser.TypeTokens.Contains(content))
                        {
                            lint = LintType.TYPE;
                        }
                        else
                        {
                            lint = LintType.VARIABLE;
                        }
                    }

                    // whitespace elimination
                    if (content.Trim().Length == 0)
                    {
                        DoNext(matched, token, content, position);
                        return(LookAhead(out token, out content, out position, out lint));
                    }

                    // comment elimination
                    if (token == TokenEnum.COMMENT)
                    {
                        Linter.Add(new LintElement(LineNumber, Position, LintType.COMMENT));
                        nextLine();
                        return(LookAhead(out token, out content, out position, out lint));
                    }

                    return(matched);
                }
            }
            throw new Exception(Resource.Strings.Error_Lexer_InvalidToken.F(LineNumber, Position, lineRemaining));
        }
コード例 #3
0
        private void nextLine()
        {
            do
            {
                lineRemaining = m_reader.ReadLine();
                LineText      = lineRemaining;
                if (LineNumber > 0)
                {
                    Linter.Add(new LintElement(LineNumber, Position, LintType.NONE));
                    Lint = LintType.NONE;
                }

                ++LineNumber;
                Position      = 0;
                TokenPosition = 0;
            } while (lineRemaining != null && lineRemaining.Length == 0);
        }