Comments (8)
I have thought about this too. If you like, you can try to implement it yourself -- modifying the code generator shouldn't be hard. Otherwise, I'll implement that myself soon.
from pegjs.
Ok, I may give this a shot, thanks.
from pegjs.
This issue hasn't seen much love… But it's something I'd like to see.
For a start, I might propose (and would submit a patch for):
- Adding an
options
argument tobuildParser
:
buildParser: function(grammar, options)
- If
options.debug
istrue
while code is being generated,options.log
(default"console"
) is used to print the result of each successful match (untested, but my best guess for the approximate implementation):
function parse_${name}() {
...
if (${resultVal} !== null)
${options.log}.debug("matcher ${name} succeeded:", ${resultVal});
return ${resultVal};
}
(of course, that debug code would only be included if the the code generator was asked to generate debug code)
from pegjs.
+1 on this. Having more debug information would be very helpful, especially for someone inexperienced at this sort of thing (this guy). Thanks for an awesome project btw.
from pegjs.
One thing I would like more information on, is whether the parser totally failed to parse (failed the first match) or semi-failed to parse. At this point, it seems that a parser can parse up to a certain point, and return output. How can you tell if the parser actually tried to fully parse the input, but failed at a certain point (syntax error)?
from pegjs.
I would love to have a --trace
option. I'm currently trying to figure out where a parser is failing, and it's been an awfully slow process. With a trace option, I could have found the answer very quickly.
from pegjs.
+1 here. I totally totally love PEG.js and have used it for more than once thing already, but debugging a grammar is pita. Will try patching with the suggestion above.
from pegjs.
In the past few weeks I worked on this issue and added tracing support to PEG.js-generated parsers. Instead of implementing a simple static solution, I added a flexible API which allows users to pass their own tracer to a parser. This tracer receives events about parsing progress and can decide what to do with them (display, store, etc.). There is also a built-in default tracer (used when no tracer is supplied by the user) that logs events to the console in a simple format.
Details can be found in the commit introducing tracing support.
The API is currently somewhat experimental (which is why it isn’t documented properly yet) and I expect it will evolve over time as experience is gained.
The default tracer is also somewhat bare-bones. I hope that PEG.js user community will develop more sophisticated tracers over time and I’ll be able to integrate their best ideas into the default tracer.
Big thanks goes to @ganeshv who implemented initial tracing support for PEG.js which I used as a source of inspiration.
With that, I’m closing this issue. Requests for improving the API or the default tracer should go into separate issues.
from pegjs.
Related Issues (20)
- Up-to-date JavaScript grammar HOT 2
- Using PEG.js at runtime works, but generated grammer fails to work? HOT 2
- Operator precedence tree compiling extremely slowly HOT 2
- Merging multiple single-character expressions
- Fork of the online editor with inline errors HOT 1
- Ignore me -- wrong project
- [composable, declarative, typescript] react-peg: parser generator based on pegjs
- Bug with context-sensitive grammar HOT 1
- option to generate an es module instead of commonjs module HOT 12
- Cannot use parseFloat inside grammar HOT 4
- literalEscape HOT 1
- Support for runtime context object? HOT 3
- [META] Switch to Peggy HOT 9
- Grammar action errors need to be more informative HOT 4
- Allow access to different rules in code blocks HOT 2
- Using same rule in pattern HOT 2
- Pegjs online can't parser parser.pegjs HOT 2
- Variables in parentheses can't be accessed
- Documentation should describe all features of the grammar specification language (e.g., dollar sign "$", "text()") HOT 3
- Deprecate/archive and recommend peggy.js as official successor project? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pegjs.