Skip to content

Commit

Permalink
[ #163 ] ListCat entrypoint: fixed for OCaml and Java
Browse files Browse the repository at this point in the history
Ocaml: Only the generated Test file was broken.
Java: Only the name of the entrypoint needed to put right (identCat instead of show)
  • Loading branch information
andreasabel committed May 21, 2019
1 parent d582835 commit 8c26bc4
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion source/src/BNFC/Backend/CSharp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ csharptest namespace cf = unlines [
"}"
]
where
def = show (head (allEntryPoints cf))
def = identCat (head (allEntryPoints cf))

projectguid :: MkFiles String
projectguid = do
Expand Down
2 changes: 1 addition & 1 deletion source/src/BNFC/Backend/HaskellProfile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,4 @@ testfile inDir name _ cf = makeA where
" _ -> do progName <- getProgName",
" putStrLn $ progName ++ \": excess arguments.\""
]
where firstParser = 'p' : show (firstEntry cf)
where firstParser = 'p' : identCat (firstEntry cf)
2 changes: 1 addition & 1 deletion source/src/BNFC/Backend/Java/CFtoCup15.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ definedRules packageAbsyn cf =

-- peteg: FIXME JavaCUP can only cope with one entry point AFAIK.
prEntryPoint :: CF -> String
prEntryPoint cf = unlines ["", "start with " ++ show (firstEntry cf) ++ ";", ""]
prEntryPoint cf = unlines ["", "start with " ++ identCat (firstEntry cf) ++ ";", ""]
-- [ep] -> unlines ["", "start with " ++ ep ++ ";", ""]
-- eps -> error $ "FIXME multiple entry points." ++ show eps

Expand Down
2 changes: 1 addition & 1 deletion source/src/BNFC/Backend/OCaml/CFtoOCamlPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

-- based on BNFC Haskell backend

module BNFC.Backend.OCaml.CFtoOCamlPrinter (cf2Printer) where
module BNFC.Backend.OCaml.CFtoOCamlPrinter (cf2Printer, prtFun) where

import Prelude'

Expand Down
12 changes: 8 additions & 4 deletions source/src/BNFC/Backend/OCaml/CFtoOCamlShow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-- on camlp4. Here we generate our own "show module".


module BNFC.Backend.OCaml.CFtoOCamlShow (cf2show) where
module BNFC.Backend.OCaml.CFtoOCamlShow (cf2show, showsFunQual) where

import Data.Char(toLower)
import Data.List (intersperse)
Expand Down Expand Up @@ -142,6 +142,10 @@ mkRhs args its =
mk _ _ = []

showsFun :: Cat -> String
showsFun c = case c of
ListCat t -> "showList" +++ showsFun t
_ -> "show" ++ (fixTypeUpper $ normCat c)
showsFun = showsFunQual id

showsFunQual :: (String -> String) -> Cat -> String
showsFunQual qual = loop where
loop = \case
ListCat c -> qual "showList" +++ loop c
c -> qual "show" ++ (fixTypeUpper $ normCat c)
25 changes: 14 additions & 11 deletions source/src/BNFC/Backend/OCaml/CFtoOCamlTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import Text.PrettyPrint

import BNFC.CF
import BNFC.Backend.OCaml.OCamlUtil
import BNFC.Backend.OCaml.CFtoOCamlYacc (epName)
import BNFC.Backend.OCaml.CFtoOCamlPrinter (prtFun)
import BNFC.Backend.OCaml.CFtoOCamlShow (showsFunQual)

-- | OCaml comment
-- >>> comment "I'm a comment"
Expand All @@ -43,17 +46,17 @@ a <^> b = a <+> "^" <+> b
ocamlTestfile :: String -> String -> String -> String -> String -> CF -> Doc
ocamlTestfile absM lexM parM printM showM cf =
let
lexerName = text lexM <> ".token"
parserName = text parM <> ".p" <> parserC
printerName =
text printM <> ".printTree " <> text printM <> ".prt" <> topTypeC
showFun = parens $
"fun x ->" <+> text showM <> ".show"
<+> parens (text showM <> ".show" <> topTypeC <+> "x")
parserC = text $ fixTypeUpper $ firstEntry cf
topTypeC = text $ fixTypeUpper dat
topType = text absM <> "." <> text (fixType dat)
dat = normCat $ firstEntry cf
cat = firstEntry cf
qualify q x = concat [ q, ".", x ]
lexerName = text $ qualify lexM "token"
parserName = text $ qualify parM $ epName cat
printerName = hsep $ map (text . qualify printM) [ "printTree", prtFun cat ]
showFun = parens . hsep $
[ "fun x ->"
, text $ qualify showM "show"
, parens $ text (showsFunQual (qualify showM) cat) <+> "x"
]
topType = text absM <> "." <> text (fixType $ normCat cat)
in vcat
[ comment "automatically generated by the BNF Converter"
, ""
Expand Down
2 changes: 1 addition & 1 deletion source/src/BNFC/Backend/OCaml/CFtoOCamlYacc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

module BNFC.Backend.OCaml.CFtoOCamlYacc
(
cf2ocamlyacc, terminal
cf2ocamlyacc, terminal, epName
)
where

Expand Down

0 comments on commit 8c26bc4

Please sign in to comment.