Skip to content

Commit

Permalink
fix: macro parsing - off-by-one and bad chord (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroo committed Aug 3, 2023
1 parent 91deb07 commit 3515e91
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion parser/src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,9 +1575,15 @@ fn parse_macro_item_impl<'a>(
let submacro = match maybe_list_var.list(s.vars()) {
Some(l) => l,
None => {
// Ensure that the unparsed text is empty since otherwise it means there is
// invalid text there
if !unparsed_str.is_empty() {
bail_expr!(&acs[0], "{MACRO_ERR}")
}
// Check for a follow-up list
rem_start = 2;
if acs.len() < 2 {
bail_expr!(&acs[1], "{MACRO_ERR}")
bail_expr!(&acs[0], "{MACRO_ERR}")
}
acs[1]
.list(s.vars())
Expand Down
21 changes: 21 additions & 0 deletions parser/src/cfg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,27 @@ fn test_include_bad2_has_original_filename() {
)));
}

#[test]
fn parse_submacro() {
let _lk = match CFG_PARSE_LOCK.lock() {
Ok(guard) => guard,
Err(poisoned) => poisoned.into_inner(),
};
let mut s = ParsedState::default();
let source = r#"
(defsrc a)
(deflayer base
(macro M-S-())
)
"#;
parse_cfg_raw_string(source, &mut s, "test")
.map_err(|e| {
eprintln!("{:?}", error_with_source(e));
""
})
.unwrap_err();
}

#[test]
fn parse_switch() {
let _lk = match CFG_PARSE_LOCK.lock() {
Expand Down

0 comments on commit 3515e91

Please sign in to comment.