Function chumsky::text::keyword

source ·
pub fn keyword<'a, C: Character + 'a, S: AsRef<C::Str> + 'a + Clone, E: Error<C> + 'a>(
    keyword: S
) -> impl Parser<C, (), Error = E> + Clone + 'a
Expand description

Like ident, but only accepts an exact identifier while ignoring trailing identifier characters.

The output type of this parser is ().

Examples

let def = text::keyword::<_, _, Simple<char>>("def");

// Exactly 'def' was found
assert_eq!(def.parse("def"), Ok(()));
// Exactly 'def' was found, with non-identifier trailing characters
assert_eq!(def.parse("def(foo, bar)"), Ok(()));
// 'def' was found, but only as part of a larger identifier, so this fails to parse
assert!(def.parse("define").is_err());