grammar: add `;` as an alternative hard line-break
authorJean Privat <jean@pryen.org>
Mon, 4 May 2015 19:25:21 +0000 (15:25 -0400)
committerJean Privat <jean@pryen.org>
Wed, 6 May 2015 12:58:00 +0000 (08:58 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/parser/nit.sablecc3xx
src/parser/parser_nodes.nit

index 4436571..a30c84c 100644 (file)
@@ -191,6 +191,7 @@ gg = '>>';
 starship = '<=>';
 bang='!';
 at='@';
+semi=';';
 
 classid = uppercase letter*;
 id = lowercase letter*;
@@ -826,10 +827,14 @@ kwend_o {-> kwend?}
        = kwend? {-> kwend}
        ;
 
-n1     = {a} comment | {b} eol;
-n {-> doc?}
-       = {a} n2? comment+ {-> New doc([comment])}
-       | {b} n2 {-> Null}
+/* A single hard break */
+n1     = {a} comment | {b} eol | {c} semi;
+
+/* A mandatory hard break, returns the last comment */
+n~nosemi {-> doc?}
+       = {a} n2* comment+ {-> New doc([comment])}
+       | {b} n2+ {-> Null}
+!nosemi | {c} n2* comment* semi n? {-> n.doc }
        ;
 no {-> doc?}
        = {empty} {-> Null}
@@ -837,8 +842,7 @@ no {-> doc?}
        ;
 
 n2
-       = {a} n2? comment+ eol+
-       | {b} eol+
+       = {a} comment* eol
        ;
 
 /*****************************************************************************/
index a9613f6..8c7b941 100644 (file)
@@ -895,6 +895,11 @@ class TAt
        super Token
 end
 
+# The symbol `;`
+class TSemi
+       super Token
+end
+
 # A class (or formal type) identifier. They start with an uppercase.
 class TClassid
        super Token