From 3bf21a1ac8b6a764b2862c693d5f3087af1e0bb9 Mon Sep 17 00:00:00 2001 From: remorhaz Date: Tue, 17 Apr 2018 23:47:44 +0300 Subject: [PATCH] CLI: command line utility implemented --- bin/unilex | 46 ++++++++++++++++++++++++++++++++++++++++++++++ build.xml | 1 + composer.json | 1 + 3 files changed, 48 insertions(+) create mode 100755 bin/unilex diff --git a/bin/unilex b/bin/unilex new file mode 100755 index 0000000..a9ce7e3 --- /dev/null +++ b/bin/unilex @@ -0,0 +1,46 @@ +#!/usr/bin/env php +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); diff --git a/build.xml b/build.xml index f981f48..ce80f18 100644 --- a/build.xml +++ b/build.xml @@ -7,6 +7,7 @@ + diff --git a/composer.json b/composer.json index bd778bb..b3b67fc 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "role": "Developer" } ], + "bin": ["bin/unilex"], "require": { "php": "^7.1", "vanilla/garden-cli": "^2.0",