From 6cb6e929f1e0eebf11368aa89509065f1db77a7e Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Mon, 1 Jan 2018 23:47:44 +0100 Subject: [PATCH] [ BNF.cf ] Fixed #215: allow extra semicolons between LBNF defs. --- .gitignore | 1 + source/src/BNF.cf | 15 +++++++++++++-- source/src/ParBNF.y | 2 ++ testing/src/ParameterizedTests.hs | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 81aea3f9..e399a3d7 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ cabal.sandbox.config /source/src/LexBNF.info /source/src/ParBNF.hs /source/src/ParBNF.info +/source/src/TestBNF diff --git a/source/src/BNF.cf b/source/src/BNF.cf index 51088e71..57a8cf46 100644 --- a/source/src/BNF.cf +++ b/source/src/BNF.cf @@ -25,14 +25,25 @@ DefAll. LDef ::= Def ; DefSome. LDef ::= [Ident] ":" Def ; LDefView. LDef ::= "views" [Ident] ; -separator LDef ";" ; +-- separator LDef ";" ; +[]. [LDef] ::= ; +(:[]). [LDef] ::= LDef ; +(:). [LDef] ::= LDef ";" [LDef] ; +-- extra semicolons allowed +_. [LDef] ::= ";" [LDef] ; + separator nonempty Ident "," ; -- A Grammar is a sequence of definitions Grammar . Grammar ::= [Def] ; -separator Def ";" ; +-- separator Def ";" ; -- Note: this still permits a final semicolon. +[]. [Def] ::= ; +(:[]). [Def] ::= Def ; +(:). [Def] ::= Def ";" [Def] ; +-- extra semicolons allowed +_. [Def] ::= ";" [Def] ; -- The rules of the grammar Rule . Def ::= Label "." Cat "::=" [Item] ; diff --git a/source/src/ParBNF.y b/source/src/ParBNF.y index 72209f52..cc563074 100644 --- a/source/src/ParBNF.y +++ b/source/src/ParBNF.y @@ -111,6 +111,7 @@ ListLDef :: { [LDef] } ListLDef : {- empty -} { [] } | LDef { (:[]) $1 } | LDef ';' ListLDef { (:) $1 $3 } + | ';' ListLDef { $2 } ListIdent :: { [Ident] } ListIdent : Ident { (:[]) $1 } | Ident ',' ListIdent { (:) $1 $3 } Grammar :: { Grammar } @@ -119,6 +120,7 @@ ListDef :: { [Def] } ListDef : {- empty -} { [] } | Def { (:[]) $1 } | Def ';' ListDef { (:) $1 $3 } + | ';' ListDef { $2 } Def :: { Def } Def : Label '.' Cat '::=' ListItem { AbsBNF.Rule $1 $3 (reverse $5) } | 'comment' String { AbsBNF.Comment $2 } diff --git a/testing/src/ParameterizedTests.hs b/testing/src/ParameterizedTests.hs index dbee7f65..1eeb3885 100644 --- a/testing/src/ParameterizedTests.hs +++ b/testing/src/ParameterizedTests.hs @@ -49,7 +49,7 @@ exitCodeTest params = makeShellyTest "Test program exits with code 1 on failure" $ withTmpDir $ \tmp -> do cd tmp - writefile "Abra.cf" "F. C ::= \"abracadabra\";" + writefile "Abra.cf" ";; F. C ::= \"abracadabra\" ;" -- leading semicolon for #215 tpBnfc params "Abra.cf" tpBuild params setStdin "bad"