mirror of
https://github.com/GrammaticalFramework/gf-rgl.git
synced 2026-05-28 09:28:54 -06:00
Factor out language config to CSV file
Compiles, not tested
This commit is contained in:
189
Make.hs
189
Make.hs
@@ -1,4 +1,4 @@
|
|||||||
import Data.List (find,intersect,isPrefixOf,isSuffixOf,(\\))
|
import Data.List (find,intersect,isPrefixOf,isSuffixOf,(\\),unfoldr)
|
||||||
import Data.Maybe (fromJust,isJust,catMaybes)
|
import Data.Maybe (fromJust,isJust,catMaybes)
|
||||||
import System.IO (hPutStrLn,stderr)
|
import System.IO (hPutStrLn,stderr)
|
||||||
import System.IO.Error (catchIOError)
|
import System.IO.Error (catchIOError)
|
||||||
@@ -163,7 +163,6 @@ rglCommands =
|
|||||||
, RGLCommand "modules" False $ \modes args bi -> do
|
, RGLCommand "modules" False $ \modes args bi -> do
|
||||||
let modules = getOptModules args
|
let modules = getOptModules args
|
||||||
flip mapM_ modules $ \m -> do
|
flip mapM_ modules $ \m -> do
|
||||||
-- TODO determine dependants, e.g. include ExtraEngAbs when specifying ExtraEng
|
|
||||||
mex <- findModule m
|
mex <- findModule m
|
||||||
case mex of
|
case mex of
|
||||||
Nothing -> die $ "Cannot find module: " ++ m
|
Nothing -> die $ "Cannot find module: " ++ m
|
||||||
@@ -172,50 +171,41 @@ rglCommands =
|
|||||||
putStrLn $ "Building [" ++ m ++ "] " ++ dst
|
putStrLn $ "Building [" ++ m ++ "] " ++ dst
|
||||||
run_gfc bi [if infoVerbose bi then "--verbose" else "--quiet", "--gfo-dir="++dst, mfull]
|
run_gfc bi [if infoVerbose bi then "--verbose" else "--quiet", "--gfo-dir="++dst, mfull]
|
||||||
|
|
||||||
-- , RGLCommand "pgf" False $ \modes args bi ->
|
, RGLCommand "parse" False $ \modes args bi -> do
|
||||||
-- parallel_ [
|
langs <- loadLangs
|
||||||
-- do let dir = getRGLBuildDir bi mode
|
let mylangs = (optml AllTenses langsParse args) langs
|
||||||
-- createDirectoryIfMissing True dir
|
gfc bi modes (summary parse) (map parse mylangs)
|
||||||
-- sequence_ [run_gfc bi ["-s","-make","-name=Lang"++la,
|
|
||||||
-- dir ++ "/Lang" ++ la ++ ".gfo"]
|
|
||||||
-- | l <- optl langsPGF args, let la = langCode l]
|
|
||||||
-- run_gfc bi (["-s","-make","-name=Lang"]++
|
|
||||||
-- ["Lang" ++ langCode l ++ ".pgf"|l <- optl langsPGF args])
|
|
||||||
-- | mode <- modes]
|
|
||||||
|
|
||||||
, RGLCommand "parse" False $ \modes args bi ->
|
|
||||||
gfc bi modes (summary parse) (map parse (optl langsParse args))
|
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
gfcp :: [Mode -> [String] -> (LangInfo -> FilePath,[LangInfo])] -> [Mode] -> [String] -> Info -> IO ()
|
gfcp :: [Mode -> [String] -> (LangInfo -> FilePath,[LangInfo] -> [LangInfo])] -> [Mode] -> [String] -> Info -> IO ()
|
||||||
gfcp cs modes args bi = parallel_ [gfcp' bi mode args cs | mode <- modes]
|
gfcp cs modes args bi = parallel_ [gfcp' bi mode args cs | mode <- modes]
|
||||||
|
|
||||||
gfcp' :: Info -> Mode -> [String] -> [Mode -> [String] -> (LangInfo -> FilePath,[LangInfo])] -> IO ()
|
gfcp' :: Info -> Mode -> [String] -> [Mode -> [String] -> (LangInfo -> FilePath,[LangInfo] -> [LangInfo])] -> IO ()
|
||||||
gfcp' bi mode args cs = gfcn bi mode (unwords ss) (concat fss)
|
gfcp' bi mode args cs = do
|
||||||
where (ss,fss) = unzip [(summary f,map f as)|c<-cs,let (f,as)=c mode args]
|
langs <- loadLangs
|
||||||
|
let (ss,fss) = unzip [ (summary f,map f (as langs)) | c<-cs, let (f,as) = c mode args]
|
||||||
|
gfcn bi mode (unwords ss) (concat fss)
|
||||||
|
|
||||||
summary :: (LangInfo -> FilePath) -> FilePath
|
summary :: (LangInfo -> FilePath) -> FilePath
|
||||||
summary f = f (LangInfo "*" "*" Nothing Nothing)
|
summary f = f (LangInfo "*" "*" Nothing Nothing False False False False)
|
||||||
|
|
||||||
l mode args = (lang,optml mode langsLang args)
|
l mode args = (lang,optml mode langsLang args)
|
||||||
s mode args = (symbol,optml mode langsAPI args)
|
s mode args = (symbol,optml mode langsAPI args)
|
||||||
c mode args = (compat,optl langsCompat args)
|
c mode args = (compat,optml AllTenses langsCompat args)
|
||||||
t mode args = (try,optml mode langsAPI args)
|
t mode args = (try,optml mode langsAPI args)
|
||||||
sc mode args = (symbolic,optml mode langsSymbolic args)
|
sc mode args = (symbolic,optml mode langsSymbolic args)
|
||||||
|
|
||||||
optl :: [LangInfo] -> [String] -> [LangInfo]
|
optml :: Mode -> ([LangInfo] -> [LangInfo]) -> [String] -> ([LangInfo] -> [LangInfo])
|
||||||
optl = optml AllTenses
|
optml mode ls args = \langs -> getOptLangs langs (shrink langs) args
|
||||||
|
|
||||||
optml :: Mode -> [LangInfo] -> [String] -> [LangInfo]
|
|
||||||
optml mode ls args = getOptLangs (shrink ls) args
|
|
||||||
where
|
where
|
||||||
shrink = case mode of
|
shrink langs = case mode of
|
||||||
Present -> intersect langsPresent
|
Present -> langsPresent langs
|
||||||
_ -> id
|
_ -> langs
|
||||||
|
|
||||||
-- | Search all language dirs for module name
|
-- | Search all language dirs for module name
|
||||||
findModule :: String -> IO (Maybe FilePath)
|
findModule :: String -> IO (Maybe FilePath)
|
||||||
findModule file = do
|
findModule file = do
|
||||||
|
langs <- loadLangs
|
||||||
let langdirs = map langDir langs
|
let langdirs = map langDir langs
|
||||||
let searchdirs = map ((</>) sourceDir) langdirs
|
let searchdirs = map ((</>) sourceDir) langdirs
|
||||||
findFile searchdirs file
|
findFile searchdirs file
|
||||||
@@ -263,9 +253,9 @@ getOptMode args =
|
|||||||
[AllTenses|have "alltenses"]
|
[AllTenses|have "alltenses"]
|
||||||
have mode = mode `elem` args
|
have mode = mode `elem` args
|
||||||
|
|
||||||
-- | List of languages overriding the definitions below
|
-- | List of languages overriding the default definitions
|
||||||
getOptLangs :: [LangInfo] -> [String] -> [LangInfo]
|
getOptLangs :: [LangInfo] -> [LangInfo] -> [String] -> [LangInfo]
|
||||||
getOptLangs defaultLangs args =
|
getOptLangs langs defaultLangs args =
|
||||||
case [ls | arg <- args,
|
case [ls | arg <- args,
|
||||||
let (f,ls) = splitAt (length lang_flag) arg,
|
let (f,ls) = splitAt (length lang_flag) arg,
|
||||||
f==lang_flag] of
|
f==lang_flag] of
|
||||||
@@ -318,94 +308,69 @@ data LangInfo = LangInfo
|
|||||||
, langDir :: String -- ^ directory name
|
, langDir :: String -- ^ directory name
|
||||||
, langFunctor :: Maybe String -- ^ functor (not used)
|
, langFunctor :: Maybe String -- ^ functor (not used)
|
||||||
, langUnlexer :: Maybe String -- ^ decoding for postprocessing linearizations
|
, langUnlexer :: Maybe String -- ^ decoding for postprocessing linearizations
|
||||||
} deriving (Eq)
|
, langPresent :: Bool
|
||||||
|
, langAPI :: Bool
|
||||||
|
, langSymbolic :: Bool
|
||||||
|
, langCompatibility :: Bool
|
||||||
|
} deriving (Show,Eq)
|
||||||
|
|
||||||
-- | List of all languages known to RGL
|
-- | Load language information from config file
|
||||||
langs :: [LangInfo]
|
loadLangs :: IO [LangInfo]
|
||||||
langs =
|
loadLangs = do
|
||||||
[ LangInfo "Afr" "afrikaans" Nothing Nothing
|
lns <- readFile conffile >>= return . lines
|
||||||
, LangInfo "Amh" "amharic" Nothing Nothing
|
mapM mkLangInfo (tail lns)
|
||||||
, LangInfo "Ara" "arabic" Nothing Nothing
|
where
|
||||||
, LangInfo "Eus" "basque" Nothing Nothing
|
conffile = "languages.csv"
|
||||||
, LangInfo "Bul" "bulgarian" Nothing Nothing
|
maybeBit bits n = if length bits >= (n+1) && length (bits !! n) > 0 then Just (bits !! n) else Nothing
|
||||||
, LangInfo "Cat" "catalan" (Just "Romance") Nothing
|
boolBit bits n def = if length bits >= (n+1) && length (bits !! n) > 0 then (bits !! n == if def then "n" else "y") else def
|
||||||
, LangInfo "Chi" "chinese" Nothing Nothing
|
mkLangInfo s =
|
||||||
, LangInfo "Dan" "danish" (Just "Scand") Nothing
|
let bits = separateBy ',' s in
|
||||||
, LangInfo "Dut" "dutch" Nothing Nothing
|
if length bits < 2
|
||||||
, LangInfo "Eng" "english" Nothing Nothing
|
then die $ "Invalid entry in " ++ conffile ++ ": " ++ s
|
||||||
, LangInfo "Est" "estonian" Nothing Nothing
|
else return $ LangInfo
|
||||||
, LangInfo "Fin" "finnish" Nothing Nothing
|
{ langCode = bits !! 0
|
||||||
, LangInfo "Fre" "french" (Just "Romance") Nothing
|
, langDir = bits !! 1
|
||||||
, LangInfo "Grc" "ancient_greek" Nothing Nothing
|
, langFunctor = maybeBit bits 2
|
||||||
, LangInfo "Gre" "greek" Nothing Nothing
|
, langUnlexer = maybeBit bits 3
|
||||||
, LangInfo "Heb" "hebrew" Nothing Nothing
|
, langPresent = boolBit bits 4 False
|
||||||
, LangInfo "Hin" "hindi" (Just "Hindustani") (Just "to_devanagari")
|
, langAPI = boolBit bits 5 True
|
||||||
, LangInfo "Ger" "german" Nothing Nothing
|
, langSymbolic = boolBit bits 6 True
|
||||||
, LangInfo "Ice" "icelandic" Nothing Nothing
|
, langCompatibility = boolBit bits 7 False
|
||||||
, LangInfo "Ina" "interlingua" Nothing Nothing
|
}
|
||||||
, LangInfo "Ita" "italian" (Just "Romance") Nothing
|
|
||||||
, LangInfo "Jpn" "japanese" Nothing Nothing
|
|
||||||
, LangInfo "Lat" "latin" Nothing Nothing
|
|
||||||
, LangInfo "Lav" "latvian" Nothing Nothing
|
|
||||||
, LangInfo "Mlt" "maltese" Nothing Nothing
|
|
||||||
, LangInfo "Mon" "mongolian" Nothing Nothing
|
|
||||||
, LangInfo "Nep" "nepali" Nothing Nothing
|
|
||||||
, LangInfo "Nor" "norwegian" (Just "Scand") Nothing
|
|
||||||
, LangInfo "Nno" "nynorsk" Nothing Nothing
|
|
||||||
, LangInfo "Pes" "persian" Nothing Nothing
|
|
||||||
, LangInfo "Pol" "polish" Nothing Nothing
|
|
||||||
, LangInfo "Por" "portuguese" (Just "Romance") Nothing
|
|
||||||
, LangInfo "Pnb" "punjabi" Nothing Nothing
|
|
||||||
, LangInfo "Ron" "romanian" Nothing Nothing
|
|
||||||
, LangInfo "Rus" "russian" Nothing Nothing
|
|
||||||
, LangInfo "Snd" "sindhi" Nothing Nothing
|
|
||||||
, LangInfo "Spa" "spanish" (Just "Romance") Nothing
|
|
||||||
, LangInfo "Swe" "swedish" (Just "Scand") Nothing
|
|
||||||
, LangInfo "Tha" "thai" Nothing (Just "to_thai")
|
|
||||||
, LangInfo "Tur" "turkish" Nothing Nothing
|
|
||||||
, LangInfo "Urd" "urdu" (Just "Hindustani") Nothing
|
|
||||||
]
|
|
||||||
|
|
||||||
-- | Languagues for which to compile Lang
|
-- | Separate a string on a character
|
||||||
langsLang :: [LangInfo]
|
-- Source: https://stackoverflow.com/a/4978733/98600
|
||||||
langsLang = langs
|
separateBy :: Eq a => a -> [a] -> [[a]]
|
||||||
|
separateBy chr = unfoldr sep where
|
||||||
|
sep [] = Nothing
|
||||||
|
sep l = Just . fmap (drop 1) . break (== chr) $ l
|
||||||
|
|
||||||
-- | Languages that have notpresent marked
|
-- -- | Exclude langs from list by code
|
||||||
langsPresent :: [LangInfo]
|
-- exceptLangs :: [LangInfo] -> [String] -> [LangInfo]
|
||||||
langsPresent = langsLang `except` ["Afr","Chi","Eus","Gre","Heb","Ice","Jpn","Mlt","Mon","Nep","Pes","Snd","Tha","Thb","Est"]
|
-- exceptLangs ls es = filter (flip notElem es . langCode) ls
|
||||||
|
|
||||||
-- | Languages for which to compile Try
|
|
||||||
langsAPI :: [LangInfo]
|
|
||||||
langsAPI = langsLang `except` langsIncomplete
|
|
||||||
|
|
||||||
-- | Languages which compile but which are incomplete
|
|
||||||
langsIncomplete :: [String]
|
|
||||||
langsIncomplete = ["Amh","Ara","Grc","Heb","Ina","Lat","Tur"]
|
|
||||||
|
|
||||||
-- | Languages for which to compile Symbolic
|
|
||||||
langsSymbolic :: [LangInfo]
|
|
||||||
langsSymbolic = langsAPI `except` ["Afr","Ice","Mon","Nep"]
|
|
||||||
|
|
||||||
-- | Languages for which to compile parsing grammars
|
|
||||||
langsParse :: [LangInfo]
|
|
||||||
langsParse = langs `only` ["Eng"]
|
|
||||||
|
|
||||||
-- | Languages for which langs.pgf is built
|
|
||||||
langsPGF :: [LangInfo]
|
|
||||||
langsPGF = langsLang `except` ["Ara","Hin","Ron","Tha"]
|
|
||||||
|
|
||||||
-- | Languages for which Compatibility exists (to be extended)
|
|
||||||
langsCompat :: [LangInfo]
|
|
||||||
langsCompat = langsLang `only` ["Cat","Eng","Fin","Fre","Ita","Lav","Spa","Swe"]
|
|
||||||
|
|
||||||
-- | Exclude langs from list by code
|
|
||||||
except :: [LangInfo] -> [String] -> [LangInfo]
|
|
||||||
except ls es = filter (flip notElem es . langCode) ls
|
|
||||||
|
|
||||||
-- | Only specified langs by code
|
-- | Only specified langs by code
|
||||||
only :: [LangInfo] -> [String] -> [LangInfo]
|
only :: [LangInfo] -> [String] -> [LangInfo]
|
||||||
only ls es = filter (flip elem es . langCode) ls
|
only ls es = filter (flip elem es . langCode) ls
|
||||||
|
|
||||||
|
langsLang :: [LangInfo] -> [LangInfo]
|
||||||
|
langsLang = id
|
||||||
|
|
||||||
|
langsPresent :: [LangInfo] -> [LangInfo]
|
||||||
|
langsPresent = filter langPresent
|
||||||
|
|
||||||
|
langsAPI :: [LangInfo] -> [LangInfo]
|
||||||
|
langsAPI = filter langAPI
|
||||||
|
|
||||||
|
langsSymbolic :: [LangInfo] -> [LangInfo]
|
||||||
|
langsSymbolic = filter langSymbolic
|
||||||
|
|
||||||
|
langsCompat :: [LangInfo] -> [LangInfo]
|
||||||
|
langsCompat = filter langCompatibility
|
||||||
|
|
||||||
|
langsParse :: [LangInfo] -> [LangInfo]
|
||||||
|
langsParse = flip only ["Eng"]
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Getting module paths/names
|
-- Getting module paths/names
|
||||||
|
|
||||||
|
|||||||
18
README.md
18
README.md
@@ -23,6 +23,24 @@ It will look for, in this order:
|
|||||||
- the file `../gf-core/DATA_DIR` (relative to this directory). This only works if you have the `gf-core` and `gf-rgl` repositories in the same top-level directory **and** you have already compiled GF from source.
|
- the file `../gf-core/DATA_DIR` (relative to this directory). This only works if you have the `gf-core` and `gf-rgl` repositories in the same top-level directory **and** you have already compiled GF from source.
|
||||||
(This is considered a bit hacky and will probably disappear in the future).
|
(This is considered a bit hacky and will probably disappear in the future).
|
||||||
|
|
||||||
|
## Language config
|
||||||
|
|
||||||
|
A list of all languages and their properties is maintained centrally in `languages.csv`.
|
||||||
|
This file should be kept up-to-date and all build methods should read this config file.
|
||||||
|
If you see something wrong, please report/fix it.
|
||||||
|
|
||||||
|
Description of columns:
|
||||||
|
- Code
|
||||||
|
- Directory
|
||||||
|
- Functor: (not used)
|
||||||
|
- Unlexer
|
||||||
|
- Present: languages that have notpresent marked
|
||||||
|
- API: languages for which to compile Try
|
||||||
|
- Symbolic: languages for which to compile Symbolic
|
||||||
|
- Compatibility: languages for which Compatibility exists
|
||||||
|
|
||||||
|
Columns can be a string, just `y`'s (where nothing means `n`) or just (`n`'s where nothing means `y`).
|
||||||
|
|
||||||
## Haskell script: `Make.hs`
|
## Haskell script: `Make.hs`
|
||||||
|
|
||||||
This build method gives you most options.
|
This build method gives you most options.
|
||||||
|
|||||||
46
languages.csv
Normal file
46
languages.csv
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
Code,Directory,Functor,Unlexer,Present,API,Symbolic,Compatibility
|
||||||
|
Afr,afrikaans,,,y,,n,
|
||||||
|
Amh,amharic,,,,n,n,
|
||||||
|
Ara,arabic,,,,n,n,
|
||||||
|
Eus,basque,,,,,,
|
||||||
|
Bul,bulgarian,,,y,,,y
|
||||||
|
Cat,catalan,Romance,,y,,,y
|
||||||
|
Chi,chinese,,,y,,,
|
||||||
|
Dan,danish,Scand,,y,,,
|
||||||
|
Dut,dutch,,,y,,,
|
||||||
|
Eng,english,,,y,,,y
|
||||||
|
Est,estonian,,,y,,,
|
||||||
|
Fin,finnish,,,y,,,y
|
||||||
|
Fre,french,Romance,,y,,,y
|
||||||
|
Grc,ancient_greek,,,y,n,n,
|
||||||
|
Gre,greek,,,y,,,
|
||||||
|
Heb,hebrew,,,,n,n,
|
||||||
|
Hin,hindi,Hindustani,to_devanagari,y,,,
|
||||||
|
Hun,hungarian,,,y,,,
|
||||||
|
Ger,german,,,,,,
|
||||||
|
Ice,icelandic,,,y,,n,
|
||||||
|
Ina,interlingua,,,y,n,n,
|
||||||
|
Ita,italian,Romance,,y,,,y
|
||||||
|
Jpn,japanese,,,y,,,
|
||||||
|
Lat,latin,,,y,n,n,
|
||||||
|
Lav,latvian,,,,,,y
|
||||||
|
Mlt,maltese,,,,,,
|
||||||
|
Mon,mongolian,,,y,,n,
|
||||||
|
Nep,nepali,,,y,,n,
|
||||||
|
Nor,norwegian,Scand,,y,,,
|
||||||
|
Nno,nynorsk,,,y,,,
|
||||||
|
Pes,persian,,,y,,,
|
||||||
|
Pol,polish,,,,,,
|
||||||
|
Por,portuguese,Romance,,y,,,y
|
||||||
|
Pnb,punjabi,,,y,,,
|
||||||
|
Ron,romanian,,,y,,,
|
||||||
|
Rus,russian,,,y,,,
|
||||||
|
Snd,sindhi,,,y,,,
|
||||||
|
Spa,spanish,Romance,,y,,,y
|
||||||
|
Swa,swahili,,,,,,y
|
||||||
|
Swe,swedish,Scand,,y,,,y
|
||||||
|
Tel,telugu,,,y,,,
|
||||||
|
Tha,thai,,to_thai,y,,,
|
||||||
|
Tur,turkish,,,,n,n,
|
||||||
|
Urd,urdu,Hindustani,,y,,,
|
||||||
|
Vot,votic,,,,,,
|
||||||
|
Reference in New Issue
Block a user