ap29600 / tree-sitter-odin

Odin grammar for tree-sitter
MIT License
17 stars 4 forks source link

`C`-style for loops with empty update statement fail to parse #5

Open ap29600 opened 2 years ago

ap29600 commented 2 years ago

The following code fails to parse:

package foo

foo :: proc () {
    for ; ; {
    }
}

the desired output should be:

(source_file
  (package_clause
    (keyword)
    (package_identifier))
  (const_declaration
    name: (const_identifier)
    (operator)
    (operator)
    value: (proc_literal
      (keyword)
      parameters: (parameter_list)
      (block
        (for_statement
          (keyword)
          body: (block))))))

actual output is:

(source_file
  (package_clause
    (keyword)
    (package_identifier))
  (const_declaration
    name: (const_identifier)
    (operator)
    (operator)
    value: (proc_literal
      (keyword)
      parameters: (parameter_list)
      (block
        (ERROR
          (keyword)
          (compound_literal))))))
ap29600 commented 2 years ago

closed by #6

ap29600 commented 2 years ago

I am pretty sure this bug is still reproducible, as the grammar as defined in the repo is actually ambiguous. I suspect a proper fix would require that we define a subset of the grammar that is allowed between 'for' and the matching '{', where the character '{' is not allowed unless within unambiguous delimiters of some kind ('()', '[]')