How to use the parser-ts.string.string 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
case 0:
              return M.unit
            case 1:
              return types[0]
            default:
              return M.tuple(types)
          }
        })
      )
    ),
    P.apFirst(rightParens)
  ),
  'a tuple'
)

const arrow = S.fold([S.spaces, S.string('->'), S.spaces])

/**
 * @since 0.4.0
 */
export const fun: P.Parser = P.expected(
  pipe(
    S.spaces,
    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
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
 */
export const data: P.Parser = P.expected(
  pipe(
    S.string('data'),
    P.chain(() =>
      pipe(
        S.spaces,
        P.apSecond(
          pipe(
            identifier,
            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),
github gcanti / fp-ts-codegen / src / haskell.ts View on Github external
P.chain(name =>
    pipe(
      S.fold([S.spaces, S.string('::'), S.spaces]),
      P.apSecond(type),
      P.map(type => ({ name, type }))
    )
  )