You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -173,14 +173,22 @@ class PeggyCLI extends Command {
173
173
"-m, --source-map [mapfile]",
174
174
"Generate a source map. If name is not specified, the source map will be named \"<input_file>.map\" if input is a file and \"source.map\" if input is a standard input. If the special filename `inline` is given, the sourcemap will be embedded in the output file as a data URI. If the filename is prefixed with `hidden:`, no mapping URL will be included so that the mapping can be specified with an HTTP SourceMap: header. This option conflicts with the `-t/--test` and `-T/--test-file` options unless `-o/--output` is also specified"
175
175
)
176
+
.addOption(
177
+
newOption(
178
+
"-a, --ast",
179
+
"Output a grammar AST instead of a parser code"
180
+
)
181
+
.default(false)
182
+
.conflicts(["test","testFile","sourceMap"])
183
+
)
176
184
.option(
177
185
"-S, --start-rule <rule>",
178
186
"When testing, use the given rule as the start rule. If this rule is not in the allowed start rules, it will be added."
179
187
)
180
-
.addOption(newOption(
188
+
.option(
181
189
"-t, --test <text>",
182
190
"Test the parser with the given text, outputting the result of running the parser instead of the parser itself. If the input to be tested is not parsed, the CLI will exit with code 2"
183
-
).conflicts("test-file"))
191
+
)
184
192
.addOption(newOption(
185
193
"-T, --test-file <filename>",
186
194
"Test the parser with the contents of the given file, outputting the result of running the parser instead of the parser itself. If the input to be tested is not parsed, the CLI will exit with code 2"
@@ -313,6 +321,10 @@ class PeggyCLI extends Command {
313
321
}
314
322
}
315
323
324
+
if(this.progOptions.ast){
325
+
this.argv.output="ast";
326
+
}
327
+
316
328
// Empty string is a valid test input. Don't just test for falsy.
317
329
if(typeofthis.progOptions.test==="string"){
318
330
this.testText=this.progOptions.test;
@@ -511,7 +523,7 @@ class PeggyCLI extends Command {
511
523
});
512
524
}
513
525
514
-
writeParser(outputStream,source){
526
+
writeOutput(outputStream,source){
515
527
returnnewPromise((resolve,reject)=>{
516
528
if(!outputStream){
517
529
resolve();
@@ -626,18 +638,24 @@ class PeggyCLI extends Command {
626
638
this.verbose("CLI",errorText="parsing grammar");
627
639
constsource=peggy.generate(input,this.argv);// All of the real work.
628
640
629
-
this.verbose("CLI",errorText="writing to output file");
<p><strong>Note</strong>: because of bug <ahref="https://github.com/mozilla/source-map/issues/444">source-map/444</a> you should also set <code>grammarSource</code> to
440
+
a not-empty string if you set this value to <code>"source-and-map"</code></p>
441
+
</blockquote></dd>
442
+
429
443
<dt><code>plugins</code></dt>
430
444
<dd>Plugins to use. See the <ahref="#plugins-api">Plugins API</a> section.</dd>
0 commit comments