Пример #1
0
        private EbnfDefinition VisitDefinitionNode(IInternalTreeNode node)
        {
            EbnfBlock      block      = null;
            EbnfDefinition definition = 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.Block == symbolValue)
                    {
                        block = VisitBlockNode(internalNode);
                    }
                    else if (EbnfGrammar.Definition == symbolValue)
                    {
                        definition = VisitDefinitionNode(internalNode);
                    }
                    break;
                }
            }

            if (definition != null)
            {
                return(new EbnfDefinitionConcatenation(block, definition));
            }

            return(new EbnfDefinition(block));
        }
Пример #2
0
 public EbnfDefinitionConcatenation(EbnfBlock block, EbnfDefinition definition)
     : base(block)
 {
     Assert.IsNotNull(definition, nameof(definition));
     Definition = definition;
     _hashCode = ComputeHashCode();
 }
Пример #3
0
 public EbnfDefinitionConcatenation(EbnfBlock block, EbnfDefinition definition)
     : base(block)
 {
     Assert.IsNotNull(definition, nameof(definition));
     Definition = definition;
     _hashCode  = ComputeHashCode();
 }
Пример #4
0
        void Block(EbnfBlock block, GrammarModel grammarModel)
        {
            switch (block.NodeType)
            {
                case EbnfNodeType.EbnfBlockLexerRule:
                    break;

                case EbnfNodeType.EbnfBlockRule:
                    var blockRule = block as EbnfBlockRule;
                    foreach (var production in Rule(blockRule.Rule))
                        grammarModel.Productions.Add(production);
                    break;

                case EbnfNodeType.EbnfBlockSetting:
                    break;
            }
        }
Пример #5
0
        void Block(EbnfBlock block, GrammarModel grammarModel)
        {
            switch (block.NodeType)
            {
            case EbnfNodeType.EbnfBlockLexerRule:
                var blockLexerRule = block as EbnfBlockLexerRule;
                grammarModel.LexerRules.Add(LexerRule(blockLexerRule));
                break;

            case EbnfNodeType.EbnfBlockRule:
                var blockRule = block as EbnfBlockRule;
                foreach (var production in Rule(blockRule.Rule))
                {
                    grammarModel.Productions.Add(production);
                }
                break;

            case EbnfNodeType.EbnfBlockSetting:
                var blockSetting = block as EbnfBlockSetting;

                switch (blockSetting.Setting.SettingIdentifier.Value)
                {
                case StartProductionSettingModel.SettingKey:
                    grammarModel.StartSetting = StartSetting(blockSetting);
                    break;

                case IgnoreSettingModel.SettingKey:
                    var ignoreSettings = IgnoreSettings(blockSetting);
                    for (var i = 0; i < ignoreSettings.Count; i++)
                    {
                        grammarModel.IgnoreSettings.Add(ignoreSettings[i]);
                    }
                    break;

                case TriviaSettingModel.SettingKey:
                    var triviaSettings = TriviaSettings(blockSetting);
                    for (var i = 0; i < triviaSettings.Count; i++)
                    {
                        grammarModel.TriviaSettings.Add(triviaSettings[i]);
                    }
                    break;
                }
                break;
            }
        }
Пример #6
0
        void Block(EbnfBlock block, GrammarModel grammarModel)
        {
            switch (block.NodeType)
            {
            case EbnfNodeType.EbnfBlockLexerRule:
                break;

            case EbnfNodeType.EbnfBlockRule:
                var blockRule = block as EbnfBlockRule;
                foreach (var production in Rule(blockRule.Rule))
                {
                    grammarModel.Productions.Add(production);
                }
                break;

            case EbnfNodeType.EbnfBlockSetting:
                break;
            }
        }
Пример #7
0
 public EbnfDefinition(EbnfBlock block)
 {
     Assert.IsNotNull(block, nameof(block));
     Block = block;
     _hashCode = ComputeHashCode();
 }
Пример #8
0
 public EbnfDefinition(EbnfBlock block)
 {
     Assert.IsNotNull(block, nameof(block));
     Block     = block;
     _hashCode = ComputeHashCode();
 }