BUGFIX: Calling macros with no arguments could not be parsed.

This commit is contained in:
Jeremy Wall 2018-11-20 17:42:39 -06:00
parent 11f86ea8f8
commit cb2f83f2ca
3 changed files with 23 additions and 3 deletions

View File

@ -1,3 +1,7 @@
let noargmacro = macro() => {
field1 = "value",
};
let simplemacro = macro(arg1, arg2, arg3) => {
field1 = arg1,
field2 = arg2,
@ -11,9 +15,13 @@ let cplxmacro = macro(argint, argstr, argfloat) => {
boolfield = argint == 1,
};
let noargresult = noargmacro();
let simpleresult = simplemacro(1, 2, 3);
let cplxresult = cplxmacro(1, "We", 3.0);
assert |
noargresult.field1 == "value";
|;
assert |
simpleresult.field1 == 1;
|;

View File

@ -661,12 +661,12 @@ make_fn!(
fn tuple_to_call<'a>(
input: SliceIter<'a, Token>,
val: Value,
exprs: Vec<Expression>,
exprs: Option<Vec<Expression>>,
) -> ParseResult<'a, Expression> {
if let Value::Selector(def) = val {
Ok(Expression::Call(CallDef {
macroref: def,
arglist: exprs,
arglist: exprs.unwrap_or_else(|| Vec::new()),
pos: (&input).into(),
}))
} else {
@ -693,7 +693,7 @@ fn call_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, Expressi
let parsed = do_each!(input.clone(),
macroname => trace_nom!(selector_value),
_ => punct!("("),
args => separated!(punct!(","), trace_nom!(expression)),
args => optional!(separated!(punct!(","), trace_nom!(expression))),
_ => punct!(")"),
(macroname, args)
);

View File

@ -887,6 +887,18 @@ fn test_call_parse() {
pos: Position::new(1, 1, 0),
})
);
assert_parse!(
call_expression("foo ()"),
Expression::Call(CallDef {
macroref: make_selector!(
make_expr!("foo", Position::new(1, 1, 0)),
Position::new(1, 1, 0)
),
arglist: Vec::new(),
pos: Position::new(1, 1, 0),
})
);
}
#[test]