Forbid using keywords as identifiers

This commit is contained in:
Joscha 2022-11-18 21:05:57 +01:00
parent 41723eb4ca
commit 4fdce864d3

View file

@ -41,6 +41,14 @@ pub fn space() -> impl Parser<char, Space, Error = Error> {
} }
pub fn ident() -> impl Parser<char, Ident, Error = Error> { pub fn ident() -> impl Parser<char, Ident, Error = Error> {
// TODO Forbid keywords text::ident().try_map(|name, span| {
text::ident().map_with_span(|name, span| Ident { name, span }) if matches!(
&name as &str,
"nil" | "true" | "false" | "local" | "not" | "and" | "or"
) {
Err(Simple::custom(span, "identifier uses reserved name"))
} else {
Ok(Ident { name, span })
}
})
} }