parser: abstract var for consistency

This commit is contained in:
Ryan Chandler 2022-07-28 00:47:15 +01:00
parent d4cae32474
commit b4f8b1bf00
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 7 additions and 3 deletions

View File

@ -14,4 +14,8 @@ impl Parser {
pub(crate) fn full_name(&mut self) -> ParseResult<String> {
Ok(expect!(self, TokenKind::Identifier(i) | TokenKind::QualifiedIdentifier(i) | TokenKind::FullyQualifiedIdentifier(i), i, "expected identifier"))
}
pub(crate) fn var(&mut self) -> ParseResult<String> {
Ok(expect!(self, TokenKind::Variable(v), v, "expected variable name"))
}
}

View File

@ -545,7 +545,7 @@ impl Parser {
var_type = Some(self.type_string()?);
}
let var = expect!(self, TokenKind::Variable(i), i, "expected variable name");
let var = self.var()?;
let mut value = None;
if self.current.kind == TokenKind::Equals {
@ -631,7 +631,7 @@ impl Parser {
},
TokenKind::Question | TokenKind::Identifier(_) | TokenKind::QualifiedIdentifier(_) | TokenKind::FullyQualifiedIdentifier(_) => {
let prop_type = self.type_string()?;
let var = expect!(self, TokenKind::Variable(v), v, "expected variable name");
let var = self.var()?;
let mut value = None;
if self.current.kind == TokenKind::Equals {
@ -647,7 +647,7 @@ impl Parser {
Ok(Statement::Property { var, value, r#type: Some(prop_type), flags: flags.into_iter().map(|f| f.into()).collect() })
},
TokenKind::Variable(_) => {
let var = expect!(self, TokenKind::Variable(v), v, "expected variable name");
let var = self.var()?;
let mut value = None;
if self.current.kind == TokenKind::Equals {