Merge pull request #728 from mir-protocol/fix_prohibited_macro_names

Fix prohibited macro names
This commit is contained in:
Daniel Lubarov 2022-09-21 13:31:03 -07:00 committed by GitHub
commit 3da80fffe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -512,6 +512,12 @@ mod tests {
assert_eq!(kernel.code, vec![push1, 42, push1, 42]);
}
#[test]
fn macro_with_reserved_prefix() {
// The name `repeat` should be allowed, even though `rep` is reserved.
parse_and_assemble(&["%macro repeat %endmacro", "%repeat"]);
}
#[test]
#[should_panic]
fn macro_with_wrong_vars() {

View File

@ -17,7 +17,7 @@ constant = ${ "@" ~ identifier }
item = { macro_def | macro_call | repeat | stack | global_label_decl | local_label_decl | macro_label_decl | bytes_item | push_instruction | prover_input_instruction | nullary_instruction }
macro_def = { ^"%macro" ~ identifier ~ paramlist? ~ item* ~ ^"%endmacro" }
macro_call = ${ "%" ~ !(^"macro" | ^"endmacro" | ^"rep" | ^"endrep" | ^"stack") ~ identifier ~ macro_arglist? }
macro_call = ${ "%" ~ !((^"macro" | ^"endmacro" | ^"rep" | ^"endrep" | ^"stack") ~ !identifier_char) ~ identifier ~ macro_arglist? }
repeat = { ^"%rep" ~ literal ~ item* ~ ^"%endrep" }
paramlist = { "(" ~ identifier ~ ("," ~ identifier)* ~ ")" }
macro_arglist = !{ "(" ~ push_target ~ ("," ~ push_target)* ~ ")" }