Example #1
0
 public function testParseEbnfGrammar()
 {
     $expectedAstNode = '\\Helstern\\Nomsky\\Grammars\\Ebnf\\Ast\\SyntaxNode';
     $grammarFile = self::getResourceFilePath('ebnf.iso.ebnf');
     $lexer = (new LexerFactory())->fromFile($grammarFile);
     $assertions = new ParseAssertions(new TokenPredicates());
     $parser = new Parser($assertions);
     $actualAstNode = $parser->parse($lexer);
     $this->assertInstanceOf($expectedAstNode, $actualAstNode, 'wrong instance type received');
 }
Example #2
0
 /**
  * @group milestone
  */
 public function testWriteDotFile()
 {
     $grammarFile = self::getResourceFilePath('ebnf.iso.ebnf');
     $lexer = (new IsoEbnfLexerFactory())->fromFile($grammarFile);
     $assertions = new ParseAssertions(new TokenPredicates());
     $parser = new IsoEbnfParser($assertions);
     $syntaxNode = $parser->parse($lexer);
     $dotFile = self::createLocalFSDotFile('ebnf.iso.graphviz', $deleteExisting = true);
     $astWriter = new AstWriter();
     $astWriter->write($syntaxNode, $dotFile);
     $actualFile = self::getOutputFileContents('ebnf.iso.graphviz');
     $this->assertNotEmpty($actualFile);
 }
 public function testBnfConversion()
 {
     $grammarFile = $this->getResourceFilePath('logo-simple.ebnf');
     $lexer = (new IsoEbnfLexerFactory())->fromFile($grammarFile);
     $assertions = new ParseAssertions(new TokenPredicates());
     $parser = new IsoEbnfParser($assertions);
     $syntaxNode = $parser->parse($lexer);
     $translator = new AstTranslator();
     $ebnfGrammar = $translator->translate($syntaxNode);
     $conversions = new Conversions();
     $bnfGrammar = $conversions->ebnfToBnf($ebnfGrammar);
     $this->assertNotNull($bnfGrammar);
 }