Idk.php
<?php
namespace Tlf\Lexer\Test\Document;
class Idk extends \Tlf\Lexer\Test\Tester {
public function testLexPhp(){
$lexer = new \Tlf\Lexer();
$phpGrammar = new \Tlf\Lexer\PhpGrammar();
$lexer->addGrammar($phpGrammar);
$starting_directives = $phpGrammar->getDirectives(':php_open');
$lexer->addDirective($starting_directives['php_open']);
$starting_ast = new \Tlf\Lexer\Ast($ast_type="file", $initial_tree=[]);
$file = $this->file('test/input/php/DocumentationExample.php');
$ast = $lexer->lexFile($file);
$tree = $ast->getTree();
$this->compare($tree, require($this->file('test/input/php/DocumentationExampleTree.php')));
}
public function testLexString(){
$lexer = new \Tlf\Lexer();
$docGrammar = new \Tlf\Lexer\DocblockGrammar();
$lexer->addGrammar($docGrammar);
$lexer->addDirective($docGrammar->getDirectives(':/*')['/*']);
$str = "/** I am docblock */";
$ast = $lexer->lex($str);
$tree = $ast->getTree();
$actual = $tree['docblock'][0];
$expect = [
'type'=>'docblock',
'description'=>'I am docblock',
];
$this->compare($expect, $actual);
$this->compare($ast->src, $str);
}
public function testLexAst(){
echo "Uses old php grammar";
$this->disable();
return;
$lexer = new \Tlf\Lexer();
$phpGrammar = new \Tlf\Lexer\PhpGrammar();
$lexer->addGrammar($phpGrammar);
$ast = new \Tlf\Lexer\Ast('code');
$ast->set ('language', 'php');
$code = '<?php class Abc extends Alphabet {}';
$ast->set('src', $code);
$ast = $lexer->lex($code, $ast);
$actual = $ast->getTree();
$expect = [
'type'=>'code',
'language'=>'php',
'src'=>$code,
'class'=>[
0=>[
'type'=>'class',
'docblock'=>'',
'namespace'=>'',
'name'=>'Abc',
'declaration'=>'class Abc extends Alphabet ',
],
],
];
$this->compare($actual, $expect);
$this->compare($ast->src, $code);
}
public function testLexFile(){
echo "Uses old php grammar";
$this->disable();
return;
$dir = dirname(__DIR__).'/php/';
$file = $dir.'SampleClass.php';
$targetTree = include($dir.'SampleClass.tree.php');
$lexer = new \Tlf\Lexer();
$lexer->useCache = false;
$lexer->addGrammar($phpGrammar = new \Tlf\Lexer\PhpGrammar());
$ast = $lexer->lexFile(dirname(__DIR__).'/php/SampleClass.php');
$tree = $ast->getTree();
$this->compare(
$targetTree,
$tree
);
}
}