Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-disable */
const fs = require('fs');
const P = require('parsimmon');
const config = require('../config');
const lTagArrow = P.string('<');
const rTagArrow = P.string('>');
const endLine = P.string('/');
const doubleQuote = P.string('"');
const singleQuote = P.string("'");
const whitespaces = P.regex(/\s*/).desc('whitespaces');
const Wxml = P.createLanguage({
Symbol: function () {
return P.regexp(/[a-zA-Z_-][a-zA-Z0-9_-]*/).desc("symbol");
},
StringExpression: function () {
// return P.regexp(/[^<]+/);
return P.regex(/((?!<\/).)+/);
},
singleQuoteString: function () {
return P.seqMap(
singleQuote,
P.regexp(/[^']*/),
singleQuote,
function (r1, r2, r3) {
return {
type: 'single',
value: [r2]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const P = require("parsimmon");
const node = require("./node");
const parser = P.createLanguage({
Type: L => P.alt(L.FunctionType, L.UnionType).trim(P.optWhitespace),
FunctionType: L => P.seq(L.FunctionArgList.skip(L.ARROW), L.Type)
.map(r => new node.FunctionType(r[0], r[1])),
FunctionArgList: L => P.sepBy(L.FunctionArg, L.COMMA).wrap(L.LPAREN, L.RPAREN),
FunctionArg: L => L.USCORE.then(L.COLON).then(L.Type),
UnionType: L => P.sepBy1(L.IntersectionType, L.OR)
.map(r => new node.UnionType(r)),
IntersectionType: L => P.sepBy1(L.ArrayType, L.AND)
.map(r => new node.IntersectionType(r)),
ArrayType: L => P.seq(L.PrimaryType, L.BRACKS)
.map(r => new node.ArrayType(r[0], r[1])),
PrimaryType: L => P.alt(L.Type.wrap(L.LPAREN, L.RPAREN), L.TupleType, L.ObjectType, L.AtomicType),
TupleType: L => P.sepBy(L.Type, L.COMMA).wrap(L.LBRACK, L.RBRACK)
.map(r => new node.TupleType(r)),
ObjectType: L => P.sepBy(P.alt(L.DOTS, L.ObjectElement), L.COMMA).wrap(L.LBRACE, L.RBRACE)
.map((r) => {
},
optBlank (r) {
return r.blank.atMost(1);
},
optNotPrefix (r) {
return r.NOT.skip(r.blank).atMost(1).map(data => !data.length ? '' : 'not_');
},
optNotSuffix (r) {
return r.NOT.skip(r.blank).atMost(1).map(data => !data.length ? '' : '_not');
}
});
const language = Pa.createLanguage(parsers);
return language[options.type];
}
export const createCommandParser = (opts: ParserOptions) => P.createLanguage({
singleWord: () => {
return P.regexp(/(\w|\d)+/);
},
quote: () => {
return P.string('"');
},
true: () => {
return P.alt(...truthy.map(P.string))
.result(true)
.desc("true");
},
false: () => {
return P.alt(...falsy.map(P.string))
.result(false)
.desc("false");
},
r: '\r',
t: '\t'
};
return str.replace(/\\(u[0-9a-fA-F]{4}|[^u])/, function (_, escape) {
var type = escape.charAt(0);
var hex = escape.slice(1);
if (type === 'u') {
return String.fromCharCode(parseInt(hex, 16));
}
if (escapes.hasOwnProperty(type)) {
return escapes[type];
}
return type;
});
}
exports.default = P.createLanguage({
_: function () { return P.optWhitespace; },
letters: function () { return P.regexp(/[a-zA-Z0-9$_]+/).skip(whitespace).desc('letters'); },
lettersArray: function (r) { return r.lbracket.then(r.letters.sepBy(r.comma)).skip(r.rbracket).desc('letters array'); },
arg: function (r) { return r.letters.or(r.lettersArray).desc('arg'); },
lbracket: function () { return word('['); },
rbracket: function () { return word(']'); },
lparen: function () { return word('('); },
get: function () { return word('get'); },
rparen: function () { return word(')'); },
lbrace: function () { return word('{'); },
rbrace: function () { return word('}'); },
comma: function () { return word(','); },
dot: function () { return word('.'); },
semi: function () { return word(';'); },
arrow: function () { return word('=>'); },
param: function (r) {
export const parse = content => {
const language = P.createLanguage(
Object.assign(
{
blocks(r) {
return P.alt(
r.fallback.map(({ name, attributes }) =>
createBlock(name, attributes)
),
...getBlockTypes().map(block => r[block.name])
)
.sepBy(r.newline.atLeast(1))
.trim(r.newline.many());
}
},
getBlockTypes().reduce((memo, block) => {
memo[block.name] = getBlockTypeParserHelper(block);
return memo;
const Parsimmon = require('parsimmon');
const Lang = Parsimmon.createLanguage({
Text: r =>
Parsimmon.alt(
r.Superscript,
r.Subscript,
r.UnaryMacro,
r.NullaryMacro,
r.Illegal,
r.PlainText
).many(),
Superscript: () =>
Parsimmon.seq(
Parsimmon.regexp(/\^\s*/),
Parsimmon.alt(
Parsimmon.regexp(/{[a-zA-Z0-9+-]+}/),
Parsimmon.regexp(/[a-zA-Z0-9+-]/)
}
}
class Identifier {
constructor(readonly text: string) {}
match(node: ts.Node, typeChecker: ts.TypeChecker) {
const s = getFullQualifiedName(node, typeChecker);
return s === this.text;
}
}
const parser = P.createLanguage({
Term: r => r.Identifier.map(qi => new Term(qi)),
Identifier: _ => P.regex(/[\/\.a-zA-Z0-9_-]+/).map(s => new Identifier(s)),
});
class InvalidPattern extends Error {
constructor(readonly index: number, readonly error: Error) {
super();
}
}
function getFullQualifiedName(node: ts.Node, typeChecker: ts.TypeChecker) {
import * as P from 'parsimmon';
import * as node from './node';
const parser = P.createLanguage({
Type: L => P.alt(L.FunctionType, L.UnionType).trim(P.optWhitespace),
FunctionType: L => P.seq(L.FunctionArgList.skip(L.ARROW), L.Type)
.map(r => new node.FunctionType(r[0], r[1])),
FunctionArgList: L => P.sepBy(L.FunctionArg, L.COMMA).wrap(L.LPAREN, L.RPAREN),
FunctionArg: L => L.USCORE.then(L.COLON).then(L.Type),
UnionType: L => P.sepBy1(L.IntersectionType, L.OR)
.map(r => new node.UnionType(r)),
IntersectionType: L => P.sepBy1(L.ArrayType, L.AND)
.map(r => new node.IntersectionType(r)),
import { typeParser } from './type/parser';
import { Pattern } from './pattern';
export function parse(patterns: string[]) {
const exprs = patterns.map((pat, idx) => {
try {
return parser.Expression.tryParse(pat);
} catch (e) {
e.index = idx;
throw e;
}
});
return new Pattern(exprs);
}
const parser = P.createLanguage({
Expression: L => P.sepBy1(L.Term, L.OR).trim(P.optWhitespace)
.map(r => new node.Expression(r)),
Term: L => P.sepBy1(L.Factor, L.AND).trim(P.optWhitespace)
.map(r => new node.Term(r)),
Factor: L => P.seq(L.Element, L.TypeAnnotation.times(0, 1)).trim(P.optWhitespace)
.map(r => new node.Factor(r[0], r[1].length === 0 ? undefined : r[1][0])),
Element: L => P.alt(
L.NOT.then(L.Element).map(f => new node.Not(f)),
L.Expression.wrap(L.LPAREN, L.RPAREN),
L.Atom,
).trim(P.optWhitespace),