It is a bit weird to not be consistent and put spaces around all
operators, but most people would agree that using no spaces for `:` and
`^` look better.
`for`-loop nodes are of kind K"=" even when using `in`. This patch fixes
the predicate for `spaces_around_assignments` to include K"in" as an
option. Note that when using `in` spaces are required, but the pass
is still useful to remove spaces when there are more than one.
This adds a pass which adds a single space between operators, for
example `a+b` -> `a + b` and `a==b` -> `a == b`. Note that comparison
chains are still left untouched (`a == b == c`) and is a todo.
Sometimes there is a need to check the kind (possibly more) of previous
and next siblings in order to decide on formatting. This patch keeps
track of this in the Context.
This is used for replacing trailing whitespace from consecutive
NewlineWs nodes since sometimes the whitespace is after the LF.
This patch changes the code quite a bit:
- Use an IOBuffer for the source text instead of a string. This make it
simpler to use byte index instead of string index.
- Utilize the seekability of the output IOBuffer to backtrack changes
when child nodes want to format something.
- Build an formatted tree as we go: unchanged nodes alias the source
tree and we build new nodes when things change.