module BNFC.Backend.Java.Utils where
import BNFC.CF
import BNFC.Utils ( mkName, NameStyle(..))
import BNFC.Backend.Common.NamedVariables
javaReserved :: [[Char]]
javaReserved =
[ [Char]
"abstract"
, [Char]
"assert"
, [Char]
"boolean"
, [Char]
"break"
, [Char]
"byte"
, [Char]
"case"
, [Char]
"catch"
, [Char]
"char"
, [Char]
"class"
, [Char]
"const"
, [Char]
"continue"
, [Char]
"default"
, [Char]
"do"
, [Char]
"double"
, [Char]
"else"
, [Char]
"enum"
, [Char]
"extends"
, [Char]
"false"
, [Char]
"final"
, [Char]
"finally"
, [Char]
"float"
, [Char]
"for"
, [Char]
"goto"
, [Char]
"if"
, [Char]
"implements"
, [Char]
"import"
, [Char]
"instanceof"
, [Char]
"int"
, [Char]
"interface"
, [Char]
"long"
, [Char]
"native"
, [Char]
"new"
, [Char]
"null"
, [Char]
"package"
, [Char]
"private"
, [Char]
"protected"
, [Char]
"public"
, [Char]
"return"
, [Char]
"short"
, [Char]
"static"
, [Char]
"strictfp"
, [Char]
"super"
, [Char]
"switch"
, [Char]
"synchronized"
, [Char]
"true"
, [Char]
"this"
, [Char]
"throw"
, [Char]
"throws"
, [Char]
"transient"
, [Char]
"try"
, [Char]
"void"
, [Char]
"volatile"
, [Char]
"while"
]
getRuleName :: String -> String
getRuleName :: [Char] -> [Char]
getRuleName [Char]
z
| [Char] -> [Char]
firstLowerCase [Char]
z [Char] -> [[Char]] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ([Char]
"grammar" [Char] -> [[Char]] -> [[Char]]
forall a. a -> [a] -> [a]
: [[Char]]
javaReserved) = [Char]
z [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"_"
| Bool
otherwise = [Char]
z
getLabelName :: Fun -> String
getLabelName :: [Char] -> [Char]
getLabelName = [[Char]] -> NameStyle -> [Char] -> [Char]
mkName [[Char]
"Rule"] NameStyle
CamelCase
getLastInPackage :: String -> String
getLastInPackage :: [Char] -> [Char]
getLastInPackage =
[[Char]] -> [Char]
forall a. [a] -> a
last ([[Char]] -> [Char]) -> ([Char] -> [[Char]]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [[Char]]
words ([Char] -> [[Char]]) -> ([Char] -> [Char]) -> [Char] -> [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Char) -> [Char] -> [Char]
forall a b. (a -> b) -> [a] -> [b]
map (\Char
c -> if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.' then Char
' ' else Char
c)
startSymbol :: String -> String
startSymbol :: [Char] -> [Char]
startSymbol = ([Char]
"Start_" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++)