Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
compile() {
const source = this.cm.getValue()
// TODO cache compiled-ness
const model = this._model
const parser = new nearley.Parser(grammar)
try {
parser.feed(source)
} catch (e) {
console.error(e)
model.scripts = { error: e }
return
}
const results = parser.results
if (results.length > 1) throw new Error("Ambiguous!")
const scripts = []
const x = 10
var y = 10
for (let script of results[0]) {
scripts.push([x, y, script])
y += measure(script) + 10
}
static compileGrammar(sourceCode) {
try {
// Parse the grammar source into an AST
const grammarParser = new nearley.Parser(nearleyGrammar);
grammarParser.feed(sourceCode);
const grammarAst = grammarParser.results[0]; // TODO check for errors
// Compile the AST into a set of rules
const grammarInfoObject = compile(grammarAst, {});
// Generate JavaScript code from the rules
const grammarJs = generate(grammarInfoObject, 'grammar');
// Pretend this is a CommonJS environment to catch exports from the grammar.
const module = {
exports: {}
};
eval(grammarJs);
return module.exports;
} catch (err) {
Logger.error(err);
function publish(input, shouldMinify, useFS, filePrefix) {
var parser = new nearley.Parser(grammar.ParserRules, grammar.ParserStart);
if(!filePrefix) filePrefix = "";
var cssFile = filePrefix + "common.css";
var themeFile = filePrefix + "themes/modern.dark.css";
var jsFile = filePrefix + "scripts.js";
if(useFS) {
fs = require("fs"); // intentional lack of var keyword
}
parser.current = 0;
parser.feed(input);
var res = parser.results[0];
var code = "";
NearlyParser.prototype.astListFromString = function (source) {
var parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar_1.default));
var results = parser.feed(source).results;
if (results.length === 0) {
console.error('Parsing failed!');
return [];
}
if (results.length > 1) {
console.error('Ambigous grammar!');
}
var astList = results[0].map(function (ret) { return ret[0]; });
return astList;
};
NearlyParser.prototype.astFromFile = function (path, opt) {
static format(formalSyntax) {
const parser = new nearley.Parser(grammar.ParserRules, grammar.ParserStart).feed(formalSyntax);
const [rootNode] = parser.results;
return JsonGrammarFormatter2._evaluateNode(rootNode);
}
getParser() {
if (!this.grammarAst) {
throw new Error('Must call setGrammar or buildGrammar before calling getParser');
}
return new nearley.Parser(nearley.Grammar.fromCompiled(this.grammarAst));
}