示例#1
0
 internal string ReadLineToEnd()
 {
     _iterator.MoveToContent();
     while (_iterator.MoveNext())
     {
         if (_iterator.CurrentSymbol == '\n')
         {
             return(_iterator.GetContents().content);
         }
     }
     return(_iterator.GetContents().content);
 }
示例#2
0
        public override Lexem ReadNextLexem(ParseIterator iterator)
        {
            bool hasDecimalPoint = false;

            while (true)
            {
                if (Char.IsDigit(iterator.CurrentSymbol))
                {
                    if (!iterator.MoveNext())
                    {
                        var lex = new Lexem()
                        {
                            Type    = LexemType.NumberLiteral,
                            Content = iterator.GetContents().content
                        };

                        return(lex);
                    }
                }
                else if (SpecialChars.IsDelimiter(iterator.CurrentSymbol))
                {
                    if (iterator.CurrentSymbol == '.')
                    {
                        if (!hasDecimalPoint)
                        {
                            hasDecimalPoint = true;
                            iterator.MoveNext();
                            continue;
                        }
                        else
                        {
                            throw CreateExceptionOnCurrentLine("Некорректно указана десятичная точка в числе", iterator);
                        }
                    }

                    var lex = new Lexem()
                    {
                        Type    = LexemType.NumberLiteral,
                        Content = iterator.GetContents().content
                    };

                    return(lex);
                }
                else
                {
                    throw CreateExceptionOnCurrentLine("Некорректный символ", iterator);
                }
            }
        }
示例#3
0
        public override Lexem ReadNextLexem(ParseIterator iterator)
        {
            var numbers = new StringBuilder();

            while (iterator.MoveNext())
            {
                var cs = iterator.CurrentSymbol;
                if (cs == SpecialChars.DateQuote)
                {
                    iterator.GetContents(1, 1);
                    iterator.MoveNext();

                    var lex = new Lexem()
                    {
                        Type    = LexemType.DateLiteral,
                        Content = numbers.ToString()
                    };

                    return(lex);
                }
                else if (Char.IsDigit(cs))
                {
                    numbers.Append(cs);
                }

                if (numbers.Length > 14)
                {
                    throw CreateExceptionOnCurrentLine("Некорректный литерал даты", iterator);
                }
            }

            throw CreateExceptionOnCurrentLine("Незавершенный литерал даты", iterator);
        }
示例#4
0
文件: Parser.cs 项目: team55/1script
        public override Lexem ReadNextLexem(ParseIterator iterator)
        {
            while (iterator.MoveNext())
            {
                var cs = iterator.CurrentSymbol;
                if (cs == SpecialChars.DateQuote)
                {
                    var lex = new Lexem()
                    {
                        Type    = LexemType.DateLiteral,
                        Content = iterator.GetContents(1, 1).content
                    };

                    iterator.MoveNext();

                    return(lex);
                }
                else if (!Char.IsDigit(cs))
                {
                    throw CreateExceptionOnCurrentLine("Незавершенный литерал даты", iterator);
                }
            }

            throw CreateExceptionOnCurrentLine("Незавершенный литерал даты", iterator);
        }
示例#5
0
        private static Lexem ExtractOperatorContent(ParseIterator iterator)
        {
            Lexem lex;
            var   content = iterator.GetContents().content;

            lex = new Lexem()
            {
                Type    = LexemType.Operator,
                Content = content,
                Token   = LanguageDef.GetToken(content)
            };
            return(lex);
        }
示例#6
0
        internal string ReadLineToEnd()
        {
            while (_iterator.CurrentSymbol != '\n')
            {
                if (!_iterator.MoveNext())
                {
                    break;
                }
            }
            string content = _iterator.GetContents().content;

            return(content == null ? "" : content);
        }
示例#7
0
        public override Lexem ReadNextLexem(ParseIterator iterator)
        {
            bool hasDecimalPoint = false;
            while (true)
            {
                if (Char.IsDigit(iterator.CurrentSymbol))
                {
                    if (!iterator.MoveNext())
                    {
                        var lex = new Lexem()
                        {
                            Type = LexemType.NumberLiteral,
                            Content = iterator.GetContents().content
                        };

                        return lex;
                    }
                }
                else if (SpecialChars.IsDelimiter(iterator.CurrentSymbol))
                {
                    if (iterator.CurrentSymbol == '.')
                    {
                        if (!hasDecimalPoint)
                        {
                            hasDecimalPoint = true;
                            iterator.MoveNext();
                            continue;
                        }
                        else
                        {
                            throw CreateExceptionOnCurrentLine("Некорректно указана десятичная точка в числе", iterator);
                        }
                    }

                    var lex = new Lexem()
                    {
                        Type = LexemType.NumberLiteral,
                        Content = iterator.GetContents().content
                    };

                    return lex;
                }
                else
                {
                    throw CreateExceptionOnCurrentLine("Некорректный символ", iterator);
                }
            }
        }
示例#8
0
 private static Lexem ExtractOperatorContent(ParseIterator iterator)
 {
     Lexem lex;
     var content = iterator.GetContents().content;
     lex = new Lexem()
     {
         Type = LexemType.Operator,
         Content = content,
         Token = LanguageDef.GetToken(content)
     };
     return lex;
 }
示例#9
0
        public override Lexem ReadNextLexem(ParseIterator iterator)
        {
            if(iterator.CurrentSymbol == '<')
            {
                if (iterator.MoveNext())
                {
                    var next = iterator.CurrentSymbol;
                    if (next != '>' && next != '=')
                    {
                        iterator.MoveBack();
                    }
                    else
                    {
                        iterator.MoveNext();
                        return ExtractOperatorContent(iterator);
                    }
                }
            }
            else if(iterator.CurrentSymbol == '>')
            {
                if (iterator.MoveNext())
                {
                    var next = iterator.CurrentSymbol;
                    if (next != '=')
                    {
                        iterator.MoveBack();
                    }
                    else
                    {
                        iterator.MoveNext();
                        return ExtractOperatorContent(iterator);
                    }
                }
            }
            else if (iterator.CurrentSymbol == '/')
            {
                if (iterator.MoveNext())
                {
                    if (iterator.CurrentSymbol == '/')
                    {
                        // это комментарий
                        while (iterator.MoveNext())
                        {
                            if (iterator.CurrentSymbol == '\n')
                            {
                                iterator.GetContents();
                                return Lexem.Empty();
                            }
                        }
                        iterator.GetContents();
                        return Lexem.EndOfText();
                    }
                    else
                    {
                        iterator.MoveBack();
                    }
                }
            }

            var lex = ExtractOperatorContent(iterator);
            
            iterator.MoveNext();

            return lex;
            
        }
示例#10
0
        public override Lexem ReadNextLexem(ParseIterator iterator)
        {
            var numbers = new StringBuilder();

            while (iterator.MoveNext())
            {
                var cs = iterator.CurrentSymbol;
                if (cs == SpecialChars.DateQuote)
                {
                    iterator.GetContents(1, 1);
                    iterator.MoveNext();

                    var lex = new Lexem()
                    {
                        Type = LexemType.DateLiteral,
                        Content = numbers.ToString()
                    };

                    return lex;
                }
                else if(Char.IsDigit(cs))
                {
                    numbers.Append(cs);
                }

                if (numbers.Length > 14)
                    throw CreateExceptionOnCurrentLine("Некорректный литерал даты", iterator);
            }

            throw CreateExceptionOnCurrentLine("Незавершенный литерал даты", iterator);
        }
示例#11
0
        public override Lexem ReadNextLexem(ParseIterator iterator)
        {
            bool isEndOfText = false;
            Char cs = '\0';
            while (true)
            {
                if (!isEndOfText)
                {
                    cs = iterator.CurrentSymbol;
                }
                if (SpecialChars.IsDelimiter(cs) || isEndOfText)
                {
                    var content = iterator.GetContents().content;
                    
                    Lexem lex;

                    if(_booleanOperators.Contains(content))
                    {
                        lex = new Lexem()
                        {
                            Type = LexemType.Operator,
                            Token = LanguageDef.GetToken(content),
                            Content = content
                        };
                    }
                    else if (_booleanLiterals.Contains(content))
                    {
                        lex = new Lexem()
                        {
                            Type = LexemType.BooleanLiteral,
                            Content = content
                        };
                    }
                    else if (_undefined.Contains(content))
                    {
                        lex = new Lexem()
                        {
                            Type = LexemType.UndefinedLiteral,
                            Content = content
                        };

                    }
                    else if (String.Compare(content, "null", true) == 0)
                    {
                        lex = new Lexem()
                        {
                            Type = LexemType.NullLiteral,
                            Content = content
                        };

                    }
                    else
                    {
                        lex = new Lexem()
                        {
                            Type = LexemType.Identifier,
                            Content = content,
                            Token = LanguageDef.GetToken(content)
                        };

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

                    return lex;
                }

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

            return Lexem.Empty();
        }
示例#12
0
        public override Lexem ReadNextLexem(ParseIterator iterator)
        {
            if (iterator.CurrentSymbol == '<')
            {
                if (iterator.MoveNext())
                {
                    var next = iterator.CurrentSymbol;
                    if (next != '>' && next != '=')
                    {
                        iterator.MoveBack();
                    }
                    else
                    {
                        iterator.MoveNext();
                        return(ExtractOperatorContent(iterator));
                    }
                }
            }
            else if (iterator.CurrentSymbol == '>')
            {
                if (iterator.MoveNext())
                {
                    var next = iterator.CurrentSymbol;
                    if (next != '=')
                    {
                        iterator.MoveBack();
                    }
                    else
                    {
                        iterator.MoveNext();
                        return(ExtractOperatorContent(iterator));
                    }
                }
            }
            else if (iterator.CurrentSymbol == '/')
            {
                if (iterator.MoveNext())
                {
                    if (iterator.CurrentSymbol == '/')
                    {
                        // это комментарий
                        while (iterator.MoveNext())
                        {
                            if (iterator.CurrentSymbol == '\n')
                            {
                                iterator.GetContents();
                                return(Lexem.Empty());
                            }
                        }
                        iterator.GetContents();
                        return(Lexem.EndOfText());
                    }
                    else
                    {
                        iterator.MoveBack();
                    }
                }
            }

            var lex = ExtractOperatorContent(iterator);

            iterator.MoveNext();

            return(lex);
        }
示例#13
0
        public override Lexem ReadNextLexem(ParseIterator iterator)
        {
            bool isEndOfText = false;
            Char cs          = '\0';

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

                    Lexem lex;

                    if (_booleanOperators.Contains(content))
                    {
                        lex = new Lexem()
                        {
                            Type    = LexemType.Operator,
                            Token   = LanguageDef.GetToken(content),
                            Content = content
                        };
                    }
                    else if (_booleanLiterals.Contains(content))
                    {
                        lex = new Lexem()
                        {
                            Type    = LexemType.BooleanLiteral,
                            Content = content
                        };
                    }
                    else if (_undefined.Contains(content))
                    {
                        lex = new Lexem()
                        {
                            Type    = LexemType.UndefinedLiteral,
                            Content = content
                        };
                    }
                    else if (String.Compare(content, "null", true) == 0)
                    {
                        lex = new Lexem()
                        {
                            Type    = LexemType.NullLiteral,
                            Content = content
                        };
                    }
                    else
                    {
                        lex = new Lexem()
                        {
                            Type    = LexemType.Identifier,
                            Content = content,
                            Token   = LanguageDef.GetToken(content)
                        };

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

                    return(lex);
                }

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

            return(Lexem.Empty());
        }
示例#14
0
        public Lexem NextLexem()
        {
            while (true)
            {
                if (_iterator.MoveToContent())
                {
                    ParserState state;

                    char cs = _iterator.CurrentSymbol;
                    if (Char.IsLetter(cs) || cs == '_')
                    {
                        state = _wordState;
                    }
                    else if (Char.IsDigit(cs))
                    {
                        state = _numberState;
                    }
                    else if (cs == SpecialChars.DateQuote)
                    {
                        state = _dateState;
                    }
                    else if (cs == SpecialChars.StringQuote)
                    {
                        state = _stringState;
                    }
                    else if (SpecialChars.IsOperatorChar(cs))
                    {
                        state = _operatorState;
                    }
                    else if (cs == SpecialChars.EndOperator)
                    {
                        _iterator.MoveNext();
                        return(new Lexem()
                        {
                            Type = LexemType.EndOperator, Token = Token.Semicolon
                        });
                    }
                    else if (cs == '?')
                    {
                        _iterator.MoveNext();
                        return(new Lexem()
                        {
                            Type = LexemType.Identifier, Token = Token.Question
                        });
                    }
                    else if (cs == SpecialChars.Directive)
                    {
                        state = _directiveState;
                    }
                    else if (cs == '&')
                    {
                        _iterator.GetContents();
                        _iterator.MoveNext();
                        state = _annotationState;
                    }
                    else
                    {
                        var cp = _iterator.GetPositionInfo(_iterator.CurrentLine);
                        throw new ParserException(cp, string.Format("Неизвестный символ {0}", cs));
                    }

                    var lex = state.ReadNextLexem(_iterator);
                    if (lex.Type == LexemType.NotALexem)
                    {
                        continue;
                    }

                    return(lex);
                }

                return(Lexem.EndOfText());
            }
        }