private EbnfBlockSetting VisitSettingNode(IInternalTreeNode node) { EbnfSettingIdentifier settingIdentifier = null; EbnfQualifiedIdentifier qualifiedIdentifier = null; for (int c = 0; c < node.Children.Count; c++) { var child = node.Children[c]; switch (child.NodeType) { case TreeNodeType.Token: var tokenNode = child as ITokenTreeNode; var token = tokenNode.Token; if (token.TokenType.Id == nameof(settingIdentifier)) { settingIdentifier = new EbnfSettingIdentifier(token.Value); } break; case TreeNodeType.Internal: var internalNode = child as IInternalTreeNode; var symbolValue = internalNode.Symbol.Value; if (EbnfGrammar.QualifiedIdentifier == symbolValue) { qualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode); } break; } } return(new EbnfBlockSetting( new EbnfSetting(settingIdentifier, qualifiedIdentifier))); }
private EbnfBlockRule VisitRuleNode(IInternalTreeNode node) { EbnfQualifiedIdentifier qualifiedIdentifier = null; EbnfExpression expression = null; for (int c = 0; c < node.Children.Count; c++) { var child = node.Children[c]; switch (child.NodeType) { case TreeNodeType.Internal: var internalNode = child as IInternalTreeNode; var symbolValue = internalNode.Symbol.Value; if (EbnfGrammar.QualifiedIdentifier == symbolValue) { qualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode); } else if (EbnfGrammar.Expression == symbolValue) { expression = VisitExpressionNode(internalNode); } break; case TreeNodeType.Token: break; } } return(new EbnfBlockRule( new EbnfRule(qualifiedIdentifier, expression))); }
private EbnfBlockLexerRule VisitLexerRuleNode(IInternalTreeNode node) { EbnfQualifiedIdentifier qualifiedIdentifier = null; EbnfLexerRuleExpression expression = null; for (int c = 0; c < node.Children.Count; c++) { var child = node.Children[c]; if (child.NodeType != TreeNodeType.Internal) { continue; } var internalNode = child as IInternalTreeNode; var symbolValue = internalNode.Symbol.Value; if (EbnfGrammar.QualifiedIdentifier == symbolValue) { qualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode); } else if (EbnfGrammar.LexerRuleExpression == symbolValue) { expression = VisitLexerRuleExpressionNode(internalNode); } } return(new EbnfBlockLexerRule( new EbnfLexerRule(qualifiedIdentifier, expression))); }
private EbnfBlockSetting VisitSettingNode(IInternalTreeNode node) { EbnfSettingIdentifier settingIdentifier = null; EbnfQualifiedIdentifier qualifiedEbnfQualifiedIdentifier = null; foreach (var child in node.Children) { switch (child) { case IInternalTreeNode internalNode: if (internalNode.Is(EbnfGrammar.QualifiedIdentifier)) { qualifiedEbnfQualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode); } break; case ITokenTreeNode tokenNode: var token = tokenNode.Token; if (token.TokenName.Equals(EbnfGrammar.TokenClasses.SettingIdentifier)) { settingIdentifier = new EbnfSettingIdentifier(token.Value); } break; } } return(new EbnfBlockSetting(new EbnfSetting(settingIdentifier, qualifiedEbnfQualifiedIdentifier))); }
public EbnfQualifiedIdentifierConcatenation( string identifier, EbnfQualifiedIdentifier qualifiedIdentifier) : base(identifier) { QualifiedIdentifier = qualifiedIdentifier; _hashCode = ComputeHashCode(); }
private static QualifiedName GetQualifiedName(EbnfQualifiedIdentifier qualifiedIdentifier) { var identifiers = qualifiedIdentifier.Identifiers; if (identifiers.Length <= 1) { return(new QualifiedName(identifiers[0])); } return(new QualifiedName( string.Join(".", identifiers.Take(identifiers.Length - 1)), identifiers[identifiers.Length - 1])); }
private static NonTerminal GetNonTerminalFromQualifiedIdentifier(EbnfQualifiedIdentifier qualifiedIdentifier) { var @namespace = new StringBuilder(); var currentQualifiedIdentifier = qualifiedIdentifier; var index = 0; while (currentQualifiedIdentifier.NodeType == EbnfNodeType.EbnfQualifiedIdentifierConcatenation) { if (index > 0) @namespace.Append("."); @namespace.Append(currentQualifiedIdentifier.Identifier); currentQualifiedIdentifier = (currentQualifiedIdentifier as EbnfQualifiedIdentifierConcatenation).QualifiedIdentifier; index++; } return new NonTerminal(@namespace.ToString(), currentQualifiedIdentifier.Identifier); }
private static NonTerminal GetNonTerminalFromQualifiedIdentifier(EbnfQualifiedIdentifier qualifiedIdentifier) { var @namespace = new StringBuilder(); var currentQualifiedIdentifier = qualifiedIdentifier; var index = 0; while (currentQualifiedIdentifier.NodeType == EbnfNodeType.EbnfQualifiedIdentifierConcatenation) { if (index > 0) { @namespace.Append("."); } @namespace.Append(currentQualifiedIdentifier.Identifier); currentQualifiedIdentifier = (currentQualifiedIdentifier as EbnfQualifiedIdentifierConcatenation).QualifiedIdentifier; index++; } return(new NonTerminal(@namespace.ToString(), currentQualifiedIdentifier.Identifier)); }
private EbnfBlockRule VisitRuleNode(IInternalTreeNode node) { EbnfQualifiedIdentifier qualifiedEbnfQualifiedIdentifier = null; IEbnfExpression expression = null; foreach (var internalNode in node.Children.OfType <IInternalTreeNode>()) { if (internalNode.Is(EbnfGrammar.QualifiedIdentifier)) { qualifiedEbnfQualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode); } else if (internalNode.Is(EbnfGrammar.Expression)) { expression = VisitExpressionNode(internalNode); } } return(new EbnfBlockRule(new EbnfRule(qualifiedEbnfQualifiedIdentifier, expression))); }
private EbnfQualifiedIdentifier VisitQualifiedIdentifierNode(IInternalTreeNode node) { #if true return(new EbnfQualifiedIdentifier(VisitQualifiedIdentifier(node))); #else EbnfQualifiedIdentifier repetitionEbnfQualifiedIdentifier = null; string identifier = null; foreach (var child in node.Children) { switch (child) { case IInternalTreeNode internalNode: if (internalNode.Is(EbnfGrammar.QualifiedIdentifier)) { repetitionEbnfQualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode); } break; case ITokenTreeNode tokenNode: var token = tokenNode.Token; if (token.TokenType.Equals(EbnfGrammar.TokenTypes.Identifier)) { identifier = token.Value; } break; } } if (repetitionEbnfQualifiedIdentifier == null) { return(new EbnfQualifiedIdentifierSimple(identifier)); } return(new EbnfQualifiedIdentifierConcatenation(identifier, repetitionEbnfQualifiedIdentifier)); #endif }
private EbnfQualifiedIdentifier VisitQualifiedIdentifierNode(IInternalTreeNode node) { EbnfQualifiedIdentifier repetitionIdentifier = null; string identifier = null; for (int c = 0; c < node.Children.Count; c++) { var child = node.Children[c]; switch (child.NodeType) { case TreeNodeType.Internal: var internalNode = child as IInternalTreeNode; var symbolValue = internalNode.Symbol.Value; if (EbnfGrammar.QualifiedIdentifier == symbolValue) { repetitionIdentifier = VisitQualifiedIdentifierNode(internalNode); } break; case TreeNodeType.Token: var tokenNode = child as ITokenTreeNode; var token = tokenNode.Token; if (token.TokenType.Id == "identifier") { identifier = token.Value; } break; } } if (repetitionIdentifier == null) { return(new EbnfQualifiedIdentifier(identifier)); } return(new EbnfQualifiedIdentifierConcatenation(identifier, repetitionIdentifier)); }
public EbnfLexerRule(EbnfQualifiedIdentifier identifier, IEbnfLexerRuleExpression expression) { Identifier = identifier; Expression = expression; }
public EbnfFactorIdentifier(EbnfQualifiedIdentifier qualifiedIdentifier) { QualifiedIdentifier = qualifiedIdentifier; _hashCode = ComputeHashCode(); }
public EbnfSetting(EbnfSettingIdentifier settingIdentifier, EbnfQualifiedIdentifier identifier) { SettingIdentifier = settingIdentifier; Identifier = identifier; }
public EbnfFactorIdentifier(EbnfQualifiedIdentifier qualifiedIdentifier) { QualifiedIdentifier = qualifiedIdentifier; }
public EbnfLexerRule(EbnfQualifiedIdentifier qualifiedIdentifier, EbnfLexerRuleExpression expression) { QualifiedIdentifier = qualifiedIdentifier; Expression = expression; _hashCode = ComputeHashCode(); }
public EbnfSetting(EbnfSettingIdentifier settingIdentifier, EbnfQualifiedIdentifier qualifiedIdentifier) { SettingIdentifier = settingIdentifier; QualifiedIdentifier = qualifiedIdentifier; _hashCode = ComputeHashCode(); }