Change reference type syntax from &{t/y/p/e} to &[t/y/p/e] to avoid ambiguity with &{my: Int, object: String}

This commit is contained in:
Mark 2024-02-15 09:30:00 +01:00
parent b85183d081
commit c130678caf

View File

@ -14,6 +14,7 @@ pub enum ParsedType {
Tuple(Vec<Vec<Self>>), Tuple(Vec<Vec<Self>>),
Object(Vec<(String, Vec<Self>)>), Object(Vec<(String, Vec<Self>)>),
Type(String), Type(String),
Function(Vec<(Self, Self)>),
TypeWithInfo(String, String), TypeWithInfo(String, String),
} }
@ -24,18 +25,18 @@ pub fn parse_single_type(src: &mut Source, srca: &Arc<Source>) -> Result<ParsedT
// Reference // Reference
Some('&') => { Some('&') => {
src.next_char(); src.next_char();
if let Some('{') = src.peek_char() { if let Some('[') = src.peek_char() {
src.next_char(); src.next_char();
let types = parse_type(src, srca)?; let types = parse_type(src, srca)?;
let nc = src.next_char(); let nc = src.next_char();
if !matches!(nc, Some('}')) { if !matches!(nc, Some(']')) {
let nc = if let Some(nc) = nc { let nc = if let Some(nc) = nc {
format!("'{nc}'") format!("'{nc}'")
} else { } else {
format!("EOF") format!("EOF")
}; };
return Err(CheckError::new().msg(format!( return Err(CheckError::new().msg(format!(
"No closing }} in reference type with opening {{! Found {nc} instead" "No closing ] in reference type with opening [! Found {nc} instead"
))); )));
} }
ParsedType::Reference(types) ParsedType::Reference(types)