The parser considers 4 spaces as an indentation token, which means that 8 spaces should be considered 2 indentations. The parser is "flexible" in that it allows for extra spaces after the initial 4, but that has less precedence than recognizing an additional indentation, so 4-7 spaces becomes the valid range for a single indentation. This doesn't necessarily seem incorrect to me, but it is brittle, and not really made clear to the user.
Since quil-rs serializes program to Quil using tabs for whitespace, and many editors and terminals default to rendering 8 spaces for tabs, this leads to a surprising error when attempting to roundtrip a serialized program copied from one's editor or terminal.
Ideas:
Allow configuration of whitespace when serializing a program. I can see this as an enum with a method that returns the desired whitespace. The serialization routine would then inject that whitespace instead of hardcoding '\t'
Implement Python-esque handling of whitespace, where indentation must be consistent within a block, but the composition of said whitespace can vary.
Capturing additional feedback from team discussion:
Whatever solution should be consistent with the Quil spec.
The Quil spec may give us some leeway here. For example, Quil may not allow for nested blocks which means we could allow for irregular indentation by making 1 or many indentations equivalent to 1.
The parser considers 4 spaces as an indentation token, which means that 8 spaces should be considered 2 indentations. The parser is "flexible" in that it allows for extra spaces after the initial 4, but that has less precedence than recognizing an additional indentation, so 4-7 spaces becomes the valid range for a single indentation. This doesn't necessarily seem incorrect to me, but it is brittle, and not really made clear to the user.
Since quil-rs serializes program to Quil using tabs for whitespace, and many editors and terminals default to rendering 8 spaces for tabs, this leads to a surprising error when attempting to roundtrip a serialized program copied from one's editor or terminal.
Ideas: