Merge pull request #93 from skjdbg/fix_chained_method

Fix chained method
This commit is contained in:
dalance 2023-11-29 12:32:43 +09:00 committed by GitHub
commit 250354e7c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
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((_, _)));