]> ocean-lang.org Git - ocean/commit
parsergen: introuce $$NEWINE pseudo-precedence.
authorNeilBrown <neil@brown.name>
Sat, 15 Jun 2019 22:29:16 +0000 (08:29 +1000)
committerNeilBrown <neil@brown.name>
Sat, 15 Jun 2019 23:04:44 +0000 (09:04 +1000)
commit1bfa4fc8cfc5fafa5b2b3ae6bdd9b77a4242e74a
tree5382f8c67cbc7b1442329b3d6e900e482044b852
parentf8c00ecff941f5f86b4d54dd73cac3680684a11e
parsergen: introuce $$NEWINE pseudo-precedence.

Sometimes we need a produce to be terminated by a newline, but we
don't want to consume the newline with a "shift".
Case in point is:
   Block -> : StatementList

Which can be used with
   Statement -> if Expression Block
   StatementList -> Statement

I want this to parse:

   if something: if otherthing: action

which might seem a little odd, but is syntactically sensible.
The NEWLINE at the end is requred, and must close both nested Statements.
The NEWLINE will already cause a REDUCE, but if we don't have
   Block -> : Statementlist NEWLINE
then something else could force a reduce, and we don't want that.
So introduce a marking "$$NEWLINE" which is similar to imposing a precedence
on a production.  Now

   Block -> : StatementList $$NEWLINE

means that a NEWLINE is required to end a Block, but it isn't
shifted.  If anything else if found here, it is an error.

We also allow $eof and OUT to reduce this production.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/parsergen.mdc