tree-sitter / tree-sitter-julia

Julia grammar for Tree-sitter
MIT License
93 stars 32 forks source link

bind colon-quote tighter #49

Closed brandonspark closed 1 year ago

brandonspark commented 2 years ago

What: Currently, parsing these Julia programs:

2 ? :(3) : 5

2 ? $(3) : 5

results in

(source_file (integer_literal) (ERROR (quote_expression (range_expression (parenthesized_expression (integer_literal)) (integer_literal)))))

(source_file (integer_literal) (ERROR (interpolation_expression (range_expression (parenthesized_expression (integer_literal)) (integer_literal)))))

These are ERRORs. They aren't supposed to be, though, because if we run the following Julia program:

macro test(thing)
  println(thing)
end

@test 2 ? :(3) : 5

we get

if 2
    $(QuoteNode(3))
else
    5
end

(and similarly for if you replace : with $)

Why: This is not in line with the fact that this is a legitimate Julia program.

Some real Julia programs on Github failed to parse because of essentially this.

How: Just made the precedence for colon-quote, the precedence that governs interpolation_expression and quote_expression, tighter. This makes it so that it binds properly when nested within something else, like a conditional, for instance.