Skip to content

Commit

Permalink
Merge pull request #15 from savetheclocktower/upgrade-pegjs
Browse files Browse the repository at this point in the history
Upgrade to PEGjs 0.10…
  • Loading branch information
savetheclocktower committed Jun 23, 2023
2 parents 78cb1c9 + c6f8325 commit 70bfe83
Show file tree
Hide file tree
Showing 6 changed files with 3,402 additions and 296 deletions.
10 changes: 7 additions & 3 deletions lib/snippet-body-parser.js
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

0 comments on commit 70bfe83

Please sign in to comment.