> with a short spec.Oh, how I wish. Dart is no C/C++ with preprocessor insanity, but it has quite a rich grammar.
> The challenge is when the program is _not_ well-formed, i.e. has errors
Being able to format erroneous code has come up as a feature request a number of times. It would be useful because then you can format even in the middle entering code into your IDE. We do have a very robust parser that can handle incorrect, incomplete code and give you a partial AST.
One of the reasons I've hesitated so far is that testing that in any sort of rigorous seems really difficult to me. Not to mention even defining what "correct" formatting is with code like that.
> refers to to code elsewhere, so you can't even decide if it's well-formed or not.
Thankfully most languages are context free, so that's rarely a problem outside of C/C++. :)
Dart does have a couple of semi-contextual syntax corners that could potentially affect formatting. An expression like:
foo.bar();
Could potentially be:
* Call the method "bar" on the local variable "foo".
* Call the top-level function "bar" imported with prefix "foo".
* Call the named constructor "bar" on the class "foo".
Because dartfmt does not do symbol or import resolution (for many reasons), it can't distinguish those cases. In practice, all that means is that we don't have th eability to have different formatting rules for those different cases and they are all formatted uniformly. So far, that seems to be an acceptable limitation (though it would be nice if we could treat import prefixes as stickier).