public Grammar Generate(IEbnfDefinition ebnf) { var grammarModel = new GrammarModel(); Definition(ebnf, grammarModel); return(grammarModel.ToGrammar()); }
public override void Visit(IInternalTreeNode node) { if (node.Is(EbnfGrammar.Definition)) { Definition = VisitDefinitionNode(node); } }
private void Definition(IEbnfDefinition definition, GrammarModel grammarModel) { Block(definition.Block, grammarModel); if (definition is EbnfDefinitionConcatenation definitionConcatenation) { Definition(definitionConcatenation.Definition, grammarModel); } }
private IEbnfDefinition VisitDefinitionNode(IInternalTreeNode node) { IEbnfBlock block = null; IEbnfDefinition definition = null; foreach (var internalNode in node.Children.OfType <IInternalTreeNode>()) { if (internalNode.Is(EbnfGrammar.Block)) { block = VisitBlockNode(internalNode); } else if (internalNode.Is(EbnfGrammar.Definition)) { definition = VisitDefinitionNode(internalNode); } } if (definition == null) { return(new EbnfDefinitionSimple(block)); } return(new EbnfDefinitionConcatenation(block, definition)); }
public EbnfDefinitionConcatenation(IEbnfBlock block, IEbnfDefinition definition) { Block = block; Definition = definition; }
private static Grammar GenerateGrammar(IEbnfDefinition definition) { var generator = new EbnfGrammarGenerator(); return(generator.Generate(definition)); }