Skip to content

Commit

Permalink
[ BNF.cf ] Fixed #215: allow extra semicolons between LBNF defs.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasabel committed Jan 1, 2018
1 parent 13ec3d4 commit 6cb6e92
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ cabal.sandbox.config
/source/src/LexBNF.info
/source/src/ParBNF.hs
/source/src/ParBNF.info
/source/src/TestBNF
15 changes: 13 additions & 2 deletions source/src/BNF.cf
Original file line number Diff line number Diff line change
Expand Up @@ -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] ;
Expand Down
2 changes: 2 additions & 0 deletions source/src/ParBNF.y
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion testing/src/ParameterizedTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6cb6e92

Please sign in to comment.