diff --git a/doc/book/gf-book.tex b/doc/book/gf-book.tex index 8d18e64c9..10394299c 100644 --- a/doc/book/gf-book.tex +++ b/doc/book/gf-book.tex @@ -76,7 +76,7 @@ is the Grammatical Framework, GF. There are many reasons why natural-language applications are not common. One reason is that they are difficult to build. No-one has ever managed to write a program that correctly recognizes arbitrary -natural-language input in any language +natural-language input in any language. GF is a special-purpose programming language for writing grammars. diff --git a/src/GF/Grammar/Compute.hs b/src/GF/Grammar/Compute.hs index 6c557b479..5573e5e4e 100644 --- a/src/GF/Grammar/Compute.hs +++ b/src/GF/Grammar/Compute.hs @@ -139,6 +139,13 @@ computeTerm gr = comp where foldr1 C (map K (str2strings (glueStr v (str a)))) | v <- x'] ,return $ Glue x y ] + (FV ks,_) -> do + kys <- mapM (comp g . flip Glue y) ks + return $ FV kys + (_,FV ks) -> do + xks <- mapM (comp g . Glue x) ks + return $ FV xks + _ -> do mapM_ checkNoArgVars [x,y] r <- composOp (comp g) t @@ -152,10 +159,17 @@ computeTerm gr = comp where C a b -> do a' <- comp g a b' <- comp g b - returnC $ case (a',b') of - (Empty,_) -> b' - (_,Empty) -> a' - _ -> C a' b' + case (a',b') of + (Alts _, K a) -> checks [do + as <- strsFromTerm a' -- this may fail when compiling opers + return $ variants [ + foldr1 C (map K (str2strings (plusStr v (str a)))) | v <- as] + , + return $ C a' b' + ] + (Empty,_) -> returnC b' + (_,Empty) -> returnC a' + _ -> returnC $ C a' b' -- reduce free variation as much as you can FV [t] -> comp g t