[Grace-core] Comment proposal

James Noble kjx at ecs.vuw.ac.nz
Wed Feb 4 11:28:58 PST 2015


On 5/02/2015, at 07:56 am, Andrew P Black <andrew.p.black at gmail.com> wrote:

>  I'm not aware of problems that our existing comment rules have caused.  If there are some, we should perhaps discuss these first, before proposing new restrictions.

so my take so far is:
 - we don't agree on what we think the existing comment rules mean
 - we not sure if those rules should stay the same or not

in particular, this bit:

> Comments are not treated as white- space. Each comment is conceptually attached to the smallest immediately preceding syntactic unit, except that comments following a blank line are attached to the largest immediately following syntactic unit.

So far, every Grace parser has ignored comments or treated comments as whitespace.
Michael is trying to build a parser that does the right thing, and that also will produce a canonical AST including comments.
That will then make building formatters, refactorizers, etc easier (as per your work with Daniel Vainsencher!) 

So the question is: how do those comments, exactly, get "attached" to the AST? 

thus questions like: 

 var 
  // comment here
  x := 1 

which I certainly though would be legal, you implied should be illegal, Michael is keen on being illegal,
Kim thought was legal and is "not excited about" banning, and I'm not sure what Tim thinks about this,
or whoever else might weigh in on this list! 


I think Michael's argument can be summarised as: 
   "restricting comment locations 
    makes attaching them to the AST easy (for the implementer) 
    and predictable (for the programer)
    and enforces good style (on the programmer)"

that's the trouble with "minor cleanups" - there aren't many things that are actually minor. 

James

PS I wonder what go does - since go has both // and /* */ comments, and relies on automatic formatting.
How does gofmt handle comments in odd places?   (hint http://gofmt.com) 
How does it handle comments in its AST?


More information about the Grace-core mailing list