Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(grammar) {
this.parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar))
this.initial_state = this.parser.save()
/* this.results = this.parser.results */
}
}
if (opts.alreadycompiled.indexOf(path) === -1) {
opts.alreadycompiled.push(path)
if (path === 'postprocessors.ne') {
var f = require('nearley/builtin/postprocessors.ne')
} else if (path === 'whitespace.ne') {
var f = require('nearley/builtin/whitespace.ne')
} else if (path === 'string.ne') {
var f = require('nearley/builtin/string.ne')
} else if (path === 'number.ne') {
var f = require('nearley/builtin/number.ne')
} else if (path === 'cow.ne') {
var f = require('nearley/builtin/cow.ne')
}
var parserGrammar = nearley.Grammar.fromCompiled(bootstraped)
var parser = new nearley.Parser(parserGrammar)
parser.feed(f)
var c = Compile(parser.results[0], {
file: path,
__proto__: opts
})
result.rules = result.rules.concat(c.rules)
result.body = result.body.concat(c.body)
// result.customTokens = result.customTokens.concat(c.customTokens);
Object.keys(c.config).forEach(function(k) {
result.config[k] = c.config[k]
})
Object.keys(c.macros).forEach(function(k) {
result.macros[k] = c.macros[k]
})
throw new UnsupportedPropertyError(propertyName);
} else if (CSS_CONSTANTS.globalValues.includes(propertyValue)) {
return getShorthandComputedProperties(propertyName).reduce((propertyMap, computedPropertyName) => (
Object.assign({ [computedPropertyName]: propertyValue }, propertyMap)
), {});
}
// get the compiled grammar file for this property
const grammar = grammars[propertyName];
// remove any block style comments and extra whitespace
const formattedPropertyValue = propertyValue.replace(R_BLOCK_COMMENT, ' ').replace(/\s+/g, ' ').trim();
let parser;
// attempt to parse the css value, using the property specific parser
try {
parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar)).feed(formattedPropertyValue);
} catch (parseError) {
throw new ParseError(`Error parsing shorthand property ${propertyName}: ${propertyValue}. ${parseError.message}`);
}
// get the first parsing and use the formatter for the specific shorthand type for this property
const { shorthandType } = shorthandProperties[propertyName];
const [rootNode] = parser.results;
LocationIndexTracker.reset();
let propertyExpansion = shorthandPropertyTypeToActionDictionaryFactoryMap[shorthandType]
.format(propertyName, rootNode, formattedPropertyValue);
if (recursivelyResolve) {
Object.keys(propertyExpansion).forEach((prop) => {
if (shorthandProperties[prop]) {
Object.assign(
propertyExpansion,
}
if (opts.alreadycompiled.indexOf(path) === -1) {
opts.alreadycompiled.push(path);
if (path === "postprocessors.ne") {
var f = require("nearley/builtin/postprocessors.ne");
} else if (path === "whitespace.ne") {
var f = require("nearley/builtin/whitespace.ne");
} else if (path === "string.ne") {
var f = require("nearley/builtin/string.ne");
} else if (path === "number.ne") {
var f = require("nearley/builtin/number.ne");
} else if (path === "cow.ne") {
var f = require("nearley/builtin/cow.ne");
}
var parserGrammar = nearley.Grammar.fromCompiled(bootstraped);
var parser = new nearley.Parser(parserGrammar);
parser.feed(f);
var c = Compile(parser.results[0], {
file: path,
__proto__: opts
});
result.rules = result.rules.concat(c.rules);
result.body = result.body.concat(c.body);
// result.customTokens = result.customTokens.concat(c.customTokens);
Object.keys(c.config).forEach(function(k) {
result.config[k] = c.config[k];
});
Object.keys(c.macros).forEach(function(k) {
result.macros[k] = c.macros[k];
});
module.exports = function isValidDeclaration(property, value) {
if (!properties[property]) {
return false;
} else if (CSS.globalValues.includes(value) || CSS.variableRegex.test(value)) {
return true;
}
const propertyGrammar = grammars[property];
try {
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(propertyGrammar)).feed(value);
return !!parser.results.length;
} catch (parseError) {
return false;
}
};
public astListFromString(source: string): Ast[] {
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
const results = parser.feed(source).results as Ast[][][];
if (results.length === 0) {
console.error('Parsing failed!');
return [];
}
if (results.length > 1) {
console.error('Ambigous grammar!');
}
const astList: Ast[] = results[0].map(ret => ret[0]);
return astList;
}
export function Parser() {
return new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
}
module.exports = (url) => {
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
try {
parser.feed(url);
const parts = parser.results;
return parts[0];
} catch (error) {
return null;
}
};
export function generateEntryPointsFromParams(params: string): EntryPoint[] {
const parser: nearley.Parser = new nearley.Parser(nearley.Grammar.fromCompiled(EntryPointTemplate));
parser.feed(params);
return parser.results[0];
}
function parseGrammar(query) {
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
let results = parser.feed(query).results;
if (results.length === 0) {
throw new Error('Found no parsings.');
}
if (results.length > 1) {
throw new Error('Ambiguous results.');
}
return results[0];
}