GithubHelp home page GithubHelp logo

Other useful debugging output about pegjs HOT 8 CLOSED

pegjs avatar pegjs commented on May 28, 2024
Other useful debugging output

from pegjs.

Comments (8)

dmajda avatar dmajda commented on May 28, 2024

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.

celer avatar celer commented on May 28, 2024

Ok, I may give this a shot, thanks.

from pegjs.

wolever avatar wolever commented on May 28, 2024

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 to buildParser:
      buildParser: function(grammar, options)
  • If options.debug is true 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.

knewter avatar knewter commented on May 28, 2024

+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.

CMCDragonkai avatar CMCDragonkai commented on May 28, 2024

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.

hegemonic avatar hegemonic commented on May 28, 2024

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.

christofmuc avatar christofmuc commented on May 28, 2024

+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.

dmajda avatar dmajda commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.