Use input/output from the config file

master
Futago-za Ryuu 6 years ago
parent 95abd42c95
commit 8b43c8419f

@ -4,6 +4,16 @@ The CLI `pegjs` can be used from terminals to generate a parser from the given g
It's usage signature is: `pegjs [options] [<input_file>] [--]`
### Configuration file
If you provide a configuration file (via `-c` or `--config`) then you can use all the options used by the [PEG.js API](./javascript-api.md), as well as:
* `input` — The grammar used as the input file
* `output` — Output's generated parser to the provided destination
> 1. Will throw if neither are strings, or the input has already been provided
> 2. the `output` option for the compiler is not usable from the config
### Input File
Only one grammar is accepted as the given input file, otherwise the CLI aborts with an error.

@ -59,7 +59,7 @@ task( "benchmark", cb => {
// Generate the grammar parser.
task( "build:parser", cb => {
node( "packages/pegjs/bin/peg src/parser.pegjs -o packages/pegjs/lib/parser.js -c src/pegjs.config.js", cb );
node( "packages/pegjs/bin/peg -c src/pegjs.config.js", cb );
} );

@ -58,6 +58,42 @@ function addExtraOptions( config ) {
}
if ( config.input !== null || config.output !== null ) {
// We don't want to touch the orignal config, just in case it comes from
// a javascript file, in which case its possible the same object is used
// for something else, somewhere else.
config = util.clone( config );
const { input, output } = config;
if ( input !== null ) {
if ( typeof input !== "string" )
abort( "The option `input` must be a string." );
if ( inputFile !== null )
abort( `The input file is already set, cannot use: "${ input }".` );
inputFile = input;
delete config.input;
}
if ( output !== null ) {
if ( typeof output !== "string" )
abort( "The option `output` must be a string." );
outputFile = output;
delete config.output;
}
}
options = util.processOptions( config, options );
}

@ -2,6 +2,9 @@
module.exports = {
input: "src/parser.pegjs",
output: "packages/pegjs/lib/parser.js",
header: "/* eslint-disable */",
dependencies: {

Loading…
Cancel
Save