How to use the parser-ts.parser.chain function in parser-ts

To help you get started, we’ve selected a few parser-ts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gcanti / fp-ts-codegen / src / haskell.ts View on Github external
P.chain(() =>
      pipe(
        ref,
        P.alt(() => tuple),
        P.chain(domain =>
          pipe(
            arrow,
            P.apSecond(type),
            P.map(codomain => M.fun(domain, codomain))
          )
        )
      )
    )
github gcanti / fp-ts-codegen / src / haskell.ts View on Github external
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())
                  )
                )
              )
            )
github gcanti / fp-ts-codegen / src / haskell.ts View on Github external
S.fold([S.spaces, S.string('::'), S.spaces]),
      P.apSecond(type),
      P.map(type => ({ name, type }))
    )
  )
)

const pairs: P.Parser> = pipe(
  S.fold([C.char('{'), S.spaces]),
  P.apSecond(P.sepBy(comma, pair)),
  P.apFirst(S.fold([S.spaces, C.char('}')]))
)

const recordConstructor: P.Parser = pipe(
  identifier,
  P.chain(name =>
    pipe(
      S.spaces,
      P.apSecond(
        pipe(
          pairs,
          P.map(pairs => M.constructor(name, pairs.map(({ name, type }) => M.member(type, some(name)))))
        )
      )
    )
  )
)

const positionalConstructor: P.Parser = pipe(
  identifier,
  P.chain(name =>
    pipe(