Current section
Files
Jump to
Current section
Files
lib/yameru/parser/items.ex
defmodule Yameru.Parser.Items do
@moduledoc """
Abstract items parser
"""
use Pelecanus, sigil_p: true
import Yameru.Parser.Literal
alias Yameru.Parser.IndentLevel
@doc """
Parses at least 1 repetition of items.
An item is combination of `some` and `tuple`.
Value the parser return is `{some, tuple}`.
`some` is which given parser returned,
`tuple` is `Yameru.Parser.Literal.tuple/1` parsing.
Before each item, it is expected that there are indents,
and no extra spaces.
"""
@spec items(Pelecanus.parser()) :: Pelecanus.parser()
def items(e) do
sequence([
IndentLevel.indents(),
not_predicate(~p/\z/m),
choice([
item(e),
ignore(empty_line())
])
])
|> repeat_1()
|> map(&List.flatten/1)
end
@doc false
@spec item(Pelecanus.parser()) :: Pelecanus.parser()
def item(e) do
seq =
sequence([
not_predicate(~p/ +/),
e,
tuple()
])
fn state ->
with {:ok, s, [some, tuple]} <- seq.(state) do
{:ok, s, {some, tuple}}
end
end
end
end