module BNFC.Backend.Java.CFtoAllVisitor (cf2AllVisitor) where
import Data.List (intercalate)
import BNFC.CF
import BNFC.Utils ((+++))
import BNFC.Backend.Common.NamedVariables
cf2AllVisitor :: String -> String -> CF -> String
cf2AllVisitor :: [Char] -> [Char] -> CF -> [Char]
cf2AllVisitor [Char]
packageBase [Char]
packageAbsyn CF
cf = [[Char]] -> [Char]
unlines ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ [[[Char]]] -> [[Char]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ [ [Char]
"package" [Char] -> [Char] -> [Char]
+++ [Char]
packageBase [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
";"
, [Char]
""
, [Char]
"/** All Visitor */"
, [Char]
""
, [Char]
"public interface AllVisitor<R,A>" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ if [[Char]] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Char]]
is then [Char]
"" else [Char]
" extends"
]
, [ [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
",\n" ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map ([Char]
" "[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) [[Char]]
is | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [[Char]] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Char]]
is ]
, [ [Char]
"{}" ]
]
where
groups :: [(Cat, [Rule])]
groups = [ (Cat, [Rule])
g
| g :: (Cat, [Rule])
g@(Cat
c,[Rule]
_) <- [(Cat, [Rule])] -> [(Cat, [Rule])]
fixCoercions (CF -> [(Cat, [Rule])]
ruleGroupsInternals CF
cf), Bool -> Bool
not (Cat -> Bool
isList Cat
c) ]
is :: [[Char]]
is = ((Cat, [Rule]) -> [Char]) -> [(Cat, [Rule])] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map ([Char] -> (Cat, [Rule]) -> [Char]
prInterface [Char]
packageAbsyn) [(Cat, [Rule])]
groups
prInterface :: String -> (Cat, [Rule]) -> String
prInterface :: [Char] -> (Cat, [Rule]) -> [Char]
prInterface [Char]
packageAbsyn (Cat
cat, [Rule]
_) =
[Char]
q [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
".Visitor<R,A>"
where q :: [Char]
q = [Char]
packageAbsyn [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"." [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Cat -> [Char]
identCat Cat
cat