-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: command line utility implemented
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use Garden\Cli\Cli; | ||
use Remorhaz\UniLex\Lexer\TokenMatcherGenerator; | ||
use Remorhaz\UniLex\Lexer\TokenMatcherSpecParser; | ||
|
||
$isComposerLoaded = false; | ||
foreach (['..', '../vendor'] as $composerAutoloadPath) { | ||
$composerAutoloadFile = __DIR__ . "/{$composerAutoloadPath}/autoload.php"; | ||
if (is_file($composerAutoloadFile) === true) { | ||
/** @noinspection PhpIncludeInspection */ | ||
require_once $composerAutoloadFile; | ||
$isComposerLoaded = true; | ||
break; | ||
} | ||
} | ||
if (!$isComposerLoaded) { | ||
fwrite(STDERR, "Composer autoload file not found!\n"); | ||
exit(1); | ||
} | ||
|
||
$cli = new Cli; | ||
/** @noinspection PhpUnhandledExceptionInspection */ | ||
$cli | ||
->description("UniLex: PHP lexical analyzer generator with Unicode support.") | ||
->opt('desc:d', "Token matcher description") | ||
->arg('source', "File to place generated matcher class.", true); | ||
|
||
$args = $cli->parse($argv, true); | ||
|
||
$matcherSpec = TokenMatcherSpecParser::loadFromFile($args->getArg('source')) | ||
->getMatcherSpec(); | ||
$description = $args->getOpt('desc'); | ||
if (isset($description)) { | ||
$matcherSpec->addFileComment($description, ''); | ||
} | ||
$matcherSpec | ||
->addFileComment( | ||
"Auto-generated file, please don't edit manually.", | ||
"Generated by UniLex." | ||
); | ||
$generator = new TokenMatcherGenerator($matcherSpec); | ||
|
||
$output = $generator->getOutput(); | ||
fwrite(STDOUT, $output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters