tex option for synopsis; not so nice-looking yet

This commit is contained in:
aarne
2007-07-04 13:21:41 +00:00
parent 0cad9315fb
commit 7ee279fa3f
4 changed files with 54 additions and 19 deletions

View File

@@ -1,47 +1,55 @@
import System import System
import Char import Char
import List
main = do main = do
xx <- getArgs
let isLatex = case xx of
"-tex":_ -> True
_ -> False
writeFile synopsis "GF Resource Grammar Library: Synopsis" writeFile synopsis "GF Resource Grammar Library: Synopsis"
append "Aarne Ranta" append "Aarne Ranta"
space space
include "synopsis-intro.txt"
title "Categories" title "Categories"
space space
link "Source 1:" commonAPI link "Source 1:" commonAPI
space space
link "Source 2:" catAPI link "Source 2:" catAPI
space space
cs1 <- getCats True commonAPI cs1 <- getCats isLatex True commonAPI
cs2 <- getCats False catAPI cs2 <- getCats isLatex False catAPI
delimit $ cs1 ++ cs2 let cs = cs1 ++ cs2
delimit cs
space space
title "Syntax Rules" title "Syntax Rules"
space space
link "Source:" syntaxAPI link "Source:" syntaxAPI
space space
rs <- getRules syntaxAPI rs <- getRules isLatex syntaxAPI
delimit rs delimit rs
space space
title "Structural Words" title "Structural Words"
space space
link "Source:" structuralAPI link "Source:" structuralAPI
space space
rs <- getRules structuralAPI rs <- getRules isLatex structuralAPI
delimit rs delimit rs
space space
mapM_ putParadigms paradigmFiles mapM_ (putParadigms isLatex) paradigmFiles
space space
title "Example Usage" title "An Example of Usage"
space space
ss <- readFile "synopsis-example.txt" >>= return . lines include "synopsis-example.txt"
mapM_ append ss
space 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 ss <- readFile file >>= return . lines
return $ mkCatTable isBeg $ getrs [] ss return $ inChunks chsize (mkCatTable (isLatex || isBeg)) $ getrs [] ss
where where
chsize = if isLatex then 40 else 1000
getrs rs ss = case ss of getrs rs ss = case ss of
('-':'-':'.':_):_ -> reverse rs ('-':'-':'.':_):_ -> reverse rs
[] -> reverse rs [] -> reverse rs
@@ -51,10 +59,11 @@ getCats isBeg file = do
(expl,ex) = span (/="e.g.") exp (expl,ex) = span (/="e.g.") exp
_ -> getrs rs ss2 _ -> getrs rs ss2
getRules file = do getRules isLatex file = do
ss <- readFile file >>= return . lines ss <- readFile file >>= return . lines
return $ mkTable $ getrs [] ss return $ inChunks chsize mkTable $ getrs [] ss
where where
chsize = if isLatex then 40 else 1000
getrs rs ss = case ss of getrs rs ss = case ss of
('-':'-':'.':_):_ -> reverse rs ('-':'-':'.':_):_ -> reverse rs
[] -> reverse rs [] -> reverse rs
@@ -65,18 +74,23 @@ getRules file = do
_ -> getrs rs ss2 _ -> getrs rs ss2
layout s = " " ++ dropWhile isSpace s layout s = " " ++ dropWhile isSpace s
putParadigms (lang,file) = do putParadigms isLatex (lang,file) = do
title ("Paradigms for " ++ lang) title ("Paradigms for " ++ lang)
space space
link "source" file link "source" file
space space
rs <- getRules file rs <- getRules isLatex file
space space
delimit rs delimit rs
space 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 row ws = ["|", name, "|", typ, "|", ex, "|"] where
name = ttf (head ws) name = ttf (head ws)
(t,e) = span (/="--") (tail ws) (t,e) = span (/="--") (tail ws)
@@ -113,6 +127,7 @@ paradigmFiles = [
append s = appendFile synopsis ('\n':s) append s = appendFile synopsis ('\n':s)
title s = append $ "=" ++ s ++ "=" title s = append $ "=" ++ s ++ "="
include s = append $ "%!include: " ++ s
space = append "\n" space = append "\n"
delimit ss = mapM_ append ss delimit ss = mapM_ append ss
link s f = append $ s ++ " [``" ++ fa ++ "`` " ++ f ++ "]" where link s f = append $ s ++ " [``" ++ fa ++ "`` " ++ f ++ "]" where

View File

@@ -1,3 +1,4 @@
The standard way of building an application has the following modules. The standard way of building an application has the following modules.
An abstract syntax: An abstract syntax:

View File

@@ -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

View File

@@ -26,12 +26,22 @@
<LI><A HREF="#toc11">Paradigms for Russian</A> <LI><A HREF="#toc11">Paradigms for Russian</A>
<LI><A HREF="#toc12">Paradigms for Spanish</A> <LI><A HREF="#toc12">Paradigms for Spanish</A>
<LI><A HREF="#toc13">Paradigms for Swedish</A> <LI><A HREF="#toc13">Paradigms for Swedish</A>
<LI><A HREF="#toc14">Example Usage</A> <LI><A HREF="#toc14">An Example of Usage</A>
</UL> </UL>
<P></P> <P></P>
<HR NOSHADE SIZE=1> <HR NOSHADE SIZE=1>
<P></P> <P></P>
<P>
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.
</P>
<P>
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
</P>
<A NAME="toc1"></A> <A NAME="toc1"></A>
<H1>Categories</H1> <H1>Categories</H1>
<P> <P>
@@ -5138,7 +5148,7 @@ source <A HREF="../swedish/ParadigmsSwe.gf"><CODE>http://www.cs.chalmers.se/~aar
<P></P> <P></P>
<A NAME="toc14"></A> <A NAME="toc14"></A>
<H1>Example Usage</H1> <H1>An Example of Usage</H1>
<P> <P>
The standard way of building an application has the following modules. The standard way of building an application has the following modules.
</P> </P>