3 ms·
The parser has well-defined behavior for malformed whitespace, and it’s not to throw a syntax error: if you advance the indentation by more than one space on a
by mbostock 8y ago
The parser has well-defined behavior for malformed whitespace, and it’s not to throw a syntax error: if you advance the indentation by more than one space on a following line, the extra spaces are ignored.
- munk-a 8y agoWait so... a ..b ..c Would be interpreted as (a (b (c)))
- mbostock 8y agoThat was the initial behavior, but I’ve changed it to ignore missing intermediate parents. Your example would be (a (b c)). See the “Handling ambiguity” section I added to the notebook. The nice property of this design is that you can use whatever indentation style you prefer (tabs, 2x spaces, 1x space, etc.) and it will do what you expect as long as you are consistent.
- munk-a 8y agoOh neato. I still think there's something for the philosophy of developing tools that expect a strict format and fail if that format is violated. I've worked in a variety of settings and with a variety of tools, as time goes by I am finding the value of tools that are strict about expectations to provide a more maintainable product over the long haul. If I were writing a project using this style I'd prefer to receive a parse failure in the case of ambiguity, rather than carrying on and hoping it is correct. If data correction needs to happen (i.e. one file that should be single-space indented is triple space indented) I'd prefer to explicitly pre-process the data rather than have a tool that can handle it gracefully.
- kgwxd 8y agohow is it supposed to know you put an item at the wrong level? thats not syntax now that i think about it, just an example of how syntax can help visualize.