Skip to content

Commit

Permalink
Allow CompilerInterface to handle null inputs
Browse files Browse the repository at this point in the history
lorisleiva committed Jul 4, 2020
1 parent 5efd88d commit f5b0df4
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Compiler/CompilerInterface.php
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@

interface CompilerInterface
{
public function lex(string $input): Enumerable;
public function parse(string $input): Symbol;
public function lex(?string $input): Enumerable;
public function parse(?string $input): Symbol;
}
6 changes: 3 additions & 3 deletions src/Compiler/HoaCompiler.php
Original file line number Diff line number Diff line change
@@ -23,21 +23,21 @@ public function __construct(SearchStringManager $manager)
$this->manager = $manager;
}

public function lex(string $input): Enumerable
public function lex(?string $input): Enumerable
{
Llk::parsePP($this->manager->getGrammar(), $tokens, $rules, $pragmas, 'streamName');
$lexer = new Lexer($pragmas);

try {
$generator = $lexer->lexMe($input, $tokens);
$generator = $lexer->lexMe($input ?? '', $tokens);
} catch (UnrecognizedToken $exception) {
throw InvalidSearchStringException::fromLexer($exception->getMessage(), $exception->getArguments()[1]);
}

return LazyCollection::make($generator);
}

public function parse(string $input): Symbol
public function parse(?string $input): Symbol
{
if (! $input) {
return new EmptySymbol();

0 comments on commit f5b0df4

Please sign in to comment.