/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0.0
src/OneScript.Language/LexicalAnalysis/LexerBuilderExtensions.cs
55 строк
2 KB
Andrei Ovsiankin
Заготовки под сквозную обработку ошибок
05 янв 2021, 21:57
05 янв 2021, 21:57
f70d724
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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/. ----------------------------------------------------------*/ namespace OneScript.Language.LexicalAnalysis { public static class LexerBuilderExtensions { public static LexerBuilder DetectWords(this LexerBuilder builder) { builder.Detect((cs, i) => char.IsLetter(cs) || cs == SpecialChars.Underscore) .HandleWith(new WordLexerState()); return builder; } public static LexerBuilder DetectStrings(this LexerBuilder builder) { builder.Detect((cs, i) => cs == SpecialChars.StringQuote) .HandleWith(new StringLexerState()); return builder; } public static LexerBuilder DetectOperators(this LexerBuilder builder) { builder.Detect((cs, i) => SpecialChars.IsOperatorChar(cs) && !(cs == '/' && i.PeekNext() == '/')) .HandleWith(new OperatorLexerState()); return builder; } public static LexerBuilder DetectComments(this LexerBuilder builder) { builder.Detect((cs, i) => cs == '/' && i.PeekNext() == '/') .HandleWith(new CommentLexerState()); return builder; } public static LexerBuilder DetectNumbers(this LexerBuilder builder) { builder.Detect((cs, i) => char.IsDigit(cs)) .HandleWith(new NumberLexerState()); return builder; } public static LexerBuilder DetectPreprocessorDirectives(this LexerBuilder builder) { builder.Detect((cs, i) => cs == SpecialChars.Preprocessor) .HandleWith(new PreprocessorDirectiveLexerState()); return builder; } } }