Forbid using keywords as identifiers
This commit is contained in:
parent
41723eb4ca
commit
4fdce864d3
1 changed files with 10 additions and 2 deletions
|
|
@ -41,6 +41,14 @@ pub fn space() -> impl Parser<char, Space, Error = Error> {
|
|||
}
|
||||
|
||||
pub fn ident() -> impl Parser<char, Ident, Error = Error> {
|
||||
// TODO Forbid keywords
|
||||
text::ident().map_with_span(|name, span| Ident { name, span })
|
||||
text::ident().try_map(|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 })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue