From 7ee279fa3fb4a49ebe97d7fbdbe145a4c14c9d06 Mon Sep 17 00:00:00 2001 From: aarne Date: Wed, 4 Jul 2007 13:21:41 +0000 Subject: [PATCH] tex option for synopsis; not so nice-looking yet --- lib/resource-1.0/doc/MkSynopsis.hs | 49 +++++++++++++++-------- lib/resource-1.0/doc/synopsis-example.txt | 1 + lib/resource-1.0/doc/synopsis-intro.txt | 9 +++++ lib/resource-1.0/doc/synopsis.html | 14 ++++++- 4 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 lib/resource-1.0/doc/synopsis-intro.txt diff --git a/lib/resource-1.0/doc/MkSynopsis.hs b/lib/resource-1.0/doc/MkSynopsis.hs index 576fddb7a..2af3e9fbe 100644 --- a/lib/resource-1.0/doc/MkSynopsis.hs +++ b/lib/resource-1.0/doc/MkSynopsis.hs @@ -1,47 +1,55 @@ import System import Char +import List main = do + xx <- getArgs + let isLatex = case xx of + "-tex":_ -> True + _ -> False writeFile synopsis "GF Resource Grammar Library: Synopsis" append "Aarne Ranta" space + include "synopsis-intro.txt" title "Categories" space link "Source 1:" commonAPI space link "Source 2:" catAPI space - cs1 <- getCats True commonAPI - cs2 <- getCats False catAPI - delimit $ cs1 ++ cs2 + cs1 <- getCats isLatex True commonAPI + cs2 <- getCats isLatex False catAPI + let cs = cs1 ++ cs2 + delimit cs space title "Syntax Rules" space link "Source:" syntaxAPI space - rs <- getRules syntaxAPI + rs <- getRules isLatex syntaxAPI delimit rs space title "Structural Words" space link "Source:" structuralAPI space - rs <- getRules structuralAPI + rs <- getRules isLatex structuralAPI delimit rs space - mapM_ putParadigms paradigmFiles + mapM_ (putParadigms isLatex) paradigmFiles space - title "Example Usage" + title "An Example of Usage" space - ss <- readFile "synopsis-example.txt" >>= return . lines - mapM_ append ss + include "synopsis-example.txt" space - system $ "txt2tags -thtml --toc " ++ synopsis + let format = if isLatex then "tex" else "html" + system $ "txt2tags -t" ++ format ++ " --toc " ++ synopsis -getCats isBeg file = do +getCats isLatex isBeg file = do ss <- readFile file >>= return . lines - return $ mkCatTable isBeg $ getrs [] ss + return $ inChunks chsize (mkCatTable (isLatex || isBeg)) $ getrs [] ss where + chsize = if isLatex then 40 else 1000 getrs rs ss = case ss of ('-':'-':'.':_):_ -> reverse rs [] -> reverse rs @@ -51,10 +59,11 @@ getCats isBeg file = do (expl,ex) = span (/="e.g.") exp _ -> getrs rs ss2 -getRules file = do +getRules isLatex file = do ss <- readFile file >>= return . lines - return $ mkTable $ getrs [] ss + return $ inChunks chsize mkTable $ getrs [] ss where + chsize = if isLatex then 40 else 1000 getrs rs ss = case ss of ('-':'-':'.':_):_ -> reverse rs [] -> reverse rs @@ -65,18 +74,23 @@ getRules file = do _ -> getrs rs ss2 layout s = " " ++ dropWhile isSpace s -putParadigms (lang,file) = do +putParadigms isLatex (lang,file) = do title ("Paradigms for " ++ lang) space link "source" file space - rs <- getRules file + rs <- getRules isLatex file space delimit rs space +inChunks :: Int -> ([a] -> [String]) -> [a] -> [String] +inChunks i f = concat . intersperse ["\n\n"] . map f . chunks i where + chunks _ [] = [] + chunks i xs = x : chunks i y where (x,y) = splitAt i xs -mkTable rs = "|| Function | Type | Example ||" : map (unwords . row . words) rs where +mkTable rs = header : map (unwords . row . words) rs where + header = "|| Function | Type | Example ||" row ws = ["|", name, "|", typ, "|", ex, "|"] where name = ttf (head ws) (t,e) = span (/="--") (tail ws) @@ -113,6 +127,7 @@ paradigmFiles = [ append s = appendFile synopsis ('\n':s) title s = append $ "=" ++ s ++ "=" +include s = append $ "%!include: " ++ s space = append "\n" delimit ss = mapM_ append ss link s f = append $ s ++ " [``" ++ fa ++ "`` " ++ f ++ "]" where diff --git a/lib/resource-1.0/doc/synopsis-example.txt b/lib/resource-1.0/doc/synopsis-example.txt index f435a2316..c07595967 100644 --- a/lib/resource-1.0/doc/synopsis-example.txt +++ b/lib/resource-1.0/doc/synopsis-example.txt @@ -1,3 +1,4 @@ + The standard way of building an application has the following modules. An abstract syntax: diff --git a/lib/resource-1.0/doc/synopsis-intro.txt b/lib/resource-1.0/doc/synopsis-intro.txt new file mode 100644 index 000000000..27fbbef9d --- /dev/null +++ b/lib/resource-1.0/doc/synopsis-intro.txt @@ -0,0 +1,9 @@ + +This document contains the most important parts of the GF Resource Grammar API. +It has been machine-generated from the source files; each chapter gives a link +to the relevant source files, which give more information. + +The last chapter contains a brief example of how application grammars can +import resource modules. It also illustrates a "design pattern" for using +the resource API to build functor-based applications + diff --git a/lib/resource-1.0/doc/synopsis.html b/lib/resource-1.0/doc/synopsis.html index 151f116f8..9607f002f 100644 --- a/lib/resource-1.0/doc/synopsis.html +++ b/lib/resource-1.0/doc/synopsis.html @@ -26,12 +26,22 @@
  • Paradigms for Russian
  • Paradigms for Spanish
  • Paradigms for Swedish -
  • Example Usage +
  • An Example of Usage


    +

    +This document contains the most important parts of the GF Resource Grammar API. +It has been machine-generated from the source files; each chapter gives a link +to the relevant source files, which give more information. +

    +

    +The last chapter contains a brief example of how application grammars can +import resource modules. It also illustrates a "design pattern" for using +the resource API to build functor-based applications +

    Categories

    @@ -5138,7 +5148,7 @@ source http://www.cs.chalmers.se/~aar

    -

    Example Usage

    +

    An Example of Usage

    The standard way of building an application has the following modules.