Grammar换成Lexer,Grammar用作生成AST Tree

This commit is contained in:
2021-03-17 12:09:38 +08:00
parent e60b5f0f78
commit 42df1352d2
9 changed files with 135 additions and 21 deletions

View File

@ -7,7 +7,7 @@
namespace JerryYan\DSL\Test\Output;
use JerryYan\DSL\Grammar\DefaultGrammar;
use JerryYan\DSL\Lexer\DefaultLexer;
use JerryYan\DSL\Output\RawOutput;
use JerryYan\DSL\Reader\StringReader;
use JerryYan\DSL\Tokenizer\Tokenizer;
@ -15,12 +15,13 @@ use PHPUnit\Framework\TestCase;
class RawOutputTest extends TestCase
{
private $text = "当 另外那个 与 另外一个 不相等时 或者 那个 和 这个 等于 -0.5 的时候";
private $text = " 当 另外那个 与 另外一个 不相等时 或者 那个 和 这个 等于 -0.5 的时候";
private $expect = "当 另外那个 与 另外一个 不相等时 或者 那个 和 这个 等于 -0.5 的时候";
private $output;
protected function setUp(): void
{
$tokenizer = new Tokenizer(new DefaultGrammar());
$tokenizer = new Tokenizer(new DefaultLexer());
$reader = new StringReader($this->text);
$token = $tokenizer->tokenize($reader);
$this->output = new RawOutput($token);
@ -28,6 +29,6 @@ class RawOutputTest extends TestCase
public function testOutput()
{
$this->assertEquals($this->text, $this->output->output(), '输出与预期不一致');
$this->assertEquals($this->expect, $this->output->output(), '输出与预期不一致');
}
}