aboutsummaryrefslogtreecommitdiffstats
path: root/Bin
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2016-01-22 08:43:39 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2016-01-22 08:43:39 +0100
commit47959bf411fa2ec32e4f6cb54a4cfc3a47135b7c (patch)
treebf38103aa96b72060f228c9da2f9dc3d71800491 /Bin
parent2e358fe956432a1cb5837604d2381cb631b5c0c4 (diff)
downloadCompiler-47959bf411fa2ec32e4f6cb54a4cfc3a47135b7c.zip
Compiler-47959bf411fa2ec32e4f6cb54a4cfc3a47135b7c.tar.gz
Compiler-47959bf411fa2ec32e4f6cb54a4cfc3a47135b7c.tar.bz2
Parser: Use the lexer as an iterator.
Diffstat (limited to 'Bin')
-rw-r--r--Bin/Pp.php15
1 files changed, 9 insertions, 6 deletions
diff --git a/Bin/Pp.php b/Bin/Pp.php
index fa42f72..2b228f4 100644
--- a/Bin/Pp.php
+++ b/Bin/Pp.php
@@ -127,13 +127,14 @@ class Pp extends Console\Dispatcher\Kit
}
$compiler = Compiler\Llk::load(new File\Read($grammar));
- $data = new File\Read($language);
+ $stream = new File\Read($language);
+ $data = $stream->readAll();
try {
- $ast = $compiler->parse($data->readAll());
+ $ast = $compiler->parse($data);
} catch (Compiler\Exception $e) {
if (true === $tokenSequence) {
- $this->printTokenSequence($compiler);
+ $this->printTokenSequence($compiler, $data);
echo "\n\n";
}
@@ -143,7 +144,7 @@ class Pp extends Console\Dispatcher\Kit
}
if (true === $tokenSequence) {
- $this->printTokenSequence($compiler);
+ $this->printTokenSequence($compiler, $data);
echo "\n\n";
}
@@ -201,11 +202,13 @@ class Pp extends Console\Dispatcher\Kit
* Print token sequence.
*
* @param \Hoa\Compiler\Llk\Parser $compiler Compiler.
+ * @param string $data Data to lex.
* @return void
*/
- protected function printTokenSequence(Compiler\Llk\Parser $compiler)
+ protected function printTokenSequence(Compiler\Llk\Parser $compiler, $data)
{
- $sequence = $compiler->getTokenSequence();
+ $lexer = new Compiler\Llk\Lexer();
+ $sequence = $lexer->lexMe($data, $compiler->getTokens());
$format = '%' . (strlen((string) count($sequence)) + 1) . 's ' .
'%-13s %-20s %s %6s' . "\n";