[Grace-core] Indentation in Grace

Andrew P. Black black at cs.pdx.edu
Wed Jul 17 16:59:49 PDT 2013


I've just had an enlightening conversation with Michael Adams about indentation-sensitive parsing.  The executive summary is

	-- It's much more complicated than I thought
	-- depending on th details of the rules that we adopt for Grace, we can probably avoid a lot of the complexity
	-- There are a number of decisions that we need to make about what we WANT indentation to do in Grace

Unfortunately, the details of what sort of indentation we want will affect (to some extent) the combinators that we need to implement indentation.

The decisions that we need to make include:

	- What productions in Grace's grammar start new indentation scopes:
		method
		object 
		class
		block
		argument-list
	  Are there any others?
	
	- When the indentation increases, does it increase relative to the line on which the indentation scope starts, or relative to the enclosing indentation scope?
	  Michael's mail message dated 12 July 2013 08:34 discusses these alternatives.  For example, consider
			
		object { method doit {
		      foobar(x)
		    }
		}

	  Is this legal?   foobar(x) is syntactically inside the method doit, so it should be indented with respect to that method.  It is indented with respect to
	  the indentation of the line on which the method starts, but not with respect to the indentation of the enclosing indentation scope, which starts 
	  with the keyword method.  

	  One problem with line-based indentation is that adding newlines matters, so while the above would be accepted, the following would be rejected:

		object { 
		             method doit {
		      foobar(x)
		    }
		}

	- Another choice is whether to require a newline after the token that starts a new indentation scope, unless the end of the scope is on the same line.
	  this would outlaw 

		object { method doit {

	  altogether, and force us to write
		
		object { 
		    method doit {

	  although it would still allow single-line objects and single-line methods if everything fits on one line.   The main objection to this is that it may make it 
	  harder to fit code snippets into papers with a hard page limit!   It's a good idea if you like to use proportionally-spaced fonts for your programs 
	  (because all indentations are now determined by the number of leading spaces, and all spaces have equal width).  It also means that the 
 	  distinction between "current indentation scope" and "current line" goes away.

	- Do we allow semicolons at all, in multi-line layout, or do we require one statement on each line?   So can I write:

		method doIt {
			stmt1 
			stmt2; stmt3
			stmt4
		}

	  If we allow semicolons, is a trailing semicolon allowed?  

	- Do we want to get rid of the braces around class, object and method?  As Michael pointed out, we can't make them optional, because that
          introduces an ambiguity.

	- Are there any productions in Grace's grammar that "forget" about indentation.  An example is Landin's "except possibly for [parenthesized] 
	  subsegments" rule, enclosed by Adam's circle-star combinator, which allows

	      x + v where
	          x = -(
	      y + z) + w


That may be all for now

		Andrew



		
	 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20130717/467ae188/attachment.html>


More information about the Grace-core mailing list