adjusted list syntax to be [<content> ...] to create a visual difference from tuples, which don't have the ... before the ].

This commit is contained in:
Dummi26 2023-03-12 12:43:21 +01:00
parent ff1f487a6f
commit 369b37371c
2 changed files with 29 additions and 17 deletions

View File

@ -123,11 +123,14 @@ fn parse_statement_adv(
file.skip_whitespaces(); file.skip_whitespaces();
if let Some(']') = file.peek() { if let Some(']') = file.peek() {
file.next(); file.next();
if file[file.get_char_index()..].starts_with("[]") { break;
list = true; }
file.next(); if file[file.get_char_index()..].starts_with("...]") {
file.next(); list = true;
} file.next();
file.next();
file.next();
file.next();
break; break;
} }
v.push(parse_statement(file)?); v.push(parse_statement(file)?);
@ -314,19 +317,24 @@ fn parse_statement_adv(
} }
}; };
file.skip_whitespaces(); file.skip_whitespaces();
if let Some('.') = file.get_char(file.get_char_index()) { if !file[file.get_char_index()..].starts_with("..") {
// consume the dot (otherwise, a.b.c syntax will break in certain cases) // dot chain syntax only works if there is only one dot
file.next(); if let Some('.') = file.get_char(file.get_char_index()) {
} // consume the dot (otherwise, a.b.c syntax will break in certain cases)
if !is_part_of_chain_already { file.next();
while let Some('.') = file.get_char(file.get_char_index().saturating_sub(1)) { }
let wrapper = parse_statement_adv(file, true)?; if !is_part_of_chain_already {
out = match *wrapper.statement { while let Some('.') = file.get_char(file.get_char_index().saturating_sub(1)) {
SStatementEnum::FunctionCall(func, args) => { let wrapper = parse_statement_adv(file, true)?;
let args = [out].into_iter().chain(args.into_iter()).collect(); out = match *wrapper.statement {
SStatementEnum::FunctionCall(func, args).into() SStatementEnum::FunctionCall(func, args) => {
let args = [out].into_iter().chain(args.into_iter()).collect();
SStatementEnum::FunctionCall(func, args).into()
}
other => {
todo!("Wrapping in this type isn't implemented (yet?). Type: {other:?}")
}
} }
other => todo!("Wrapping in this type isn't implemented (yet?). Type: {other:?}"),
} }
} }
} }

View File

@ -832,6 +832,10 @@ impl Display for VDataEnum {
for v in v { for v in v {
write!(f, "{v}")?; write!(f, "{v}")?;
} }
match self {
Self::List(..) => write!(f, "...")?,
_ => (),
}
write!(f, "]")?; write!(f, "]")?;
Ok(()) Ok(())
} }