Skip to content

Subpar trees for unclosed blocks #171

@dominikh

Description

@dominikh

For the following snippet

package pkg

func foo() {
// bar

the grammar produces an ERROR (not a MISSING "}"), and places the commentnode outside thefunction_declaration`:

source_file [0, 0] - [5, 0]
  package_clause [0, 0] - [0, 11]
    package [0, 0] - [0, 7]
    package_identifier [0, 8] - [0, 11]
  
 [0, 11] - [2, 0]
  function_declaration [2, 0] - [2, 10]
    func [2, 0] - [2, 4]
    name: identifier [2, 5] - [2, 8]
    parameters: parameter_list [2, 8] - [2, 10]
      ( [2, 8] - [2, 9]
      ) [2, 9] - [2, 10]
  ERROR [2, 11] - [2, 12]
    { [2, 11] - [2, 12]
  comment [3, 0] - [3, 6]

(In fact we get ERROR instead of MISSING for a completely empty body, too.)

If there's some other node in the body (either in addition to or instead of the comment), we get a more useful tree. For

package pkg

func foo() {
bar()

we get

source_file [0, 0] - [5, 0]
  package_clause [0, 0] - [0, 11]
    package [0, 0] - [0, 7]
    package_identifier [0, 8] - [0, 11]
  
 [0, 11] - [2, 0]
  function_declaration [2, 0] - [5, 0]
    func [2, 0] - [2, 4]
    name: identifier [2, 5] - [2, 8]
    parameters: parameter_list [2, 8] - [2, 10]
      ( [2, 8] - [2, 9]
      ) [2, 9] - [2, 10]
    body: block [2, 11] - [5, 0]
      { [2, 11] - [2, 12]
      expression_statement [3, 0] - [3, 5]
        call_expression [3, 0] - [3, 5]
          function: identifier [3, 0] - [3, 3]
          arguments: argument_list [3, 3] - [3, 5]
            ( [3, 3] - [3, 4]
            ) [3, 4] - [3, 5]
      
 [3, 5] - [5, 0]
      MISSING "}" [5, 0] - [5, 0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions