From 61673565cbae5410bc7592da35c995ef6c5d453e Mon Sep 17 00:00:00 2001 From: Thomas Heuschling Date: Mon, 27 Nov 2023 22:06:39 +0100 Subject: [PATCH] Fixed chained method call parsing and added related tests --- .../src/expressions/subroutine_calls.rs | 14 +++++++++++++- sv-parser-parser/src/tests.rs | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/sv-parser-parser/src/expressions/subroutine_calls.rs b/sv-parser-parser/src/expressions/subroutine_calls.rs index c4a96bb..2385e5a 100644 --- a/sv-parser-parser/src/expressions/subroutine_calls.rs +++ b/sv-parser-parser/src/expressions/subroutine_calls.rs @@ -150,8 +150,20 @@ pub(crate) fn method_call(s: Span) -> IResult { 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] diff --git a/sv-parser-parser/src/tests.rs b/sv-parser-parser/src/tests.rs index 3f4678b..2a3d8b8 100644 --- a/sv-parser-parser/src/tests.rs +++ b/sv-parser-parser/src/tests.rs @@ -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((_, _)));