예제 #1
0
        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)));
        }
예제 #2
0
        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)));
        }
예제 #3
0
        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)));
        }
예제 #4
0
        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)));
        }
예제 #5
0
 public EbnfQualifiedIdentifierConcatenation(
     string identifier,
     EbnfQualifiedIdentifier qualifiedIdentifier)
     : base(identifier)
 {
     QualifiedIdentifier = qualifiedIdentifier;
     _hashCode = ComputeHashCode();
 }
예제 #6
0
 public EbnfQualifiedIdentifierConcatenation(
     string identifier,
     EbnfQualifiedIdentifier qualifiedIdentifier)
     : base(identifier)
 {
     QualifiedIdentifier = qualifiedIdentifier;
     _hashCode           = ComputeHashCode();
 }
예제 #7
0
        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]));
        }
예제 #8
0
 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);
 }
예제 #9
0
        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));
        }
예제 #10
0
        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)));
        }
예제 #11
0
        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
        }
예제 #12
0
        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));
        }
예제 #13
0
 public EbnfLexerRule(EbnfQualifiedIdentifier identifier, IEbnfLexerRuleExpression expression)
 {
     Identifier = identifier;
     Expression = expression;
 }
예제 #14
0
 public EbnfFactorIdentifier(EbnfQualifiedIdentifier qualifiedIdentifier)
 {
     QualifiedIdentifier = qualifiedIdentifier;
     _hashCode           = ComputeHashCode();
 }
예제 #15
0
 public EbnfSetting(EbnfSettingIdentifier settingIdentifier, EbnfQualifiedIdentifier identifier)
 {
     SettingIdentifier = settingIdentifier;
     Identifier        = identifier;
 }
예제 #16
0
 public EbnfFactorIdentifier(EbnfQualifiedIdentifier qualifiedIdentifier)
 {
     QualifiedIdentifier = qualifiedIdentifier;
 }
예제 #17
0
 public EbnfLexerRule(EbnfQualifiedIdentifier qualifiedIdentifier, EbnfLexerRuleExpression expression)
 {
     QualifiedIdentifier = qualifiedIdentifier;
     Expression = expression;
     _hashCode = ComputeHashCode();
 }
예제 #18
0
 public EbnfSetting(EbnfSettingIdentifier settingIdentifier, EbnfQualifiedIdentifier qualifiedIdentifier)
 {
     SettingIdentifier   = settingIdentifier;
     QualifiedIdentifier = qualifiedIdentifier;
     _hashCode           = ComputeHashCode();
 }
예제 #19
0
 public EbnfLexerRule(EbnfQualifiedIdentifier qualifiedIdentifier, EbnfLexerRuleExpression expression)
 {
     QualifiedIdentifier = qualifiedIdentifier;
     Expression          = expression;
     _hashCode           = ComputeHashCode();
 }
예제 #20
0
 public EbnfSetting(EbnfSettingIdentifier settingIdentifier, EbnfQualifiedIdentifier qualifiedIdentifier)
 {
     SettingIdentifier = settingIdentifier;
     QualifiedIdentifier = qualifiedIdentifier;
     _hashCode = ComputeHashCode();
 }