Expand description
§Example
let env = LanguageEnv::new(LanguageDef {
ident: Identifier {
start: letter(),
rest: alpha_num(),
reserved: ["if", "then", "else", "let", "in", "type"].iter()
.map(|x| (*x).into())
.collect(),
},
op: Identifier {
start: satisfy(|c| "+-*/".chars().any(|x| x == c)),
rest: satisfy(|c| "+-*/".chars().any(|x| x == c)),
reserved: ["+", "-", "*", "/"].iter().map(|x| (*x).into()).collect()
},
comment_start: string("/*").map(|_| ()),
comment_end: string("*/").map(|_| ()),
comment_line: string("//").map(|_| ()),
});
let id = env.identifier();//An identifier parser
let integer = env.integer();//An integer parser
let result = (id, integer).easy_parse("this /* Skips comments */ 42");
assert_eq!(result, Ok(((String::from("this"), 42), "")));
Structs§
- Assoc
- Struct for encompassing the associativity of an operator
- Between
Char - Parses
P
between two delimiter characters - Expression
- Expression parser which handles binary operators
- Identifier
- Defines how to define an identifier (or operator)
- Language
Def - A struct type which contains the necessary definitions to construct a language parser
- Language
Env - A type containing parsers for a specific language.
For some parsers there are two version where the parser which ends with a
_
is a variant which does not skip whitespace and comments after parsing the token itself. - Lex
- A lexing parser for a language
- Reserved
- Parses a reserved word
- White
Space - A whitespace parser for a language
Enums§
- Fixity
- Enumeration on fixities for the expression parser
Functions§
- expression_
parser - Constructs an expression parser out of a term parser, an operator parser and a function which combines a binary expression to new expressions.
- float