private Lexem CreateCommentLexem(SourceCodeIterator iterator)
 {
     return(new Lexem()
     {
         Content = iterator.GetContents().TrimEnd('\r', '\n'),
         Type = LexemType.Comment,
         Token = Token.NotAToken
     });
 }
Exemplo n.º 2
0
        private static Lexem ExtractOperatorContent(SourceCodeIterator iterator)
        {
            Lexem lex;
            var   content = iterator.GetContents();

            lex = new Lexem()
            {
                Type    = LexemType.Operator,
                Content = content,
                Token   = LanguageDef.GetToken(content)
            };
            return(lex);
        }
Exemplo n.º 3
0
        public override Lexem ReadNextLexem(SourceCodeIterator iterator)
        {
            bool isEndOfText = false;
            char cs          = '\0';
            int  currentLine = iterator.CurrentLine;

            while (true)
            {
                if (!isEndOfText)
                {
                    cs = iterator.CurrentSymbol;
                }
                if (SpecialChars.IsDelimiter(cs) || isEndOfText)
                {
                    var content = iterator.GetContents();

                    Lexem lex;

                    if (LanguageDef.IsLogicalOperatorString(content))
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.Operator,
                            Token      = LanguageDef.GetToken(content),
                            Content    = content,
                            LineNumber = currentLine
                        };
                    }
                    else if (LanguageDef.IsBooleanLiteralString(content))
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.BooleanLiteral,
                            Content    = content,
                            LineNumber = currentLine
                        };
                    }
                    else if (LanguageDef.IsUndefinedString(content))
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.UndefinedLiteral,
                            Content    = content,
                            LineNumber = currentLine
                        };
                    }
                    else if (LanguageDef.IsNullString(content))
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.NullLiteral,
                            Content    = content,
                            LineNumber = currentLine
                        };
                    }
                    else
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.Identifier,
                            Content    = content,
                            Token      = LanguageDef.GetToken(content),
                            LineNumber = currentLine
                        };

                        if (LanguageDef.IsBuiltInFunction(lex.Token))
                        {
                            iterator.SkipSpaces();
                            if (iterator.CurrentSymbol != '(')
                            {
                                lex.Token = Token.NotAToken;
                            }
                        }
                    }

                    return(lex);
                }

                if (!iterator.MoveNext())
                {
                    isEndOfText = true;
                }
            }
        }