Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const isPunctuation = (c: string): boolean => '| =\n():,{};[]->'.indexOf(c) !== -1
const identifierFirstLetter = P.sat(c => !isDigit(c) && !isPunctuation(c))
const identifierBody = P.sat(c => !isPunctuation(c))
/**
* @since 0.4.0
*/
export const identifier: P.Parser = P.expected(
S.fold([identifierFirstLetter, C.many(identifierBody)]),
'an identifier'
)
const leftParens: P.Parser = S.fold([C.char('('), S.spaces])
const rightParens: P.Parser = S.fold([S.spaces, C.char(')')])
const withParens = <a>(parser: P.Parser): P.Parser => {
return pipe(
leftParens,
P.apSecond(parser),
P.apFirst(rightParens)
)
}
const unparametrizedRef: P.Parser = pipe(
identifier,
P.map(name => M.ref(name))
)
</a>
P.chain(name =>
pipe(
S.spaces,
P.apSecond(P.sepBy(S.spaces, parameterDeclaration)),
P.apFirst(equal),
P.chain(typeParameters =>
pipe(
P.sepBy1(pipeParser, constructor),
P.map(constructors => M.data(name, typeParameters, constructors)),
P.apFirst(S.spaces),
P.apFirst(P.eof())
)
)
)
)