summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeb <unknown>2004-06-02 11:17:15 +0000
committerpeb <unknown>2004-06-02 11:17:15 +0000
commit7716f818869971da138cf706c124a6be73bbab62 (patch)
tree4ec44ec8a042d15b48a4554ef8333e6395487689
parent9b0a96859790a4d30bf2071a20a7e7d29dbd1131 (diff)
*** empty log message ***
-rw-r--r--grammars/testConversions/MicroAbs.gf12
-rw-r--r--grammars/testConversions/MicroCnc.gf22
-rw-r--r--grammars/testConversions/SimpleAbs.gf7
-rw-r--r--grammars/testConversions/SimpleEng.gf5
-rw-r--r--src/GF/Data/Operations.hs8
-rw-r--r--src/GF/UseGrammar/Custom.hs26
-rw-r--r--src/GF/UseGrammar/Parsing.hs18
7 files changed, 72 insertions, 26 deletions
diff --git a/grammars/testConversions/MicroAbs.gf b/grammars/testConversions/MicroAbs.gf
index 44a3a0982..3e2e6c24b 100644
--- a/grammars/testConversions/MicroAbs.gf
+++ b/grammars/testConversions/MicroAbs.gf
@@ -1,8 +1,16 @@
abstract MicroAbs = {
-cat S;
+cat S; V; VV; W;
-fun vars : S;
+fun
+sv : V -> S;
+vars : VV;
+ww : W -> W;
+svw : V -> W -> S;
+supr : V -> V -> S;
+supredup : S -> S -> S;
+suplbl : V -> S;
+reorder : V -> V -> V;
}
diff --git a/grammars/testConversions/MicroCnc.gf b/grammars/testConversions/MicroCnc.gf
index c58c44c9b..a88795ec4 100644
--- a/grammars/testConversions/MicroCnc.gf
+++ b/grammars/testConversions/MicroCnc.gf
@@ -1,10 +1,26 @@
-concrete MicroCnc of MicroAbs = {
+concrete MicroCnc of MicroAbs = open MicroRes in {
-lincat S = {a : {s1:Str ; s2:Str}};
+lincat
+S = {s : Str};
+VV = {a : {s1:Str ; s2:Str}};
+V = {s1 : Str ; s2 : Str ; p : PQ};
+W = {s : Num => Str ; p : PQ => Num};
-lin vars = {a = variants { {s1="a" ; s2=variants{"b";"c"}} ; {s1="d";s2="e"} }};
+lin
+sv x = {s = x.s1 ++ x.s2};
+vars = {a = variants { {s1="a" ; s2=variants{"b";"c"}} ; {s1="d";s2="e"} }};
+ww x = {s = table {Sg => x.s!(x.p!P);
+ Pl => x.s!(x.p!Q Pl)};
+ p = table {P => Sg ; Q n => n}};
+svw x y = {s = x.s2 ++ y.s!(y.p!x.p) ++ x.s1};
+supr x y = {s = x.s1 ++ "a" ++ x.s2};
+supredup x y = {s = x.s ++ "b" ++ x.s};
+suplbl x = {s = x.s1};
+reorder x y = {s1 = x.s2 ++ y.s1 ++ x.s1;
+ s2 = y.s2 ++ y.s1;
+ p = x.p};
}
diff --git a/grammars/testConversions/SimpleAbs.gf b/grammars/testConversions/SimpleAbs.gf
index 0cd6d3a05..2222bfc28 100644
--- a/grammars/testConversions/SimpleAbs.gf
+++ b/grammars/testConversions/SimpleAbs.gf
@@ -2,14 +2,16 @@
abstract SimpleAbs = {
cat
-S; VP; NP; V; N; D;
+S; VP; NP; V; N; D; P; PP;
fun
cyclic : S -> S;
-mkS : NP -> V -> S;
+mkS : NP -> VP -> S;
mkVP : V -> NP -> VP;
mkNP1 : D -> N -> NP;
mkNP2 : N -> NP;
+mkNP3 : NP -> PP -> NP;
+mkPP : P -> NP -> PP;
robin : NP;
dog : N;
@@ -18,6 +20,7 @@ love : V;
hate : V;
one : D;
all : D;
+inside : P;
}
diff --git a/grammars/testConversions/SimpleEng.gf b/grammars/testConversions/SimpleEng.gf
index dce5fb999..20bed94ff 100644
--- a/grammars/testConversions/SimpleEng.gf
+++ b/grammars/testConversions/SimpleEng.gf
@@ -8,6 +8,8 @@ NP = {s : Str ; n : Num};
V = {s : Num => Str};
N = {s : Num => Str};
D = {s : Str ; n : Num};
+P = {s : Str};
+PP = {s : Str};
lin
cyclic x = x;
@@ -15,6 +17,8 @@ mkS x y = {s = x.s ++ y.s ! x.n};
mkVP x y = {s = table {n => x.s ! n ++ y.s}};
mkNP1 x y = {s = x.s ++ y.s ! x.n ; n = x.n};
mkNP2 x = {s = x.s ! Pl ; n = Pl};
+mkNP3 x y = {s = x.s ++ y.s; n = x.n};
+mkPP x y = {s = x.s ++ y.s};
robin = {s = "Robin" ; n = Sg};
dog = {s = table {Sg => "dog" ; Pl => "dogs"}};
@@ -23,6 +27,7 @@ love = {s = table {Sg => "loves" ; Pl => "love"}};
hate = {s = table {Sg => "hates" ; Pl => "hate"}};
one = {s = "one" ; n = Sg};
all = {s = "all" ; n = Pl};
+inside= {s = "in"};
}
diff --git a/src/GF/Data/Operations.hs b/src/GF/Data/Operations.hs
index a23309575..15b6d5d82 100644
--- a/src/GF/Data/Operations.hs
+++ b/src/GF/Data/Operations.hs
@@ -407,8 +407,8 @@ begindocument =
"\\setlength{\\parskip}{2mm}" ++++
"\\setlength{\\parindent}{0mm}" ++++
"\\setlength{\\oddsidemargin}{0mm}" ++++
- "\\setlength{\\evensidemargin}{-2mm}" ++++
- "\\setlength{\\topmargin}{-8mm}" ++++
+ ("\\setlength{\\evensidemargin}{"++"-2mm}") ++++ -- peb 27/5-04: to prevent hugs-mode
+ ("\\setlength{\\topmargin}{"++"-8mm}") ++++ -- from treating the rest as comments
"\\setlength{\\textheight}{240mm}" ++++
"\\setlength{\\textwidth}{158mm}" ++++
"\\begin{document}\n"
@@ -416,6 +416,7 @@ begindocument =
enddocument =
"\n\\end{document}\n"
+
sortByLongest :: [[a]] -> [[a]]
sortByLongest = sortBy longer where
longer x y
@@ -426,11 +427,14 @@ sortByLongest = sortBy longer where
x' = length x
y' = length y
+-- "combinations" is the same as "sequence"!!!
+-- peb 30/5-04
combinations :: [[a]] -> [[a]]
combinations t = case t of
[] -> [[]]
aa:uu -> [a:u | a <- aa, u <- combinations uu]
+
mkTextFile :: String -> IO ()
mkTextFile name = do
s <- readFile name
diff --git a/src/GF/UseGrammar/Custom.hs b/src/GF/UseGrammar/Custom.hs
index 952f6dc07..23bd55afe 100644
--- a/src/GF/UseGrammar/Custom.hs
+++ b/src/GF/UseGrammar/Custom.hs
@@ -37,12 +37,15 @@ import GrammarToHaskell
-- the cf parsing algorithms
import ChartParser -- or some other CF Parser
-import NewChartParser
-import NewerChartParser
+import qualified ParseCFviaCFG as PCF
+--import qualified ParseGFCviaCFG as PGFC
+--import NewChartParser
+--import NewerChartParser
-- grammar conversions -- peb 19/4-04
-- see also customGrammarPrinter
import qualified ConvertGrammar as Cnv
+import qualified PrintParser as Prt
import MyParser
@@ -174,9 +177,11 @@ customGrammarPrinter =
-- add your own grammar printers here
-- grammar conversions, (peb)
,(strCI "gfc_show", show . grammar2canon . stateGrammarST)
- ,(strCI "tnf", prCanon . Cnv.convertCanonToTNF . stateGrammarST)
- ,(strCI "mcfg", Cnv.prMCFG . Cnv.convertCanonToMCFG . stateGrammarST)
- ,(strCI "mcfg_cf", Cnv.prCFG . Cnv.convertCanonToCFG . stateGrammarST)
+ -- ,(strCI "tnf", prCanon . Cnv.convertCanonToTNF . stateGrammarST)
+ ,(strCI "emcfg", Prt.prt . Cnv.convertCanonToEMCFG . stateGrammarST)
+ ,(strCI "emcfg_cf", Prt.prt . Cnv.convertCanonViaEMCFGtoCFG . stateGrammarST)
+ ,(strCI "mcfg", Prt.prt . Cnv.convertCanonToMCFG . stateGrammarST)
+ ,(strCI "mcfg_cf", Prt.prt . Cnv.convertCanonToCFG . stateGrammarST)
,(strCI "mcfg_show", show . Cnv.convertCanonToMCFG . stateGrammarST)
--- also include printing via grammar2syntax!
]
@@ -262,11 +267,14 @@ customParser =
,(strCI "myparser", myParser)
-- add your own parsers here
]
+ -- 31/5-04, peb:
+ ++ [ (strCI ("new"++name), PCF.parse descr . stateCF) |
+ (descr, names) <- PCF.alternatives, name <- names ]
-- 21/5-04, peb:
- ++ [ (strCI ("new"++name), newChartParser descr . stateCF) |
- (descr, names) <- newChartParserAlternatives, name <- names ]
- ++ [ (strCI ("newer"++name), newerChartParser descr . stateParserInfo) |
- (descr, names) <- newerChartParserAlternatives, name <- names ]
+ -- ++ [ (strCI ("new"++name), newChartParser descr . stateCF) |
+ -- (descr, names) <- newChartParserAlternatives, name <- names ]
+ -- ++ [ (strCI ("newer"++name), newerChartParser descr . stateParserInfo) |
+ -- (descr, names) <- newerChartParserAlternatives, name <- names ]
++ moreCustomParser
customTokenizer =
diff --git a/src/GF/UseGrammar/Parsing.hs b/src/GF/UseGrammar/Parsing.hs
index 91e811f22..6e6356081 100644
--- a/src/GF/UseGrammar/Parsing.hs
+++ b/src/GF/UseGrammar/Parsing.hs
@@ -20,7 +20,7 @@ import Option
import Custom
import ShellState
-import qualified ExportParser as N
+import qualified ParseGFCviaCFG as N
import Operations
@@ -43,9 +43,9 @@ parseStringC opts0 sg cat s
---- to test peb's new parser 6/10/2003
| oElem newParser opts0 = do
let pm = maybe "" id $ getOptVal opts0 useParser -- -parser=pm
- gr = grammar sg
+ gr = stateGrammarST sg
ct = cfCat2Cat cat
- ts <- checkErr $ N.newParser pm gr (cfCat2Cat cat) s
+ ts <- checkErr $ N.newParser pm sg ct s -- peb 27/5-04 (changed gr -> sg)
mapM (checkErr . (annotate gr)) ts
| otherwise = do
@@ -58,11 +58,13 @@ parseStringC opts0 sg cat s
tokens2trms opts sg cn parser (tok s)
tokens2trms :: Options ->StateGrammar ->Ident -> CFParser -> [CFTok] -> Check [Tree]
-tokens2trms opts sg cn parser as = do
- let res@(trees,info) = parser as
- ts0 <- return $ cfParseResults res -- removed nub, peb 25/5-04
- -- ts0 <- return $ nub (cfParseResults res) -- nub gives quadratic behaviour!
- -- SortedList.nubsort is O(n log n)
+tokens2trms opts sg cn parser toks = trees2trms opts sg cn toks trees info
+ where result = parser toks
+ info = snd result
+ trees = {- nub $ -} cfParseResults result -- peb 25/5-04: removed nub (O(n^2))
+
+trees2trms :: Options -> StateGrammar -> Ident -> [CFTok] -> [CFTree] -> String -> Check [Tree]
+trees2trms opts sg cn as ts0 info = do
ts <- case () of
_ | null ts0 -> checkWarn "No success in cf parsing" >> return []
_ | raw -> do