Commit Graph

468 Commits

Author SHA1 Message Date
hallgren
d262bb0e48 Bug fix for pattern macros in pre{}
This bug was introduced sometime between 2013-08-21 and 2013-11-01 and caused
the function convertTerm in GF.Compile.GeneratePMCFG to encounter a EPatt where
it expected Strs. I fixed it by applying the function getPatts (from the old
partial evaluator) to the pattern.
2014-04-01 10:54:41 +00:00
kr.angelov
5f3b35a5f9 refactor the compilation of CFG and EBNF grammars. Now they are parsed by using GF.Grammar.Parser just like the ordinary GF grammars. Furthermore now GF.Speech.CFG is moved to GF.Grammar.CFG. The new module is used by both the speech conversion utils and by the compiler for CFG grammars. The parser for CFG now consumes a lot less memory and can be used with grammars with more than 4 000 000 productions. 2014-03-21 21:25:05 +00:00
hallgren
6cc8557e6b gf -server: add a command to manually flush the PGF cache
This can be used if the cloud service seems slow, but it would probably
be better to automatically expire unused PGFs from the cache after some time.
2014-03-19 16:15:05 +00:00
aarne
6d8aff65c8 show the value in the error message when failing to get Str from value 2014-03-17 18:02:07 +00:00
kr.angelov
ddb0d90c18 bugfix in the compiler for linref of empty record 2014-03-15 11:33:54 +00:00
kr.angelov
e566756746 fix in GF.Compile.Compute.ConcreteNew which makes it possible to compile DocumentationBul.gf 2014-02-17 09:00:14 +00:00
hallgren
d99f3e19d7 GFServer.hs: avoid intertwined log messages from parallel requests 2014-02-11 14:22:12 +00:00
aarne
bcabc34527 disabled ad hoc overloading, as it still causes mysterious errors. It is just a few lines in Rename.hs 2014-02-09 19:55:17 +00:00
hallgren
c8310cf17c GFC.hs: encodeFile_ is not available in the standard Data.Binary 2014-02-04 13:36:16 +00:00
aarne
cf196cb0dd new overload resolution, taking care of ad hoc overloading. 2014-02-01 13:17:52 +00:00
aarne
2552b859fd ad hoc overloading: a new way to deal with name resolution conflicts. Previously the renamer warned if there was e.g. an unqualified reference to mkAdv, which could come from either Syntax or Paradigms. The renamer picked randomly one of the alternatives, which then often failed in type checking. Now, all candidates are collected into a new structure AdHocOverload [Term], which is accessed by the type checker to make the choice based on the type of the constant. This eliminates some of the warnings and some of the error due to wrong choices. In some rare cases, the inherited constants have the same type, which cannot be resolved by overloading. In such cases, the type checker does the same as the renamer did before: pick the "first" option (i.e. the one that happens to be the first in the list returned by the renamer) and issues a warning. In this patch, only a couple of lines are changed. The typechecker (RConcrete) has more substantial changes, and will be recorded as the next patch. 2014-02-01 13:10:36 +00:00
aarne
c727f7c85c typo in Concrete type checker: when type checking <e : t>, return annotated e and not e itself. Fixed in RConcrete, which should soon replace Concrete; and hopefully will be replaced by some cleaner code soon, such as ConcreteNew which has been under construction for quite some time. 2014-01-31 21:16:07 +00:00
aarne
e19a28f46c experimental type checker module GF.Compile.TypeCheck.RConcrete.hs with record updates enabled by ** expressions. Can be changed back to Concrete.hs by just changing one import command in GF.Compile.CheckGrammar.hs. The worst thing that *should* happen with the new type checker is that some old code is detected to be invalid, which happens if it contains a type-incompatible record extension, e.g. {x = "foo"} ** {x = 1}. Previously such errors were silently ignored. A set of test runs detected one such error in the RGL, which was corrected. On the positive side, the new type checker now enables record updates in the natural way: R ** {x = 1} will give value x = 1 overshadowing any value of x in R (provided the expected type of x is Int). lib/src/experimental/PredicationSwe.gf illustrates this, as opposed to PredicationSwO.gf which has to use old-style copying of even the unchanged record fields. 2014-01-31 20:28:25 +00:00
hallgren
1d251b2395 gf -server: fix a redirection bug...
...that was introduced with the recent changes to the handling of the
current working directory
2014-01-27 16:30:03 +00:00
hallgren
39a0d9b668 gf -server: allow multiple PGF service requests to be handled in parallel
PGF service requests are stateless and can run in parallel, but some other
requests handled by the server are not and might even change the current
working directory temporarily, and this affects all threads, so it is
important that the PGF service requests access PGF files by absolute paths.
2014-01-24 13:49:02 +00:00
hallgren
b8f3914209 Optionally include C run-time support
If the C run-time library is compiled and installed on your system, you can now
do 'cabal configure -fc-runtime' to get the following extras:
  + The haskell binding to the C run-time library will be included in the
    PGF library (so you can import it in Haskell applications).
    Documentation on the new modules will be included when you run
    'cabal haddock'.
  + The new command 'pgf-shell', implemented on top of haskell binding to
    the C run-time system.
  + Three new commands in the web API: c-parse, c-linearize and
    c-translate. Their interfaces are similar to the corresponding commands
    without the "c-" prefix, but they should be considered preliminary.
2014-01-20 17:06:11 +00:00
hallgren
a158bbce53 Check file datestamp before creating PGF file when compiling grammars
When running a command like

	gf -make L_1.gf ... L_n.gf

gf now avoids recreating the target PGF file if it already exists and is
up-to-date. 

gf still reads all required .gfo files, so significant additional speed
improvements are still possible. This could be done by reading .gfo files
more lazily...
2014-01-09 17:30:24 +00:00
hallgren
de5b714573 Check file datestamps before unioning PGF files (fix)
Also check that no additional output formats have been selected.
2014-01-09 15:14:35 +00:00
hallgren
40b8c5fb99 Check file datestamps before unioning PGF files
When running a command like

 gf -make -name=T L_1.pgf ... L_n.pgf

gf now checks if T.pgf exists and is up-to-date before reading and computing
the union of the L_i.pgf files.

The name (T) of the target PGF file has to be given explicitly for this to work,
since otherwise the name is not known until the union has been computed.
If the functions for reading PGF files and computing the union were lazier,
this would not be necessary...
2014-01-09 14:18:21 +00:00
hallgren
35f86b7d81 PGFtoPython: add Python translations for nonExist, BIND and SOFT_BIND
Someone who is familiar with the Python translation should check this.
2013-12-18 15:31:39 +00:00
hallgren
9812c6ff90 GF.Compile.ReadFiles: reduced code duplication 2013-12-16 14:04:57 +00:00
kr.angelov
faed1348b1 option --split-pgf replaces option --mk-index. This splits the PGF into one file for the abstract and one more for each concrete syntax. This is a preparation for being able to load only specific languages from the whole grammar. 2013-12-10 10:43:13 +00:00
hallgren
41827b1aab Show relative file paths in error messages
This is to avoid one trivial reason for failures in the test suite.
2013-12-06 15:43:34 +00:00
hallgren
0d047707fc GF.Compile.CheckGrammar: add source path to error message for circular definitions 2013-12-06 13:46:59 +00:00
hallgren
e6096bffc5 GF shell: fix help text for generate_trees
Trees are not generated with increasing depth.
2013-12-06 13:45:12 +00:00
aarne
1778cd7c19 removed the unlines-lines wrapper from Lexing.unlexer to prevent empty lines when an unlexer (such as -bind or -unchars) is used as an option in linearization. Don't know really why the input had been broken into lines in the first place. You can see the effect by importing LangEng and running "gr -cat=Cl | l -table -bind" before and after recompiling GF. 2013-12-03 13:27:22 +00:00
hallgren
7934c0a88b Commment code and options relating to the old partial evaluator
This means that the -old-comp and -new-comp flags are not recognized anymore.

The only functional difference is that printnames were still normalized with
the old partial evaluator. Now that is done with the new partial evaluator.
2013-11-29 16:26:49 +00:00
hallgren
537caca039 Move typePredefined from GF.Compile.Compute.AppPredefined to GF.Compile.TypeCheck.Primitives
Also move the list of primitives
2013-11-29 15:47:26 +00:00
hallgren
6f590a3f2c Move checkPredefError from GF.Compile.Compute.ConcreteLazy to GF.Grammar.Macros
Also simplified its type.
2013-11-29 14:43:01 +00:00
hallgren
dcf07aaad6 GFI: adapt to character encoding changes
GF.Compile.Coding is not used any more.
2013-11-28 13:55:08 +00:00
hallgren
4ef30ca450 SimpleEditor.Convert: adapt to recent character encoding changes
Things got simpler!
2013-11-28 13:27:45 +00:00
hallgren
a617e50d95 Represent identifiers as UTF-8-encoded ByteStrings
This was a fairly simple change thanks to previous work on making the Ident
type abstract and the fact that PGF.CId already uses UTF-8-encoded
ByteStrings.

One potential pitfall is that Data.ByteString.UTF8 uses the same type for
ByteStrings as Data.ByteString. I renamed ident2bs to ident2utf8 and
bsCId to utf8CId, to make it clearer that they work with UTF-8-encoded
ByteStrings.

Since both the compiler input and identifiers are now UTF-8-encoded
ByteStrings, the lexer now creates identifiers without copying any characters.
**END OF DESCRIPTION***

Place the long patch description above the ***END OF DESCRIPTION*** marker.
The first line of this file will be the patch name.


This patch contains the following changes:

M ./src/compiler/GF/Compile/CheckGrammar.hs -3 +3
M ./src/compiler/GF/Compile/GrammarToPGF.hs -2 +2
M ./src/compiler/GF/Grammar/Binary.hs -5 +1
M ./src/compiler/GF/Grammar/Lexer.x -11 +13
M ./src/compiler/GF/Infra/Ident.hs -19 +36
M ./src/runtime/haskell/PGF.hs -1 +1
M ./src/runtime/haskell/PGF/CId.hs -2 +3
2013-11-26 16:12:03 +00:00
hallgren
30fc46e934 Change how GF deals with character encodings in grammar files
1. The default encoding is changed from Latin-1 to UTF-8.

2. Alternate encodings should be specified as "--# -coding=enc", the old
   "flags coding=enc" declarations have no effect but are still checked for
   consistency.

3. A transitional warning is generated for files that contain non-ASCII
   characters without specifying a character encoding:

	"Warning: default encoding has changed from Latin-1 to UTF-8"

4. Conversion to Unicode is now done *before* lexing. This makes it possible
   to allow arbitrary Unicode characters in identifiers. But identifiers are
   still stored as ByteStrings, so they are limited to Latin-1 characters
   for now.

5. Lexer.hs is no longer part of the repository. We now generate the lexer
   from Lexer.x with alex>=3. Some workarounds for bugs in alex-3.0 were
   needed. These bugs might already be fixed in newer versions of alex, but
   we should be compatible with what is shipped in the Haskell Platform.
2013-11-25 21:12:11 +00:00
kr.angelov
c119627dfc fix the export for CFG grammars with BIND, SOFT_BIND and nonExist 2013-11-22 13:36:14 +00:00
kr.angelov
4254b101f4 the GF syntax for identifiers is exteded with quoted forms, i.e. you could write for instance 'ab.c' and then everything between the quites is identifier. This includes Unicode characters and non-ASCII symbols. This is useful for automatically generated GF grammars. 2013-11-22 13:30:18 +00:00
hallgren
14bbbf1f27 Some refactoring in GF.Compile and GF.Compile.GetGrammar
Move source transcoding function GF.Compile to GF.Compile.GetGrammar, in
preparation for doing transcoding before lexing.
2013-11-21 16:27:26 +00:00
hallgren
c8d2ed96fd Some more monadic lifting changes 2013-11-21 15:01:04 +00:00
hallgren
ab8037c3c6 Removed some code duplication in GF.Compile.Update 2013-11-20 01:26:41 +00:00
hallgren
c8cbd4477f Reduced clutter in monadic code
+ Eliminated vairous ad-hoc coersion functions between specific monads 
  (IO, Err, IOE, Check) in favor of more general lifting functions
  (liftIO, liftErr).
+ Generalized many basic monadic operations from specific monads to
  arbitrary monads in the appropriate class (MonadIO and/or ErrorMonad),
  thereby completely eliminating the need for lifting functions in lots
  of places.

This can be considered a small step forward towards a cleaner
compiler API and more malleable compiler code in general.
2013-11-20 00:45:33 +00:00
hallgren
c29326d074 GF shell: improved system_pipe (aka "?") command
1. No temporary files are created.

2. The output of a system command is read lazily, making it feasible to 
   process large or even infinite output, e.g. the following works as
   expected:

	? "yes" | ? "head -5" | ps -lextext
2013-11-19 15:18:58 +00:00
hallgren
4a5b9ca8cb Fix Issue 60: Weird output when executing system commands from the gf shell
The system_pipe (aka "?") command creates a temporary file _tmpi containing
the input of the system command. It *both* appends _tmpi as an extra argument
to the system command line *and* adds an input redirection "< _tmpi". (It
also uses and output redirection "> _tmpo" to captures the output of the
command.)

With this patch, the _tmpi argument is no longer appended to the command line.
This allows system_pipe to work with pure filters, such as the "tr" commands,
but it will no longer work with commands that require an input file name.
(It is possible to use write_file instead...)

TODO: it would also be fairly easy to eliminate the creation of the _tmpi and
_tmpo files altogether.
2013-11-12 18:07:38 +00:00
hallgren
12d86604b2 Fix Issue 68: Cannot use an overloaded operator in table defined using square brackets
Add proper type checking of course-of-values tables:

 + Make sure that all subterms have the same type.
 + Resolve overloaded operators.

Note though that the GF book states in C.4.12 that the "course-of-values
table [...] format is not recommended for GF source code, since the
ordering of parameter values is not specified and therefore a
compiler-internal decision."
2013-11-12 13:55:38 +00:00
hallgren
a3de4b6e86 GF.System.Chatch: remove redundant #include 2013-11-12 13:51:11 +00:00
kr.angelov
1d7b6f44b6 added Predef.SOFT_BIND. This special token allows zero or more spaces between ordinary tokens. It is also used in the English RGL to attach the commas to the previous word. 2013-11-12 09:54:57 +00:00
hallgren
2da15f558e Fix Issue 41: "," in context-free rules causes parsing failure
The CF parser in GF.Grammar.CF assigns function names to the rules, but they
are not always unique, causing rules to be dropped in the follwing CF->GF
conversion. So a pass has been added before the CF->GF conversion, to make
sure that function names are unique.

A comment says "rules have an amazingly easy parser", but the parser looks
like quick hack. It is very sloppy and silently ignores many errors, e.g.
- Explicitly given function names should end with '.', but if the do not, the
  last character in the function name is silently dropped.
- Everything following a ';' is silently dropped.
2013-11-11 16:50:43 +00:00
hallgren
d1314dcbcd Fix issue 61: GF shell cannot parse a system command ending with a space
Trailing spaces caused the command line parse to be ambiguous, and
ambiguous parses were rejected by function readCommandLine, causing
the cryptic error message "command not parsed".
2013-11-11 15:13:24 +00:00
hallgren
5beded9330 Make PGF.Tree internal
The only use of PGF.Tree outside the PGF library was in GF.Command.Commands,
and it was eliminated by using PGF.Expr directly instead.
PGF.Paraphrase still uses PGF.Tree.
2013-11-06 14:29:17 +00:00
hallgren
06453afb1c Remove PGF.Signature
This module should not be part of the public PGF library API, and it was only
used in GF.CompileToAPI, so the code was moved there. The module defined
constFuncs and syntaxFuncs, but only syntaxFuncs was used.
2013-11-06 13:27:29 +00:00
kr.angelov
bd69ad83f7 fix the deserialization of flags from the GFO files 2013-11-06 13:05:51 +00:00
kr.angelov
475f213c99 the content of ParseEngAbs3.probs is now merged with ParseEngAbs.probs. The later is now retrained. Once the grammar is compiled with the .probs file now it doesn't need anything more to do robust parsing. The robustness itself is controlled by the flags 'heuristic_search_factor', 'meta_prob' and 'meta_token_prob' in ParseEngAbs.gf 2013-11-06 10:21:46 +00:00