1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

use function syntax for log, reserve log, add test

This commit is contained in:
schaeff 2022-07-04 17:19:07 +02:00
parent 81d670e531
commit 3b07c156ad
6 changed files with 12 additions and 6 deletions

View file

@ -715,7 +715,7 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedStatement<'ast, T> {
}
TypedStatement::Log(ref l, ref expressions) => write!(
f,
"log!({}, {})",
"log({}, {})",
l,
expressions
.iter()

View file

@ -431,7 +431,7 @@ impl<'ast> fmt::Display for Statement<'ast> {
}
Statement::Log(ref l, ref expressions) => write!(
f,
"log!({}, {})",
"log({}, {})",
l,
expressions
.iter()

View file

@ -181,7 +181,7 @@ impl<'ast, T: fmt::Display> ZirStatement<'ast, T> {
}
ZirStatement::Log(ref l, ref expressions) => write!(
f,
"log!(\"{}\"), {})",
"log(\"{}\"), {})",
l,
expressions
.iter()

View file

@ -4,6 +4,6 @@ struct Foo {
}
def main(Foo x, field y) {
log!("x is {}, y is {}", x, y);
log("x is {}, y is {}", x, y);
return;
}

View file

@ -0,0 +1,6 @@
// "log" is reserved
def log():
return
def main()
return

View file

@ -59,7 +59,7 @@ statement = { (iteration_statement // does not require semicolon
| assertion_statement
) ~ semicolon)) ~ NEWLINE* }
log_statement = { "log!(\"" ~ format_string ~ "\"" ~ "," ~ expression_list ~ ")"}
log_statement = { "log" ~ "(" ~ "\"" ~ format_string ~ "\"" ~ "," ~ expression_list ~ ")"}
format_string = { (!"\"" ~ ANY)* }
block_statement = _{ "{" ~ NEWLINE* ~ statement* ~ NEWLINE* ~ "}" }
iteration_statement = { "for" ~ typed_identifier ~ "in" ~ expression ~ ".." ~ expression ~ block_statement }
@ -181,6 +181,6 @@ COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) }
// the ordering of reserved keywords matters: if "as" is before "assert", then "assert" gets parsed as (as)(sert) and incorrectly
// accepted
keyword = @{
"assert"|"as"|"bool"|"const"|"def"|"else"|"false"|"field"|"for"|"if"|"then"|"fi"|"import"|"from"|
"log"|"assert"|"as"|"bool"|"const"|"def"|"else"|"false"|"field"|"for"|"if"|"then"|"fi"|"import"|"from"|
"in"|"mut"|"private"|"public"|"return"|"struct"|"true"|"u8"|"u16"|"u32"|"u64"
}