pelecanus v0.1.0 Pelecanus.Operator

Basic operators of PEG.

What you can do with regex should be done with regex.

Link to this section Summary

Functions

And-predicate operator which succeeds when given parser succeeds

Ordered choice operator which is given a list of parsers

Return a parser which always succeeds with {:ok, given_state}

And-predicate operator which succeeds when given parser fails

Optional operator which succeeds regardless given parser succeeds or fails

Zero-or-more operator which invoke given parser until it fails

One-or-more operator which invoke given parser until it fails

Sequence operator which is given a list of parsers

Link to this section Functions

Link to this function and_predicate(e)
and_predicate(Pelecanus.parser()) :: Pelecanus.parser()

And-predicate operator which succeeds when given parser succeeds.

The parser return given state and no value even if given parser succeeds. This is useful for lookahead.

Ordered choice operator which is given a list of parsers.

The parser invoke given parsers in order. Each parser are given the state which the parser is given.

When one of parsers succeeds, the parser succeeds and return it’s result.

If no parser succeeds, the parser fails.

If given list is [], the parser fails.

Return a parser which always succeeds with {:ok, given_state}.

Link to this function not_predicate(e)
not_predicate(Pelecanus.parser()) :: Pelecanus.parser()

And-predicate operator which succeeds when given parser fails.

This function is counterpart of and_predicate/1.

Optional operator which succeeds regardless given parser succeeds or fails.

If given parser fails, the result is same to empty()

Zero-or-more operator which invoke given parser until it fails.

The parser returns {:ok, state, value}. state is returned given parser last succeeding. value is a list of given parser returned.

When given parser succeeds 0 times, the parser return given state and [].

When given parser return {ok, state}, no value is append to the result.

One-or-more operator which invoke given parser until it fails.

It is differ from repeat/1 that This one fails when given parser succeeds 0 times.

Link to this function sequence(e_list)
sequence([Pelecanus.parser()]) :: Pelecanus.parser()

Sequence operator which is given a list of parsers.

The parser invoke each parser in order. Each parser are passed state which previous parser return.

When one of parsers fails, the parser breaks sequence and fails.

If all parsers succeeds, the parser return {:ok, state, value}. state is last parser returned. value is a list of values each parser returned.

If given parser return {:ok, state}, no value is appended to the result.