module BNFC.Backend.Java.Utils where

import BNFC.CF
import BNFC.Utils ( mkName, NameStyle(..))
import BNFC.Backend.Common.NamedVariables

-- | Make a Java line comment

comment :: String -> String
comment :: String -> String
comment = (String
"// " String -> String -> String
forall a. [a] -> [a] -> [a]
++)

javaReserved :: [String]
javaReserved :: [String]
javaReserved =
  [ String
"abstract"
  , String
"assert"
  , String
"boolean"
  , String
"break"
  , String
"byte"
  , String
"case"
  , String
"catch"
  , String
"char"
  , String
"class"
  , String
"const"
  , String
"continue"
  , String
"default"
  , String
"do"
  , String
"double"
  , String
"else"
  , String
"enum"
  , String
"extends"
  , String
"false"         -- there for Java/ANTLR backend
  , String
"final"
  , String
"finally"
  , String
"float"
  , String
"for"
  , String
"goto"
  , String
"if"
  , String
"implements"
  , String
"import"
  , String
"instanceof"
  , String
"int"
  , String
"interface"
  , String
"long"
  , String
"native"
  , String
"new"
  , String
"null"          -- there for Java/ANTLR backend
  -- , "Object"
  , String
"package"
  , String
"private"
  , String
"protected"
  , String
"public"
  , String
"return"
  , String
"short"
  , String
"static"
  , String
"strictfp"
  , String
"super"
  , String
"switch"
  , String
"synchronized"
  , String
"true"          -- there for Java/ANTLR backend
  , String
"this"
  , String
"throw"
  , String
"throws"
  , String
"transient"
  , String
"try"
  , String
"void"
  , String
"volatile"
  , String
"while"
  ]

-- | Append an underscore if there is a clash with a java or ANTLR keyword.
--   E.g. "Grammar" clashes with ANTLR keyword "grammar" since
--   we sometimes need the upper and sometimes the lower case version
--   of "Grammar" in the generated parser.
getRuleName :: String -> String
getRuleName :: String -> String
getRuleName String
z
  | String -> String
firstLowerCase String
z String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (String
"grammar" String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
javaReserved) = String
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"_"
  | Bool
otherwise = String
z

getLabelName :: Fun -> String
getLabelName :: String -> String
getLabelName = [String] -> NameStyle -> String -> String
mkName [String
"Rule"] NameStyle
CamelCase

getLastInPackage :: String -> String
getLastInPackage :: String -> String
getLastInPackage =
    [String] -> String
forall a. [a] -> a
last ([String] -> String) -> (String -> [String]) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
words (String -> [String]) -> (String -> String) -> String -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Char) -> String -> String
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)

-- | Make a new entrypoint NT for an existing NT.

startSymbol :: String -> String
startSymbol :: String -> String
startSymbol = (String
"Start_" String -> String -> String
forall a. [a] -> [a] -> [a]
++)