disallow datatype redefining

This commit is contained in:
mos 2024-11-01 11:30:13 +01:00
parent 393db5da62
commit 0b3d5b2e54
1 changed files with 5 additions and 1 deletions

View File

@ -28,6 +28,7 @@ pub enum Error {
BadWrite(std::io::Error), BadWrite(std::io::Error),
NotDefined, NotDefined,
ExpectedID, ExpectedID,
RedefData,
} }
impl fmt::Display for Error { impl fmt::Display for Error {
@ -37,6 +38,7 @@ impl fmt::Display for Error {
Self::BadWrite(e) => write!(f, "{}", e), Self::BadWrite(e) => write!(f, "{}", e),
Self::NotDefined => write!(f, "undefined data type"), Self::NotDefined => write!(f, "undefined data type"),
Self::ExpectedID => write!(f, "expected identifier"), Self::ExpectedID => write!(f, "expected identifier"),
Self::RedefData => write!(f, "redefining existing datatype"),
} }
} }
} }
@ -189,7 +191,9 @@ impl Writer {
if s == "data" { if s == "data" {
let lhs = lhs.clone(); let lhs = lhs.clone();
let data = self.parse_data_type(rhs); let data = self.parse_data_type(rhs);
self.data.insert(lhs, data); self.data
.insert(lhs, data)
.map_or(Ok(()), |_| Err(Error::RedefData))?;
} else { } else {
self.parse_id(rhs)?; self.parse_id(rhs)?;
} }