Skip to content

Parse error on chained method call #91

@skjdbg

Description

@skjdbg

It seems chaining 2 method calls makes the parser throw an error.
I found two examples (see below) where calling parse_sv would fail while simply removing .method2() would fix the issue.
The examples are very similar, but the place at which the error is indicated is different so I thought it might help.
I also took a look at the BNF definition of Systemverilog, and I believe all those examples should be valid since a method_call_root can itself be a method_call. (Note that I only kept what was required to see the recursion in the BNF bellow)

  • subroutine_call ::= method_call
  • method_call ::= method_call_root . method_call_body
  • method_call_body ::= method_identifier { attribute_instance } [ ( list_of_arguments ) ]
  • method_call_root ::= primary
  • primary ::= function_subroutine_call
  • function_subroutine_call ::= subroutine_call

Example 1

Content of test_file_1.sv:

package A;
   class B;
      function bar foo();
         bit test = variable.method1().method2();
      endfunction : foo
   endclass : B
endpackage : A

Return value of the parser (indicates the last letter of bit):

Err(Parse(Some(("path/to/test_file_1.sv", 62))))

Example 2

Content of test_file_2.sv:

package A;
   class B;
      function bar foo();
         bit test;
         test = variable.method1().method2();
      endfunction : foo
   endclass : B
endpackage : A

Return value of the parser (indicates the closing parenthesis of method1):

Err(Parse(Some(("path/to/test_file_2.sv", 102))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions