Expand description
A declarative parsing library for extremely simple, concise parsing. See parser! for usage instructions.
Example JSON parser using Untwine:
ⓘ
untwine::parser! {
[error = ParseJSONError]
sep = #{char::is_ascii_whitespace}*;
comma = sep "," sep;
int: num=<"-"? '0'-'9'+> -> JSONValue { JSONValue::Int(num.parse()?) }
float: num=<"-"? '0'-'9'+ "." '0'-'9'+> -> JSONValue { JSONValue::Float(num.parse()?) }
str_char = ("\\" . | [^"\""]) -> char;
str: "\"" chars=str_char* "\"" -> JSONValue { JSONValue::String(chars.into_iter().collect()) }
null: "null" -> JSONValue { JSONValue::Null }
bool: bool=<"true" | "false"> -> JSONValue { JSONValue::Bool(bool == "true") }
list: "[" sep values=json$comma* sep "]" -> JSONValue { JSONValue::List(values) }
map_entry: key=str sep ":" sep value=json -> (String, JSONValue) { (key.string().unwrap(), value) }
map: "{" sep values=map_entry$comma* sep "}" -> JSONValue { JSONValue::Map(values.into_iter().collect()) }
pub json = (bool | null | str | float | int | list | map) -> JSONValue;
}Re-exports§
pub use error::ParserError;pub use recoverable::Recoverable;
Modules§
Macros§
- parser
- Generate parsers using a series of declarative patterns and blocks evaluating their values.
Structs§
- Span
- Represents data corresponding to a specific portion of a parsing input.
Functions§
- parse
- Parse a value with a parser function created by the parser! block.
- parse_
pretty - Parse a value with a parser function created by the parser! block, and convert the error to a pretty string if there is one.
- parser_
repl - Launches a (very) simple REPL where you can enter individual lines and see the parser output, useful for testing.
Multiline inputs are not supported, so literal
\nin the input will be replaced with a newline.