/
smwwiki
/
OneScript_fork
Обзор
Документация
Войти
/
smwwiki
/
OneScript_fork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/Tests/OneScript.Language.Tests/TestAstNode.cs
60 строк
2 KB
EvilBeaver
Поддержка парсером Асинх и Ждать
18 окт 2023, 09:29
18 окт 2023, 09:29
a45e044
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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 System.Collections.Generic; using System.Linq; using OneScript.Language.SyntaxAnalysis.AstNodes; namespace OneScript.Language.Tests { public class TestAstNode : BslSyntaxNode { private Lazy<IReadOnlyList<TestAstNode>> _childrenLazy; public BslSyntaxNode RealNode { get; } public TestAstNode(BslSyntaxNode node) { RealNode = node; Kind = node.Kind; if (node is NonTerminalNode nonTerm) { _childrenLazy = new Lazy<IReadOnlyList<TestAstNode>>(nonTerm.Children.Select(x => new TestAstNode(x)).ToArray()); Value = nonTerm switch { AnnotationNode anno => anno.Name, BinaryOperationNode binary => binary.Operation.ToString(), UnaryOperationNode unary => unary.Operation.ToString(), PreprocessorDirectiveNode preproc => preproc.DirectiveName, _ => nonTerm.ToString() }; } else if(node is TerminalNode term) { _childrenLazy = new Lazy<IReadOnlyList<TestAstNode>>(new TestAstNode[0]); Value = term.Lexem.Content; } else { _childrenLazy = new Lazy<IReadOnlyList<TestAstNode>>(new TestAstNode[0]); Value = node.ToString(); } } public string Value { get; set; } public IReadOnlyList<TestAstNode> ChildrenList => _childrenLazy.Value; public override IReadOnlyList<BslSyntaxNode> Children => ChildrenList; public override string ToString() { return $"{Kind} ({Location.LineNumber},{Location.ColumnNumber})"; } } }