I understand the reason that parenthesis can't be added to nullary local functions and that if you walk the AST without keeping any state the formatter can't discern a local type from a local nullary function call.
However, when the formatter does keep some state while walking the tree it should be possible for the formatter to understand which AST nodes are part of a typespec?
Given the following typespec:
@type my_type :: my_other_type
The corresponding AST should be something like:
{:@, [line: 1],
[
{:type, [line: 1],
[
{:::, [line: 1],
[{:my_type, [line: 1], nil}, {:my_other_type, [line: 1], nil}]}
]}
]}
So the formatter encounters an attribute node {:@, ...}, updates it state that if the next node starts with :type, we are at the start of a typespec, etc.
Is interpreting the AST like this considered too fragile/brittle, or am I missing something else?
Best,
Vincent
Op maandag 5 februari 2018 15:10:05 UTC+1 schreef Eric Meadows-Jönsson: