/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0.3-alpha
src/OneScript.Native/Compiler/NativeRuntimeAnnotationHandler.cs
49 строк
2 KB
EvilBeaver
Несколько переименований и перемещений для разделения компиляторов
15 ноя 2021, 22:27
15 ноя 2021, 22:27
cfc291d
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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; using OneScript.Language.LexicalAnalysis; using OneScript.Language.SyntaxAnalysis; using OneScript.Language.SyntaxAnalysis.AstNodes; namespace OneScript.Native.Compiler { public class NativeRuntimeAnnotationHandler : ModuleAnnotationDirectiveHandler { private readonly ILexer _allLineContentLexer; public NativeRuntimeAnnotationHandler(IErrorSink errorSink) : base(errorSink) { var builder = new LexerBuilder(); builder.Detect((cs, i) => !char.IsWhiteSpace(cs)) .HandleWith(new WordLexerState()); _allLineContentLexer = builder.Build(); } protected override bool DirectiveSupported(string directive) { return string.Equals(directive, "native", StringComparison.CurrentCultureIgnoreCase); } protected override void ParseAnnotationInternal(ref Lexem lastExtractedLexem, ILexer lexer, ParserContext parserContext) { var node = new PreprocessorDirectiveNode(lastExtractedLexem); _allLineContentLexer.Iterator = lexer.Iterator; lastExtractedLexem = _allLineContentLexer.NextLexemOnSameLine(); if (lastExtractedLexem.Type != LexemType.EndOfText) { var child = new TerminalNode(NodeKind.Unknown, lastExtractedLexem); node.AddChild(child); } lastExtractedLexem = lexer.NextLexem(); parserContext.AddChild(node); } } }