mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
BUGFIX: Calling macros with no arguments could not be parsed.
This commit is contained in:
parent
11f86ea8f8
commit
cb2f83f2ca
@ -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;
|
||||
|;
|
||||
|
@ -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)
|
||||
);
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user