Make the default tracer an optional feature

master
Futago-za Ryuu 6 years ago
parent 72ba85b3af
commit 3745195315

@ -97,7 +97,7 @@ cache | `false` | makes the generated parser cache results, avoiding exponential
context | `{}` | contains a map of variables used by `peg.util.vm.runInContext()` when the `output` option is set to `"parser"`
dependencies | `{}` | parser dependencies, the value is an object which maps variables used to access the dependencies to module IDs used to load them; valid only when `format` is set to `"amd"`, `"commonjs"`, `"es"`, or `"umd"`
exportVar | `null` | name of an optional global variable into which the generated parser object is assigned to when no module loader is detected; valid only when `format` is set to `"globals"` or `"umd"`
features | `null` | map of optional features that are set to `true` by default: `"text"`, `"offset"`, `"range"`, `"location"`, `"expected"`, `"error"` and `"filename"`
features | `null` | map of optional features that are set to `true` by default: `"text"`, `"offset"`, `"range"`, `"location"`, `"expected"`, `"error"`, `"filename"` and `"DefaultTracer"`
format | `"bare"` | format of the generated parser (`"amd"`, `"bare"`, `"commonjs"`, `"es"`, `"globals"`, or `"umd"`); valid only when `output` is set to `"source"`
header | `null` | adds additional comments or content after the `Generated by ...` comment; this option is only handled if it's an array or a string:
optimize | `"speed"` | selects between optimizing the generated parser for parsing speed (`"speed"`) or code size (`"size"`)

@ -1120,6 +1120,8 @@ function generateJS( ast, session, options ) {
if ( options.trace ) {
if ( use( "DefaultTracer" ) )
parts.push( [
"function peg$DefaultTracer() {",
" this.indentLevel = 0;",
@ -1177,6 +1179,15 @@ function generateJS( ast, session, options ) {
""
].join( "\n" ) );
else
parts.push( [
"var peg$FauxTracer = {",
" trace: function(event) { }",
"};",
""
].join( "\n" ) );
}
parts.push( [
@ -1257,11 +1268,20 @@ function generateJS( ast, session, options ) {
}
if ( use( "DefaultTracer" ) )
parts.push( [
" var peg$tracer = \"tracer\" in options ? options.tracer : new peg$DefaultTracer();",
""
].join( "\n" ) );
else
parts.push( [
" var peg$tracer = \"tracer\" in options ? options.tracer : peg$FauxTracer;",
""
].join( "\n" ) );
}
parts.push( [
@ -1595,7 +1615,7 @@ function generateJS( ast, session, options ) {
function generateParserObject() {
return options.trace
return options.trace && use( "DefaultTracer" )
? [
"{",
" SyntaxError: peg$SyntaxError,",
@ -1614,7 +1634,7 @@ function generateJS( ast, session, options ) {
function generateParserExports() {
return options.trace
return options.trace && use( "DefaultTracer" )
? [
"{",
" peg$SyntaxError as SyntaxError,",

@ -408,6 +408,7 @@ declare namespace peg {
expected: boolean;
error: boolean;
filename: boolean;
DefaultTracer: boolean;
}

Loading…
Cancel
Save