diff --git a/lib/resource-1.0/doc/MkSynopsis.hs b/lib/resource-1.0/doc/MkSynopsis.hs index c1b0d80ce..945770eb1 100644 --- a/lib/resource-1.0/doc/MkSynopsis.hs +++ b/lib/resource-1.0/doc/MkSynopsis.hs @@ -2,6 +2,9 @@ import System import Char import List +type Cats = [(String,String,String)] +type Rules = [(String,String,String)] + main = do xx <- getArgs let isLatex = case xx of @@ -36,10 +39,10 @@ main = do space link "Source:" structuralAPI space - rs <- rulesTable False isLatex structuralAPI + rs <- rulesTable False isLatex cs structuralAPI delimit rs space - mapM_ (putParadigms isLatex) paradigmFiles + mapM_ (putParadigms isLatex cs) paradigmFiles space include "synopsis-browse.txt" space @@ -52,7 +55,7 @@ main = do if isLatex then (system $ "pdflatex synopsis.tex") >> return () else return () -getCats :: FilePath -> IO [(String, String, String)] +getCats :: FilePath -> IO Cats getCats file = do ss <- readFile file >>= return . lines return $ getrs [] ss @@ -66,13 +69,13 @@ getCats file = do (expl,ex) = span (/="e.g.") exp _ -> getrs rs ss2 -rulesTable :: Bool -> Bool -> FilePath -> IO [String] -rulesTable hasEx isLatex file = do +rulesTable :: Bool -> Bool -> Cats -> FilePath -> IO [String] +rulesTable hasEx isLatex cs file = do rs <- getRules file - return $ mkTable hasEx isLatex rs + return $ mkTable hasEx isLatex cs rs -getRules :: FilePath -> IO [(String,String,String)] +getRules :: FilePath -> IO Rules getRules file = do ss <- readFile file >>= return . lines return $ getrs [] ss @@ -97,12 +100,13 @@ getRules file = do n:ws | last n == '.' && not (null (init n)) && all isDigit (init n) -> ws _ -> e -putParadigms isLatex (lang,file) = do +putParadigms :: Bool -> Cats -> (String, FilePath) -> IO () +putParadigms isLatex cs (lang,file) = do title ("Paradigms for " ++ lang) space link "source" file space - rs <- rulesTable False isLatex file + rs <- rulesTable False isLatex cs file space delimit rs space @@ -114,16 +118,16 @@ inChunks i f = concat . intersperse ["\n\n"] . map f . chunks i where -- Makes one table per result category. -- Adds a subsection header for each table. -mkSplitTables :: Bool -> Bool -> [(String,String,String)] -> [(String,String,String)] -> [String] +mkSplitTables :: Bool -> Bool -> Cats -> Rules -> [String] mkSplitTables hasEx isLatex cs rs = concatMap t (sortRules rs) - where t xs = [subtitle c] ++ expl ++ mkTable hasEx isLatex xs + where t xs = [subtitle c expl] ++ mkTable hasEx isLatex cs xs where c = resultCat (head xs) expl = case [e | (n,e,_) <- cs, n == c] of - [] -> [] - e:_ -> ["", e, ""] + [] -> "" + e:_ -> e -mkTable :: Bool -> Bool -> [(String,String,String)] -> [String] -mkTable hasEx isLatex = inChunks chsize (\rs -> header : map (unwords . row) rs) +mkTable :: Bool -> Bool -> Cats -> Rules -> [String] +mkTable hasEx isLatex cs = inChunks chsize (\rs -> header : map (unwords . row) rs) where chsize = if isLatex then 40 else 1000 header = if hasEx then "|| Function | Type | Example ||" @@ -133,15 +137,15 @@ mkTable hasEx isLatex = inChunks chsize (\rs -> header : map (unwords . row) rs) else ["|", name', "|", typ', "|"] where name' = ttf name - typ' = showTyp typ + typ' = showTyp cs typ ex' = if null ex then "-" else itf ex -mkCatTable :: Bool -> [(String, String, String)] -> [String] -mkCatTable isLatex = inChunks chsize (\rs -> header ++ map mk1 rs) +mkCatTable :: Bool -> Cats -> [String] +mkCatTable isLatex cs = inChunks chsize (\rs -> header ++ map mk1 rs) cs where header = ["|| Category | Explanation | Example ||"] chsize = if isLatex then 40 else 1000 - mk1 (name,expl,ex) = unwords ["|", showCat name, "|", expl, "|", typo ex, "|"] + mk1 (name,expl,ex) = unwords ["|", showCat cs name, "|", expl, "|", typo ex, "|"] typo ex = if take 1 ex == "\"" then itf (init (tail ex)) else ex synopsis = "synopsis.txt" @@ -176,12 +180,12 @@ itf s = "//" ++ s ++ "//" ----------------- -- sort category synopsis by category, retain one table -sortCats :: [(String,String,String)] -> [(String,String,String)] +sortCats :: Cats -> Cats sortCats = sortBy compareCat where compareCat (n1,_,_) (n2,_,_) = compare n1 n2 -- sort function synopsis by category, into separate tables -sortRules :: [(String,String,String)] -> [[(String,String,String)]] +sortRules :: Rules -> [Rules] sortRules = groupBy sameCat . sortBy compareRules where sameCat r1 r2 = resultCat r1 == resultCat r2 compareRules r1@(n1,_,_) r2@(n2,_,_) @@ -191,14 +195,17 @@ resultCat :: (String,String,String) -> String resultCat (_,t,_) = last (words t) -subtitle cat = "==" ++ cat ++ "==" ++ "[" ++ cat ++ "]" +subtitle cat expl = "==" ++ cat ++ e ++ "==" ++ "[" ++ cat ++ "]" + where e = if null expl then "" else " - " ++ expl -showCat cat = "[" ++ cat ++ " #" ++ cat ++ "]" +showCat :: Cats -> String -> String +showCat cs cat = "[" ++ cat ++ " #" ++ cat ++ "]" -showTyp = unwords . map f . words +showTyp :: Cats -> String -> String +showTyp cs = unwords . map f . words where f s | head s == '(' && last s == ')' && isCat c - = "(" ++ showCat c ++ ")" - | isCat s = showCat s + = "(" ++ showCat cs c ++ ")" + | isCat s = showCat cs s | otherwise = ttf s where c = init (tail s) isCat cat = cat `notElem` ["Str","Int"] diff --git a/lib/resource-1.0/doc/synopsis.html b/lib/resource-1.0/doc/synopsis.html index 7920ab51d..6395bd1f8 100644 --- a/lib/resource-1.0/doc/synopsis.html +++ b/lib/resource-1.0/doc/synopsis.html @@ -20,44 +20,44 @@
Paradigms modules.
Source: http://www.cs.chalmers.se/~aarne/GF/lib/resource/api/Constructors.gf
--adjectival phrase -
+| Function | @@ -500,10 +497,7 @@ adjectival phrase
|---|
-numeral-modifying adverb -
+| Function | @@ -518,10 +512,7 @@ numeral-modifying adverb
|---|
-verb-phrase-modifying adverb -
+| Function | @@ -581,10 +572,7 @@ verb-phrase-modifying adverb
|---|
-anteriority -
+| Function | @@ -604,10 +592,7 @@ anteriority
|---|
-common noun (without determiner) -
+| Function | @@ -707,10 +692,7 @@ common noun (without determiner)
|---|
-declarative clause, with all tenses -
+| Function | @@ -845,10 +827,7 @@ declarative clause, with all tenses
|---|
-determiner phrase -
+| Function | @@ -928,10 +907,7 @@ determiner phrase
|---|
-interrogative adverb -
+| Function | @@ -946,10 +922,7 @@ interrogative adverb
|---|
-interrogative pronoun -
+| Function | @@ -974,10 +947,7 @@ interrogative pronoun
|---|
-imperative -
+| Function | @@ -1107,10 +1077,7 @@ imperative
|---|
-noun phrase (subject or object) -
+| Function | @@ -1235,10 +1202,7 @@ noun phrase (subject or object)
|---|
-cardinal number (used with QuantPl) -
+| Function | @@ -1338,10 +1302,7 @@ cardinal number (used with QuantPl)
|---|
-ordinal number (used in Det) -
+| Function | @@ -1366,10 +1327,7 @@ ordinal number (used in Det)
|---|
-phrase-beginning conjunction -
+| Function | @@ -1384,10 +1342,7 @@ phrase-beginning conjunction
|---|
-phrase in a text -
+| Function | @@ -1427,10 +1382,7 @@ phrase in a text
|---|
-polarity -
+| Function | @@ -1475,10 +1427,7 @@ polarity
|---|
-question clause, with all tenses -
+| Function | @@ -1528,10 +1477,7 @@ question clause, with all tenses
|---|
-question -
+| Function | @@ -1556,10 +1502,7 @@ question
|---|
-quantifier with both sg and pl -
+| Function | @@ -1654,10 +1597,7 @@ quantifier with both sg and pl
|---|
-relative clause, with all tenses -
+| Function | @@ -1687,10 +1627,7 @@ relative clause, with all tenses
|---|
-relative pronoun -
+| Function | @@ -1710,10 +1647,7 @@ relative pronoun
|---|
-relative -
+| Function | @@ -1733,10 +1667,7 @@ relative
|---|
-declarative sentence -
+| Function | @@ -1781,10 +1712,7 @@ declarative sentence
|---|
-clause missing NP (S/NP in GPSG) -
+| Function | @@ -1814,10 +1742,7 @@ clause missing NP (S/NP in GPSG)
|---|
-tense -
+| Function | @@ -1847,10 +1772,7 @@ tense
|---|
-text consisting of several phrases -
+| Function | @@ -1900,10 +1822,7 @@ text consisting of several phrases
|---|
-sentence, question, word... -
+| Function | @@ -1968,10 +1887,7 @@ sentence, question, word...
|---|
-verb phrase -
+| Function | @@ -2091,10 +2007,7 @@ verb phrase
|---|
-vocative or "please" -
+| Function |
|---|