Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import P from 'parsimmon'
import type { NodeType } from '../../types'
export default P.regexp(
/(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/
).map((value: string): NodeType => ({
name: 'primitive',
value
}))
function contributorsParser(strict) {
// Need to remove '^' and '$' from the regex, parsimmon does not expect those.
const contributor = strict
? pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/\/, 1), (name, username) => ({ name, url: "https://github.com/" + username }))
: pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/<([^>]+)>/, 1), (name, url) => ({ name, url }));
const contributors = pm.sepBy1(contributor, separator);
if (!strict) {
// Allow trailing whitespace.
return pm.seqMap(contributors, pm.regexp(/ */), a => a);
}
return contributors;
}
// TODO: Should we do something with the URL?
// @flow
import P from 'parsimmon'
import type { InputPropNodeType } from '../types'
export default P.regexp(/\.[$A-Z_][0-9A-Z_$]*/i)
.map((value: string): InputPropNodeType => ({
name: 'inputProp',
value
}))
.desc('inputProp')
_: () => Parsimmon.regexp(/\s*/),
});
import P from 'parsimmon'
import BinaryOperatorParser from '../abstract/binaryOperator'
import UnaryOperatorParser from './unaryOperator'
import type { ParserType } from '../../types'
const processBoolean2 = (x: string): string => x + '='
const processBoolean3 = (x: string): string =>
x === 'or' ? '||' : x === 'and' ? '&&' : x
const operatorPrecedenceTable = [
['unary', UnaryOperatorParser],
['multiplicative', P.regexp(/[*/%]/)],
['additive', P.regexp(/[+-]/)],
['boolean1', P.regexp(/[<>]=?/)],
['boolean2', P.regexp(/[=!]=/).map(processBoolean2)],
['boolean3', P.regexp(/(\|\||&&|or|and)/).map(processBoolean3)]
]
export default operatorPrecedenceTable
.slice(1)
.reduce(
(
ParentParser: ParserType,
[parserDecription, Parser]: [string, ParserType]
): ParserType =>
BinaryOperatorParser(ParentParser, Parser, parserDecription),
operatorPrecedenceTable[0][1]
)
param: r =>
P.regexp(/"((?:\\.|.)*?)"/, 1)
.map(value => ({
type: 'string',
value: interpretEscapes(value)
}))
.or(P.regexp(/'((?:\\.|.)*?)'/, 1).map(value => ({
type: 'string',
value: interpretEscapes(value)
})))
.or(P.regexp(/\d+/).map(value => ({
type: 'number',
value: Number(value)
})))
.or(r.letters.map(value => ({
type: 'variable',
value,
}))),
const typeVariable = (token(P.regexp(/[A-Z]+[A-Z0-9]*/)).map((n) => {
let t = var_map.get(n)
if (t === undefined) {
t = new AST.TypeVariable(n)
var_map.set(n, t)
}
return t
})).desc('type-variable')
let texp
const tl2 = P.sepBy(P.lazy(() => {return texp}), comma).desc('type-list')
const typeList = token(P.string('[')).then(tl2).skip(token(P.string(']')))
const typeConstructor = P.seqMap(
token(P.regexp(/^(?=.*[a-z])[A-Z][a-zA-Z0-9]+/)).desc('type-constructor'),
typeList.or(P.succeed([])),
(n, ps) => {return new AST.TypeConstructor(n, ps)}
)
const typeSubExpression = P.seqMap(
typeList.map((ts) => {return new AST.TypeConstructor('Product', ts)}).
or(typeConstructor).or(typeVariable).or(inParenthesis(P.lazy(() => {return texp}))),
optional(token(P.string('as')).then(typeVariable)),
(texp, mu) => {
if (mu !== undefined) {
if (!unify.types(texp, mu)) {
throw 'unification error when parsing recursive type'
}
}
return texp
}
param: function (r) {
return P.regexp(/"((?:\\.|.)*?)"/, 1)
.map(function (value) { return ({
type: 'string',
value: interpretEscapes(value)
}); })
.or(P.regexp(/'((?:\\.|.)*?)'/, 1).map(function (value) { return ({
type: 'string',
value: interpretEscapes(value)
}); }))
.or(P.regexp(/\d+/).map(function (value) { return ({
type: 'number',
value: Number(value)
}); }))
.or(r.letters.map(function (value) { return ({
type: 'variable',
value: value,
}); }));
},
field: function (r) { return r._
param: function (r) {
return P.regexp(/"((?:\\.|.)*?)"/, 1)
.map(function (value) { return ({
type: 'string',
value: interpretEscapes(value)
}); })
.or(P.regexp(/'((?:\\.|.)*?)'/, 1).map(function (value) { return ({
type: 'string',
value: interpretEscapes(value)
}); }))
.or(P.regexp(/\d+/).map(function (value) { return ({
type: 'number',
value: Number(value)
}); }))
.or(r.letters.map(function (value) { return ({
type: 'variable',
value: value,
}); }));
},
field: function (r) { return r._