forked from atom/snippets
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from savetheclocktower/upgrade-pegjs
Upgrade to PEGjs 0.10…
- Loading branch information
Showing
6 changed files
with
3,402 additions
and
296 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
let parser | ||
try { | ||
// When the .pegjs file is stable and you're ready for release, run `npx | ||
// pegjs lib/snippet-body.pegjs` to compile the parser. That way end users | ||
// won't have to pay the cost of runtime evaluation. | ||
parser = require('./snippet-body') | ||
} catch (error) { | ||
const {allowUnsafeEval} = require('loophole') | ||
// When you're iterating on the parser, rename or delete `snippet-body.js` so | ||
// you can make changes to the .pegjs file and have them reflected after a | ||
// window reload. | ||
const fs = require('fs') | ||
const PEG = require('pegjs') | ||
|
||
const grammarSrc = fs.readFileSync(require.resolve('./snippet-body.pegjs'), 'utf8') | ||
parser = null | ||
allowUnsafeEval(() => parser = PEG.buildParser(grammarSrc)) | ||
parser = PEG.generate(grammarSrc) | ||
} | ||
|
||
module.exports = parser |
Oops, something went wrong.