ramble
Types
pub type FinalParseResult(t, a) {
FinalParseResult(
value: Result(a, ParseError(t)),
errors: List(ParseError(t)),
)
}
Constructors
-
FinalParseResult( value: Result(a, ParseError(t)), errors: List(ParseError(t)), )
pub type ParseError(t) {
Unexpected(
pos: Position,
token: Token(t),
expected: List(Token(t)),
)
}
Constructors
-
Unexpected( pos: Position, token: Token(t), expected: List(Token(t)), )
pub type ParseResult(t, a) {
ParseResult(
value: Result(a, ParseError(t)),
rest: List(t),
new_pos: Position,
errors: List(ParseError(t)),
)
}
Constructors
-
ParseResult( value: Result(a, ParseError(t)), rest: List(t), new_pos: Position, errors: List(ParseError(t)), )
The parser type, parameterized by the type it parses and the user-defined error type it can return.
pub type Parser(t, a) {
Parser(
parse: fn(
List(t),
Position,
ParserConfig(t),
Option(Parser(t, t)),
) ->
ParseResult(t, a),
)
}
Constructors
-
Parser( parse: fn( List(t), Position, ParserConfig(t), Option(Parser(t, t)), ) -> ParseResult(t, a), )
pub type ParserConfig(t) {
ParserConfig(
newline: t,
eof: t,
source_name: String,
token_to_string: fn(t) -> String,
)
}
Constructors
-
ParserConfig( newline: t, eof: t, source_name: String, token_to_string: fn(t) -> String, )
The type for positions within a string.
pub type Position {
Position(row: Int, col: Int)
}
Constructors
-
Position(row: Int, col: Int)
pub type Token(t) {
Token(t)
LabeledToken(String)
}
Constructors
-
Token(t)
-
LabeledToken(String)
Functions
pub fn an_token(c: String) -> Parser(String, String)
pub fn any_token() -> Parser(a, a)
pub fn char_in_range(
from from: Int,
until to: Int,
) -> Parser(String, String)
pub fn choice(ps: List(Parser(a, b))) -> Parser(a, b)
Parse with the first parser in the list that doesn’t fail.
pub fn consume_and_discard_until(
p: Parser(a, a),
) -> Parser(a, Nil)
pub fn desperate_custom_parser(
parse: fn(
List(a),
Position,
ParserConfig(a),
Option(Parser(a, a)),
) -> ParseResult(a, b),
) -> Parser(a, b)
This grants full control over parsing by allowing a custom parse function. This is like making the Parser type not-opaque. Use this with caution, and be sure to mind the invariants of the library. It should be very rare that you need to use this.
pub fn do_and_recover(
p: Parser(a, b),
recovery: Parser(a, a),
) -> Parser(a, b)
pub fn either(p1: Parser(a, b), p2: Parser(a, b)) -> Parser(a, b)
pub fn extract(
p: Parser(a, b),
k: fn(b) -> Parser(a, c),
) -> Parser(a, c)
pub fn get_config() -> Parser(a, ParserConfig(a))
pub fn get_errors(res: ParseResult(a, b)) -> List(ParseError(a))
pub fn go(
p: Parser(String, a),
src: String,
config: ParserConfig(String),
) -> FinalParseResult(String, a)
Apply a parser to a string.
pub fn go_on_tokens(
p: Parser(a, b),
src: List(a),
config: ParserConfig(a),
) -> FinalParseResult(a, b)
pub fn label(
label: String,
p: fn() -> Parser(a, b),
) -> Parser(a, b)
pub fn main() -> Nil
pub fn map(p: Parser(a, b), f: fn(b) -> c) -> Parser(a, c)
Do p
, then apply f
to the result if it succeeded.
pub fn recover() -> Parser(a, Nil)
pub fn return(a: a) -> Parser(b, a)
pub fn satisfy(when pred: fn(a) -> Bool) -> Parser(a, a)
Parse a character if it matches the predicate.
pub fn seq(p1: Parser(a, b), p2: Parser(a, c)) -> Parser(a, c)