the Error type; better lexer error reporting

This commit is contained in:
aarne
2006-09-01 15:11:22 +00:00
parent 04933ef3c9
commit 39a31d07d5
7 changed files with 121 additions and 44 deletions

View File

@@ -14,7 +14,46 @@ Changes in functionality since May 17, 2005, release of GF Version 2.2
<p>
22/6 (AR) Release of GF version 2.6.
1/9 (AR) New way for managing errors in grammar compilation:
<pre>
Predef.Error : Type ;
Predef.error : Str -> Predef.Error ;
</pre>
Denotationally, <tt>Error</tt> is the empty type and thus a
subtype of any other types: it can be used anywhere. But the
<tt>error</tt> function is not canonical. Hence the compilation
is interrupted when <tt>(error s)</tt> is translated to GFC, and
the message <tt>s</tt> is emitted. An example use is given in
<tt>english/ParadigmsEng.gf</tt>:
<pre>
regDuplV : Str -> V ;
regDuplV fit =
case last fit of {
("a" | "e" | "i" | "o" | "u" | "y") =>
Predef.error (["final duplication makes no sense for"] ++ fit) ;
t =>
let fitt = fit + t in
mkV fit (fit + "s") (fitt + "ed") (fitt + "ed") (fitt + "ing")
} ;
</pre>
This function thus cannot be applied to a stem ending with a vowel,
which is exactly what we want. In future, it may be good to add similar
checks to all morphological paradigms in the resource.
<p>
16/8 (AR) New generation algorithm: slower but works with less
memory. Default of <tt>gt</tt>; use <tt>gt -mem</tt> for the old
algorithm. The new option <tt>gt -all</tt> lazily generates all
trees until interrupted. It cannot be piped to other GF commands,
hence use <tt>gt -all -lin</tt> to print out linearized strings
rather than trees.
<hr>
22/6 (AR) <b>Release of GF version 2.6</b>.
<p>

View File

@@ -288,6 +288,7 @@ computeLType gr t = do
App (Q (IC "Predef") (IC "Ints")) _ -> return ty ---- shouldn't be needed
Q (IC "Predef") (IC "Int") -> return ty ---- shouldn't be needed
Q (IC "Predef") (IC "Float") -> return ty ---- shouldn't be needed
Q (IC "Predef") (IC "Error") -> return ty ---- shouldn't be needed
Q m c | elem c [cPredef,cPredefAbs] -> return ty
Q m c | elem c [zIdent "Int"] ->
@@ -777,13 +778,16 @@ checkEqLType env t u trm = do
checkWarn $ "WARNING: missing lock field" +++ unwords (map prt lo)
return t'
Bad s -> raise (s +++ "type of" +++ prt trm +++
": expected" ++++ prt t' ++++ "inferred" ++++ prt u')
": expected" ++++ prt t' ++++ "inferred" ++++ prt u' ++++ show u')
where
-- t is a subtype of u
--- quick hack version of TC.eqVal
alpha g t u = case (t,u) of
-- error (the empty type!) is subtype of any other type
(_,Q (IC "Predef") (IC "Error")) -> True
-- contravariance
(Prod x a b, Prod y c d) -> alpha g c a && alpha ((x,y):g) b d

View File

@@ -194,11 +194,12 @@ redCTerm t = case t of
Vr x -> checkAgain
(liftM G.Arg $ redArgvar x)
(liftM G.LI $ redIdent x) --- for parametrize optimization
App _ _ -> do -- only constructor applications can remain
App _ s -> do -- only constructor applications can remain
(_,c,xx) <- termForm t
xx' <- mapM redCTerm xx
case c of
QC p c -> liftM2 G.Par (redQIdent (p,c)) (return xx')
Q (IC "Predef") (IC "error") -> fail $ "error: " ++ stringFromTerm s
_ -> prtBad "expected constructor head instead of" c
Q p c -> liftM G.I (redQIdent (p,c))
QC p c -> liftM2 G.Par (redQIdent (p,c)) (return [])

View File

@@ -31,8 +31,10 @@ typPredefined :: Ident -> Err Type
typPredefined c@(IC f) = case f of
"Int" -> return typePType
"Float" -> return typePType
"Error" -> return typeType
"Ints" -> return $ mkFunType [cnPredef "Int"] typePType
"PBool" -> return typePType
"error" -> return $ mkFunType [typeStr] (cnPredef "Error") -- non-can. of empty set
"PFalse" -> return $ cnPredef "PBool"
"PTrue" -> return $ cnPredef "PBool"
"dp" -> return $ mkFunType [cnPredef "Int",typeTok] typeTok

View File

@@ -614,7 +614,9 @@ txtHelpFile =
"\n The default is share for concrete, none for resource modules." ++
"\n Each of the flags can have the suffix _subs, which performs" ++
"\n common subexpression elimination after the main optimization." ++
"\n Thus, -optimize=all_subs is the most aggressive one." ++
"\n Thus, -optimize=all_subs is the most aggressive one. The _subs" ++
"\n strategy only works in GFC, and applies therefore in concrete but" ++
"\n not in resource modules." ++
"\n -optimize=share share common branches in tables" ++
"\n -optimize=parametrize first try parametrize then do share with the rest" ++
"\n -optimize=values represent tables as courses-of-values" ++

File diff suppressed because one or more lines are too long

View File

@@ -585,7 +585,9 @@ q, quit: q
The default is share for concrete, none for resource modules.
Each of the flags can have the suffix _subs, which performs
common subexpression elimination after the main optimization.
Thus, -optimize=all_subs is the most aggressive one.
Thus, -optimize=all_subs is the most aggressive one. The _subs
strategy only works in GFC, and applies therefore in concrete but
not in resource modules.
-optimize=share share common branches in tables
-optimize=parametrize first try parametrize then do share with the rest
-optimize=values represent tables as courses-of-values