First usable generator source.
Still issues with usage rules and error reporting, but functional.
This commit is contained in:
31
generator/demo/README.md
Normal file
31
generator/demo/README.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Demonstration of templates being re-written for a specific argument specification
|
||||
|
||||
## Requirements
|
||||
|
||||
* mustache
|
||||
* bison (to compile)
|
||||
* flex (to compile)
|
||||
|
||||
## How to re-write
|
||||
|
||||
```sh
|
||||
mustache demo.yml ../templates/<file>
|
||||
```
|
||||
|
||||
To save the result to a file:
|
||||
|
||||
```sh
|
||||
mustache demo.yml ../templates/<file> /path/to/output/file
|
||||
```
|
||||
|
||||
## How to run
|
||||
|
||||
Run `mustache` on all the templates in `../templates/`, and on _`main.cpp`_ (in this folder) to an empty output directory (`/path/to/output`).
|
||||
Then:
|
||||
|
||||
```sh
|
||||
bison /path/to/output/*.yy
|
||||
flex /path/to/output/*.ll
|
||||
g++ /path/to/output/*.cpp /path/to/output*.cc -o demo
|
||||
/path/to/output/demo
|
||||
```
|
||||
53
generator/demo/demo.yml
Normal file
53
generator/demo/demo.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
---
|
||||
argspec: "dc"
|
||||
any_parameters: true
|
||||
|
||||
argument_tokens:
|
||||
- argument: "expression"
|
||||
usage: "evaluates an expression"
|
||||
short_argument: "e"
|
||||
clean_token: "EXPRESSION"
|
||||
has_parameters: true
|
||||
parameters:
|
||||
- index: 1
|
||||
name: "expression"
|
||||
- argument: "file"
|
||||
usage: "evaluates the contents of a file"
|
||||
short_argument: "f"
|
||||
clean_token: "FILE"
|
||||
has_parameters: true
|
||||
parameters:
|
||||
- index: 1
|
||||
name: "file"
|
||||
help_token:
|
||||
- usage: false
|
||||
short_argument: "h"
|
||||
|
||||
version_token:
|
||||
- usage: false
|
||||
short_argument: false
|
||||
|
||||
license_token:
|
||||
- usage: false
|
||||
short_argument: false
|
||||
|
||||
argument_explanation: false
|
||||
|
||||
usage:
|
||||
- flags:
|
||||
- "OPTIONS"
|
||||
positional: false
|
||||
|
||||
usage_rules:
|
||||
- rule_name: "OPTIONS"
|
||||
options:
|
||||
- option: "EXPRESSION"
|
||||
has_next: true
|
||||
- option: "FILE"
|
||||
|
||||
version: "dc (GNU bc 1.07.1) 1.4.1\\n\\nCopyright 1994, 1997, 1998, 2000, 2001, 2003-2006, 2008, 2010, 2012-2017 Free Software Foundation, Inc."
|
||||
|
||||
license: "This is free software; see the source for copying conditions.\\nThere is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, to the extent permitted by law."
|
||||
|
||||
help_addendum: "Email bug reports to: bug-dc@gnu.org"
|
||||
---
|
||||
19
generator/demo/main.cpp
Normal file
19
generator/demo/main.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
{{=@@ @@=}}
|
||||
#include "@@argspec@@ArgGrammarDriver.hpp"
|
||||
#include <sstream>
|
||||
|
||||
using Result = @@argspec@@ArgGrammar::Driver::Result;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@argspec@@ArgGrammar::Driver driver{ argc, argv };
|
||||
auto res = driver.parse();
|
||||
|
||||
if (res != Result::success) {
|
||||
if (res == Result::completedAction)
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user