question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Run-time requiring of pegjs files

See original GitHub issue

Issue type

  • Bug Report: no
  • Feature Request: yes
  • Question: no
  • Not an issue: no

Prerequisites

  • Can you reproduce the issue?: n/a
  • Did you search the repository issues?: yes
  • Did you check the forums?: I don’t see links to forums
  • Did you perform a web search (google, yahoo, etc)?: yes

Description

While there might be other use cases for being able to require PEGJS files directly in Node at run-time, the main intent of this issue is for code coverage (e.g., for Mocha tests).

This latter use case of code coverage would first need #93 (providing source maps) to be first implemented. If implemented, one could avoid the need for a separate instrumented copy of one’s tests + peg code.

I see that Node’s require.extensions is used to accomplish this for ts-node, and though require.extensions is technically deprecated in Node, as per the discussions around https://stackoverflow.com/questions/28884377/better-way-to-require-extensions-with-node-js (particularly in the vein of this answer), it seems to be the only practical mechanism here, and as per the comment, I don’t think we have to worry about Node breaking Babel.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

2reactions
StoneCyphercommented, Feb 3, 2020

@brettz9 - I was about to say “I’m talking to someone else about this same thing” and then I realized it’s you, so, I’m going to cease this instance of this discussion in favor of the similar one we’re having on #633, if that seems okay to you

I’m writing something long there currently

1reaction
StoneCyphercommented, Feb 2, 2020

Also, it looks like what you actually want is testing

You don’t put the coverage hooks in the library. You put them in the test file.

If you want coverage, you can install jest and just be done. It auto-includes everything you need and no modifications need to take place to the library. Coverage tools are designed to be added from the outside, not the inside.

This parser generator should not suddenly become tied to the node.js package ecosystem as an internal feature.

Besides, coverage is a false desire for a parser. Consider the following:

Food
    / "Peanuts"
    / "Shellfish"
    / "Rice"

Now, just write a test for rice. peg is going to try Peanuts first, then when it doesn’t work peg will try Shellfish, then peg will try Rice

Notice you only wrote a test for Rice, but you’re incorrectly showing coverage for all three

The way a packrat parser (honestly the way ever parser I can think of) works means coverage is fake

Don’t waste your time

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation » PEG.js – Parser Generator for JavaScript
This writes parser source code into a file with the same name as the grammar file but with “.js” ... In Node.js, require...
Read more >
PEG.js
PEG.js as a Script Interpreter. A file converter is already quite practical, but computer science students actually thirst for their own programming language....
Read more >
A Peggy.js Tutorial - Strumenta - Federico Tomassetti
In this tutorial, we'll give an introduction to Peggy. As usual in our articles, all the code is on GitHub. Peggy is the...
Read more >
Intro to Peg.js - Nathan Pointer - Web developer
pegjs hello.pegjs. or if you need to generate a parser at run time: var peg = require("pegjs"); var grammar = "start = ('a'...
Read more >
pegjs-otf - npm
The API returned by require("pegjs-otf") is really just the PEG.js API with an additional injected method generateFromFile(filename, options) .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found