Skip to content

Commit

Permalink
[ fixed #212 ] generate Java package name as SnakeCase
Browse files Browse the repository at this point in the history
Just the name of the .cf file might be an invalid java package name.
  • Loading branch information
andreasabel committed Jan 4, 2020
1 parent 99078db commit f4e3f48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions source/src/BNFC/Backend/Java.hs
Expand Up @@ -68,12 +68,15 @@ import BNFC.PrettyPrint

-- | This creates the Java files.
makeJava :: SharedOptions -> CF -> MkFiles ()
makeJava options@Options{..} cf = do
makeJava opt = makeJava' opt{ lang = mkName javaReserved SnakeCase $ lang opt }
-- issue #212: make a legal package name, see also
-- https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html

makeJava' :: SharedOptions -> CF -> MkFiles ()
makeJava' options@Options{..} cf = do
-- Create the package directories if necessary.
let packageBase = case inPackage of
Nothing -> lang
Just p -> p ++ "." ++ lang
packageAbsyn = packageBase ++ "." ++ "Absyn"
let packageBase = maybe id (+.+) inPackage lang
packageAbsyn = packageBase +.+ "Absyn"
dirBase = pkgToDir packageBase
dirAbsyn = pkgToDir packageAbsyn
javaex str = dirBase ++ str +.+ "java"
Expand Down
6 changes: 3 additions & 3 deletions testing/src/RegressionTests.hs
Expand Up @@ -24,7 +24,7 @@ all = makeTestSuite "Regression tests" $
]

current = makeTestSuite "Regression tests" $
[ issue222 ]
[ issue60 ]

-- | A full regression test for the Haskell backend
haskellRegressionTest
Expand Down Expand Up @@ -76,11 +76,11 @@ issue60 :: Test
issue60 = makeShellyTest "#60 Compilation error in Java when a production uses more than one user-defined token" $
withTmpDir $ \tmp -> do
cd tmp
writefile "multiple_token.cf" $ T.unlines
writefile "multiple-token-123.cf" $ T.unlines
[ "Label. Category ::= FIRST SECOND;"
, "token FIRST 'a';"
, "token SECOND 'b';" ]
cmd "bnfc" "--java" "-m" "multiple_token.cf"
cmd "bnfc" "--java" "-m" "multiple-token-123.cf" -- test for package name sanitization #212
cmd "make"

issue108 :: Test
Expand Down

0 comments on commit f4e3f48

Please sign in to comment.