Commit Graph

14 Commits

Author SHA1 Message Date
hallgren
38ce5826a8 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
5339c1e6b5 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
11ec4bc655 Various small changes for improved documentation 2014-10-22 15:45:52 +00:00
hallgren
46e18b9291 Remove some dead code
* The following modules are no longer used and have been removed completely:

	GF.Compile.Compute.ConcreteLazy
	GF.Compile.Compute.ConcreteStrict
	GF.Compile.Refresh

* The STM monad has been commented out. It was only used in
  GF.Compile.SubExpOpt, where could be replaced with a plain State monad,
  since no error handling was needed. One of the functions was hardwired to
  the Err monad, but did in fact not use error handling, so it was turned
  into a pure function.

* The function errVal has been renamed to fromErr (since it is analogous to
  fromMaybe).

* Replaced 'fail' with 'raise' and 'return ()' with 'done' in a few places.

* Some additional old code that was already commented out has been removed.
2014-10-20 15:05:43 +00:00
hallgren
f109b44c97 More haddock documentation improvements 2014-10-16 14:03:57 +00:00
hallgren
1cfdffd5e9 Fix warnings in 16 modules, mostly forward compatibility warnings from GHC 7.8 2014-08-13 22:16:18 +00:00
hallgren
05c70fdc41 Spring cleaning
Nothing major...
2014-04-28 13:56:20 +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
decd7122de Eliminate mutual dependencies between the GF compiler and the PGF library
+ References to modules under src/compiler have been eliminated from the PGF
  library (under src/runtime/haskell). Only two functions had to be moved (from
  GF.Data.Utilities to PGF.Utilities) to make this possible, other apparent
  dependencies turned out to be vacuous.

+ In gf.cabal, the GF executable no longer directly depends on the PGF library
  source directory, but only on the exposed library modules. This means that
  there is less duplication in gf.cabal and that the 30 modules in the
  PGF library will no longer be compiled twice while building GF.

  To make this possible, additional PGF library modules have been exposed, even
  though they should probably be considered for internal use only. They could
  be collected in a PGF.Internal module, or marked as "unstable", to make
  this explicit.

+ Also, by using the -fwarn-unused-imports flag, ~220 redundant imports were
  found and removed, reducing the total number of imports by ~15%.
2013-11-05 13:11:10 +00:00
hallgren
e61f2f8d03 Fix a bug that could cause "Prelude.head: empty list"
In Data.Operations, the function topoTest2 assumed too much about the form of
the input, compared to the older function topoTest.
2013-02-28 17:46:13 +00:00
hallgren
a912ad813d Some changed/new utility functions
GF.Data.Utilities:  Rename mapFst to apFst, mapSnd to apSnd.
		    Add apBoth, mapFst, mapSnd, mapBoth.
GF.Data.Operations: Remove onSnd (same as apSnd)
2012-11-07 15:31:45 +00:00
hallgren
5b577baf02 Report many type errors instead of stopping after the first one
In GF.Compile.CheckGrammar, use a new topological sorting function that
groups independent judgements, allowing them all to be checked before
continuing or reporting errors.
2012-06-26 14:46:18 +00:00
krasimir
c92f9d1c0c reorganize the directories under src, and rescue the JavaScript interpreter from deprecated 2009-12-13 18:50:29 +00:00