Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line to generate the same output as the "online" version? #188

Open
tomqwpl opened this issue Oct 4, 2021 · 1 comment
Open

Comments

@tomqwpl
Copy link

tomqwpl commented Oct 4, 2021

I'm trying to work out how to use the peggy command line to generate the same output as the online version. So far I've been unable.

It looks like the online version prepends the "module.exports = " bit on to the front of whatever it is that the parser generates, that bit isn't being generated by the parser generator itself. But even accounting for that, I can't find a set of command line options that make the rest get generated in the same way. "--format=globals" seems to generate the closest output that I've seen, but even this isn't quite right.

I'm not that expert in javascript, I'm just trying to set up automation of the build process rather than actually developing the parser, or the javascript that makes use of it, so forgive me if my question seems dumb. I've tried looking at the source code of the online version and the source code of the command line, but found neither particularly illuminating.

What gets you closes, is the "--format=globals" output, but the command line generates this:

// Generated by Peggy 1.2.0.
//
// https://peggyjs.org/
(function(root) {
  "use strict";
...
  root.null = {
    SyntaxError: peg$SyntaxError,
    parse: peg$parse
  };
})(this);

The online version generates:

module.exports = // Generated by Peggy 1.2.0.
//
// https://peggyjs.org/
(function() {
  "use strict";
...
  return {
    SyntaxError: peg$SyntaxError,
    parse: peg$parse
  };
})();

Thanks.

@hildjj
Copy link
Contributor

hildjj commented Oct 4, 2021

The way that the online version does it is super-manual, here:

var blob = new Blob( [$( "#parser-var" ).val() + " = " + parserSource + ";\n"], {type: "application/javascript"} );

So there's not currently a command line option that does exactly that. Depending on what you're trying to accomplish --format umd --export-var myParser might be useful. That will allow the .js file to be imported, required, or used with window.myParser in the browser.

No, I'm not sure why the online version does that, so let's keep this bug open for the online version to be normalized in some way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants