How to use the parser-ts.parser.apFirst 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
)

const equal = S.fold([S.spaces, C.char('='), S.spaces])

const unconstrainedParameterDeclaration: P.Parser = pipe(
  identifier,
  P.map(name => M.parameterDeclaration(name))
)

const constrainedParameterDeclaration: P.Parser = pipe(
  S.fold([C.char('('), S.spaces]),
  P.apSecond(
    pipe(
      pair,
      P.map(({ name, type }) => M.parameterDeclaration(name, some(type))),
      P.apFirst(S.fold([S.spaces, C.char(')')]))
    )
  )
)

export const parameterDeclaration = P.expected(
  pipe(
    unconstrainedParameterDeclaration,
    P.alt(() => constrainedParameterDeclaration)
  ),
  'a parameter'
)

const pipeParser = S.fold([S.spaces, C.char('|'), S.spaces])

/**
 * @since 0.4.0
github gcanti / fp-ts-codegen / src / haskell.ts View on Github external
const withParens = <a>(parser: P.Parser): P.Parser =&gt; {
  return pipe(
    leftParens,
    P.apSecond(parser),
    P.apFirst(rightParens)
  )
}
</a>
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
P.chain(typeParameters =>
                  pipe(
                    P.sepBy1(pipeParser, constructor),
                    P.map(constructors => M.data(name, typeParameters, constructors)),
                    P.apFirst(S.spaces),
                    P.apFirst(P.eof())
                  )
                )