Combine.Parsers.Text
This module defines common textual parsers, i.e. char, word, space, etc. To use them, just add import Combine.Parsers.Text
to your module, or reference them directly.
Summary↑
alphanumeric() | Parses any alphanumeric character (0-9, A-Z, a-z) |
alphanumeric(parser) | Same as alphanumeric/0, but acts as a combinator |
bin_digit() | Parses any binary digit (0 | 1) |
bin_digit(parser) | Same as bin_digit/0, but acts as a combinator |
char() | This parser parses a single valid character from the input |
char(c) | Parses a single character from the input and verifies it matches the provided character |
char(parser, c \\ nil) | Same as char/0 or char/1 except acts as a combinator |
digit() | Parses any digit (0..9). Result is returned as an integer |
digit(parser) | Same as digit/0, but acts as a combinator |
float() | Parses a floating point number from the input |
float(parser) | Same as float/0, but acts as a combinator |
hex_digit() | Parses any hexadecimal digit (0-9, A-F, a-f) |
hex_digit(parser) | Same as hex_digit/0, but acts as a combinator |
integer() | Parses an integer value from the input |
integer(parser) | Same as integer/0, but acts as a combinator |
letter() | Parses any letter in the English alphabet (A..Z or a..z) |
letter(parser) | Same as letter/0, but acts as a combinator |
lower() | Parses any lower case character |
lower(parser) | Same as lower/0, but acts as a combinator |
newline() | This parser will parse a single newline from the input, this can be either LF, or CRLF newlines ( |
newline(parser) | Same as newline/0, but acts as a combinator |
octal_digit() | Parses any octal digit (0-7) |
octal_digit(parser) | Same as octal_digit/0, but acts as a combinator |
space() | This parser parses a single space character from the input |
space(parser) | Same as space/0 except acts as a combinator, applying the first parser, then parsing a single space character |
spaces() | Parses spaces until a non-space character is encountered. Returns all spaces collapsed as a single result |
spaces(parser) | Same as spaces/0, but acts as a combinator |
string(expected) | Parses the given string constant from the input |
string(parser, expected) | Same as string/1, but acts as a combinator |
tab() | This parser will parse a single tab character from the input |
tab(parser) | Same as tab/0 except acts as a combinator, applying the first parser, then parsing a single tab character |
upper() | Parses any upper case character |
upper(parser) | Same as upper/0, but acts as a combinator |
word() | Parses a string consisting of non-word characters from the input |
word(parser) | Same as word/0, but acts as a combinator |
Types ↑
Functions
Specs:
- alphanumeric :: parser
Parses any alphanumeric character (0-9, A-Z, a-z).
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("d3", alphanumeric)
["d"]
Same as alphanumeric/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("d3", alphanumeric |> alphanumeric)
["d", "3"]
Specs:
- bin_digit :: parser
Parses any binary digit (0 | 1).
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("1010", bin_digit)
[1]
Same as bin_digit/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("1010", bin_digit |> bin_digit)
[1, 0]
Specs:
- char :: parser
This parser parses a single valid character from the input.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("Hi", char)
["H"]
Specs:
Parses a single character from the input and verifies it matches the provided character.
Example
iex> import Elixir.Combine.Parsers.Text
...> parser = char("H")
...> Combine.parse("Hi!", parser)
["H"]
Specs:
Same as char/0 or char/1 except acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> parser = char("H") |> char("i") |> char
...> Combine.parse("Hi!", parser)
["H", "i", "!"]
Specs:
- digit :: parser
Parses any digit (0..9). Result is returned as an integer.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("1010", digit)
[1]
Same as digit/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("1010", digit |> digit)
[1, 0]
Specs:
- float :: parser
Parses a floating point number from the input.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("1234.5, stuff", float)
[1234.5]
Same as float/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("float: 1234.5", word |> char(":") |> space |> float)
["float", ":", " ", 1234.5]
Specs:
- hex_digit :: parser
Parses any hexadecimal digit (0-9, A-F, a-f).
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("d3adbeeF", hex_digit)
["d"]
Same as hex_digit/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("d3adbeeF", hex_digit |> hex_digit)
["d", "3"]
Specs:
- integer :: parser
Parses an integer value from the input.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("1234, stuff", integer)
[1234]
Same as integer/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("stuff, 1234", word |> char(",") |> space |> integer)
["stuff", ",", " ", 1234]
Specs:
- letter :: parser
Parses any letter in the English alphabet (A..Z or a..z).
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("hi", letter)
["h"]
Same as letter/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("hi", char("h") |> letter)
["h", "i"]
Specs:
- lower :: parser
Parses any lower case character.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("hi", lower)
["h"]
Specs:
Same as lower/0, but acts as a combinator
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("Hi", char("H") |> lower)
["H", "i"]
Specs:
- newline :: parser
This parser will parse a single newline from the input, this can be either LF, or CRLF newlines ( or
). The result is normalized to
.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("\r\n", newline)
["\n"]
Same as newline/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("H\r\n", upper |> newline)
["H", "\n"]
Specs:
- octal_digit :: parser
Parses any octal digit (0-7).
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("3157", octal_digit)
[3]
Same as octal_digit/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("3157", octal_digit |> octal_digit)
[3, 1]
Specs:
- space :: parser
This parser parses a single space character from the input.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse(" ", space)
[" "]
Same as space/0 except acts as a combinator, applying the first parser, then parsing a single space character.
Example
iex> import Elixir.Combine.Parsers.Text
...> parser = char("h") |> char("i") |> space |> char("!")
...> Combine.parse("hi !", parser)
["h", "i", " ", "!"]
Specs:
- spaces :: parser
Parses spaces until a non-space character is encountered. Returns all spaces collapsed as a single result.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse(" hi!", spaces)
[" "]
Same as spaces/0, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("Hi Paul", string("Hi") |> spaces |> string("Paul"))
["Hi", " ", "Paul"]
Specs:
Parses the given string constant from the input.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("Hi Paul", string("Hi"))
["Hi"]
Same as string/1, but acts as a combinator.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("Hi Paul", string("Hi") |> space |> string("Paul"))
["Hi", " ", "Paul"]
Specs:
- tab :: parser
This parser will parse a single tab character from the input.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse(" ", tab)
[" "]
Same as tab/0 except acts as a combinator, applying the first parser, then parsing a single tab character.
Example
iex> import Elixir.Combine.Parsers.Text
...> parser = char("h") |> char("i") |> tab |> char("!")
...> Combine.parse("hi !", parser)
["h", "i", " ", "!"]
Specs:
- upper :: parser
Parses any upper case character.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("Hi", upper)
["H"]
Specs:
Same as upper/0, but acts as a combinator
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("HI", char("H") |> upper)
["H", "I"]
Specs:
- word :: parser
Parses a string consisting of non-word characters from the input.
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("Hi, Paul", word)
["Hi"]
Same as word/0, but acts as a combinator
Example
iex> import Elixir.Combine.Parsers.Text
...> Combine.parse("Hi Paul", word |> space |> word)
["Hi", " ", "Paul"]