Skip to content

Commit

Permalink
#1 Emit EOF token at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilos committed Jan 19, 2014
1 parent e6006e4 commit 38247ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/AerialShip/Lex/EOF.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace AerialShip\Lex;


class EOF extends Token
{
public function __construct($offset, $count)
{
parent::__construct(null, null, $offset, $count);
}
}
1 change: 1 addition & 0 deletions src/AerialShip/Lex/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function tokenizeAsync($input, callable $callback)
throw new UnknownTokenException($offset);
}
}
call_user_func($callback, new EOF($offset, $count));
}


Expand Down
6 changes: 5 additions & 1 deletion src/AerialShip/Lex/Tests/LexerFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function shouldFailAtBadOffsetAsync()
protected function assertTokens($arr)
{
$this->assertInternalType('array', $arr);
$this->assertCount(5, $arr);
$this->assertCount(6, $arr);
$this->assertContainsOnlyInstancesOf('AerialShip\Lex\Token', $arr);

$this->assertEquals('number', $arr[0]->getToken());
Expand All @@ -111,5 +111,9 @@ protected function assertTokens($arr)
$this->assertEquals('567', $arr[4]->getValue());
$this->assertEquals(15, $arr[4]->getOffset());
$this->assertEquals(4, $arr[4]->getCount());

$this->assertInstanceOf('AerialShip\Lex\EOF', $arr[5]);
$this->assertEquals(18, $arr[5]->getOffset());
$this->assertEquals(5, $arr[5]->getCount());
}
}

0 comments on commit 38247ae

Please sign in to comment.