Commit Graph

23 Commits

Author SHA1 Message Date
krangelov
2a2d7269cf remove the Term(Error) constructor. Better propagation of errors. 2021-10-05 19:31:12 +02:00
krangelov
cf7673525f the compiler now compiles with the new runtime 2021-09-13 18:32:57 +02:00
John J. Camilleri
0a70eca6e2 Make GF.Grammar.Canonical.Id a type synonym for GF.Infra.Ident.RawIdent
This avoids a lot of conversion back and forth between Strings and ByteStrings

This commit was cherry-picked from d0c27cdaae (lpgf branch)
2021-06-30 10:58:23 +02:00
Thomas Hallgren
b11d7d93dc GF.Grammar.Canonical: some Functor/Foldable/Traversable instances 2019-03-13 01:51:26 +01:00
Thomas Hallgren
5b401f3880 Expose GF.Grammar.Canonical + some refactoring
to make it available in other tools by depending on the gf package and
importing it
2019-03-07 17:41:16 +01:00
Thomas Hallgren
b783299b73 Rename module GF.Compile.ConcreteToCanonical to GF.Compile.GrammarToCanonical 2019-03-07 14:47:37 +01:00
Thomas Hallgren
951b884118 Export of concrete syntax to Haskell now goes via Canonical GF
TODO: better treatment of Predef functions and record subtyping coercions
2019-01-23 02:47:10 +01:00
Thomas Hallgren
e4abff7725 More work on the canonica_gf export
+ Abstract syntax now is converted directly from the Grammar and not via PGF,
  so you can use `gf -batch -no-pmcfg -f canonical_gf ...`, to export to
  canonical_gf while skipping PMCFG and PGF file generation completely.
+ Flags that are normally copied to PGF files are now included in the
  caninical_gf output as well (in particular the startcat flag).
2019-01-22 17:16:32 +01: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
krasimir
1e0d7be4f4 added all orthographic primitives 2015-05-11 13:01:39 +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
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
hallgren
efb1b540f4 Translating linearization functions to Haskell: more simplifications
+ Some additional simplifying rewrites.
+ Use an intermediate representation for Haskell types, for separation of
  concerns and cleaner code.
+ Pretty printer layout tuning
+ Code cleanup.
2015-02-12 16:05:48 +00:00
hallgren
63f79fb250 Translating linearization functions to Haskell: simplify the generated Haskell code
Introduced an intermediate representation for the generated Haskell expressions.
This allows pretty printing concerns to be separated from conversion concerns,
and makes it easy to apply some simplifying rewrites to the generated
expressions, e.g.

	[x] ++ [y]    ==> [x,y]
	pure f <*> x  ==> f <$> x
	f <$> pure x  ==> pure (f x)
	join (pure x) ==> x
2015-02-11 23:50:19 +00:00
hallgren
8e4e8da105 Translating linearization functions to Haskell: support for variants
By adding the flag -haskell=variants to the command line, GF will now generate
linearization functions in Haskell that support variants. Variants are
represented as lists in Haskell.

Variants inside pre { ... } expressions are still ignored.

TODO: apply some monad laws to generate more compact code (using an
intermediate representation of the generated Haskell code, instead of
pretty printing directly from the GF code).
2015-02-09 16:24:33 +00:00
hallgren
7e1120d271 Translating linearization functions to Haskell: move a common record type to PGF.Haskell
Move the Haskell representation of the common linearization type {s:T} to the
shared module PGF.Haskell, so that the same overloaded projection function
proj_s can be used for all concrete syntaxes.
2015-01-19 12:43:32 +00:00
hallgren
20b271a238 Translating linearization functions to Haskell: better treatment of special tokens
Common code has been lifted out from the generated Haskell modules to
an auxiliary module PGF.Haskell, which is currently included in the
regular PGF library, although it is independent of it and probably belongs
in a separate library.

The type Str used by linearization functions is now based on a token
type Tok, which is defined in PGF.Haskell.

PGF.Haskell.Tok is similar to the type GF.Data.Str.Tok, but it has
constructors for the special tokens BIND, SOFT_BIND and CAPIT, and there is
a function

	fromStr :: Str -> String

that computes the effects of these special tokens.
2015-01-14 14:35:39 +00:00
hallgren
2e642ace8a Translating linearization functions to Haskell: add support for pre {...}
STILL TODO:

	- variants
	- better treatment of special tokens BIND, SOFT_BIND & CAPIT.
2015-01-08 17:52:45 +00:00
hallgren
ef84f7d842 Translating linearization functions to Haskell: use qualified names to avoid name clashes
All languages in the Phasebook can now be converted to compilable Haskell
code.

STILL TODO:
  
  	- variants
  	- pre { ... }
2015-01-07 16:13:28 +00:00
hallgren
0694a915d2 Translating linearization functions to Haskell: significant code size reductions
+ Instead of including lists of parameter values generated by GF, generate
  code to enumerate parameter values (in the same order as GF). This seems
  to give a factor of 2-3 code size reduction in the Phrasebook (e.g.
  from 84MB to 25MB for Hin, from 338MB to 154MB for Fre).

+ Deduplicate table entries, i.e. convert "table [..,E,..,E,..,E,..]" into
  "let x = E in table [..,x,..,x,..,x,..]". This gives even more significant
  code size reduction in some cases, e.g. from 569MB to 15MB for
  PhrasebookFin.

All phrasebook languages can now be converted to compilable Haskell code,
except PhrasebookPes, which still has the name clash problem.
2015-01-06 19:57:24 +00:00
hallgren
cbd873839b More work on translating linearization functions to Haskell
Many Phrasebook languages can now be converted to compilable Haskell code.
Some languages (Fre, Hin, Snd, Urd) generate too much Haskell code to be
practically useful (e.g. 338MB for Fre). One language (Fin) took too long
to convert to Haskell. One language (Pes) has problems with name clashes in
the generated Haskell code.

STILL TODO:

  	- variants
  	- pre { ... }
  	- reduce code duplication for large tables
	- generate qualified names to avoid name clashes
2015-01-06 16:48:03 +00:00
hallgren
2eaf46f610 Work in progress on translating linearization functions to Haskell
The translation is currently good enough to translate all concrete syntaxes
of the Foods and Letter grammars, and some concrete syntaxes of the Phrasebook
grammar (e.g. PhrasebookEng & PhrasebookSpa works, but there are problems with
e.g. PhrasebookSwe and PhrasebookChi)

This functionality is enabled by running

	gf -make -output-format=haskell -haskell=concrete ...

TODO:
	- variants
	- pre { ... }
	- eta expansion of linearization functions
	- record subtyping can still cause type errors in the Haskell code
	  in some cases
	- reduce code large tables
2014-12-11 16:08:36 +00:00