Commit Graph

611 Commits

Author SHA1 Message Date
hallgren
beccb68ddd GF.Interactive2: extension FlexibleContexts is needed for GHC 7.10 compatibility 2015-10-02 09:59:55 +00:00
hallgren
13a8515164 cc -trace: don't try to show the bodies of lambda abstractions
This triggers evaluation of terms with free variables, which the partial
evaluator isn't equipped to handle.

Reported by Aarne.
2015-09-30 10:30:19 +00:00
hallgren
1ccdd0d9fd GF source lexer: allow numeric character escapes in string literals
This makes the output from PGF.showExpr (and other Haskell code that uses
the Prelude.show function to show strings) parsable as GF source code in
more cases.

This is a workaround for the problem that GHC's implementation of the show
function uses numeric escapes for printable non-ASCII characters, e.g.
show "dålig" = "d\229lig"...
2015-09-29 12:18:35 +00:00
hallgren
35be182824 Preliminary new shell feature: cc -trace.
You can now do things like 

	cc -trace mkV "debug"

to see a trace of all opers with their arguments and results during the
computation of mkV "debug".
2015-09-28 22:23:56 +00:00
hallgren
bde7347045 Remove debug output introduced in previous patch
Oops.
2015-09-11 14:46:31 +00:00
hallgren
9556cf453f Parallel compilation: "gf -make -j" and "gf -make -j=n" now work as expected
* "gf -make -j=n" uses n parallel threads.
  * "gf -make -j" adapts to the number of processors in the system.

This mimics how "cabal build -j" and "ghc --make -j" works.

Support for this is implemented in the new module GF.System.Concurrency and
it depends on the function Control.Concurrent.setNumCapabilities, which is
only available in GHC>=7.6 (base>=4.6). GF can still be compiled with
GHC<7.6, but then you have to use +RTS -N -RTS to take advantage of
multicore processors.

To detect the number of processors in the system, the code depends on a
foreign import of a C function in the GHC run-time system.
2015-09-11 14:18:01 +00:00
hallgren
32f18b515e GF shell: write_file now writes one tree per line
This compensates for other changes that removed line breaks.
Maybe it should have a -lines options like ps and rf?
2015-09-03 20:42:38 +00:00
hallgren
1c86783e17 GF.Infra.SIO: The SIO monad now supports putStr in addition to putStrLn
Also included some unrelated minor changes.
2015-08-31 12:22:13 +00:00
hallgren
5bfaf10de5 Comment out some dead code found with -fwarn-unused-binds
Also fixed some warnings and tightened some imports
2015-08-28 13:59:43 +00:00
hallgren
128236eab9 GF shell: change parse & linearize to obtain useful results from p|l and l|p in more cases
These changes are inspired by the gf -cshell implementation of these commands.

The output of the linearize command has been changed to remove superfluous
blank lines and commas, and deliver the result as a list of strings instead of
a single multi-line string. This makes it possible to use -all and pipe the
results to the parse command. This also means that with -treebank -all,
the language tag will be repeated for each result from the same language.

The parse command, when trying to parse with more than one language, would
"forget" other results after a failed parse, and thus not send all
successful parses through the pipe. For example, if English is not the first
language in the grammar,

    p "hello" | l

would output nothing, instead of translations of "hello" to all languages,
forcing the user to write

   p -lang=Eng "hello" | l

instead, to get the expected result. The cause of this behaviour was in the
function fromParse, which was rather messy, so I assume it is not intentional,
but the result of a programming mistake at some point.

The fromParse function has now been refactored from a big recursive function
into 

    fromParse opts = foldr (joinPiped . fromParse1 opts) void

where the helper functions fromParse1 deals with a single parse result and
joinPiped combines multiple parse results.
2015-08-26 13:56:23 +00:00
hallgren
c25705519a GF shell bug fix: visualize_parse didn't accept the -lang flag
Even though the -lang flag was handled in the implementation, it was not
documented, and GF.Command.Interpreter rejects undocumented flags:

	option not interpreted: lang

This must be a fairly old bug, so it suggests that the vp command isn't used
much...
2015-08-21 12:20:40 +00:00
hallgren
e178615338 GF -cshell: implement visualize_parse
Supported options and flags: -lang -format -view
None of the rendering options available in the Haskell run-time are supported.
2015-08-21 12:14:47 +00:00
krasimir
d1b46ece28 add a type signature in GF.Interactive2 to make ghc-7.6.3 happy 2015-08-21 11:58:32 +00:00
hallgren
026d6a73ad gf -cshell: implement visualize_tree
But the following options are not supported: -mk -nocats -nofuns
2015-08-21 10:14:46 +00:00
hallgren
786ef54d62 gf -cshell: implement a subset of print_grammar and abstract_info
pg supports only the -funs, -cats and -langs output modes.

ai IDENTIFIER shows info about a category or a function. ai can not type check
and refine metavariables in expressions.
2015-08-20 16:06:10 +00:00
hallgren
2ff7e829dc gf -cshell: linearize: implement options -all -list -treebank
Options -all and -list use PGF2.linearizeAll, which lists all variants, but
not all forms...
Also, there is no attempt to be compatible with the output from the Haskell
run-rime shell, which produces superfluous blank lines (-all) or
commas (-list), and mixes tagged and untagged lines (-treebank -all).
2015-08-18 16:05:45 +00:00
hallgren
41075fb50a GF shell: restore the eh command to working order and document it
Also, when the command line parser fails, append the problematic command line
to the error message "command not parsed".
2015-08-18 13:13:31 +00:00
hallgren
17e7a01ae1 GF shell: add the start options to GFEnv, turn "reload" into an ordinary command 2015-08-17 15:56:39 +00:00
hallgren
2df2d4a683 GF Shell: "ph | wf -file=foo.gfs" now works as advertised
The print_history command was among the commands implemented in an ad-hoc
way instead of being handled by the command line interpreter, which means
it could not be used in a pipe, as in the example in the help info.
The refactoring in the previous patch made this old bug easy to fix.

Also fixed a bug in the "empty" command, introduced when moving the PGF from
CommandEnv to GFEnv.

TODO: fix the undocumented eh command. A comment in the help info for
print_history, and some commented out old code, suggest that eh means
"execute_history", but at present it does nothing...
2015-08-13 15:30:23 +00:00
hallgren
87e64a804c GF Shell: refactoring for improved modularity and reusability:
+ Generalize the CommandInfo type by parameterizing it on the monad
  instead of just the environment.
+ Generalize the commands defined in
  GF.Command.{Commands,Commands2,CommonCommands,SourceCommands,HelpCommand}
  to work in any monad that supports the needed operations.
+ Liberate GF.Command.Interpreter from the IO monad.
  Also, move the current PGF from CommandEnv to GFEnv in
  GF.Interactive, making the command interpreter even more generic.
+ Use a state monad to maintain the state of the interpreter in
  GF.{Interactive,Interactive2}.
2015-08-13 10:49:50 +00:00
hallgren
d860a921e0 GF Shell: turn set_encoding into a common command
Implemented in GF.Command.CommonCommands instead of GF.Interactive &
GF.Interactive2.
2015-08-12 15:00:03 +00:00
hallgren
b536b02534 GF.Interactive2: cleanup 2015-08-12 12:33:36 +00:00
hallgren
6fff2def39 GF shell: source commands (cc, sd, so, ss & dg) can now be used in pipes
These commands are now implemented as regular commands (i.e. using the
CommandInfo data type) in the new module GF.Command.SourceCommands.

The list of commands exported from GF.Command.Commmands now called pgfCommands
instead of allCommands.

The list allCommands of all commands is now assembled
from sourceCommands, pgfCommands, commonCommands and helpCommand in
GF.Interactive.
2015-08-12 11:05:08 +00:00
hallgren
063912c386 Move welcome message from GF.Interactive & GF.Interactive2 to GF.Command.Messages
...to avoid the duplication.
2015-08-12 11:01:45 +00:00
hallgren
e50f92c41d GF shell: make environment types abstract, comment out some dead code 2015-08-11 16:14:38 +00:00
hallgren
911310bb40 gf -cshell: improved help for the 'import' command 2015-08-10 16:39:31 +00:00
hallgren
10e7bacbfd Factor out common code from GF.Command.Commands and GF.Command.Commands2
Created module GF.Command.CommonCommands with ~250 lines of code for commands
that do not depend on the type of PGF in the environemnt, either because they
don't use the PGF or because they are just documented here and implemented
elsewhere.

TODO: further refactoring so that documentation and implementation of
*all* commands can be kept together.
2015-08-10 16:30:17 +00:00
hallgren
8d6e61a8df gf -cshell: preliminary support for the C run-time system in the GF shell
Some C run-time functionality is now available in the GF shell, by starting
GF with 'gf -cshell' or 'gf -crun'. Only limited functionality is available
when running the shell in these modes:

- You can only import .pgf files, not source files.
- The -retain flag can not be used and the commands that require it to work
  are not available.
- Only 18 of the 40 commands available in the usual shell have been
  implemented. The 'linearize' and 'parse' commands are the only ones
  that call the C run-time system, and they support only a limited set of
  options and flags. Use the 'help' commmands for details.
- A new command 'generate_all', that calls PGF2.generateAll, has been added.
  Unfortuntaly, using it causes 'segmentation fault'.

This is implemented by adding two new modules: GF.Command.Commands2 and
GF.Interactive2. They are copied and modified versions of GF.Command.Commands
and GF.Interactive, respectively. Code for unimplemented commands and other
code that has not been adapted to the C run-time system has been left in
place, but commented out, pending further work.
2015-08-10 14:12:51 +00:00
hallgren
d38efbaa6a Refactor GF shell modules to improve modularity and reusability
+ Move type CommandInfo from GF.Command.Commands to a new module
  GF.Commands.CommandInfo and make it independent of the PGF type.
+ Make the module GF.Command.Interpreter independent of the PGF type and
  eliminate the import of GF.Command.Commands.
+ Move the implementation of the "help" command to its own module
  GF.Command.Help
2015-08-10 13:01:02 +00:00
hallgren
22ba8d34ff Bump version of .gfo and .pgf files, improve error messages on version mismatch
Becacuse of the new special tokens added to the Symbol type, .gfo and .pgf
files produced with the current version of GF can not always be used with
older versions of GF and the PGF run-time system.

The PGF version number was increased from (2,0) to (2,1). GF can still
read version (2,0) and (1,0), so old PGF files continue to work.

The GFO version was increased from "GF03" to "GF04".
2015-06-23 12:58:14 +00:00
krasimir
b4e41cabdd "flags case_sensitive=off" makes the parser case insensitive 2015-05-11 14:11:42 +00:00
krasimir
1e0d7be4f4 added all orthographic primitives 2015-05-11 13:01:39 +00:00
hallgren
c1265db3a7 GF.Haskell: small pretty printing improvement 2015-05-05 14:06:20 +00:00
hallgren
b0e8a49b9a GF.CompileOne: use random numbers to avoid temporary file name clashes
When using make -j to compile examples/app or examples/phrasebook, since
the dependencies are not completely specified in the Makefiles, it can
happen that the same file is compiled at the same by more than one process,
resulting in an error when they try to write the same .gfo.tmp file. Adding a
random number to the temporary file name avoids this problem.
2015-05-05 13:51:35 +00:00
krasimir
8c697b72a4 drop the dependency to FST 2015-04-20 11:56:13 +00:00
hallgren
3263968c79 gf -server: include grammar modification time in the info returned by /version 2015-04-17 13:21:20 +00:00
hallgren
8cfb989c9c Translating linearization functions to Haskell: move Haskell AST and pretty printer to GF.Haskell
For further separation of pretty printing concerns from conversion concerns,
the Haskell AST and pretty printer has been moved to its own module,
GF.Haskell, also allowing it to be reused in other places where Haskell
code is generated.
2015-04-14 12:44:14 +00:00
hallgren
d249538469 GF.Compile.ConcreteToHaskell: some documentation 2015-04-07 14:51:52 +00:00
hallgren
6e81383231 GF.CompileInParallel: get rid of the cryptic 'thread blocked indefinitely in an MVar operation' message after compilation errors
Instead show a message saying how many modules were affected by the compilation
errors.
2015-03-31 13:26:51 +00:00
hallgren
421bdf3903 GF.CompileInParallel: fix a Win32 problem
Recognize \ in addition to / when extracting path components.
2015-03-13 13:48:14 +00:00
hallgren
748ebae433 GF.Server: request logging: increase length limit from 100 500 chars per field 2015-03-11 15:56:06 +00:00
krasimir
0238579610 remove some more old code 2015-03-05 14:47:36 +00:00
krasimir
7539809461 removed some operations in GeneratePMCFG. They didn't work well with variants and are now obsolete with the new partial evaluator 2015-03-05 13:58:18 +00:00
hallgren
854fec6d3a GF.Compile.Compute.ConcreteNew: add dynamic table conversion
If the enumaration of table parameter values fails during the static
traversal phase, try again in the dynamic computation phase, when the values
of bound variables are known.

This is necessary to properly deal with generic table construction in opers,
like the ones found in prelude/Coordination.gf, e.g.

  consTable : (P : PType) -> ... = \P ... -> {s1 = table P {...} ; ... }
2015-03-04 18:20:16 +00:00
hallgren
814c80124b GF.Compile.Compute.ConcreteNew: some refactoring for readability 2015-03-04 13:30:11 +00:00
hallgren
6480620e1d Fix to avoid "error (no reason given) OCCURRED IN optimizing <cat>"
GF.Compile.Optimize.mkLinReference can fail and cause this error because
the helper function inside it applies msum to a list that might be empty
(if there is a record type that does not contain a field of type Str).
This means that it can return mzero::Err, i.e.

   Bad "error (no reason given)"

which can slip through the top level test that only catches Bad "no string".
2015-03-02 14:27:36 +00:00
hallgren
632aab83c3 GF shell: fixed problems with previous change of the -retain flag
Because the prompt included the name of the abstract syntax, the loading
of the PGF was forced even if -retain was used. Even worse,
if an error occured while loading the PGF, it was repeated and caught
every time the prompt was printed, creating an infite loop. The solution
is to not print the name of the abstract syntax when the grammar is
imported with -retain, which is the way things were before anyway.
2015-02-27 16:42:09 +00:00
hallgren
e0bc6308e0 GF shell: create a PGF also when the -retain flag is used
The commands available in the shell after import -retain are now a superset
of the commands available after import without -retain.

The PGF is created lazily, so there should be no performance penalty if
the PGF isn't needed. If there are errors, they won't be reported until a
command that uses the PGF is entered.
2015-02-27 13:49:13 +00:00
krasimir
f848857519 added option -plus-as-bind which treats (+) as a bind when used with runtime variables 2015-02-20 13:26:12 +00:00
krasimir
8fae104957 remove the meta prob flags 2015-02-20 13:00:51 +00:00