View Source Cogito.Combinators (Cogito v1.2.0)

A list of basic combinators.

Building example (collect primitive):

[
  parser,
  [
    ws(),
    delimiter,
    ws(),
    parser
  ]
  |> nth(1)
  |> many()
]
|> fseq(fn [h, t] -> [h | t] end)
|> option([])

The meaning of each of them is derived from the names.

Summary

Functions

between(parser, left, right)

@spec between(Cogito.parser(), Cogito.parser(), Cogito.parser()) :: Cogito.parser()

Don't use it with Cogito.Primitives.ws() because nth(1) will break everything.

char(predicate)

@spec char((integer() -> true | false) | integer()) :: Cogito.parser()

choice(parsers)

@spec choice([Cogito.parser()]) :: Cogito.parser()

eos(parser)

@spec eos(Cogito.parser()) :: (String.t() -> {:ok, any()} | {:error, any()})

eos!(parser)

@spec eos!(Cogito.parser()) :: Cogito.parser!()

fseq(parsers, function)

@spec fseq([Cogito.parser()], (any() -> any())) :: Cogito.parser()

identity(value)

@spec identity(any()) :: Cogito.parser()

ignore(parser)

@spec ignore(Cogito.parser()) :: Cogito.parser()

join(parser)

@spec join(Cogito.parser()) :: Cogito.parser()

lazy(parser)

(macro)
@spec lazy(Cogito.parser()) :: Macro.t()

many1(parser)

@spec many1(Cogito.parser()) :: Cogito.parser()

many(parser)

@spec many(Cogito.parser()) :: Cogito.parser()

map(parser, function)

@spec map(Cogito.parser(), (any() -> any())) :: Cogito.parser()

nth(parsers, n)

@spec nth([Cogito.parser()], integer()) :: Cogito.parser()

option(parser, value)

@spec option(Cogito.parser(), any()) :: Cogito.parser()

repeat(parser, n)

@spec repeat(Cogito.parser(), integer()) :: Cogito.parser()

seq(parsers)

@spec seq([Cogito.parser()]) :: Cogito.parser()