Fixed chained method call parsing and added related tests

This commit is contained in:
Thomas Heuschling 2023-11-27 22:06:39 +01:00
parent 12e4d213f6
commit 61673565cb
2 changed files with 20 additions and 1 deletions

View File

@ -150,8 +150,20 @@ pub(crate) fn method_call(s: Span) -> IResult<Span, MethodCall> {
let (s, a) = method_call_root(s)?;
let (s, b) = symbol(".")(s)?;
let (s, c) = method_call_body(s)?;
let mut init_method_call = MethodCall { nodes: (a, b, c) };
Ok((s, MethodCall { nodes: (a, b, c) }))
//check for chained method method
let (s, sub_calls) = many0(pair(symbol("."), method_call_body))(s)?;
for (dot, body) in sub_calls {
let fun_sub_call = Primary::FunctionSubroutineCall(Box::new(FunctionSubroutineCall {
nodes: (SubroutineCall::MethodCall(Box::new(init_method_call)),),
}));
init_method_call = MethodCall {
nodes: (MethodCallRoot::Primary(Box::new(fun_sub_call)), dot, body),
};
}
Ok((s, init_method_call))
}
#[tracable_parser]

View File

@ -45,6 +45,13 @@ macro_rules! error_test {
mod unit {
use super::*;
#[test]
fn test_chained_method_call() {
test!(method_call, "variable.method1().method2()", Ok((_, _)));
test!(method_call, "variable.member.method2()", Ok((_, _)));
test!(method_call, "variable.method1().member", Ok((_, _)));
}
#[test]
fn test_pulldown_strength() {
test!(pulldown_strength, "(supply0, strong1)", Ok((_, _)));