/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v1.8.3
src/OneScript.Language/LexicalAnalysis/NumberLexerState.cs
63 строки
2 KB
Andrey Ovsiankin
Перенесены классы состояний лексера
04 июл 2019, 16:04
04 июл 2019, 16:04
5a39d03
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System; namespace OneScript.Language.LexicalAnalysis { public class NumberLexerState : LexerState { public override Lexem ReadNextLexem(SourceCodeIterator iterator) { bool hasDecimalPoint = false; while (true) { if (Char.IsDigit(iterator.CurrentSymbol)) { if (!iterator.MoveNext()) { var lex = new Lexem() { Type = LexemType.NumberLiteral, Content = iterator.GetContents() }; 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() }; return lex; } else { throw CreateExceptionOnCurrentLine("Некорректный символ", iterator); } } } } }