-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add web workers, parse automatically
I thought the demo might be nicer if it used web workers to parse the grammar in the background. That way it doesn't block the DOM, so it's a bit smoother. Additionally, since we're not blocking the DOM, we can just automatically re-parse the file as the user types. I set a debounce of 700ms so that it doesn't fire too frequently. I also removed the "Generate" button entirely, and set it up so there's a little "Parsing..." message while it's parsing. I also made to sure to do a fallback if web workers aren't supported in the browser (and I tested that it works). You can try a demo [here](https://nolanlawson.s3.amazonaws.com/jison/try/index.html).
- Loading branch information
1 parent
245f6dd
commit 28debc7
Showing
5 changed files
with
132 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
importScripts('jison.js'); | ||
Jison.print = function () {}; | ||
|
||
// request to parse a grammar | ||
self.addEventListener('message', function (e) { | ||
if (typeof e.data !== 'string') { | ||
return; | ||
} | ||
|
||
var grammar = e.data; | ||
|
||
var cfg; | ||
|
||
try { | ||
cfg = JSON.parse(grammar); | ||
} catch (e) { | ||
// intentionally throw an error here if it fails to parse | ||
cfg = bnf.parse(grammar); | ||
} | ||
|
||
self.postMessage({result: {cfg: cfg, type: "lalr"}}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters