Parselix

Provides the macro for creating parser and some helper functions.

Source

Summary

get_position(current, target, consumed)
parse(parser, target, position \\ %Parselix.Position{index: 0, vertical: 0, horizontal: 0})
parser(name, list2)

Macro for creating a parser

position(index \\ 0, vertical \\ 0, horizontal \\ 0)

Types

ok :: {:ok, any, String.t, %Parselix.Position{horizontal: term, index: term, vertical: term}}

A successful result of product parser. {:ok, RESULT, REMAINDER, NEW_POSITION}

error :: {:error, String.t, %Parselix.Position{horizontal: term, index: term, vertical: term}}

A failed result of product parser. {:error, ERROR_MESSAGE, POSITION}

ok_1 :: {:ok, any, integer}

A successful result of source parser. {:ok, RESULT, LENGTH_OF_CONSUMED_STRING}

ok_2 :: {:ok, any, String.t}

A successful result of source parser. {:ok, RESULT, REMAINDER}

error_1 :: {:error, String.t}

A failed result of source parser. {:error, ERROR_MESSAGE}

product_parser :: (String.t, %Parselix.Position{horizontal: term, index: term, vertical: term} -> ok | error)

A parser generated by parser/2.

source_parser :: (product_parser, any, String.t, %Parselix.Position{horizontal: term, index: term, vertical: term} -> ok | ok_1 | ok_2 | error | error_1)

A parser passed to parser/2.

Parameters

  1. Its own parser.
  2. The option which is passed to your parser.
  3. Target string.
  4. Current position.

Functions

get_position(current, target, consumed)
Source
parse(parser, target, position \\ %Parselix.Position{index: 0, vertical: 0, horizontal: 0})
Source

Macros

parser(name, list2)

Specs:

Macro for creating a parser.

Result format which you can return in the function.

Example

parser "any" do
  fn
    _, _, "", position -> {:error, "EOF appeared.", position}
    _, _, x, _ -> {:ok, String.first(x), 1}
  end
end
Source
position(index \\ 0, vertical \\ 0, horizontal \\ 0)
Source