-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
27 additions
and
5 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,2 +1,2 @@ | ||
node_modules/ | ||
RuleParser.production.js | ||
RuleParser.production.* |
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,11 +1,34 @@ | ||
const fs = require('fs') | ||
|
||
function makeid(length) { | ||
let result = ''; | ||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
const charactersLength = characters.length; | ||
let counter = 0; | ||
while (counter < length) { | ||
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | ||
counter += 1; | ||
} | ||
return result; | ||
} | ||
|
||
let replacements = {} | ||
const ParserRules = require('../src/RuleParser.ebnf.js') | ||
const rules = JSON.stringify(ParserRules) | ||
RegExp.prototype.toJSON = function(){ | ||
// generate a random string: | ||
const randomString = makeid(256) | ||
replacements[randomString] = this | ||
return randomString | ||
} | ||
|
||
let rules = JSON.stringify(ParserRules) | ||
for(const key in replacements){ | ||
rules = rules.replace(`"${key}"`, replacements[key].toString()) | ||
} | ||
|
||
fs.writeFileSync('src/RuleParser.ebnf.json', rules) | ||
fs.writeFileSync('src/RuleParser.production.ebnf.js', "module.exports="+rules) | ||
|
||
const ruleParserJs = fs.readFileSync('src/RuleParser.js', 'utf8') | ||
const ruleParserJsFixed = ruleParserJs.replace("require('./RuleParser.ebnf.js')", 'require(\'./RuleParser.ebnf.json\')') | ||
const ruleParserJsFixed = ruleParserJs.replace("require('./RuleParser.ebnf.js')", 'require(\'./RuleParser.production.ebnf.js\')') | ||
|
||
fs.writeFileSync('src/RuleParser.production.js', ruleParserJsFixed) |
This file was deleted.
Oops, something went wrong.