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.

Question: is there a way to load the .ne files in the browser?

See original GitHub issue

I’m considering adding a nearley-based parser to one of the projects I work on (HERITAGE). As it stands now, I can’t keep it client-side only, and have to compile the .ne files server-side, with node.js. Is there a way to do this on the client?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
kachcommented, Dec 15, 2016
  1. If you look at the source code for quick-compiler.html, you’ll understand how to compile grammars client-side. Then you can just do that directly in the JS for your project.
window.addEventListener("load", function() {
    var grammarInput = document.getElementById("grammar-input");
    var compileInput = document.getElementById("compile-grammar");
    compileInput.addEventListener("click", function() {
        var grm = grammarInput.value;
        var parser = new nearley.Parser(grammar.ParserRules, grammar.ParserStart);
        parser.feed(grammarInput.value);
        var result = parser.results[0];
        var compiled = Compile(result, {});
        var js = generate(compiled);
        window.open("data:text/javascript;charset=utf-8,"+encodeURIComponent(js));
    }, false);

}, false);
  1. Your adblocker catches it as a popup because it tries to open a pop-up with the JS file you’re supposed to download. Just make your adblocker ignore that website via a whitelist or something and you’ll be fine.
1reaction
kachcommented, Nov 28, 2016

IF is short for Interactive Fiction, or text-based adventure games. 😃

To clarify, anyone using HERITAGE won’t need node, because you can just give them compiled .ne.js files. Assuming the grammar is fixed, you can even develop HERITAGE without node.

If you insist on being able to develop HERITAGE without node, though, you still have a few options:

  1. As you suggested, compile it once and then modify the generated JS file manually — it’s not that difficult once you get used to it.
  2. I could write a simple web-based frontend to the compiler, in the style of http://pegjs.org/online, so that you can compile without installing node and then copy the generated JS code to your project.
  3. I guess I could add an option in nearley to read a grammar directly from a string and compile it on-the-fly. But I think (1) or (2) are better ideas.

What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the best way to upload files in a modern browser
Short answer:​​ XMLHttpRequest is the best way to upload files in a modern browser. What is XMLHttpRequest? XMLHttpRequest is a JavaScript object ...
Read more >
Dealing with files - Learn web development | MDN
Save your HTML file, then load it in your web browser (double-click the file). You should see your new webpage displaying your image!...
Read more >
Windows Basics: Working with Files - GCFGlobal
There are two main ways to open a file: Find the file on your computer and double-click it. This will open the file...
Read more >
Download files from the web - Microsoft Support
Learn how to download files from the web, change your default download location, and find files you've downloaded on your PC using Internet...
Read more >
The File System Access API: simplifying access to local files
To save a file, call showSaveFilePicker() , which shows the file picker in "save" mode, allowing the user to pick a new file...
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