\" for full help on a command. " ++
+ "\n" ++
+ "\n-- commands that change the state" ++
+ "\n" ++
+ "\ni, import: i File" ++
+ "\n Reads a grammar from File and compiles it into a GF runtime grammar." ++
+ "\n Files \"include\"d in File are read recursively, nubbing repetitions." ++
+ "\n If a grammar with the same language name is already in the state," ++
+ "\n it is overwritten - but only if compilation succeeds. " ++
+ "\n The grammar parser depends on the file name suffix:" ++
+ "\n .gf normal GF source" ++
+ "\n .gfc canonical GF" ++
+ "\n .gfr precompiled GF resource " ++
+ "\n .gfcm multilingual canonical GF" ++
+ "\n .gfe example-based grammar files (only with the -ex option)" ++
+ "\n .gfwl multilingual word list (preprocessed to abs + cncs)" ++
+ "\n .ebnf Extended BNF format" ++
+ "\n .cf Context-free (BNF) format" ++
+ "\n .trc TransferCore format" ++
+ "\n options:" ++
+ "\n -old old: parse in GF<2.0 format (not necessary)" ++
+ "\n -v verbose: give lots of messages " ++
+ "\n -s silent: don't give error messages" ++
+ "\n -src from source: ignore precompiled gfc and gfr files" ++
+ "\n -gfc from gfc: use compiled modules whenever they exist" ++
+ "\n -retain retain operations: read resource modules (needed in comm cc) " ++
+ "\n -nocf don't build old-style context-free grammar (default without HOAS)" ++
+ "\n -docf do build old-style context-free grammar (default with HOAS)" ++
+ "\n -nocheckcirc don't eliminate circular rules from CF " ++
+ "\n -cflexer build an optimized parser with separate lexer trie" ++
+ "\n -noemit do not emit code (default with old grammar format)" ++
+ "\n -o do emit code (default with new grammar format)" ++
+ "\n -ex preprocess .gfe files if needed" ++
+ "\n -prob read probabilities from top grammar file (format --# prob Fun Double)" ++
+ "\n -treebank read a treebank file to memory (xml format)" ++
+ "\n flags:" ++
+ "\n -abs set the name used for abstract syntax (with -old option)" ++
+ "\n -cnc set the name used for concrete syntax (with -old option)" ++
+ "\n -res set the name used for resource (with -old option)" ++
+ "\n -path use the (colon-separated) search path to find modules" ++
+ "\n -optimize select an optimization to override file-defined flags" ++
+ "\n -conversion select parsing method (values strict|nondet)" ++
+ "\n -probs read probabilities from file (format (--# prob) Fun Double)" ++
+ "\n -preproc use a preprocessor on each source file" ++
+ "\n -noparse read nonparsable functions from file (format --# noparse Funs) " ++
+ "\n examples:" ++
+ "\n i English.gf -- ordinary import of Concrete" ++
+ "\n i -retain german/ParadigmsGer.gf -- import of Resource to test" ++
+ "\n" ++
+ "\nr, reload: r" ++
+ "\n Executes the previous import (i) command." ++
+ "\n " ++
+ "\nrl, remove_language: rl Language" ++
+ "\n Takes away the language from the state." ++
+ "\n" ++
+ "\ne, empty: e" ++
+ "\n Takes away all languages and resets all global flags." ++
+ "\n" ++
+ "\nsf, set_flags: sf Flag*" ++
+ "\n The values of the Flags are set for Language. If no language" ++
+ "\n is specified, the flags are set globally." ++
+ "\n examples:" ++
+ "\n sf -nocpu -- stop showing CPU time" ++
+ "\n sf -lang=Swe -- make Swe the default concrete" ++
+ "\n" ++
+ "\ns, strip: s" ++
+ "\n Prune the state by removing source and resource modules." ++
+ "\n" ++
+ "\ndc, define_command Name Anything" ++
+ "\n Add a new defined command. The Name must star with '%'. Later," ++
+ "\n if 'Name X' is used, it is replaced by Anything where #1 is replaced" ++
+ "\n by X. " ++
+ "\n Restrictions: Currently at most one argument is possible, and a defined" ++
+ "\n command cannot appear in a pipe. " ++
+ "\n To see what definitions are in scope, use help -defs." ++
+ "\n examples:" ++
+ "\n dc %tnp p -cat=NP -lang=Eng #1 | l -lang=Swe -- translate NPs" ++
+ "\n %tnp \"this man\" -- translate and parse" ++
+ "\n" ++
+ "\ndt, define_term Name Tree" ++
+ "\n Add a constant for a tree. The constant can later be called by" ++
+ "\n prefixing it with '$'. " ++
+ "\n Restriction: These terms are not yet usable as a subterm. " ++
+ "\n To see what definitions are in scope, use help -defs." ++
+ "\n examples:" ++
+ "\n p -cat=NP \"this man\" | dt tm -- define tm as parse result" ++
+ "\n l -all $tm -- linearize tm in all forms" ++
+ "\n" ++
+ "\n-- commands that give information about the state" ++
+ "\n" ++
+ "\npg, print_grammar: pg" ++
+ "\n Prints the actual grammar (overridden by the -lang=X flag)." ++
+ "\n The -printer=X flag sets the format in which the grammar is" ++
+ "\n written." ++
+ "\n N.B. since grammars are compiled when imported, this command" ++
+ "\n generally does not show the grammar in the same format as the" ++
+ "\n source. In particular, the -printer=latex is not supported. " ++
+ "\n Use the command tg -printer=latex File to print the source " ++
+ "\n grammar in LaTeX." ++
+ "\n options:" ++
+ "\n -utf8 apply UTF8-encoding to the grammar" ++
+ "\n flags: " ++
+ "\n -printer" ++
+ "\n -lang" ++
+ "\n -startcat -- The start category of the generated grammar." ++
+ "\n Only supported by some grammar printers." ++
+ "\n examples:" ++
+ "\n pg -printer=cf -- show the context-free skeleton" ++
+ "\n" ++
+ "\npm, print_multigrammar: pm" ++
+ "\n Prints the current multilingual grammar in .gfcm form." ++
+ "\n (Automatically executes the strip command (s) before doing this.)" ++
+ "\n options:" ++
+ "\n -utf8 apply UTF8 encoding to the tokens in the grammar" ++
+ "\n -utf8id apply UTF8 encoding to the identifiers in the grammar" ++
+ "\n examples:" ++
+ "\n pm | wf Letter.gfcm -- print the grammar into the file Letter.gfcm" ++
+ "\n pm -printer=graph | wf D.dot -- then do 'dot -Tps D.dot > D.ps'" ++
+ "\n" ++
+ "\nvg, visualize_graph: vg" ++
+ "\n Show the dependency graph of multilingual grammar via dot and gv." ++
+ "\n" ++
+ "\npo, print_options: po" ++
+ "\n Print what modules there are in the state. Also" ++
+ "\n prints those flag values in the current state that differ from defaults." ++
+ "\n" ++
+ "\npl, print_languages: pl" ++
+ "\n Prints the names of currently available languages." ++
+ "\n" ++
+ "\npi, print_info: pi Ident" ++
+ "\n Prints information on the identifier." ++
+ "\n" ++
+ "\n-- commands that execute and show the session history" ++
+ "\n" ++
+ "\neh, execute_history: eh File" ++
+ "\n Executes commands in the file." ++
+ "\n" ++
+ "\nph, print_history; ph" ++
+ "\n Prints the commands issued during the GF session." ++
+ "\n The result is readable by the eh command." ++
+ "\n examples:" ++
+ "\n ph | wf foo.hist\" -- save the history into a file" ++
+ "\n" ++
+ "\n-- linearization, parsing, translation, and computation" ++
+ "\n" ++
+ "\nl, linearize: l PattList? Tree" ++
+ "\n Shows all linearization forms of Tree by the actual grammar" ++
+ "\n (which is overridden by the -lang flag). " ++
+ "\n The pattern list has the form [P, ... ,Q] where P,...,Q follow GF " ++
+ "\n syntax for patterns. All those forms are generated that match with the" ++
+ "\n pattern list. Too short lists are filled with variables in the end." ++
+ "\n Only the -table flag is available if a pattern list is specified." ++
+ "\n HINT: see GF language specification for the syntax of Pattern and Term." ++
+ "\n You can also copy and past parsing results." ++
+ "\n options: " ++
+ "\n -struct bracketed form" ++
+ "\n -table show parameters (not compatible with -record, -all)" ++
+ "\n -record record, i.e. explicit GF concrete syntax term (not compatible with -table, -all)" ++
+ "\n -all show all forms and variants (not compatible with -record, -table)" ++
+ "\n -multi linearize to all languages (can be combined with the other options)" ++
+ "\n flags:" ++
+ "\n -lang linearize in this grammar" ++
+ "\n -number give this number of forms at most" ++
+ "\n -unlexer filter output through unlexer" ++
+ "\n examples:" ++
+ "\n l -lang=Swe -table -- show full inflection table in Swe" ++
+ "\n" ++
+ "\np, parse: p String" ++
+ "\n Shows all Trees returned for String by the actual" ++
+ "\n grammar (overridden by the -lang flag), in the category S (overridden" ++
+ "\n by the -cat flag)." ++
+ "\n options for batch input:" ++
+ "\n -lines parse each line of input separately, ignoring empty lines" ++
+ "\n -all as -lines, but also parse empty lines" ++
+ "\n -prob rank results by probability" ++
+ "\n -cut stop after first lexing result leading to parser success" ++
+ "\n -fail show strings whose parse fails prefixed by #FAIL" ++
+ "\n -ambiguous show strings that have more than one parse prefixed by #AMBIGUOUS" ++
+ "\n options for selecting parsing method:" ++
+ "\n -fcfg parse using a fast variant of MCFG (default is no HOAS in grammar)" ++
+ "\n -old parse using an overgenerating CFG (default if HOAS in grammar)" ++
+ "\n -cfg parse using a much less overgenerating CFG" ++
+ "\n -mcfg parse using an even less overgenerating MCFG" ++
+ "\n Note: the first time parsing with -cfg, -mcfg, and -fcfg may take a long time" ++
+ "\n options that only work for the -old default parsing method:" ++
+ "\n -n non-strict: tolerates morphological errors" ++
+ "\n -ign ignore unknown words when parsing" ++
+ "\n -raw return context-free terms in raw form" ++
+ "\n -v verbose: give more information if parsing fails" ++
+ "\n flags:" ++
+ "\n -cat parse in this category" ++
+ "\n -lang parse in this grammar" ++
+ "\n -lexer filter input through this lexer" ++
+ "\n -parser use this parsing strategy" ++
+ "\n -number return this many results at most" ++
+ "\n examples:" ++
+ "\n p -cat=S -mcfg \"jag \228r gammal\" -- parse an S with the MCFG" ++
+ "\n rf examples.txt | p -lines -- parse each non-empty line of the file" ++
+ "\n" ++
+ "\nat, apply_transfer: at (Module.Fun | Fun)" ++
+ "\n Transfer a term using Fun from Module, or the topmost transfer" ++
+ "\n module. Transfer modules are given in the .trc format. They are" ++
+ "\n shown by the 'po' command." ++
+ "\n flags:" ++
+ "\n -lang typecheck the result in this lang instead of default lang" ++
+ "\n examples:" ++
+ "\n p -lang=Cncdecimal \"123\" | at num2bin | l -- convert dec to bin" ++
+ "\n" ++
+ "\ntb, tree_bank: tb" ++
+ "\n Generate a multilingual treebank from a list of trees (default) or compare" ++
+ "\n to an existing treebank." ++
+ "\n options:" ++
+ "\n -c compare to existing xml-formatted treebank" ++
+ "\n -trees return the trees of the treebank" ++
+ "\n -all show all linearization alternatives (branches and variants)" ++
+ "\n -table show tables of linearizations with parameters" ++
+ "\n -record show linearization records" ++
+ "\n -xml wrap the treebank (or comparison results) with XML tags" ++
+ "\n -mem write the treebank in memory instead of a file TODO" ++
+ "\n examples:" ++
+ "\n gr -cat=S -number=100 | tb -xml | wf tb.xml -- random treebank into file" ++
+ "\n rf tb.xml | tb -c -- compare-test treebank from file" ++
+ "\n rf old.xml | tb -trees | tb -xml -- create new treebank from old" ++
+ "\n" ++
+ "\nut, use_treebank: ut String" ++
+ "\n Lookup a string in a treebank and return the resulting trees." ++
+ "\n Use 'tb' to create a treebank and 'i -treebank' to read one from" ++
+ "\n a file." ++
+ "\n options:" ++
+ "\n -assocs show all string-trees associations in the treebank" ++
+ "\n -strings show all strings in the treebank" ++
+ "\n -trees show all trees in the treebank" ++
+ "\n -raw return the lookup result as string, without typechecking it" ++
+ "\n flags:" ++
+ "\n -treebank use this treebank (instead of the latest introduced one)" ++
+ "\n examples:" ++
+ "\n ut \"He adds this to that\" | l -multi -- use treebank lookup as parser in translation" ++
+ "\n ut -assocs | grep \"ComplV2\" -- show all associations with ComplV2" ++
+ "\n" ++
+ "\ntt, test_tokenizer: tt String" ++
+ "\n Show the token list sent to the parser when String is parsed." ++
+ "\n HINT: can be useful when debugging the parser." ++
+ "\n flags: " ++
+ "\n -lexer use this lexer" ++
+ "\n examples:" ++
+ "\n tt -lexer=codelit \"2*(x + 3)\" -- a favourite lexer for program code" ++
+ "\n" ++
+ "\ng, grep: g String1 String2" ++
+ "\n Grep the String1 in the String2. String2 is read line by line," ++
+ "\n and only those lines that contain String1 are returned." ++
+ "\n flags:" ++
+ "\n -v return those lines that do not contain String1." ++
+ "\n examples:" ++
+ "\n pg -printer=cf | grep \"mother\" -- show cf rules with word mother" ++
+ "\n" ++
+ "\ncc, compute_concrete: cc Term" ++
+ "\n Compute a term by concrete syntax definitions. Uses the topmost" ++
+ "\n resource module (the last in listing by command po) to resolve " ++
+ "\n constant names. " ++
+ "\n N.B. You need the flag -retain when importing the grammar, if you want " ++
+ "\n the oper definitions to be retained after compilation; otherwise this" ++
+ "\n command does not expand oper constants." ++
+ "\n N.B.' The resulting Term is not a term in the sense of abstract syntax," ++
+ "\n and hence not a valid input to a Tree-demanding command." ++
+ "\n flags:" ++
+ "\n -table show output in a similar readable format as 'l -table'" ++
+ "\n -res use another module than the topmost one" ++
+ "\n examples:" ++
+ "\n cc -res=ParadigmsFin (nLukko \"hyppy\") -- inflect \"hyppy\" with nLukko" ++
+ "\n" ++
+ "\nso, show_operations: so Type" ++
+ "\n Show oper operations with the given value type. Uses the topmost " ++
+ "\n resource module to resolve constant names. " ++
+ "\n N.B. You need the flag -retain when importing the grammar, if you want " ++
+ "\n the oper definitions to be retained after compilation; otherwise this" ++
+ "\n command does not find any oper constants." ++
+ "\n N.B.' The value type may not be defined in a supermodule of the" ++
+ "\n topmost resource. In that case, use appropriate qualified name." ++
+ "\n flags:" ++
+ "\n -res use another module than the topmost one" ++
+ "\n examples:" ++
+ "\n so -res=ParadigmsFin ResourceFin.N -- show N-paradigms in ParadigmsFin" ++
+ "\n" ++
+ "\nt, translate: t Lang Lang String" ++
+ "\n Parses String in Lang1 and linearizes the resulting Trees in Lang2." ++
+ "\n flags:" ++
+ "\n -cat" ++
+ "\n -lexer" ++
+ "\n -parser" ++
+ "\n examples:" ++
+ "\n t Eng Swe -cat=S \"every number is even or odd\"" ++
+ "\n" ++
+ "\ngr, generate_random: gr Tree?" ++
+ "\n Generates a random Tree of a given category. If a Tree" ++
+ "\n argument is given, the command completes the Tree with values to" ++
+ "\n the metavariables in the tree. " ++
+ "\n options:" ++
+ "\n -prob use probabilities (works for nondep types only)" ++
+ "\n -cf use a very fast method (works for nondep types only)" ++
+ "\n flags:" ++
+ "\n -cat generate in this category" ++
+ "\n -lang use the abstract syntax of this grammar" ++
+ "\n -number generate this number of trees (not impl. with Tree argument)" ++
+ "\n -depth use this number of search steps at most" ++
+ "\n examples:" ++
+ "\n gr -cat=Query -- generate in category Query" ++
+ "\n gr (PredVP ? (NegVG ?)) -- generate a random tree of this form" ++
+ "\n gr -cat=S -tr | l -- gererate and linearize" ++
+ "\n" ++
+ "\ngt, generate_trees: gt Tree?" ++
+ "\n Generates all trees up to a given depth. If the depth is large," ++
+ "\n a small -alts is recommended. If a Tree argument is given, the" ++
+ "\n command completes the Tree with values to the metavariables in" ++
+ "\n the tree." ++
+ "\n options:" ++
+ "\n -metas also return trees that include metavariables" ++
+ "\n -all generate all (can be infinitely many, lazily)" ++
+ "\n -lin linearize result of -all (otherwise, use pipe to linearize)" ++
+ "\n flags:" ++
+ "\n -depth generate to this depth (default 3)" ++
+ "\n -atoms take this number of atomic rules of each category (default unlimited)" ++
+ "\n -alts take this number of alternatives at each branch (default unlimited)" ++
+ "\n -cat generate in this category" ++
+ "\n -nonub don't remove duplicates (faster, not effective with -mem)" ++
+ "\n -mem use a memorizing algorithm (often faster, usually more memory-consuming)" ++
+ "\n -lang use the abstract syntax of this grammar" ++
+ "\n -number generate (at most) this number of trees (also works with -all)" ++
+ "\n -noexpand don't expand these categories (comma-separated, e.g. -noexpand=V,CN)" ++
+ "\n -doexpand only expand these categories (comma-separated, e.g. -doexpand=V,CN)" ++
+ "\n examples:" ++
+ "\n gt -depth=10 -cat=NP -- generate all NP's to depth 10 " ++
+ "\n gt (PredVP ? (NegVG ?)) -- generate all trees of this form" ++
+ "\n gt -cat=S -tr | l -- generate and linearize" ++
+ "\n gt -noexpand=NP | l -mark=metacat -- the only NP is meta, linearized \"?0 +NP\"" ++
+ "\n gt | l | p -lines -ambiguous | grep \"#AMBIGUOUS\" -- show ambiguous strings" ++
+ "\n" ++
+ "\nma, morphologically_analyse: ma String" ++
+ "\n Runs morphological analysis on each word in String and displays" ++
+ "\n the results line by line." ++
+ "\n options:" ++
+ "\n -short show analyses in bracketed words, instead of separate lines" ++
+ "\n -status show just the work at success, prefixed with \"*\" at failure" ++
+ "\n flags:" ++
+ "\n -lang" ++
+ "\n examples:" ++
+ "\n wf Bible.txt | ma -short | wf Bible.tagged -- analyse the Bible" ++
+ "\n" ++
+ "\n" ++
+ "\n-- elementary generation of Strings and Trees" ++
+ "\n" ++
+ "\nps, put_string: ps String" ++
+ "\n Returns its argument String, like Unix echo." ++
+ "\n HINT. The strength of ps comes from the possibility to receive the " ++
+ "\n argument from a pipeline, and altering it by the -filter flag." ++
+ "\n flags:" ++
+ "\n -filter filter the result through this string processor " ++
+ "\n -length cut the string after this number of characters" ++
+ "\n examples:" ++
+ "\n gr -cat=Letter | l | ps -filter=text -- random letter as text" ++
+ "\n" ++
+ "\npt, put_tree: pt Tree" ++
+ "\n Returns its argument Tree, like a specialized Unix echo." ++
+ "\n HINT. The strength of pt comes from the possibility to receive " ++
+ "\n the argument from a pipeline, and altering it by the -transform flag." ++
+ "\n flags:" ++
+ "\n -transform transform the result by this term processor" ++
+ "\n -number generate this number of terms at most" ++
+ "\n examples:" ++
+ "\n p \"zero is even\" | pt -transform=solve -- solve ?'s in parse result" ++
+ "\n" ++
+ "\n* st, show_tree: st Tree" ++
+ "\n Prints the tree as a string. Unlike pt, this command cannot be" ++
+ "\n used in a pipe to produce a tree, since its output is a string." ++
+ "\n flags:" ++
+ "\n -printer show the tree in a special format (-printer=xml supported)" ++
+ "\n" ++
+ "\nwt, wrap_tree: wt Fun" ++
+ "\n Wraps the tree as the sole argument of Fun." ++
+ "\n flags:" ++
+ "\n -c compute the resulting new tree to normal form" ++
+ "\n" ++
+ "\nvt, visualize_tree: vt Tree" ++
+ "\n Shows the abstract syntax tree via dot and gv (via temporary files" ++
+ "\n grphtmp.dot, grphtmp.ps)." ++
+ "\n flags:" ++
+ "\n -c show categories only (no functions)" ++
+ "\n -f show functions only (no categories)" ++
+ "\n -g show as graph (sharing uses of the same function)" ++
+ "\n -o just generate the .dot file" ++
+ "\n examples:" ++
+ "\n p \"hello world\" | vt -o | wf my.dot ;; ! open -a GraphViz my.dot" ++
+ "\n -- This writes the parse tree into my.dot and opens the .dot file" ++
+ "\n -- with another application without generating .ps." ++
+ "\n" ++
+ "\n-- subshells" ++
+ "\n" ++
+ "\nes, editing_session: es" ++
+ "\n Opens an interactive editing session." ++
+ "\n N.B. Exit from a Fudget session is to the Unix shell, not to GF. " ++
+ "\n options:" ++
+ "\n -f Fudget GUI (necessary for Unicode; only available in X Window System)" ++
+ "\n" ++
+ "\nts, translation_session: ts" ++
+ "\n Translates input lines from any of the actual languages to all other ones." ++
+ "\n To exit, type a full stop (.) alone on a line." ++
+ "\n N.B. Exit from a Fudget session is to the Unix shell, not to GF. " ++
+ "\n HINT: Set -parser and -lexer locally in each grammar." ++
+ "\n options:" ++
+ "\n -f Fudget GUI (necessary for Unicode; only available in X Windows)" ++
+ "\n -lang prepend translation results with language names" ++
+ "\n flags:" ++
+ "\n -cat the parser category" ++
+ "\n examples:" ++
+ "\n ts -cat=Numeral -lang -- translate numerals, show language names" ++
+ "\n" ++
+ "\ntq, translation_quiz: tq Lang Lang" ++
+ "\n Random-generates translation exercises from Lang1 to Lang2," ++
+ "\n keeping score of success." ++
+ "\n To interrupt, type a full stop (.) alone on a line." ++
+ "\n HINT: Set -parser and -lexer locally in each grammar." ++
+ "\n flags:" ++
+ "\n -cat" ++
+ "\n examples:" ++
+ "\n tq -cat=NP TestResourceEng TestResourceSwe -- quiz for NPs" ++
+ "\n" ++
+ "\ntl, translation_list: tl Lang Lang" ++
+ "\n Random-generates a list of ten translation exercises from Lang1" ++
+ "\n to Lang2. The number can be changed by a flag." ++
+ "\n HINT: use wf to save the exercises in a file." ++
+ "\n flags:" ++
+ "\n -cat" ++
+ "\n -number" ++
+ "\n examples:" ++
+ "\n tl -cat=NP TestResourceEng TestResourceSwe -- quiz list for NPs" ++
+ "\n" ++
+ "\nmq, morphology_quiz: mq" ++
+ "\n Random-generates morphological exercises," ++
+ "\n keeping score of success." ++
+ "\n To interrupt, type a full stop (.) alone on a line." ++
+ "\n HINT: use printname judgements in your grammar to" ++
+ "\n produce nice expressions for desired forms." ++
+ "\n flags:" ++
+ "\n -cat" ++
+ "\n -lang" ++
+ "\n examples:" ++
+ "\n mq -cat=N -lang=TestResourceSwe -- quiz for Swedish nouns" ++
+ "\n" ++
+ "\nml, morphology_list: ml" ++
+ "\n Random-generates a list of ten morphological exercises," ++
+ "\n keeping score of success. The number can be changed with a flag." ++
+ "\n HINT: use wf to save the exercises in a file." ++
+ "\n flags:" ++
+ "\n -cat" ++
+ "\n -lang" ++
+ "\n -number" ++
+ "\n examples:" ++
+ "\n ml -cat=N -lang=TestResourceSwe -- quiz list for Swedish nouns" ++
+ "\n" ++
+ "\n" ++
+ "\n-- IO related commands" ++
+ "\n" ++
+ "\nrf, read_file: rf File" ++
+ "\n Returns the contents of File as a String; error if File does not exist." ++
+ "\n" ++
+ "\nwf, write_file: wf File String" ++
+ "\n Writes String into File; File is created if it does not exist." ++
+ "\n N.B. the command overwrites File without a warning." ++
+ "\n" ++
+ "\naf, append_file: af File" ++
+ "\n Writes String into the end of File; File is created if it does not exist." ++
+ "\n" ++
+ "\n* tg, transform_grammar: tg File" ++
+ "\n Reads File, parses as a grammar, " ++
+ "\n but instead of compiling further, prints it. " ++
+ "\n The environment is not changed. When parsing the grammar, the same file" ++
+ "\n name suffixes are supported as in the i command." ++
+ "\n HINT: use this command to print the grammar in " ++
+ "\n another format (the -printer flag); pipe it to wf to save this format." ++
+ "\n flags:" ++
+ "\n -printer (only -printer=latex supported currently)" ++
+ "\n" ++
+ "\n* cl, convert_latex: cl File" ++
+ "\n Reads File, which is expected to be in LaTeX form." ++
+ "\n Three environments are treated in special ways:" ++
+ "\n \\begGF - \\end{verbatim}, which contains GF judgements," ++
+ "\n \\begTGF - \\end{verbatim}, which contains a GF expression (displayed)" ++
+ "\n \\begInTGF - \\end{verbatim}, which contains a GF expressions (inlined)." ++
+ "\n Moreover, certain macros should be included in the file; you can" ++
+ "\n get those macros by applying 'tg -printer=latex foo.gf' to any grammar" ++
+ "\n foo.gf. Notice that the same File can be imported as a GF grammar," ++
+ "\n consisting of all the judgements in \\begGF environments." ++
+ "\n HINT: pipe with 'wf Foo.tex' to generate a new Latex file." ++
+ "\n" ++
+ "\nsa, speak_aloud: sa String" ++
+ "\n Uses the Flite speech generator to produce speech for String." ++
+ "\n Works for American English spelling. " ++
+ "\n examples:" ++
+ "\n h | sa -- listen to the list of commands" ++
+ "\n gr -cat=S | l | sa -- generate a random sentence and speak it aloud" ++
+ "\n" ++
+ "\nsi, speech_input: si" ++
+ "\n Uses an ATK speech recognizer to get speech input. " ++
+ "\n flags:" ++
+ "\n -lang: The grammar to use with the speech recognizer." ++
+ "\n -cat: The grammar category to get input in." ++
+ "\n -language: Use acoustic model and dictionary for this language." ++
+ "\n -number: The number of utterances to recognize." ++
+ "\n" ++
+ "\nh, help: h Command?" ++
+ "\n Displays the paragraph concerning the command from this help file." ++
+ "\n Without the argument, shows the first lines of all paragraphs." ++
+ "\n options" ++
+ "\n -all show the whole help file" ++
+ "\n -defs show user-defined commands and terms" ++
+ "\n -FLAG show the values of FLAG (works for grammar-independent flags)" ++
+ "\n examples:" ++
+ "\n h print_grammar -- show all information on the pg command" ++
+ "\n" ++
+ "\nq, quit: q" ++
+ "\n Exits GF." ++
+ "\n HINT: you can use 'ph | wf history' to save your session." ++
+ "\n" ++
+ "\n!, system_command: ! String" ++
+ "\n Issues a system command. No value is returned to GF." ++
+ "\n example:" ++
+ "\n ! ls" ++
+ "\n" ++
+ "\n?, system_command: ? String" ++
+ "\n Issues a system command that receives its arguments from GF pipe" ++
+ "\n and returns a value to GF." ++
+ "\n example:" ++
+ "\n h | ? 'wc -l' | p -cat=Num" ++
+ "\n" ++
+ "\n" ++
+ "\n-- Flags. The availability of flags is defined separately for each command." ++
+ "\n" ++
+ "\n-cat, category in which parsing is performed." ++
+ "\n The default is S." ++
+ "\n" ++
+ "\n-depth, the search depth in e.g. random generation." ++
+ "\n The default depends on application." ++
+ "\n" ++
+ "\n-filter, operation performed on a string. The default is identity." ++
+ "\n -filter=identity no change" ++
+ "\n -filter=erase erase the text" ++
+ "\n -filter=take100 show the first 100 characters" ++
+ "\n -filter=length show the length of the string" ++
+ "\n -filter=text format as text (punctuation, capitalization)" ++
+ "\n -filter=code format as code (spacing, indentation)" ++
+ "\n" ++
+ "\n-lang, grammar used when executing a grammar-dependent command." ++
+ "\n The default is the last-imported grammar." ++
+ "\n" ++
+ "\n-language, voice used by Festival as its --language flag in the sa command. " ++
+ "\n The default is system-dependent. " ++
+ "\n" ++
+ "\n-length, the maximum number of characters shown of a string. " ++
+ "\n The default is unlimited." ++
+ "\n" ++
+ "\n-lexer, tokenization transforming a string into lexical units for a parser." ++
+ "\n The default is words." ++
+ "\n -lexer=words tokens are separated by spaces or newlines" ++
+ "\n -lexer=literals like words, but GF integer and string literals recognized" ++
+ "\n -lexer=vars like words, but \"x\",\"x_...\",\"$...$\" as vars, \"?...\" as meta" ++
+ "\n -lexer=chars each character is a token" ++
+ "\n -lexer=code use Haskell's lex" ++
+ "\n -lexer=codevars like code, but treat unknown words as variables, ?? as meta " ++
+ "\n -lexer=textvars like text, but treat unknown words as variables, ?? as meta " ++
+ "\n -lexer=text with conventions on punctuation and capital letters" ++
+ "\n -lexer=codelit like code, but treat unknown words as string literals" ++
+ "\n -lexer=textlit like text, but treat unknown words as string literals" ++
+ "\n -lexer=codeC use a C-like lexer" ++
+ "\n -lexer=ignore like literals, but ignore unknown words" ++
+ "\n -lexer=subseqs like ignore, but then try all subsequences from longest" ++
+ "\n" ++
+ "\n-number, the maximum number of generated items in a list. " ++
+ "\n The default is unlimited." ++
+ "\n" ++
+ "\n-optimize, optimization on generated code." ++
+ "\n The default is share for concrete, none for resource modules." ++
+ "\n Each of the flags can have the suffix _subs, which performs" ++
+ "\n common subexpression elimination after the main optimization." ++
+ "\n Thus, -optimize=all_subs is the most aggressive one. The _subs" ++
+ "\n strategy only works in GFC, and applies therefore in concrete but" ++
+ "\n not in resource modules." ++
+ "\n -optimize=share share common branches in tables" ++
+ "\n -optimize=parametrize first try parametrize then do share with the rest" ++
+ "\n -optimize=values represent tables as courses-of-values" ++
+ "\n -optimize=all first try parametrize then do values with the rest" ++
+ "\n -optimize=none no optimization" ++
+ "\n" ++
+ "\n-parser, parsing strategy. The default is chart. If -cfg or -mcfg are" ++
+ "\n selected, only bottomup and topdown are recognized." ++
+ "\n -parser=chart bottom-up chart parsing" ++
+ "\n -parser=bottomup a more up to date bottom-up strategy" ++
+ "\n -parser=topdown top-down strategy" ++
+ "\n -parser=old an old bottom-up chart parser" ++
+ "\n" ++
+ "\n-printer, format in which the grammar is printed. The default is" ++
+ "\n gfc. Those marked with M are (only) available for pm, the rest" ++
+ "\n for pg." ++
+ "\n -printer=gfc GFC grammar" ++
+ "\n -printer=gf GF grammar" ++
+ "\n -printer=old old GF grammar" ++
+ "\n -printer=cf context-free grammar, with profiles" ++
+ "\n -printer=bnf context-free grammar, without profiles" ++
+ "\n -printer=lbnf labelled context-free grammar for BNF Converter" ++
+ "\n -printer=plbnf grammar for BNF Converter, with precedence levels" ++
+ "\n *-printer=happy source file for Happy parser generator (use lbnf!)" ++
+ "\n -printer=haskell abstract syntax in Haskell, with transl to/from GF" ++
+ "\n -printer=haskell_gadt abstract syntax GADT in Haskell, with transl to/from GF" ++
+ "\n -printer=morpho full-form lexicon, long format" ++
+ "\n *-printer=latex LaTeX file (for the tg command)" ++
+ "\n -printer=fullform full-form lexicon, short format" ++
+ "\n *-printer=xml XML: DTD for the pg command, object for st" ++
+ "\n -printer=old old GF: file readable by GF 1.2" ++
+ "\n -printer=stat show some statistics of generated GFC" ++
+ "\n -printer=probs show probabilities of all functions" ++
+ "\n -printer=gsl Nuance GSL speech recognition grammar" ++
+ "\n -printer=jsgf Java Speech Grammar Format" ++
+ "\n -printer=jsgf_sisr_old Java Speech Grammar Format with semantic tags in " ++
+ "\n SISR WD 20030401 format" ++
+ "\n -printer=srgs_abnf SRGS ABNF format" ++
+ "\n -printer=srgs_abnf_non_rec SRGS ABNF format, without any recursion." ++
+ "\n -printer=srgs_abnf_sisr_old SRGS ABNF format, with semantic tags in" ++
+ "\n SISR WD 20030401 format" ++
+ "\n -printer=srgs_xml SRGS XML format" ++
+ "\n -printer=srgs_xml_non_rec SRGS XML format, without any recursion." ++
+ "\n -printer=srgs_xml_prob SRGS XML format, with weights" ++
+ "\n -printer=srgs_xml_sisr_old SRGS XML format, with semantic tags in" ++
+ "\n SISR WD 20030401 format" ++
+ "\n -printer=vxml Generate a dialogue system in VoiceXML." ++
+ "\n -printer=slf a finite automaton in the HTK SLF format" ++
+ "\n -printer=slf_graphviz the same automaton as slf, but in Graphviz format" ++
+ "\n -printer=slf_sub a finite automaton with sub-automata in the " ++
+ "\n HTK SLF format" ++
+ "\n -printer=slf_sub_graphviz the same automaton as slf_sub, but in " ++
+ "\n Graphviz format" ++
+ "\n -printer=fa_graphviz a finite automaton with labelled edges" ++
+ "\n -printer=regular a regular grammar in a simple BNF" ++
+ "\n -printer=unpar a gfc grammar with parameters eliminated" ++
+ "\n -printer=functiongraph abstract syntax functions in 'dot' format" ++
+ "\n -printer=typegraph abstract syntax categories in 'dot' format" ++
+ "\n -printer=transfer Transfer language datatype (.tr file format)" ++
+ "\n -printer=cfg-prolog M cfg in prolog format (also pg)" ++
+ "\n -printer=gfc-prolog M gfc in prolog format (also pg)" ++
+ "\n -printer=gfcm M gfcm file (default for pm)" ++
+ "\n -printer=graph M module dependency graph in 'dot' (graphviz) format" ++
+ "\n -printer=header M gfcm file with header (for GF embedded in Java)" ++
+ "\n -printer=js M JavaScript type annotator and linearizer" ++
+ "\n -printer=mcfg-prolog M mcfg in prolog format (also pg)" ++
+ "\n -printer=missing M the missing linearizations of each concrete" ++
+ "\n" ++
+ "\n-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)" ++
+ "\n" ++
+ "\n-transform, transformation performed on a syntax tree. The default is identity." ++
+ "\n -transform=identity no change" ++
+ "\n -transform=compute compute by using definitions in the grammar" ++
+ "\n -transform=nodup return the term only if it has no constants duplicated" ++
+ "\n -transform=nodupatom return the term only if it has no atomic constants duplicated" ++
+ "\n -transform=typecheck return the term only if it is type-correct" ++
+ "\n -transform=solve solve metavariables as derived refinements" ++
+ "\n -transform=context solve metavariables by unique refinements as variables" ++
+ "\n -transform=delete replace the term by metavariable" ++
+ "\n" ++
+ "\n-unlexer, untokenization transforming linearization output into a string." ++
+ "\n The default is unwords." ++
+ "\n -unlexer=unwords space-separated token list (like unwords)" ++
+ "\n -unlexer=text format as text: punctuation, capitals, paragraph " ++
+ "\n -unlexer=code format as code (spacing, indentation)" ++
+ "\n -unlexer=textlit like text, but remove string literal quotes" ++
+ "\n -unlexer=codelit like code, but remove string literal quotes" ++
+ "\n -unlexer=concat remove all spaces" ++
+ "\n -unlexer=bind like identity, but bind at \"&+\"" ++
+ "\n" ++
+ "\n-mark, marking of parts of tree in linearization. The default is none." ++
+ "\n -mark=metacat append \"+CAT\" to every metavariable, showing its category" ++
+ "\n -mark=struct show tree structure with brackets" ++
+ "\n -mark=java show tree structure with XML tags (used in gfeditor)" ++
+ "\n" ++
+ "\n-coding, Some grammars are in UTF-8, some in isolatin-1." ++
+ "\n If the letters \228 (a-umlaut) and \246 (o-umlaut) look strange, either" ++
+ "\n change your terminal to isolatin-1, or rewrite the grammar with" ++
+ "\n 'pg -utf8'. For Windows you also may have to change your font to TrueType." ++
+ "\n" ++
+ "\n-- *: Commands and options marked with * are not currently implemented." ++
+ []
diff --git a/src-2.9/GF/Shell/JGF.hs b/src-2.9/GF/Shell/JGF.hs
new file mode 100644
index 000000000..0ff678809
--- /dev/null
+++ b/src-2.9/GF/Shell/JGF.hs
@@ -0,0 +1,89 @@
+----------------------------------------------------------------------
+-- |
+-- Module : JGF
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/06/03 22:44:36 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.13 $
+--
+-- GF editing session controlled by e.g. a Java program. AR 16\/11\/2001
+-----------------------------------------------------------------------------
+
+module GF.Shell.JGF where
+
+import GF.Data.Operations
+import GF.Infra.UseIO
+import GF.Text.Unicode
+
+import GF.API.IOGrammar
+import GF.Infra.Option
+import GF.Compile.ShellState
+import GF.UseGrammar.Session
+import GF.Shell.Commands
+import GF.Shell.CommandL
+import GF.Text.UTF8
+
+import Control.Monad (foldM)
+import System
+
+
+
+-- GF editing session controlled by e.g. a Java program. AR 16/11/2001
+
+-- | the Boolean is a temporary hack to have two parallel GUIs
+sessionLineJ :: Bool -> ShellState -> IO ()
+sessionLineJ isNew env = do
+ putStrLnFlush $ initEditMsgJavaX env
+ let env' = addGlobalOptions (options [sizeDisplay "short",beSilent]) env
+ editLoopJnewX isNew env' (initSState)
+
+-- | this is the real version, with XML
+--
+-- the Boolean is a temporary hack to have two parallel GUIs
+editLoopJnewX :: Bool -> CEnv -> SState -> IO ()
+editLoopJnewX isNew env state = do
+ mscs <- getCommandUTF (isCEnvUTF8 env state) ----
+ let (ms,cs) = unzip mscs
+ m = unlines ms --- ?
+ if null cs
+ then editLoopJnewX isNew env state
+ else
+ case cs of
+ [CQuit] -> return ()
+ _ -> do
+ (env',state') <- foldM exec (env,state) cs
+ let inits = initAndEditMsgJavaX isNew env' state' m
+ let
+ package = case last cs of
+ CCEnvImport _ -> inits
+ CCEnvEmptyAndImport _ -> inits
+ CCEnvOpenTerm _ -> inits
+ CCEnvOpenString _ -> inits
+ CCEnvEmpty -> initEditMsgJavaX env'
+ _ -> displaySStateJavaX isNew env' state' m
+ putStrLnFlush package
+ editLoopJnewX isNew env' state'
+ where
+ exec (env,state) c = do
+ execCommand env c state
+
+welcome :: String
+welcome =
+ "An experimental GF Editor for Java." ++
+ "(c) Kristofer Johannisson, Janna Khegai, and Aarne Ranta 2002 under CNU GPL."
+
+initEditMsgJavaX :: CEnv -> String
+initEditMsgJavaX env = encodeUTF8 $ mkUnicode $ unlines $ tagXML "gfinit" $
+ tagsXML "newcat" [["n" +++ cat] | (_,cat) <- newCatMenu env] ++
+ tagXML "topic" [abstractName env] ++
+ tagXML "language" [prLanguage langAbstract] ++
+ concat [tagAttrXML "language" ("file",file) [prLanguage lang] |
+ (file,lang) <- zip (allGrammarFileNames env) (allLanguages env)]
+
+
+initAndEditMsgJavaX :: Bool -> CEnv -> SState -> String -> String
+initAndEditMsgJavaX isNew env state m =
+ initEditMsgJavaX env ++++ displaySStateJavaX isNew env state m
diff --git a/src-2.9/GF/Shell/PShell.hs b/src-2.9/GF/Shell/PShell.hs
new file mode 100644
index 000000000..68cb4d629
--- /dev/null
+++ b/src-2.9/GF/Shell/PShell.hs
@@ -0,0 +1,174 @@
+----------------------------------------------------------------------
+-- |
+-- Module : PShell
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/10/06 14:21:34 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.28 $
+--
+-- parsing GF shell commands. AR 11\/11\/2001
+-----------------------------------------------------------------------------
+
+module GF.Shell.PShell where
+
+import GF.Data.Operations
+import GF.Infra.UseIO
+import GF.Compile.ShellState
+import GF.Shell.ShellCommands
+import GF.Shell
+import GF.Infra.Option
+import GF.Compile.PGrammar (pzIdent, pTrm) --- (string2formsAndTerm)
+import GF.API
+import GF.System.Arch (fetchCommand)
+import GF.UseGrammar.Tokenize (wordsLits)
+
+import Data.Char (isDigit, isSpace)
+import System.IO.Error
+
+-- parsing GF shell commands. AR 11/11/2001
+
+-- | getting a sequence of command lines as input
+getCommandLines :: HState -> IO (String,[CommandLine])
+getCommandLines st = do
+ s <- fetchCommand "> "
+ return (s,pCommandLines st s)
+
+getCommandLinesBatch :: HState -> IO (String,[CommandLine])
+getCommandLinesBatch st = do
+ s <- catch getLine (\e -> if isEOFError e then return "q" else ioError e)
+ return $ (s,pCommandLines st s)
+
+pCommandLines :: HState -> String -> [CommandLine]
+pCommandLines st =
+ map (pCommandLine st) . concatMap (chunks ";;" . wordsLits) . lines
+
+-- | Remove single or double quotes around a string
+unquote :: String -> String
+unquote (x:xs@(_:_)) | x `elem` "\"'" && x == last xs = init xs
+unquote s = s
+
+pCommandLine :: HState -> [String] -> CommandLine
+pCommandLine st (c@('%':_):args) = pCommandLine st $ resolveShMacro st c args
+pCommandLine st (dc:c:def) | abbrevCommand dc == "dc" = ((CDefineCommand c def, noOptions),AUnit,[])
+pCommandLine st s = pFirst (chks s) where
+ pFirst cos = case cos of
+ (c,os,[a]) : cs -> ((c,os), a, pCont cs)
+ _ -> ((CVoid,noOptions), AError "no parse", [])
+ pCont cos = case cos of
+ (c,os,_) : cs -> (c,os) : pCont cs
+ _ -> []
+ chks = map (pCommandOpt st) . chunks "|"
+
+pCommandOpt :: HState -> [String] -> (Command, Options, [CommandArg])
+pCommandOpt _ (w:ws) = let
+ (os, co) = getOptions "-" ws
+ (comm, args) = pCommand (abbrevCommand w:co)
+ in
+ (comm, os, args)
+pCommandOpt _ s = (CVoid, noOptions, [AError "no parse"])
+
+pInputString :: String -> [CommandArg]
+pInputString s = case s of
+ ('"':_:_) | last s == '"' -> [AString (read s)]
+ _ -> [AError "illegal string"]
+
+-- | command @rl@ can be written @remove_language@ etc.
+abbrevCommand :: String -> String
+abbrevCommand = hds . words . map u2sp where
+ u2sp c = if c=='_' then ' ' else c
+ hds s = case s of
+ [w@[_,_]] -> w
+ _ -> map head s
+
+pCommand :: [String] -> (Command, [CommandArg])
+pCommand ws = case ws of
+
+ "i" : f : [] -> aUnit (CImport (unquote f))
+ "rl" : l : [] -> aUnit (CRemoveLanguage (language l))
+ "e" : [] -> aUnit CEmptyState
+ "cm" : a : [] -> aUnit (CChangeMain (Just (pzIdent a)))
+ "cm" : [] -> aUnit (CChangeMain Nothing)
+ "s" : [] -> aUnit CStripState
+ "tg" : f : [] -> aUnit (CTransformGrammar f)
+ "cl" : f : [] -> aUnit (CConvertLatex f)
+
+ "ph" : [] -> aUnit CPrintHistory
+ "dt" : f : t -> aTerm (CDefineTerm (unquote f)) t
+
+ "l" : s -> aTermLi CLinearize s
+
+ "p" : s -> aString CParse s
+ "t" : i:o: s -> aString (CTranslate (language i) (language o)) s
+ "gr" : [] -> aUnit CGenerateRandom
+ "gr" : t -> aTerm CGenerateRandom t
+ "gt" : [] -> aUnit CGenerateTrees
+ "gt" : t -> aTerm CGenerateTrees t
+ "pt" : s -> aTerm CPutTerm s
+ "wt" : f : s -> aTerm (CWrapTerm (pzIdent f)) s
+ "at" : f : s -> aTerm (CApplyTransfer (pmIdent f)) s
+ "ma" : s -> aString CMorphoAnalyse s
+ "tt" : s -> aString CTestTokenizer s
+ "cc" : s -> aUnit $ CComputeConcrete $ unwords s
+ "so" : s -> aUnit $ CShowOpers $ unwords s
+ "tb" : [] -> aUnit CTreeBank
+ "ut" : s -> aString CLookupTreebank s
+
+ "tq" : i:o:[] -> aUnit (CTranslationQuiz (language i) (language o))
+ "tl":i:o:[] -> aUnit (CTranslationList (language i) (language o))
+ "mq" : [] -> aUnit CMorphoQuiz
+ "ml" : [] -> aUnit CMorphoList
+
+ "wf" : f : s -> aString (CWriteFile (unquote f)) s
+ "af" : f : s -> aString (CAppendFile (unquote f)) s
+ "rf" : f : [] -> aUnit (CReadFile (unquote f))
+ "sa" : s -> aString CSpeakAloud s
+ "si" : [] -> aUnit CSpeechInput
+ "ps" : s -> aString CPutString s
+ "st" : s -> aTerm CShowTerm s
+ "!" : s -> aUnit (CSystemCommand (unwords s))
+ "?" : s : x -> aString (CSystemCommand (unquote s)) x
+ "sc" : s -> aUnit (CSystemCommand (unwords s))
+ "g" : f : s -> aString (CGrep (unquote f)) s
+
+ "sf" : l : [] -> aUnit (CSetLocalFlag (language l))
+ "sf" : [] -> aUnit CSetFlag
+
+ "pg" : [] -> aUnit CPrintGrammar
+ "pi" : c : [] -> aUnit $ CPrintInformation (pzIdent c)
+
+ "pj" : [] -> aUnit CPrintGramlet
+ "pxs" : [] -> aUnit CPrintCanonXMLStruct
+ "px" : [] -> aUnit CPrintCanonXML
+ "pm" : [] -> aUnit CPrintMultiGrammar
+ "vg" : [] -> aUnit CShowGrammarGraph
+ "vt" : s -> aTerm CShowTreeGraph s
+ "sg" : [] -> aUnit CPrintSourceGrammar
+ "po" : [] -> aUnit CPrintGlobalOptions
+ "pl" : [] -> aUnit CPrintLanguages
+ "h" : c : [] -> aUnit $ CHelp (Just (abbrevCommand c))
+ "h" : [] -> aUnit $ CHelp Nothing
+
+ "q" : [] -> aImpure ICQuit
+ "eh" : f : [] -> aImpure (ICExecuteHistory f)
+ n : [] | all isDigit n -> aImpure (ICEarlierCommand (readIntArg n))
+
+ "es" : [] -> aImpure ICEditSession
+ "ts" : [] -> aImpure ICTranslateSession
+ "r" : [] -> aImpure ICReload
+ _ -> (CVoid, [])
+
+ where
+ aString c ss = (c, pInputString (unwords ss))
+ aTerm c ss = (c, [ASTrm $ unwords ss]) ---- [ASTrms [s2t (unwords ss)]])
+ aUnit c = (c, [AUnit])
+ aImpure = aUnit . CImpure
+
+ aTermLi c ss = (c [], [ASTrm $ unwords ss])
+ ---- (c forms, [ASTrms [term]]) where
+ ---- (forms,term) = ([], s2t (unwords ss)) ----string2formsAndTerm(unwords ss)
+ pmIdent m = case span (/='.') m of
+ (k,_:f) -> (Just (pzIdent k), pzIdent f)
+ _ -> (Nothing,pzIdent m)
diff --git a/src-2.9/GF/Shell/ShellCommands.hs b/src-2.9/GF/Shell/ShellCommands.hs
new file mode 100644
index 000000000..70238817b
--- /dev/null
+++ b/src-2.9/GF/Shell/ShellCommands.hs
@@ -0,0 +1,246 @@
+----------------------------------------------------------------------
+-- |
+-- Module : ShellCommands
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/14 16:03:41 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.46 $
+--
+-- The datatype of shell commands and the list of their options.
+-----------------------------------------------------------------------------
+
+module GF.Shell.ShellCommands where
+
+import qualified GF.Infra.Ident as I
+import GF.Compile.ShellState
+import GF.UseGrammar.Custom
+import GF.Grammar.PrGrammar
+
+import GF.Infra.Option
+import GF.Data.Operations
+import GF.Infra.Modules
+
+import Data.Char (isDigit)
+import Control.Monad (mplus)
+
+-- shell commands and their options
+-- moved to separate module and added option check: AR 27/5/2004
+--- TODO: single source for
+--- (1) command interpreter (2) option check (3) help file
+
+data Command =
+ CImport FilePath
+ | CRemoveLanguage Language
+ | CEmptyState
+ | CChangeMain (Maybe I.Ident)
+ | CStripState
+ | CTransformGrammar FilePath
+ | CConvertLatex FilePath
+
+ | CDefineCommand String [String]
+ | CDefineTerm String
+
+ | CLinearize [()] ---- parameters
+ | CParse
+ | CTranslate Language Language
+ | CGenerateRandom
+ | CGenerateTrees
+ | CTreeBank
+ | CPutTerm
+ | CWrapTerm I.Ident
+ | CApplyTransfer (Maybe I.Ident, I.Ident)
+ | CMorphoAnalyse
+ | CTestTokenizer
+ | CComputeConcrete String
+ | CShowOpers String
+
+ | CLookupTreebank
+
+ | CTranslationQuiz Language Language
+ | CTranslationList Language Language
+ | CMorphoQuiz
+ | CMorphoList
+
+ | CReadFile FilePath
+ | CWriteFile FilePath
+ | CAppendFile FilePath
+ | CSpeakAloud
+ | CSpeechInput
+ | CPutString
+ | CShowTerm
+ | CSystemCommand String
+ | CGrep String
+
+ | CSetFlag
+ | CSetLocalFlag Language
+
+ | CPrintGrammar
+ | CPrintGlobalOptions
+ | CPrintLanguages
+ | CPrintInformation I.Ident
+ | CPrintMultiGrammar
+ | CPrintSourceGrammar
+ | CShowGrammarGraph
+ | CShowTreeGraph
+ | CPrintGramlet
+ | CPrintCanonXML
+ | CPrintCanonXMLStruct
+ | CPrintHistory
+ | CHelp (Maybe String)
+
+ | CImpure ImpureCommand
+
+ | CVoid
+
+-- to isolate the commands that are executed on top level
+data ImpureCommand =
+ ICQuit
+ | ICExecuteHistory FilePath
+ | ICEarlierCommand Int
+ | ICEditSession
+ | ICTranslateSession
+ | ICReload
+
+type CommandOpt = (Command, Options)
+
+-- the top-level option warning action
+
+checkOptions :: ShellState -> (Command,Options) -> IO ()
+checkOptions sh (co, Opts opts) = do
+ let (_,s) = errVal ([],"option check failed") $ mapErr check opts
+ if (null s) then return ()
+ else putStr "WARNING: " >> putStrLn s
+ where
+ check = isValidOption sh co
+
+isValidOption :: ShellState -> Command -> Option -> Err ()
+isValidOption st co op = case op of
+ Opt (o,[]) ->
+ testErr (elem o $ optsOf co) ("invalid option:" +++ prOpt op)
+ Opt (o,[x]) -> do
+ testErr (elem o (flagsOf co)) ("invalid flag:" +++ o)
+ testValidFlag st co o x
+ _ -> Bad $ "impossible option" +++ prOpt op
+ where
+ optsOf co = ("tr" :) $ fst $ optionsOfCommand co
+ flagsOf co = snd $ optionsOfCommand co
+
+testValidFlag :: ShellState -> Command -> OptFunId -> String -> Err ()
+testValidFlag st co f x = case f of
+ "cat" -> testIn (map prQIdent_ (allCategories st))
+ "lang" -> testIn (map prt (allLanguages st))
+ "transfer" -> testIn (map prt (allTransfers st))
+ "res" -> testIn (map prt (allResources (srcModules st)))
+ "number" -> testN
+ "printer" -> case co of
+ CPrintGrammar -> testInc customGrammarPrinter
+ CPrintMultiGrammar -> testInc customMultiGrammarPrinter
+ CSetFlag -> testInc customGrammarPrinter `mplus`
+ testInc customMultiGrammarPrinter
+ "lexer" -> testInc customTokenizer
+ "unlexer" -> testInc customUntokenizer
+ "depth" -> testN
+ "rawtrees"-> testN
+ "parser" -> testInc customParser
+ -- hack for the -newer parsers: (to be changed in the future)
+ -- `mplus` testIn (words "mcfg mcfg-bottomup mcfg-topdown cfg cfg-bottomup cfg-topdown bottomup topdown")
+ -- if not(null x) && head x `elem` "mc" then return () else Bad ""
+ "alts" -> testN
+ "transform" -> testInc customTermCommand
+ "filter" -> testInc customStringCommand
+ "length" -> testN
+ "optimize"-> testIn $ words "parametrize values all share none"
+ "conversion" -> testIn $ words "strict nondet finite finite2 finite3 singletons finite-strict finite-singletons"
+ _ -> return ()
+ where
+ testInc ci =
+ let vs = snd (customInfo ci) in testIn vs
+ testIn vs =
+ if elem x vs
+ then return ()
+ else Bad ("flag:" +++ f +++ "invalid value:" +++ x ++++
+ "possible values:" +++ unwords vs)
+ testN =
+ if all isDigit x
+ then return ()
+ else Bad ("flag:" +++ f +++ "invalid value:" +++ x ++++
+ "expected integer")
+
+
+optionsOfCommand :: Command -> ([String],[String])
+optionsOfCommand co = case co of
+ CSetFlag ->
+ both "utf8 table struct record all multi"
+ "cat lang lexer parser number depth rawtrees unlexer optimize path conversion printer"
+ CImport _ ->
+ both "old v s src make gfc retain docf nocf nocheckcirc cflexer noemit o make ex prob treebank"
+ "abs cnc res path optimize conversion cat preproc probs noparse"
+ CRemoveLanguage _ -> none
+ CEmptyState -> none
+ CStripState -> none
+ CTransformGrammar _ -> flags "printer"
+ CConvertLatex _ -> none
+ CLinearize _ -> both "utf8 table struct record all multi" "lang number unlexer mark"
+ CParse ->
+ both "ambiguous fail cut new newer old overload cfg mcfg fcfg n ign raw v lines all prob"
+ "cat lang lexer parser number rawtrees"
+ CTranslate _ _ -> opts "cat lexer parser"
+ CGenerateRandom -> both "cf prob" "cat lang number depth atoms noexpand doexpand"
+ CGenerateTrees -> both "metas" "atoms depth alts cat lang number noexpand doexpand"
+ CPutTerm -> flags "transform number"
+ CTreeBank -> opts "c xml trees all table record"
+ CLookupTreebank -> both "assocs raw strings trees" "treebank"
+ CWrapTerm _ -> opts "c"
+ CApplyTransfer _ -> flags "lang transfer"
+ CMorphoAnalyse -> both "short status" "lang"
+ CTestTokenizer -> flags "lexer"
+ CComputeConcrete _ -> both "table" "res"
+ CShowOpers _ -> flags "res"
+
+ CTranslationQuiz _ _ -> flags "cat"
+ CTranslationList _ _ -> flags "cat number"
+ CMorphoQuiz -> flags "cat lang"
+ CMorphoList -> flags "cat lang number"
+
+ CReadFile _ -> none
+ CWriteFile _ -> none
+ CAppendFile _ -> none
+ CSpeakAloud -> flags "language"
+ CSpeechInput -> flags "lang cat language number"
+
+ CPutString -> both "utf8" "filter length"
+ CShowTerm -> flags "printer"
+ CShowTreeGraph -> opts "c f g o"
+ CSystemCommand _ -> none
+ CGrep _ -> opts "v"
+
+ CPrintGrammar -> both "utf8" "printer lang startcat"
+ CPrintMultiGrammar -> both "utf8 utf8id" "printer"
+ CPrintSourceGrammar -> both "utf8" "printer"
+
+ CHelp _ -> opts "all alts atoms coding defs filter length lexer unlexer printer probs transform depth number cat"
+
+ CImpure ICEditSession -> both "f" "file"
+ CImpure ICTranslateSession -> both "f langs" "cat"
+
+ _ -> none
+
+{-
+ CSetLocalFlag Language
+ CPrintGlobalOptions
+ CPrintLanguages
+ CPrintInformation I.Ident
+ CPrintGramlet
+ CPrintCanonXML
+ CPrintCanonXMLStruct
+ CPrintHistory
+ CVoid
+-}
+ where
+ flags fs = ([],words fs)
+ opts fs = (words fs,[])
+ both os fs = (words os,words fs)
+ none = ([],[])
diff --git a/src-2.9/GF/Shell/SubShell.hs b/src-2.9/GF/Shell/SubShell.hs
new file mode 100644
index 000000000..5ef0459e5
--- /dev/null
+++ b/src-2.9/GF/Shell/SubShell.hs
@@ -0,0 +1,66 @@
+----------------------------------------------------------------------
+-- |
+-- Module : SubShell
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:46:12 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.9 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Shell.SubShell where
+
+import GF.Data.Operations
+import GF.Infra.UseIO
+import GF.Compile.ShellState
+import GF.Infra.Option
+import GF.API
+
+import GF.Shell.CommandL
+import GF.System.ArchEdit
+
+import Data.List
+
+-- AR 20/4/2000 -- 12/11/2001
+
+editSession :: Options -> ShellState -> IO ()
+editSession opts st
+ | oElem makeFudget opts = fudlogueEdit font st'
+ | otherwise = initEditLoop st' (return ())
+ where
+ st' = addGlobalOptions opts st
+ font = maybe myUniFont mkOptFont $ getOptVal opts useFont
+
+myUniFont :: String
+myUniFont = "-mutt-clearlyu-medium-r-normal--0-0-100-100-p-0-iso10646-1"
+
+mkOptFont :: String -> String
+mkOptFont = id
+
+translateSession :: Options -> ShellState -> IO ()
+translateSession opts st = do
+ let grs = allStateGrammars st
+ cat = firstCatOpts opts (firstStateGrammar st)
+ trans s = unlines $
+ if oElem showLang opts then
+ sort $ [l +++ ":" +++ s | (l,s) <- zip (map (prIdent . cncId) grs)
+ (translateBetweenAll grs cat s)]
+ else translateBetweenAll grs cat s
+ translateLoop opts trans
+
+translateLoop :: Options -> (String -> String) -> IO ()
+translateLoop opts trans = do
+ let fud = oElem makeFudget opts
+ font = maybe myUniFont mkOptFont $ getOptVal opts useFont
+ if fud then fudlogueWrite font trans else loopLine
+ where
+ loopLine = do
+ putStrFlush "trans> "
+ s <- getLine
+ if s == "." then return () else do
+ putStrLnFlush $ trans s
+ loopLine
diff --git a/src-2.9/GF/Shell/TeachYourself.hs b/src-2.9/GF/Shell/TeachYourself.hs
new file mode 100644
index 000000000..7e5a8afe2
--- /dev/null
+++ b/src-2.9/GF/Shell/TeachYourself.hs
@@ -0,0 +1,87 @@
+----------------------------------------------------------------------
+-- |
+-- Module : TeachYourself
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:46:13 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.7 $
+--
+-- translation and morphology quiz. AR 10\/5\/2000 -- 12\/4\/2002
+-----------------------------------------------------------------------------
+
+module GF.Shell.TeachYourself where
+
+import GF.Compile.ShellState
+import GF.API
+import GF.UseGrammar.Linear
+import GF.Grammar.PrGrammar
+
+import GF.Infra.Option
+import GF.System.Arch (myStdGen)
+import GF.Data.Operations
+import GF.Infra.UseIO
+
+import System.Random --- (randoms) --- bad import for hbc
+import System
+
+-- translation and morphology quiz. AR 10/5/2000 -- 12/4/2002
+
+teachTranslation :: Options -> GFGrammar -> GFGrammar -> IO ()
+teachTranslation opts ig og = do
+ tts <- transTrainList opts ig og infinity
+ let qas = [ (q, mkAnswer as) | (q,as) <- tts]
+ teachDialogue qas "Welcome to GF Translation Quiz."
+
+transTrainList ::
+ Options -> GFGrammar -> GFGrammar -> Integer -> IO [(String,[String])]
+transTrainList opts ig og number = do
+ ts <- randomTreesIO (addOption beSilent opts) ig (fromInteger number)
+ return $ map mkOne $ ts
+ where
+ cat = firstCatOpts opts ig
+ mkOne t = (norml (linearize ig t),map (norml . linearize og) (homonyms ig cat t))
+
+
+teachMorpho :: Options -> GFGrammar -> IO ()
+teachMorpho opts ig = useIOE () $ do
+ tts <- morphoTrainList opts ig infinity
+ let qas = [ (q, mkAnswer as) | (q,as) <- tts]
+ ioeIO $ teachDialogue qas "Welcome to GF Morphology Quiz."
+
+morphoTrainList :: Options -> GFGrammar -> Integer -> IOE [(String,[String])]
+morphoTrainList opts ig number = do
+ ts <- ioeIO $ randomTreesIO (addOption beSilent opts) ig (fromInteger number)
+ gen <- ioeIO $ myStdGen (fromInteger number)
+ mkOnes gen ts
+ where
+ mkOnes gen (t:ts) = do
+ psss <- ioeErr $ allLinTables True gr cnc t
+ let pss = concat $ map snd $ concat psss
+ let (i,gen') = randomR (0, length pss - 1) gen
+ (ps,ss) <- ioeErr $ pss !? i
+ (_,ss0) <- ioeErr $ pss !? 0
+ let bas = unwords ss0 --- concat $ take 1 ss0
+ more <- mkOnes gen' ts
+ return $ (bas +++ ":" +++ unwords (map prt_ ps), return (unwords ss)) : more
+ mkOnes gen [] = return []
+
+ gr = grammar ig
+ cnc = cncId ig
+
+-- | compare answer to the list of right answers, increase score and give feedback
+mkAnswer :: [String] -> String -> (Integer, String)
+mkAnswer as s = if (elem (norml s) as)
+ then (1,"Yes.")
+ else (0,"No, not" +++ s ++ ", but" ++++ unlines as)
+
+
+norml :: String -> String
+norml = unwords . words
+
+-- | the maximal number of precompiled quiz problems
+infinity :: Integer
+infinity = 123
+
diff --git a/src-2.9/GF/Source/AbsGF.hs b/src-2.9/GF/Source/AbsGF.hs
new file mode 100644
index 000000000..63cc43006
--- /dev/null
+++ b/src-2.9/GF/Source/AbsGF.hs
@@ -0,0 +1,306 @@
+module GF.Source.AbsGF where
+
+-- Haskell module generated by the BNF converter
+
+newtype LString = LString String deriving (Eq,Ord,Show)
+newtype PIdent = PIdent ((Int,Int),String) deriving (Eq,Ord,Show)
+data Grammar =
+ Gr [ModDef]
+ deriving (Eq,Ord,Show)
+
+data ModDef =
+ MMain PIdent PIdent [ConcSpec]
+ | MModule ComplMod ModType ModBody
+ deriving (Eq,Ord,Show)
+
+data ConcSpec =
+ ConcSpec PIdent ConcExp
+ deriving (Eq,Ord,Show)
+
+data ConcExp =
+ ConcExp PIdent [Transfer]
+ deriving (Eq,Ord,Show)
+
+data Transfer =
+ TransferIn Open
+ | TransferOut Open
+ deriving (Eq,Ord,Show)
+
+data ModType =
+ MTAbstract PIdent
+ | MTResource PIdent
+ | MTInterface PIdent
+ | MTConcrete PIdent PIdent
+ | MTInstance PIdent PIdent
+ | MTTransfer PIdent Open Open
+ deriving (Eq,Ord,Show)
+
+data ModBody =
+ MBody Extend Opens [TopDef]
+ | MNoBody [Included]
+ | MWith Included [Open]
+ | MWithBody Included [Open] Opens [TopDef]
+ | MWithE [Included] Included [Open]
+ | MWithEBody [Included] Included [Open] Opens [TopDef]
+ | MReuse PIdent
+ | MUnion [Included]
+ deriving (Eq,Ord,Show)
+
+data Extend =
+ Ext [Included]
+ | NoExt
+ deriving (Eq,Ord,Show)
+
+data Opens =
+ NoOpens
+ | OpenIn [Open]
+ deriving (Eq,Ord,Show)
+
+data Open =
+ OName PIdent
+ | OQualQO QualOpen PIdent
+ | OQual QualOpen PIdent PIdent
+ deriving (Eq,Ord,Show)
+
+data ComplMod =
+ CMCompl
+ | CMIncompl
+ deriving (Eq,Ord,Show)
+
+data QualOpen =
+ QOCompl
+ | QOIncompl
+ | QOInterface
+ deriving (Eq,Ord,Show)
+
+data Included =
+ IAll PIdent
+ | ISome PIdent [PIdent]
+ | IMinus PIdent [PIdent]
+ deriving (Eq,Ord,Show)
+
+data Def =
+ DDecl [Name] Exp
+ | DDef [Name] Exp
+ | DPatt Name [Patt] Exp
+ | DFull [Name] Exp Exp
+ deriving (Eq,Ord,Show)
+
+data TopDef =
+ DefCat [CatDef]
+ | DefFun [FunDef]
+ | DefFunData [FunDef]
+ | DefDef [Def]
+ | DefData [DataDef]
+ | DefTrans [Def]
+ | DefPar [ParDef]
+ | DefOper [Def]
+ | DefLincat [PrintDef]
+ | DefLindef [Def]
+ | DefLin [Def]
+ | DefPrintCat [PrintDef]
+ | DefPrintFun [PrintDef]
+ | DefFlag [FlagDef]
+ | DefPrintOld [PrintDef]
+ | DefLintype [Def]
+ | DefPattern [Def]
+ | DefPackage PIdent [TopDef]
+ | DefVars [Def]
+ | DefTokenizer PIdent
+ deriving (Eq,Ord,Show)
+
+data CatDef =
+ SimpleCatDef PIdent [DDecl]
+ | ListCatDef PIdent [DDecl]
+ | ListSizeCatDef PIdent [DDecl] Integer
+ deriving (Eq,Ord,Show)
+
+data FunDef =
+ FunDef [PIdent] Exp
+ deriving (Eq,Ord,Show)
+
+data DataDef =
+ DataDef PIdent [DataConstr]
+ deriving (Eq,Ord,Show)
+
+data DataConstr =
+ DataId PIdent
+ | DataQId PIdent PIdent
+ deriving (Eq,Ord,Show)
+
+data ParDef =
+ ParDefDir PIdent [ParConstr]
+ | ParDefIndir PIdent PIdent
+ | ParDefAbs PIdent
+ deriving (Eq,Ord,Show)
+
+data ParConstr =
+ ParConstr PIdent [DDecl]
+ deriving (Eq,Ord,Show)
+
+data PrintDef =
+ PrintDef [Name] Exp
+ deriving (Eq,Ord,Show)
+
+data FlagDef =
+ FlagDef PIdent PIdent
+ deriving (Eq,Ord,Show)
+
+data Name =
+ IdentName PIdent
+ | ListName PIdent
+ deriving (Eq,Ord,Show)
+
+data LocDef =
+ LDDecl [PIdent] Exp
+ | LDDef [PIdent] Exp
+ | LDFull [PIdent] Exp Exp
+ deriving (Eq,Ord,Show)
+
+data Exp =
+ EIdent PIdent
+ | EConstr PIdent
+ | ECons PIdent
+ | ESort Sort
+ | EString String
+ | EInt Integer
+ | EFloat Double
+ | EMeta
+ | EEmpty
+ | EData
+ | EList PIdent Exps
+ | EStrings String
+ | ERecord [LocDef]
+ | ETuple [TupleComp]
+ | EIndir PIdent
+ | ETyped Exp Exp
+ | EProj Exp Label
+ | EQConstr PIdent PIdent
+ | EQCons PIdent PIdent
+ | EApp Exp Exp
+ | ETable [Case]
+ | ETTable Exp [Case]
+ | EVTable Exp [Exp]
+ | ECase Exp [Case]
+ | EVariants [Exp]
+ | EPre Exp [Altern]
+ | EStrs [Exp]
+ | EConAt PIdent Exp
+ | EPatt Patt
+ | EPattType Exp
+ | ESelect Exp Exp
+ | ETupTyp Exp Exp
+ | EExtend Exp Exp
+ | EGlue Exp Exp
+ | EConcat Exp Exp
+ | EAbstr [Bind] Exp
+ | ECTable [Bind] Exp
+ | EProd Decl Exp
+ | ETType Exp Exp
+ | ELet [LocDef] Exp
+ | ELetb [LocDef] Exp
+ | EWhere Exp [LocDef]
+ | EEqs [Equation]
+ | EExample Exp String
+ | ELString LString
+ | ELin PIdent
+ deriving (Eq,Ord,Show)
+
+data Exps =
+ NilExp
+ | ConsExp Exp Exps
+ deriving (Eq,Ord,Show)
+
+data Patt =
+ PChar
+ | PChars String
+ | PMacro PIdent
+ | PM PIdent PIdent
+ | PW
+ | PV PIdent
+ | PCon PIdent
+ | PQ PIdent PIdent
+ | PInt Integer
+ | PFloat Double
+ | PStr String
+ | PR [PattAss]
+ | PTup [PattTupleComp]
+ | PC PIdent [Patt]
+ | PQC PIdent PIdent [Patt]
+ | PDisj Patt Patt
+ | PSeq Patt Patt
+ | PRep Patt
+ | PAs PIdent Patt
+ | PNeg Patt
+ deriving (Eq,Ord,Show)
+
+data PattAss =
+ PA [PIdent] Patt
+ deriving (Eq,Ord,Show)
+
+data Label =
+ LIdent PIdent
+ | LVar Integer
+ deriving (Eq,Ord,Show)
+
+data Sort =
+ Sort_Type
+ | Sort_PType
+ | Sort_Tok
+ | Sort_Str
+ | Sort_Strs
+ deriving (Eq,Ord,Show)
+
+data Bind =
+ BIdent PIdent
+ | BWild
+ deriving (Eq,Ord,Show)
+
+data Decl =
+ DDec [Bind] Exp
+ | DExp Exp
+ deriving (Eq,Ord,Show)
+
+data TupleComp =
+ TComp Exp
+ deriving (Eq,Ord,Show)
+
+data PattTupleComp =
+ PTComp Patt
+ deriving (Eq,Ord,Show)
+
+data Case =
+ Case Patt Exp
+ deriving (Eq,Ord,Show)
+
+data Equation =
+ Equ [Patt] Exp
+ deriving (Eq,Ord,Show)
+
+data Altern =
+ Alt Exp Exp
+ deriving (Eq,Ord,Show)
+
+data DDecl =
+ DDDec [Bind] Exp
+ | DDExp Exp
+ deriving (Eq,Ord,Show)
+
+data OldGrammar =
+ OldGr Include [TopDef]
+ deriving (Eq,Ord,Show)
+
+data Include =
+ NoIncl
+ | Incl [FileName]
+ deriving (Eq,Ord,Show)
+
+data FileName =
+ FString String
+ | FIdent PIdent
+ | FSlash FileName
+ | FDot FileName
+ | FMinus FileName
+ | FAddId PIdent FileName
+ deriving (Eq,Ord,Show)
+
diff --git a/src-2.9/GF/Source/ErrM.hs b/src-2.9/GF/Source/ErrM.hs
new file mode 100644
index 000000000..63840758e
--- /dev/null
+++ b/src-2.9/GF/Source/ErrM.hs
@@ -0,0 +1,26 @@
+-- BNF Converter: Error Monad
+-- Copyright (C) 2004 Author: Aarne Ranta
+
+-- This file comes with NO WARRANTY and may be used FOR ANY PURPOSE.
+module GF.Source.ErrM where
+
+-- the Error monad: like Maybe type with error msgs
+
+import Control.Monad (MonadPlus(..), liftM)
+
+data Err a = Ok a | Bad String
+ deriving (Read, Show, Eq, Ord)
+
+instance Monad Err where
+ return = Ok
+ fail = Bad
+ Ok a >>= f = f a
+ Bad s >>= f = Bad s
+
+instance Functor Err where
+ fmap = liftM
+
+instance MonadPlus Err where
+ mzero = Bad "Err.mzero"
+ mplus (Bad _) y = y
+ mplus x _ = x
diff --git a/src-2.9/GF/Source/GF.cf b/src-2.9/GF/Source/GF.cf
new file mode 100644
index 000000000..364550e6f
--- /dev/null
+++ b/src-2.9/GF/Source/GF.cf
@@ -0,0 +1,370 @@
+-- AR 2/5/2003, 14-16 o'clock, Torino
+
+-- 17/6/2007: marked with suffix --% those lines that are obsolete and
+-- should not be included in documentation
+
+entrypoints Grammar, ModDef,
+ OldGrammar, --%
+ Exp ; -- let's see if more are needed
+
+comment "--" ;
+comment "{-" "-}" ;
+
+-- the top-level grammar
+
+Gr. Grammar ::= [ModDef] ;
+
+-- semicolon after module is permitted but not obligatory
+
+terminator ModDef "" ;
+_. ModDef ::= ModDef ";" ;
+
+-- The $main$ multilingual grammar structure --%
+
+MMain. ModDef ::= "grammar" PIdent "=" "{" "abstract" "=" PIdent ";" [ConcSpec] "}" ;--%
+
+ConcSpec. ConcSpec ::= PIdent "=" ConcExp ;--%
+separator ConcSpec ";" ;--%
+
+ConcExp. ConcExp ::= PIdent [Transfer] ;--%
+
+separator Transfer "" ;--%
+TransferIn. Transfer ::= "(" "transfer" "in" Open ")" ; --%
+TransferOut. Transfer ::= "(" "transfer" "out" Open ")" ; --%
+
+-- the module header
+
+MModule2. ModHeader ::= ComplMod ModType "=" ModHeaderBody ;
+
+MBody2. ModHeaderBody ::= Extend Opens ;
+MNoBody2. ModHeaderBody ::= [Included] ;
+MWith2. ModHeaderBody ::= Included "with" [Open] ;
+MWithBody2. ModHeaderBody ::= Included "with" [Open] "**" Opens ;
+MWithE2. ModHeaderBody ::= [Included] "**" Included "with" [Open] ;
+MWithEBody2. ModHeaderBody ::= [Included] "**" Included "with" [Open] "**" Opens ;
+
+MReuse2. ModHeaderBody ::= "reuse" PIdent ; --%
+MUnion2. ModHeaderBody ::= "union" [Included] ;--%
+
+-- the individual modules
+
+MModule. ModDef ::= ComplMod ModType "=" ModBody ;
+
+MTAbstract. ModType ::= "abstract" PIdent ;
+MTResource. ModType ::= "resource" PIdent ;
+MTInterface. ModType ::= "interface" PIdent ;
+MTConcrete. ModType ::= "concrete" PIdent "of" PIdent ;
+MTInstance. ModType ::= "instance" PIdent "of" PIdent ;
+MTTransfer. ModType ::= "transfer" PIdent ":" Open "->" Open ;
+
+
+MBody. ModBody ::= Extend Opens "{" [TopDef] "}" ;
+MNoBody. ModBody ::= [Included] ;
+MWith. ModBody ::= Included "with" [Open] ;
+MWithBody. ModBody ::= Included "with" [Open] "**" Opens "{" [TopDef] "}" ;
+MWithE. ModBody ::= [Included] "**" Included "with" [Open] ;
+MWithEBody. ModBody ::= [Included] "**" Included "with" [Open] "**" Opens "{" [TopDef] "}" ;
+
+MReuse. ModBody ::= "reuse" PIdent ; --%
+MUnion. ModBody ::= "union" [Included] ;--%
+
+separator TopDef "" ;
+
+Ext. Extend ::= [Included] "**" ;
+NoExt. Extend ::= ;
+
+separator Open "," ;
+NoOpens. Opens ::= ;
+OpenIn. Opens ::= "open" [Open] "in" ;
+
+OName. Open ::= PIdent ;
+OQualQO. Open ::= "(" QualOpen PIdent ")" ;
+OQual. Open ::= "(" QualOpen PIdent "=" PIdent ")" ;
+
+CMCompl. ComplMod ::= ;
+CMIncompl. ComplMod ::= "incomplete" ;
+
+QOCompl. QualOpen ::= ;
+QOIncompl. QualOpen ::= "incomplete" ;--%
+QOInterface. QualOpen ::= "interface" ;--%
+
+separator Included "," ;
+
+IAll. Included ::= PIdent ;
+ISome. Included ::= PIdent "[" [PIdent] "]" ;
+IMinus. Included ::= PIdent "-" "[" [PIdent] "]" ;
+
+-- definitions after the $oper$ keywords
+
+DDecl. Def ::= [Name] ":" Exp ;
+DDef. Def ::= [Name] "=" Exp ;
+DPatt. Def ::= Name [Patt] "=" Exp ; -- non-empty pattern list
+DFull. Def ::= [Name] ":" Exp "=" Exp ;
+
+-- top-level definitions
+
+DefCat. TopDef ::= "cat" [CatDef] ;
+DefFun. TopDef ::= "fun" [FunDef] ;
+DefFunData.TopDef ::= "data" [FunDef] ;
+DefDef. TopDef ::= "def" [Def] ;
+DefData. TopDef ::= "data" [DataDef] ;
+
+DefTrans. TopDef ::= "transfer" [Def] ;--%
+
+DefPar. TopDef ::= "param" [ParDef] ;
+DefOper. TopDef ::= "oper" [Def] ;
+
+DefLincat. TopDef ::= "lincat" [PrintDef] ;
+DefLindef. TopDef ::= "lindef" [Def] ;
+DefLin. TopDef ::= "lin" [Def] ;
+
+DefPrintCat. TopDef ::= "printname" "cat" [PrintDef] ;
+DefPrintFun. TopDef ::= "printname" "fun" [PrintDef] ;
+DefFlag. TopDef ::= "flags" [FlagDef] ;
+
+SimpleCatDef. CatDef ::= PIdent [DDecl] ;
+ListCatDef. CatDef ::= "[" PIdent [DDecl] "]" ;
+ListSizeCatDef. CatDef ::= "[" PIdent [DDecl] "]" "{" Integer "}" ;
+
+FunDef. FunDef ::= [PIdent] ":" Exp ;
+
+DataDef. DataDef ::= PIdent "=" [DataConstr] ;
+DataId. DataConstr ::= PIdent ;
+DataQId. DataConstr ::= PIdent "." PIdent ;
+separator DataConstr "|" ;
+
+
+ParDefDir. ParDef ::= PIdent "=" [ParConstr] ;
+ParDefIndir. ParDef ::= PIdent "=" "(" "in" PIdent ")" ;
+ParDefAbs. ParDef ::= PIdent ;
+
+ParConstr. ParConstr ::= PIdent [DDecl] ;
+
+PrintDef. PrintDef ::= [Name] "=" Exp ;
+
+FlagDef. FlagDef ::= PIdent "=" PIdent ;
+
+terminator nonempty Def ";" ;
+terminator nonempty CatDef ";" ;
+terminator nonempty FunDef ";" ;
+terminator nonempty DataDef ";" ;
+terminator nonempty ParDef ";" ;
+
+terminator nonempty PrintDef ";" ;
+terminator nonempty FlagDef ";" ;
+
+separator ParConstr "|" ;
+
+separator nonempty PIdent "," ;
+
+-- names of categories and functions in definition LHS
+
+IdentName. Name ::= PIdent ;
+ListName. Name ::= "[" PIdent "]" ;
+
+separator nonempty Name "," ;
+
+-- definitions in records and $let$ expressions
+
+LDDecl. LocDef ::= [PIdent] ":" Exp ;
+LDDef. LocDef ::= [PIdent] "=" Exp ;
+LDFull. LocDef ::= [PIdent] ":" Exp "=" Exp ;
+
+separator LocDef ";" ;
+
+-- terms and types
+
+EIdent. Exp6 ::= PIdent ;
+EConstr. Exp6 ::= "{" PIdent "}" ;--%
+ECons. Exp6 ::= "%" PIdent "%" ;--%
+ESort. Exp6 ::= Sort ;
+EString. Exp6 ::= String ;
+EInt. Exp6 ::= Integer ;
+EFloat. Exp6 ::= Double ;
+EMeta. Exp6 ::= "?" ;
+EEmpty. Exp6 ::= "[" "]" ;
+EData. Exp6 ::= "data" ;
+EList. Exp6 ::= "[" PIdent Exps "]" ;
+EStrings. Exp6 ::= "[" String "]" ;
+ERecord. Exp6 ::= "{" [LocDef] "}" ; -- !
+ETuple. Exp6 ::= "<" [TupleComp] ">" ; --- needed for separator ","
+EIndir. Exp6 ::= "(" "in" PIdent ")" ; -- indirection, used in judgements --%
+ETyped. Exp6 ::= "<" Exp ":" Exp ">" ; -- typing, used for annotations
+
+EProj. Exp5 ::= Exp5 "." Label ;
+EQConstr. Exp5 ::= "{" PIdent "." PIdent "}" ; -- qualified constructor --%
+EQCons. Exp5 ::= "%" PIdent "." PIdent ; -- qualified constant --%
+
+EApp. Exp4 ::= Exp4 Exp5 ;
+ETable. Exp4 ::= "table" "{" [Case] "}" ;
+ETTable. Exp4 ::= "table" Exp6 "{" [Case] "}" ;
+EVTable. Exp4 ::= "table" Exp6 "[" [Exp] "]" ;
+ECase. Exp4 ::= "case" Exp "of" "{" [Case] "}" ;
+EVariants. Exp4 ::= "variants" "{" [Exp] "}" ;
+--- EPreCase. Exp4 ::= "pre" "{" [Case] "}" ;
+EPre. Exp4 ::= "pre" "{" Exp ";" [Altern] "}" ;
+EStrs. Exp4 ::= "strs" "{" [Exp] "}" ;
+EConAt. Exp4 ::= PIdent "@" Exp6 ; --%
+
+EPatt. Exp4 ::= "#" Patt2 ;
+EPattType. Exp4 ::= "pattern" Exp5 ;
+
+ESelect. Exp3 ::= Exp3 "!" Exp4 ;
+ETupTyp. Exp3 ::= Exp3 "*" Exp4 ;
+EExtend. Exp3 ::= Exp3 "**" Exp4 ;
+
+EGlue. Exp1 ::= Exp2 "+" Exp1 ;
+
+EConcat. Exp ::= Exp1 "++" Exp ;
+
+EAbstr. Exp ::= "\\" [Bind] "->" Exp ;
+ECTable. Exp ::= "\\""\\" [Bind] "=>" Exp ;
+EProd. Exp ::= Decl "->" Exp ;
+ETType. Exp ::= Exp3 "=>" Exp ; -- these are thus right associative
+ELet. Exp ::= "let" "{" [LocDef] "}" "in" Exp ;
+ELetb. Exp ::= "let" [LocDef] "in" Exp ;
+EWhere. Exp ::= Exp3 "where" "{" [LocDef] "}" ;
+EEqs. Exp ::= "fn" "{" [Equation] "}" ; --%
+
+EExample. Exp ::= "in" Exp5 String ;
+
+coercions Exp 6 ;
+
+separator Exp ";" ; -- in variants
+
+-- list of arguments to category
+NilExp. Exps ::= ;
+ConsExp. Exps ::= Exp6 Exps ; -- Exp6 to force parantheses
+
+-- patterns
+
+PChar. Patt2 ::= "?" ;
+PChars. Patt2 ::= "[" String "]" ;
+PMacro. Patt2 ::= "#" PIdent ;
+PM. Patt2 ::= "#" PIdent "." PIdent ;
+PW. Patt2 ::= "_" ;
+PV. Patt2 ::= PIdent ;
+PCon. Patt2 ::= "{" PIdent "}" ; --%
+PQ. Patt2 ::= PIdent "." PIdent ;
+PInt. Patt2 ::= Integer ;
+PFloat. Patt2 ::= Double ;
+PStr. Patt2 ::= String ;
+PR. Patt2 ::= "{" [PattAss] "}" ;
+PTup. Patt2 ::= "<" [PattTupleComp] ">" ;
+PC. Patt1 ::= PIdent [Patt] ;
+PQC. Patt1 ::= PIdent "." PIdent [Patt] ;
+PDisj. Patt ::= Patt "|" Patt1 ;
+PSeq. Patt ::= Patt "+" Patt1 ;
+PRep. Patt1 ::= Patt2 "*" ;
+PAs. Patt1 ::= PIdent "@" Patt2 ;
+PNeg. Patt1 ::= "-" Patt2 ;
+
+coercions Patt 2 ;
+
+PA. PattAss ::= [PIdent] "=" Patt ;
+
+-- labels
+
+LIdent. Label ::= PIdent ;
+LVar. Label ::= "$" Integer ;
+
+-- basic types
+
+rules Sort ::=
+ "Type"
+ | "PType"
+ | "Tok" --%
+ | "Str"
+ | "Strs" ;
+
+separator PattAss ";" ;
+
+-- this is explicit to force higher precedence level on rhs
+(:[]). [Patt] ::= Patt2 ;
+(:). [Patt] ::= Patt2 [Patt] ;
+
+
+-- binds in lambdas and lin rules
+
+BIdent. Bind ::= PIdent ;
+BWild. Bind ::= "_" ;
+
+separator Bind "," ;
+
+
+-- declarations in function types
+
+DDec. Decl ::= "(" [Bind] ":" Exp ")" ;
+DExp. Decl ::= Exp4 ; -- can thus be an application
+
+-- tuple component (term or pattern)
+
+TComp. TupleComp ::= Exp ;
+PTComp. PattTupleComp ::= Patt ;
+
+separator TupleComp "," ;
+separator PattTupleComp "," ;
+
+-- case branches
+
+Case. Case ::= Patt "=>" Exp ;
+
+separator nonempty Case ";" ;
+
+-- cases in abstract syntax --%
+
+Equ. Equation ::= [Patt] "->" Exp ; --%
+
+separator Equation ";" ; --%
+
+-- prefix alternatives
+
+Alt. Altern ::= Exp "/" Exp ;
+
+separator Altern ";" ;
+
+-- in a context, higher precedence is required than in function types
+
+DDDec. DDecl ::= "(" [Bind] ":" Exp ")" ;
+DDExp. DDecl ::= Exp6 ; -- can thus *not* be an application
+
+separator DDecl "" ;
+
+
+-------------------------------------- --%
+
+-- for backward compatibility --%
+
+OldGr. OldGrammar ::= Include [TopDef] ; --%
+
+NoIncl. Include ::= ; --%
+Incl. Include ::= "include" [FileName] ; --%
+
+FString. FileName ::= String ; --%
+
+terminator nonempty FileName ";" ; --%
+
+FIdent. FileName ::= PIdent ; --%
+FSlash. FileName ::= "/" FileName ; --%
+FDot. FileName ::= "." FileName ; --%
+FMinus. FileName ::= "-" FileName ; --%
+FAddId. FileName ::= PIdent FileName ; --%
+
+token LString '\'' (char - '\'')* '\'' ; --%
+ELString. Exp6 ::= LString ; --%
+ELin. Exp4 ::= "Lin" PIdent ; --%
+
+DefPrintOld. TopDef ::= "printname" [PrintDef] ; --%
+DefLintype. TopDef ::= "lintype" [Def] ; --%
+DefPattern. TopDef ::= "pattern" [Def] ; --%
+
+-- deprecated packages are attempted to be interpreted --%
+DefPackage. TopDef ::= "package" PIdent "=" "{" [TopDef] "}" ";" ; --%
+
+-- these two are just ignored after parsing --%
+DefVars. TopDef ::= "var" [Def] ; --%
+DefTokenizer. TopDef ::= "tokenizer" PIdent ";" ; --%
+
+-- identifiers
+
+position token PIdent ('_' | letter) (letter | digit | '_' | '\'')* ;
diff --git a/src-2.9/GF/Source/GrammarToSource.hs b/src-2.9/GF/Source/GrammarToSource.hs
new file mode 100644
index 000000000..6d48e4ced
--- /dev/null
+++ b/src-2.9/GF/Source/GrammarToSource.hs
@@ -0,0 +1,259 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GrammarToSource
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/10/04 11:05:07 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.23 $
+--
+-- From internal source syntax to BNFC-generated (used for printing).
+-----------------------------------------------------------------------------
+
+module GF.Source.GrammarToSource ( trGrammar,
+ trModule,
+ trAnyDef,
+ trLabel,
+ trt, tri, trp
+ ) where
+
+import GF.Data.Operations
+import GF.Grammar.Grammar
+import GF.Infra.Modules
+import GF.Infra.Option
+import qualified GF.Source.AbsGF as P
+import GF.Infra.Ident
+
+-- | AR 13\/5\/2003
+--
+-- translate internal to parsable and printable source
+trGrammar :: SourceGrammar -> P.Grammar
+trGrammar (MGrammar ms) = P.Gr (map trModule ms) -- no includes
+
+trModule :: (Ident,SourceModInfo) -> P.ModDef
+trModule (i,mo) = case mo of
+ ModMod m -> P.MModule compl typ body where
+ compl = case mstatus m of
+ MSIncomplete -> P.CMIncompl
+ _ -> P.CMCompl
+ i' = tri i
+ typ = case typeOfModule mo of
+ MTResource -> P.MTResource i'
+ MTAbstract -> P.MTAbstract i'
+ MTConcrete a -> P.MTConcrete i' (tri a)
+ MTTransfer a b -> P.MTTransfer i' (trOpen a) (trOpen b)
+ MTInstance a -> P.MTInstance i' (tri a)
+ MTInterface -> P.MTInterface i'
+ body = P.MBody
+ (trExtends (extend m))
+ (mkOpens (map trOpen (opens m)))
+ (mkTopDefs (concatMap trAnyDef (tree2list (jments m)) ++ map trFlag (flags m)))
+
+trExtends :: [(Ident,MInclude Ident)] -> P.Extend
+trExtends [] = P.NoExt
+trExtends es = (P.Ext $ map tre es) where
+ tre (i,c) = case c of
+ MIAll -> P.IAll (tri i)
+ MIOnly is -> P.ISome (tri i) (map tri is)
+ MIExcept is -> P.IMinus (tri i) (map tri is)
+
+---- this has to be completed with other mtys
+forName (MTConcrete a) = tri a
+
+trOpen :: OpenSpec Ident -> P.Open
+trOpen o = case o of
+ OSimple OQNormal i -> P.OName (tri i)
+ OSimple q i -> P.OQualQO (trQualOpen q) (tri i)
+ OQualif q i j -> P.OQual (trQualOpen q) (tri i) (tri j)
+
+trQualOpen q = case q of
+ OQNormal -> P.QOCompl
+ OQIncomplete -> P.QOIncompl
+ OQInterface -> P.QOInterface
+
+
+mkOpens ds = if null ds then P.NoOpens else P.OpenIn ds
+mkTopDefs ds = ds
+
+trAnyDef :: (Ident,Info) -> [P.TopDef]
+trAnyDef (i,info) = let i' = tri i in case info of
+ AbsCat (Yes co) pd -> [P.DefCat [P.SimpleCatDef i' (map trDecl co)]]
+ AbsFun (Yes ty) (Yes EData) -> [P.DefFunData [P.FunDef [i'] (trt ty)]]
+ AbsFun (Yes ty) pt -> [P.DefFun [P.FunDef [i'] (trt ty)]] ++ case pt of
+ Yes t -> [P.DefDef [P.DDef [mkName i'] (trt t)]]
+ _ -> []
+ AbsFun (May b) _ -> [P.DefFun [P.FunDef [i'] (P.EIndir (tri b))]]
+ ---- don't destroy definitions!
+ AbsTrans f -> [P.DefTrans [P.DDef [mkName i'] (trt f)]]
+
+ ResOper pty ptr -> [P.DefOper [trDef i' pty ptr]]
+ ResParam pp -> [P.DefPar [case pp of
+ Yes (ps,_) -> P.ParDefDir i' [P.ParConstr (tri c) (map trDecl co) | (c,co) <- ps]
+ May b -> P.ParDefIndir i' $ tri b
+ _ -> P.ParDefAbs i']]
+
+ ResOverload tysts ->
+ [P.DefOper [P.DDef [mkName i'] (
+ P.EApp (P.EIdent $ tri $ identC "overload")
+ (P.ERecord [P.LDFull [i'] (trt ty) (trt fu) | (ty,fu) <- tysts]))]]
+
+ CncCat (Yes ty) Nope _ ->
+ [P.DefLincat [P.PrintDef [mkName i'] (trt ty)]]
+ CncCat pty ptr ppr ->
+ [P.DefLindef [trDef i' pty ptr]] ++
+ [P.DefPrintCat [P.PrintDef [mkName i'] (trt pr)] | Yes pr <- [ppr]]
+ CncFun _ ptr ppr ->
+ [P.DefLin [trDef i' nope ptr]] ++
+ [P.DefPrintFun [P.PrintDef [mkName i'] (trt pr)] | Yes pr <- [ppr]]
+{-
+ ---- encoding of AnyInd without changing syntax. AR 20/9/2007
+ AnyInd s b ->
+ [P.DefOper [P.DDef [mkName i]
+ (P.EApp (P.EInt (if s then 1 else 0)) (P.EIdent (tri b)))]]
+-}
+ _ -> []
+
+
+trDef :: P.PIdent -> Perh Type -> Perh Term -> P.Def
+trDef i pty ptr = case (pty,ptr) of
+ (Nope, Nope) -> P.DDef [mkName i] (P.EMeta) ---
+ (_, Nope) -> P.DDecl [mkName i] (trPerh pty)
+ (Nope, _ ) -> P.DDef [mkName i] (trPerh ptr)
+ (_, _ ) -> P.DFull [mkName i] (trPerh pty) (trPerh ptr)
+
+trPerh p = case p of
+ Yes t -> trt t
+ May b -> P.EIndir $ tri b
+ _ -> P.EMeta ---
+
+
+trFlag :: Option -> P.TopDef
+trFlag o = case o of
+ Opt (f,[x]) -> P.DefFlag [P.FlagDef (tri $ identC f) (tri $ identC x)]
+ _ -> P.DefFlag [] --- warning?
+
+trt :: Term -> P.Exp
+trt trm = case trm of
+ Vr s -> P.EIdent $ tri s
+ Cn s -> P.ECons $ tri s
+ Con s -> P.EConstr $ tri s
+ Sort s -> P.ESort $ case s of
+ "Type" -> P.Sort_Type
+ "PType" -> P.Sort_PType
+ "Tok" -> P.Sort_Tok
+ "Str" -> P.Sort_Str
+ "Strs" -> P.Sort_Strs
+ _ -> error $ "not yet sort " +++ show trm ----
+
+ App c a -> P.EApp (trt c) (trt a)
+ Abs x b -> P.EAbstr [trb x] (trt b)
+ Eqs pts -> P.EEqs [P.Equ (map trp ps) (trt t) | (ps,t) <- pts]
+ Meta m -> P.EMeta
+ Prod x a b | isWildIdent x -> P.EProd (P.DExp (trt a)) (trt b)
+ Prod x a b -> P.EProd (P.DDec [trb x] (trt a)) (trt b)
+
+ Example t s -> P.EExample (trt t) s
+ R [] -> P.ETuple [] --- to get correct parsing when read back
+ R r -> P.ERecord $ map trAssign r
+ RecType r -> P.ERecord $ map trLabelling r
+ ExtR x y -> P.EExtend (trt x) (trt y)
+ P t l -> P.EProj (trt t) (trLabel l)
+ PI t l _ -> P.EProj (trt t) (trLabel l)
+ Q t l -> P.EQCons (tri t) (tri l)
+ QC t l -> P.EQConstr (tri t) (tri l)
+ TSh (TComp ty) cc -> P.ETTable (trt ty) (map trCases cc)
+ TSh (TTyped ty) cc -> P.ETTable (trt ty) (map trCases cc)
+ TSh (TWild ty) cc -> P.ETTable (trt ty) (map trCases cc)
+ T (TTyped ty) cc -> P.ETTable (trt ty) (map trCase cc)
+ T (TComp ty) cc -> P.ETTable (trt ty) (map trCase cc)
+ T (TWild ty) cc -> P.ETTable (trt ty) (map trCase cc)
+ T _ cc -> P.ETable (map trCase cc)
+ V ty cc -> P.EVTable (trt ty) (map trt cc)
+
+ Table x v -> P.ETType (trt x) (trt v)
+ S f x -> P.ESelect (trt f) (trt x)
+---- Alias c a t -> "{-" +++ prt c +++ "=" +++ "-}" +++ prt t
+-- Alias c a t -> prt (Let (c,(Just a,t)) (Vr c)) -- thus Alias is only internal
+
+ Let (x,(ma,b)) t ->
+ P.ELet [maybe (P.LDDef x' b') (\ty -> P.LDFull x' (trt ty) b') ma] (trt t)
+ where
+ b' = trt b
+ x' = [tri x]
+
+ Empty -> P.EEmpty
+ K [] -> P.EEmpty
+ K a -> P.EString a
+ C a b -> P.EConcat (trt a) (trt b)
+
+ EInt i -> P.EInt i
+ EFloat i -> P.EFloat i
+
+ EPatt p -> P.EPatt (trp p)
+ EPattType t -> P.EPattType (trt t)
+
+ Glue a b -> P.EGlue (trt a) (trt b)
+ Alts (t, tt) -> P.EPre (trt t) [P.Alt (trt v) (trt c) | (v,c) <- tt]
+ FV ts -> P.EVariants $ map trt ts
+ Strs tt -> P.EStrs $ map trt tt
+ EData -> P.EData
+ _ -> error $ "not yet" +++ show trm ----
+
+trp :: Patt -> P.Patt
+trp p = case p of
+ PW -> P.PW
+ PV s | isWildIdent s -> P.PW
+ PV s -> P.PV $ tri s
+ PC c [] -> P.PCon $ tri c
+ PC c a -> P.PC (tri c) (map trp a)
+ PP p c [] -> P.PQ (tri p) (tri c)
+ PP p c a -> P.PQC (tri p) (tri c) (map trp a)
+ PR r -> P.PR [P.PA [tri $ trLabelIdent l] (trp p) | (l,p) <- r]
+ PString s -> P.PStr s
+ PInt i -> P.PInt i
+ PFloat i -> P.PFloat i
+ PT t p -> trp p ---- prParenth (prt p +++ ":" +++ prt t)
+
+ PAs x p -> P.PAs (tri x) (trp p)
+
+ PAlt p q -> P.PDisj (trp p) (trp q)
+ PSeq p q -> P.PSeq (trp p) (trp q)
+ PRep p -> P.PRep (trp p)
+ PNeg p -> P.PNeg (trp p)
+ PChar -> P.PChar
+ PChars s -> P.PChars s
+ PM m c -> P.PM (tri m) (tri c)
+
+
+trAssign (lab, (mty, t)) = maybe (P.LDDef x t') (\ty -> P.LDFull x (trt ty) t') mty
+ where
+ t' = trt t
+ x = [tri $ trLabelIdent lab]
+
+trLabelling (lab,ty) = P.LDDecl [tri $ trLabelIdent lab] (trt ty)
+
+trCase (patt, trm) = P.Case (trp patt) (trt trm)
+trCases (patts,trm) = P.Case (foldl1 P.PDisj (map trp patts)) (trt trm)
+
+trDecl (x,ty) = P.DDDec [trb x] (trt ty)
+
+tri :: Ident -> P.PIdent
+tri = ppIdent . prIdent
+
+ppIdent i = P.PIdent ((0,0),i)
+
+trb i = if isWildIdent i then P.BWild else P.BIdent (tri i)
+
+trLabel :: Label -> P.Label
+trLabel i = case i of
+ LIdent s -> P.LIdent $ ppIdent s
+ LVar i -> P.LVar $ toInteger i
+
+trLabelIdent i = identC $ case i of
+ LIdent s -> s
+ LVar i -> "v" ++ show i --- should not happen
+
+mkName :: P.PIdent -> P.Name
+mkName = P.IdentName
diff --git a/src-2.9/GF/Source/LexGF.hs b/src-2.9/GF/Source/LexGF.hs
new file mode 100644
index 000000000..89067b6b6
--- /dev/null
+++ b/src-2.9/GF/Source/LexGF.hs
@@ -0,0 +1,345 @@
+{-# OPTIONS -fglasgow-exts -cpp #-}
+{-# LINE 3 "GF/Source/LexGF.x" #-}
+{-# OPTIONS -fno-warn-incomplete-patterns #-}
+module GF.Source.LexGF where
+
+
+import qualified Data.ByteString.Char8 as BS
+
+#if __GLASGOW_HASKELL__ >= 603
+#include "ghcconfig.h"
+#else
+#include "config.h"
+#endif
+#if __GLASGOW_HASKELL__ >= 503
+import Data.Array
+import Data.Char (ord)
+import Data.Array.Base (unsafeAt)
+#else
+import Array
+import Char (ord)
+#endif
+#if __GLASGOW_HASKELL__ >= 503
+import GHC.Exts
+#else
+import GlaExts
+#endif
+alex_base :: AlexAddr
+alex_base = AlexA# "\x01\x00\x00\x00\x15\x00\x00\x00\x39\x00\x00\x00\x3a\x00\x00\x00\x18\x00\x00\x00\x19\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x45\x00\x00\x00\x1b\x00\x00\x00\x1c\x00\x00\x00\x1d\x00\x00\x00\x42\x00\x00\x00\x00\x00\x00\x00\x26\x00\x00\x00\x27\x00\x00\x00\x13\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x2c\x00\x00\x00\x2d\x00\x00\x00\x6c\x01\x00\x00\x3c\x02\x00\x00\x0c\x03\x00\x00\x00\x00\x00\x00\x17\x01\x00\x00\xe7\x01\x00\x00\xd5\x00\x00\x00\x35\x00\x00\x00\xe7\x00\x00\x00\xf2\x00\x00\x00\x1d\x01\x00\x00\xc2\x01\x00\x00\xcc\x01\x00\x00"#
+
+alex_table :: AlexAddr
+alex_table = AlexA# "\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0d\x00\x0e\x00\x1a\x00\x0e\x00\x0e\x00\x0e\x00\xff\xff\x14\x00\x0e\x00\x0e\x00\x0f\x00\x10\x00\x0e\x00\x05\x00\x0e\x00\x0e\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x0e\x00\x0e\x00\x0e\x00\x11\x00\x0e\x00\x0e\x00\x0e\x00\x04\x00\xff\xff\xff\xff\x02\x00\x02\x00\x09\x00\x09\x00\x09\x00\x0a\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0e\x00\x0e\x00\x0e\x00\x13\x00\x13\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x0e\x00\x0e\x00\xff\xff\x12\x00\xff\xff\x0d\x00\x20\x00\x00\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x00\x00\x00\x00\x09\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x0e\x00\x0e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x06\x00\x07\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x1b\x00\xff\xff\x00\x00\x00\x00\x17\x00\x1b\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\xff\xff\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00\x00\x00\x21\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x1c\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x18\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x22\x00\x00\x00\xff\xff\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x1c\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x17\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x18\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x00\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x00\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00"#
+
+alex_check :: AlexAddr
+alex_check = AlexA# "\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x2d\x00\x0a\x00\x0a\x00\x2d\x00\x2d\x00\x2d\x00\x2d\x00\x2d\x00\x2d\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x2a\x00\x3e\x00\x2b\x00\x27\x00\x27\x00\xff\xff\xff\xff\x3e\x00\xff\xff\xff\xff\xff\xff\xff\xff\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x20\x00\x2e\x00\xff\xff\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\x2d\x00\x2d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\x7d\x00\x7d\x00\x27\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xd7\x00\xff\xff\xff\xff\xff\xff\xff\xff\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x22\x00\xf7\x00\xff\xff\xff\xff\x5f\x00\x27\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x0a\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5c\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x22\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x6e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x74\x00\xff\xff\xff\xff\x65\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\x5c\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\x27\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\xff\xff\xff\xff\xff\xff\xff\xff\x5f\x00\xff\xff\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\xff\xff\x0a\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\x22\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\x5c\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\x27\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\xff\xff\xff\xff\xff\xff\xff\xff\x5f\x00\xff\xff\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xff\xff\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\x27\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\xff\xff\xff\xff\xff\xff\xff\xff\x5f\x00\xff\xff\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xff\xff\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xff\xff\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00"#
+
+alex_deflt :: AlexAddr
+alex_deflt = AlexA# "\x16\x00\xff\xff\x03\x00\x03\x00\xff\xff\xff\xff\x0b\x00\xff\xff\x0b\x00\x0b\x00\x0b\x00\x0b\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x15\x00\x15\x00\xff\xff\xff\xff\xff\xff\xff\xff\x1b\x00\x1b\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
+
+alex_accept = listArray (0::Int,34) [[],[],[(AlexAccSkip)],[(AlexAccSkip)],[],[(AlexAcc (alex_action_3))],[(AlexAccSkip)],[(AlexAccSkip)],[],[],[],[],[(AlexAcc (alex_action_3))],[(AlexAccSkip)],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_4))],[],[],[(AlexAcc (alex_action_5))],[(AlexAcc (alex_action_5))],[(AlexAcc (alex_action_5))],[(AlexAcc (alex_action_7))],[],[],[],[(AlexAcc (alex_action_8))],[(AlexAcc (alex_action_9))],[(AlexAcc (alex_action_9))],[],[],[]]
+{-# LINE 36 "GF/Source/LexGF.x" #-}
+
+tok f p s = f p s
+
+share :: String -> String
+share = id
+
+data Tok =
+ TS !String -- reserved words and symbols
+ | TL !String -- string literals
+ | TI !String -- integer literals
+ | TV !String -- identifiers
+ | TD !String -- double precision float literals
+ | TC !String -- character literals
+ | T_LString !String
+ | T_PIdent !String
+
+ deriving (Eq,Show,Ord)
+
+data Token =
+ PT Posn Tok
+ | Err Posn
+ deriving (Eq,Show,Ord)
+
+tokenPos (PT (Pn _ l _) _ :_) = "line " ++ show l
+tokenPos (Err (Pn _ l _) :_) = "line " ++ show l
+tokenPos _ = "end of file"
+
+posLineCol (Pn _ l c) = (l,c)
+mkPosToken t@(PT p _) = (posLineCol p, prToken t)
+
+prToken t = case t of
+ PT _ (TS s) -> s
+ PT _ (TI s) -> s
+ PT _ (TV s) -> s
+ PT _ (TD s) -> s
+ PT _ (TC s) -> s
+ PT _ (T_LString s) -> s
+ PT _ (T_PIdent s) -> s
+
+ _ -> show t
+
+data BTree = N | B String Tok BTree BTree deriving (Show)
+
+eitherResIdent :: (String -> Tok) -> String -> Tok
+eitherResIdent tv s = treeFind resWords
+ where
+ treeFind N = tv s
+ treeFind (B a t left right) | s < a = treeFind left
+ | s > a = treeFind right
+ | s == a = t
+
+resWords = b "lincat" (b "def" (b "Type" (b "Str" (b "PType" (b "Lin" N N) N) (b "Tok" (b "Strs" N N) N)) (b "cat" (b "case" (b "abstract" N N) N) (b "data" (b "concrete" N N) N))) (b "include" (b "fun" (b "fn" (b "flags" N N) N) (b "in" (b "grammar" N N) N)) (b "interface" (b "instance" (b "incomplete" N N) N) (b "lin" (b "let" N N) N)))) (b "resource" (b "out" (b "of" (b "lintype" (b "lindef" N N) N) (b "oper" (b "open" N N) N)) (b "pattern" (b "param" (b "package" N N) N) (b "printname" (b "pre" N N) N))) (b "union" (b "table" (b "strs" (b "reuse" N N) N) (b "transfer" (b "tokenizer" N N) N)) (b "where" (b "variants" (b "var" N N) N) (b "with" N N))))
+ where b s = B s (TS s)
+
+unescapeInitTail :: String -> String
+unescapeInitTail = unesc . tail where
+ unesc s = case s of
+ '\\':c:cs | elem c ['\"', '\\', '\''] -> c : unesc cs
+ '\\':'n':cs -> '\n' : unesc cs
+ '\\':'t':cs -> '\t' : unesc cs
+ '"':[] -> []
+ c:cs -> c : unesc cs
+ _ -> []
+
+-------------------------------------------------------------------
+-- Alex wrapper code.
+-- A modified "posn" wrapper.
+-------------------------------------------------------------------
+
+data Posn = Pn !Int !Int !Int
+ deriving (Eq, Show,Ord)
+
+alexStartPos :: Posn
+alexStartPos = Pn 0 1 1
+
+alexMove :: Posn -> Char -> Posn
+alexMove (Pn a l c) '\t' = Pn (a+1) l (((c+7) `div` 8)*8+1)
+alexMove (Pn a l c) '\n' = Pn (a+1) (l+1) 1
+alexMove (Pn a l c) _ = Pn (a+1) l (c+1)
+
+type AlexInput = (Posn, -- current position,
+ Char, -- previous char
+ BS.ByteString) -- current input string
+
+tokens :: BS.ByteString -> [Token]
+tokens str = go (alexStartPos, '\n', str)
+ where
+ go :: AlexInput -> [Token]
+ go inp@(pos, _, str) =
+ case alexScan inp 0 of
+ AlexEOF -> []
+ AlexError (pos, _, _) -> [Err pos]
+ AlexSkip inp' len -> go inp'
+ AlexToken inp' len act -> act pos (BS.unpack (BS.take len str)) : (go inp')
+
+alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
+alexGetChar (p,_,cs) | BS.null cs = Nothing
+ | otherwise = let c = BS.head cs
+ cs' = BS.tail cs
+ p' = alexMove p c
+ in p' `seq` cs' `seq` Just (c, (p', c, cs'))
+
+alexInputPrevChar :: AlexInput -> Char
+alexInputPrevChar (p, c, s) = c
+
+alex_action_3 = tok (\p s -> PT p (TS $ share s))
+alex_action_4 = tok (\p s -> PT p (eitherResIdent (T_LString . share) s))
+alex_action_5 = tok (\p s -> PT p (eitherResIdent (T_PIdent . share) s))
+alex_action_6 = tok (\p s -> PT p (eitherResIdent (TV . share) s))
+alex_action_7 = tok (\p s -> PT p (TL $ share $ unescapeInitTail s))
+alex_action_8 = tok (\p s -> PT p (TI $ share s))
+alex_action_9 = tok (\p s -> PT p (TD $ share s))
+{-# LINE 1 "GenericTemplate.hs" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "GenericTemplate.hs" #-}
+-- -----------------------------------------------------------------------------
+-- ALEX TEMPLATE
+--
+-- This code is in the PUBLIC DOMAIN; you may copy it freely and use
+-- it for any purpose whatsoever.
+
+-- -----------------------------------------------------------------------------
+-- INTERNALS and main scanner engine
+
+{-# LINE 35 "GenericTemplate.hs" #-}
+
+{-# LINE 45 "GenericTemplate.hs" #-}
+
+
+data AlexAddr = AlexA# Addr#
+
+#if __GLASGOW_HASKELL__ < 503
+uncheckedShiftL# = shiftL#
+#endif
+
+{-# INLINE alexIndexInt16OffAddr #-}
+alexIndexInt16OffAddr (AlexA# arr) off =
+#ifdef WORDS_BIGENDIAN
+ narrow16Int# i
+ where
+ i = word2Int# ((high `uncheckedShiftL#` 8#) `or#` low)
+ high = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
+ low = int2Word# (ord# (indexCharOffAddr# arr off'))
+ off' = off *# 2#
+#else
+ indexInt16OffAddr# arr off
+#endif
+
+
+
+
+
+{-# INLINE alexIndexInt32OffAddr #-}
+alexIndexInt32OffAddr (AlexA# arr) off =
+#ifdef WORDS_BIGENDIAN
+ narrow32Int# i
+ where
+ i = word2Int# ((b3 `uncheckedShiftL#` 24#) `or#`
+ (b2 `uncheckedShiftL#` 16#) `or#`
+ (b1 `uncheckedShiftL#` 8#) `or#` b0)
+ b3 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 3#)))
+ b2 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 2#)))
+ b1 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
+ b0 = int2Word# (ord# (indexCharOffAddr# arr off'))
+ off' = off *# 4#
+#else
+ indexInt32OffAddr# arr off
+#endif
+
+
+
+
+
+#if __GLASGOW_HASKELL__ < 503
+quickIndex arr i = arr ! i
+#else
+-- GHC >= 503, unsafeAt is available from Data.Array.Base.
+quickIndex = unsafeAt
+#endif
+
+
+
+
+-- -----------------------------------------------------------------------------
+-- Main lexing routines
+
+data AlexReturn a
+ = AlexEOF
+ | AlexError !AlexInput
+ | AlexSkip !AlexInput !Int
+ | AlexToken !AlexInput !Int a
+
+-- alexScan :: AlexInput -> StartCode -> AlexReturn a
+alexScan input (I# (sc))
+ = alexScanUser undefined input (I# (sc))
+
+alexScanUser user input (I# (sc))
+ = case alex_scan_tkn user input 0# input sc AlexNone of
+ (AlexNone, input') ->
+ case alexGetChar input of
+ Nothing ->
+
+
+
+ AlexEOF
+ Just _ ->
+
+
+
+ AlexError input'
+
+ (AlexLastSkip input len, _) ->
+
+
+
+ AlexSkip input len
+
+ (AlexLastAcc k input len, _) ->
+
+
+
+ AlexToken input len k
+
+
+-- Push the input through the DFA, remembering the most recent accepting
+-- state it encountered.
+
+alex_scan_tkn user orig_input len input s last_acc =
+ input `seq` -- strict in the input
+ let
+ new_acc = check_accs (alex_accept `quickIndex` (I# (s)))
+ in
+ new_acc `seq`
+ case alexGetChar input of
+ Nothing -> (new_acc, input)
+ Just (c, new_input) ->
+
+
+
+ let
+ base = alexIndexInt32OffAddr alex_base s
+ (I# (ord_c)) = ord c
+ offset = (base +# ord_c)
+ check = alexIndexInt16OffAddr alex_check offset
+
+ new_s = if (offset >=# 0#) && (check ==# ord_c)
+ then alexIndexInt16OffAddr alex_table offset
+ else alexIndexInt16OffAddr alex_deflt s
+ in
+ case new_s of
+ -1# -> (new_acc, input)
+ -- on an error, we want to keep the input *before* the
+ -- character that failed, not after.
+ _ -> alex_scan_tkn user orig_input (len +# 1#)
+ new_input new_s new_acc
+
+ where
+ check_accs [] = last_acc
+ check_accs (AlexAcc a : _) = AlexLastAcc a input (I# (len))
+ check_accs (AlexAccSkip : _) = AlexLastSkip input (I# (len))
+ check_accs (AlexAccPred a pred : rest)
+ | pred user orig_input (I# (len)) input
+ = AlexLastAcc a input (I# (len))
+ check_accs (AlexAccSkipPred pred : rest)
+ | pred user orig_input (I# (len)) input
+ = AlexLastSkip input (I# (len))
+ check_accs (_ : rest) = check_accs rest
+
+data AlexLastAcc a
+ = AlexNone
+ | AlexLastAcc a !AlexInput !Int
+ | AlexLastSkip !AlexInput !Int
+
+data AlexAcc a user
+ = AlexAcc a
+ | AlexAccSkip
+ | AlexAccPred a (AlexAccPred user)
+ | AlexAccSkipPred (AlexAccPred user)
+
+type AlexAccPred user = user -> AlexInput -> Int -> AlexInput -> Bool
+
+-- -----------------------------------------------------------------------------
+-- Predicates on a rule
+
+alexAndPred p1 p2 user in1 len in2
+ = p1 user in1 len in2 && p2 user in1 len in2
+
+--alexPrevCharIsPred :: Char -> AlexAccPred _
+alexPrevCharIs c _ input _ _ = c == alexInputPrevChar input
+
+--alexPrevCharIsOneOfPred :: Array Char Bool -> AlexAccPred _
+alexPrevCharIsOneOf arr _ input _ _ = arr ! alexInputPrevChar input
+
+--alexRightContext :: Int -> AlexAccPred _
+alexRightContext (I# (sc)) user _ _ input =
+ case alex_scan_tkn user input 0# input sc AlexNone of
+ (AlexNone, _) -> False
+ _ -> True
+ -- TODO: there's no need to find the longest
+ -- match when checking the right context, just
+ -- the first match will do.
+
+-- used by wrappers
+iUnbox (I# (i)) = i
diff --git a/src-2.9/GF/Source/LexGF.x b/src-2.9/GF/Source/LexGF.x
new file mode 100644
index 000000000..7ea768e75
--- /dev/null
+++ b/src-2.9/GF/Source/LexGF.x
@@ -0,0 +1,137 @@
+-- -*- haskell -*-
+-- This Alex file was machine-generated by the BNF converter
+{
+module LexGF where
+
+import ErrM
+import SharedString
+}
+
+
+$l = [a-zA-Z\192 - \255] # [\215 \247] -- isolatin1 letter FIXME
+$c = [A-Z\192-\221] # [\215] -- capital isolatin1 letter FIXME
+$s = [a-z\222-\255] # [\247] -- small isolatin1 letter FIXME
+$d = [0-9] -- digit
+$i = [$l $d _ '] -- identifier character
+$u = [\0-\255] -- universal: any character
+
+@rsyms = -- reserved words consisting of special symbols
+ \; | \= | \{ | \} | \( | \) | \: | \- \> | \* \* | \, | \[ | \] | \- | \. | \| | \% | \? | \< | \> | \@ | \! | \* | \+ | \+ \+ | \\ | \= \> | \_ | \$ | \/
+
+:-
+"--" [.]* ; -- Toss single line comments
+"{-" ([$u # \-] | \- [$u # \}])* ("-")+ "}" ;
+
+$white+ ;
+@rsyms { tok (\p s -> PT p (TS $ share s)) }
+\' ($u # \')* \' { tok (\p s -> PT p (eitherResIdent (T_LString . share) s)) }
+
+$l $i* { tok (\p s -> PT p (eitherResIdent (TV . share) s)) }
+\" ([$u # [\" \\ \n]] | (\\ (\" | \\ | \' | n | t)))* \"{ tok (\p s -> PT p (TL $ share $ unescapeInitTail s)) }
+
+$d+ { tok (\p s -> PT p (TI $ share s)) }
+$d+ \. $d+ (e (\-)? $d+)? { tok (\p s -> PT p (TD $ share s)) }
+
+{
+
+tok f p s = f p s
+
+share :: String -> String
+share = shareString
+
+data Tok =
+ TS !String -- reserved words
+ | TL !String -- string literals
+ | TI !String -- integer literals
+ | TV !String -- identifiers
+ | TD !String -- double precision float literals
+ | TC !String -- character literals
+ | T_LString !String
+
+ deriving (Eq,Show,Ord)
+
+data Token =
+ PT Posn Tok
+ | Err Posn
+ deriving (Eq,Show,Ord)
+
+tokenPos (PT (Pn _ l _) _ :_) = "line " ++ show l
+tokenPos (Err (Pn _ l _) :_) = "line " ++ show l
+tokenPos _ = "end of file"
+
+posLineCol (Pn _ l c) = (l,c)
+mkPosToken t@(PT p _) = (posLineCol p, prToken t)
+
+prToken t = case t of
+ PT _ (TS s) -> s
+ PT _ (TI s) -> s
+ PT _ (TV s) -> s
+ PT _ (TD s) -> s
+ PT _ (TC s) -> s
+ PT _ (T_LString s) -> s
+
+ _ -> show t
+
+data BTree = N | B String Tok BTree BTree deriving (Show)
+
+eitherResIdent :: (String -> Tok) -> String -> Tok
+eitherResIdent tv s = treeFind resWords
+ where
+ treeFind N = tv s
+ treeFind (B a t left right) | s < a = treeFind left
+ | s > a = treeFind right
+ | s == a = t
+
+resWords = b "lincat" (b "def" (b "Type" (b "Str" (b "PType" (b "Lin" N N) N) (b "Tok" (b "Strs" N N) N)) (b "cat" (b "case" (b "abstract" N N) N) (b "data" (b "concrete" N N) N))) (b "include" (b "fun" (b "fn" (b "flags" N N) N) (b "in" (b "grammar" N N) N)) (b "interface" (b "instance" (b "incomplete" N N) N) (b "lin" (b "let" N N) N)))) (b "resource" (b "out" (b "of" (b "lintype" (b "lindef" N N) N) (b "oper" (b "open" N N) N)) (b "pattern" (b "param" (b "package" N N) N) (b "printname" (b "pre" N N) N))) (b "union" (b "table" (b "strs" (b "reuse" N N) N) (b "transfer" (b "tokenizer" N N) N)) (b "where" (b "variants" (b "var" N N) N) (b "with" N N))))
+ where b s = B s (TS s)
+
+unescapeInitTail :: String -> String
+unescapeInitTail = unesc . tail where
+ unesc s = case s of
+ '\\':c:cs | elem c ['\"', '\\', '\''] -> c : unesc cs
+ '\\':'n':cs -> '\n' : unesc cs
+ '\\':'t':cs -> '\t' : unesc cs
+ '"':[] -> []
+ c:cs -> c : unesc cs
+ _ -> []
+
+-------------------------------------------------------------------
+-- Alex wrapper code.
+-- A modified "posn" wrapper.
+-------------------------------------------------------------------
+
+data Posn = Pn !Int !Int !Int
+ deriving (Eq, Show,Ord)
+
+alexStartPos :: Posn
+alexStartPos = Pn 0 1 1
+
+alexMove :: Posn -> Char -> Posn
+alexMove (Pn a l c) '\t' = Pn (a+1) l (((c+7) `div` 8)*8+1)
+alexMove (Pn a l c) '\n' = Pn (a+1) (l+1) 1
+alexMove (Pn a l c) _ = Pn (a+1) l (c+1)
+
+type AlexInput = (Posn, -- current position,
+ Char, -- previous char
+ String) -- current input string
+
+tokens :: String -> [Token]
+tokens str = go (alexStartPos, '\n', str)
+ where
+ go :: (Posn, Char, String) -> [Token]
+ go inp@(pos, _, str) =
+ case alexScan inp 0 of
+ AlexEOF -> []
+ AlexError (pos, _, _) -> fail $ show pos ++ ": lexical error"
+ AlexSkip inp' len -> go inp'
+ AlexToken inp' len act -> act pos (take len str) : (go inp')
+
+alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
+alexGetChar (p, c, []) = Nothing
+alexGetChar (p, _, (c:s)) =
+ let p' = alexMove p c
+ in p' `seq` Just (c, (p', c, s))
+
+alexInputPrevChar :: AlexInput -> Char
+alexInputPrevChar (p, c, s) = c
+}
diff --git a/src-2.9/GF/Source/ParGF.hs b/src-2.9/GF/Source/ParGF.hs
new file mode 100644
index 000000000..30f83eef6
--- /dev/null
+++ b/src-2.9/GF/Source/ParGF.hs
@@ -0,0 +1,7845 @@
+{-# OPTIONS -fglasgow-exts -cpp #-}
+{-# OPTIONS -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
+ module GF.Source.ParGF (pGrammar, pModDef, pOldGrammar, pExp, pModHeader, myLexer) where --H
+import GF.Source.AbsGF --H
+import GF.Source.LexGF --H
+import GF.Infra.Ident --H
+import GF.Data.ErrM --H
+#if __GLASGOW_HASKELL__ >= 503
+import GHC.Exts
+#else
+import GlaExts
+#endif
+
+-- parser produced by Happy Version 1.17
+
+data HappyAbsSyn
+ = HappyTerminal Token
+ | HappyErrorToken Int
+ | HappyAbsSyn8 (Integer)
+ | HappyAbsSyn9 (String)
+ | HappyAbsSyn10 (Double)
+ | HappyAbsSyn11 (LString)
+ | HappyAbsSyn12 (PIdent)
+ | HappyAbsSyn13 (Grammar)
+ | HappyAbsSyn14 ([ModDef])
+ | HappyAbsSyn15 (ModDef)
+ | HappyAbsSyn16 (ConcSpec)
+ | HappyAbsSyn17 ([ConcSpec])
+ | HappyAbsSyn18 (ConcExp)
+ | HappyAbsSyn19 ([Transfer])
+ | HappyAbsSyn20 (Transfer)
+ | HappyAbsSyn22 (ModBody)
+ | HappyAbsSyn23 (ModType)
+ | HappyAbsSyn25 ([TopDef])
+ | HappyAbsSyn26 (Extend)
+ | HappyAbsSyn27 ([Open])
+ | HappyAbsSyn28 (Opens)
+ | HappyAbsSyn29 (Open)
+ | HappyAbsSyn30 (ComplMod)
+ | HappyAbsSyn31 (QualOpen)
+ | HappyAbsSyn32 ([Included])
+ | HappyAbsSyn33 (Included)
+ | HappyAbsSyn34 (Def)
+ | HappyAbsSyn35 (TopDef)
+ | HappyAbsSyn36 (CatDef)
+ | HappyAbsSyn37 (FunDef)
+ | HappyAbsSyn38 (DataDef)
+ | HappyAbsSyn39 (DataConstr)
+ | HappyAbsSyn40 ([DataConstr])
+ | HappyAbsSyn41 (ParDef)
+ | HappyAbsSyn42 (ParConstr)
+ | HappyAbsSyn43 (PrintDef)
+ | HappyAbsSyn44 (FlagDef)
+ | HappyAbsSyn45 ([Def])
+ | HappyAbsSyn46 ([CatDef])
+ | HappyAbsSyn47 ([FunDef])
+ | HappyAbsSyn48 ([DataDef])
+ | HappyAbsSyn49 ([ParDef])
+ | HappyAbsSyn50 ([PrintDef])
+ | HappyAbsSyn51 ([FlagDef])
+ | HappyAbsSyn52 ([ParConstr])
+ | HappyAbsSyn53 ([PIdent])
+ | HappyAbsSyn54 (Name)
+ | HappyAbsSyn55 ([Name])
+ | HappyAbsSyn56 (LocDef)
+ | HappyAbsSyn57 ([LocDef])
+ | HappyAbsSyn58 (Exp)
+ | HappyAbsSyn65 ([Exp])
+ | HappyAbsSyn66 (Exps)
+ | HappyAbsSyn67 (Patt)
+ | HappyAbsSyn70 (PattAss)
+ | HappyAbsSyn71 (Label)
+ | HappyAbsSyn72 (Sort)
+ | HappyAbsSyn73 ([PattAss])
+ | HappyAbsSyn74 ([Patt])
+ | HappyAbsSyn75 (Bind)
+ | HappyAbsSyn76 ([Bind])
+ | HappyAbsSyn77 (Decl)
+ | HappyAbsSyn78 (TupleComp)
+ | HappyAbsSyn79 (PattTupleComp)
+ | HappyAbsSyn80 ([TupleComp])
+ | HappyAbsSyn81 ([PattTupleComp])
+ | HappyAbsSyn82 (Case)
+ | HappyAbsSyn83 ([Case])
+ | HappyAbsSyn84 (Equation)
+ | HappyAbsSyn85 ([Equation])
+ | HappyAbsSyn86 (Altern)
+ | HappyAbsSyn87 ([Altern])
+ | HappyAbsSyn88 (DDecl)
+ | HappyAbsSyn89 ([DDecl])
+ | HappyAbsSyn90 (OldGrammar)
+ | HappyAbsSyn91 (Include)
+ | HappyAbsSyn92 (FileName)
+ | HappyAbsSyn93 ([FileName])
+
+type HappyReduction m =
+ Int#
+ -> (Token)
+ -> HappyState (Token) (HappyStk HappyAbsSyn -> [(Token)] -> m HappyAbsSyn)
+ -> [HappyState (Token) (HappyStk HappyAbsSyn -> [(Token)] -> m HappyAbsSyn)]
+ -> HappyStk HappyAbsSyn
+ -> [(Token)] -> m HappyAbsSyn
+
+action_0,
+ action_1,
+ action_2,
+ action_3,
+ action_4,
+ action_5,
+ action_6,
+ action_7,
+ action_8,
+ action_9,
+ action_10,
+ action_11,
+ action_12,
+ action_13,
+ action_14,
+ action_15,
+ action_16,
+ action_17,
+ action_18,
+ action_19,
+ action_20,
+ action_21,
+ action_22,
+ action_23,
+ action_24,
+ action_25,
+ action_26,
+ action_27,
+ action_28,
+ action_29,
+ action_30,
+ action_31,
+ action_32,
+ action_33,
+ action_34,
+ action_35,
+ action_36,
+ action_37,
+ action_38,
+ action_39,
+ action_40,
+ action_41,
+ action_42,
+ action_43,
+ action_44,
+ action_45,
+ action_46,
+ action_47,
+ action_48,
+ action_49,
+ action_50,
+ action_51,
+ action_52,
+ action_53,
+ action_54,
+ action_55,
+ action_56,
+ action_57,
+ action_58,
+ action_59,
+ action_60,
+ action_61,
+ action_62,
+ action_63,
+ action_64,
+ action_65,
+ action_66,
+ action_67,
+ action_68,
+ action_69,
+ action_70,
+ action_71,
+ action_72,
+ action_73,
+ action_74,
+ action_75,
+ action_76,
+ action_77,
+ action_78,
+ action_79,
+ action_80,
+ action_81,
+ action_82,
+ action_83,
+ action_84,
+ action_85,
+ action_86,
+ action_87,
+ action_88,
+ action_89,
+ action_90,
+ action_91,
+ action_92,
+ action_93,
+ action_94,
+ action_95,
+ action_96,
+ action_97,
+ action_98,
+ action_99,
+ action_100,
+ action_101,
+ action_102,
+ action_103,
+ action_104,
+ action_105,
+ action_106,
+ action_107,
+ action_108,
+ action_109,
+ action_110,
+ action_111,
+ action_112,
+ action_113,
+ action_114,
+ action_115,
+ action_116,
+ action_117,
+ action_118,
+ action_119,
+ action_120,
+ action_121,
+ action_122,
+ action_123,
+ action_124,
+ action_125,
+ action_126,
+ action_127,
+ action_128,
+ action_129,
+ action_130,
+ action_131,
+ action_132,
+ action_133,
+ action_134,
+ action_135,
+ action_136,
+ action_137,
+ action_138,
+ action_139,
+ action_140,
+ action_141,
+ action_142,
+ action_143,
+ action_144,
+ action_145,
+ action_146,
+ action_147,
+ action_148,
+ action_149,
+ action_150,
+ action_151,
+ action_152,
+ action_153,
+ action_154,
+ action_155,
+ action_156,
+ action_157,
+ action_158,
+ action_159,
+ action_160,
+ action_161,
+ action_162,
+ action_163,
+ action_164,
+ action_165,
+ action_166,
+ action_167,
+ action_168,
+ action_169,
+ action_170,
+ action_171,
+ action_172,
+ action_173,
+ action_174,
+ action_175,
+ action_176,
+ action_177,
+ action_178,
+ action_179,
+ action_180,
+ action_181,
+ action_182,
+ action_183,
+ action_184,
+ action_185,
+ action_186,
+ action_187,
+ action_188,
+ action_189,
+ action_190,
+ action_191,
+ action_192,
+ action_193,
+ action_194,
+ action_195,
+ action_196,
+ action_197,
+ action_198,
+ action_199,
+ action_200,
+ action_201,
+ action_202,
+ action_203,
+ action_204,
+ action_205,
+ action_206,
+ action_207,
+ action_208,
+ action_209,
+ action_210,
+ action_211,
+ action_212,
+ action_213,
+ action_214,
+ action_215,
+ action_216,
+ action_217,
+ action_218,
+ action_219,
+ action_220,
+ action_221,
+ action_222,
+ action_223,
+ action_224,
+ action_225,
+ action_226,
+ action_227,
+ action_228,
+ action_229,
+ action_230,
+ action_231,
+ action_232,
+ action_233,
+ action_234,
+ action_235,
+ action_236,
+ action_237,
+ action_238,
+ action_239,
+ action_240,
+ action_241,
+ action_242,
+ action_243,
+ action_244,
+ action_245,
+ action_246,
+ action_247,
+ action_248,
+ action_249,
+ action_250,
+ action_251,
+ action_252,
+ action_253,
+ action_254,
+ action_255,
+ action_256,
+ action_257,
+ action_258,
+ action_259,
+ action_260,
+ action_261,
+ action_262,
+ action_263,
+ action_264,
+ action_265,
+ action_266,
+ action_267,
+ action_268,
+ action_269,
+ action_270,
+ action_271,
+ action_272,
+ action_273,
+ action_274,
+ action_275,
+ action_276,
+ action_277,
+ action_278,
+ action_279,
+ action_280,
+ action_281,
+ action_282,
+ action_283,
+ action_284,
+ action_285,
+ action_286,
+ action_287,
+ action_288,
+ action_289,
+ action_290,
+ action_291,
+ action_292,
+ action_293,
+ action_294,
+ action_295,
+ action_296,
+ action_297,
+ action_298,
+ action_299,
+ action_300,
+ action_301,
+ action_302,
+ action_303,
+ action_304,
+ action_305,
+ action_306,
+ action_307,
+ action_308,
+ action_309,
+ action_310,
+ action_311,
+ action_312,
+ action_313,
+ action_314,
+ action_315,
+ action_316,
+ action_317,
+ action_318,
+ action_319,
+ action_320,
+ action_321,
+ action_322,
+ action_323,
+ action_324,
+ action_325,
+ action_326,
+ action_327,
+ action_328,
+ action_329,
+ action_330,
+ action_331,
+ action_332,
+ action_333,
+ action_334,
+ action_335,
+ action_336,
+ action_337,
+ action_338,
+ action_339,
+ action_340,
+ action_341,
+ action_342,
+ action_343,
+ action_344,
+ action_345,
+ action_346,
+ action_347,
+ action_348,
+ action_349,
+ action_350,
+ action_351,
+ action_352,
+ action_353,
+ action_354,
+ action_355,
+ action_356,
+ action_357,
+ action_358,
+ action_359,
+ action_360,
+ action_361,
+ action_362,
+ action_363,
+ action_364,
+ action_365,
+ action_366,
+ action_367,
+ action_368,
+ action_369,
+ action_370,
+ action_371,
+ action_372,
+ action_373,
+ action_374,
+ action_375,
+ action_376,
+ action_377,
+ action_378,
+ action_379,
+ action_380,
+ action_381,
+ action_382,
+ action_383,
+ action_384,
+ action_385,
+ action_386,
+ action_387,
+ action_388,
+ action_389,
+ action_390,
+ action_391,
+ action_392,
+ action_393,
+ action_394,
+ action_395,
+ action_396,
+ action_397,
+ action_398,
+ action_399,
+ action_400,
+ action_401,
+ action_402,
+ action_403,
+ action_404,
+ action_405,
+ action_406,
+ action_407,
+ action_408,
+ action_409,
+ action_410,
+ action_411,
+ action_412,
+ action_413,
+ action_414,
+ action_415,
+ action_416,
+ action_417,
+ action_418,
+ action_419,
+ action_420,
+ action_421,
+ action_422,
+ action_423,
+ action_424,
+ action_425,
+ action_426,
+ action_427,
+ action_428,
+ action_429,
+ action_430,
+ action_431,
+ action_432,
+ action_433,
+ action_434,
+ action_435,
+ action_436,
+ action_437,
+ action_438,
+ action_439,
+ action_440,
+ action_441,
+ action_442,
+ action_443,
+ action_444,
+ action_445,
+ action_446,
+ action_447,
+ action_448,
+ action_449,
+ action_450,
+ action_451,
+ action_452,
+ action_453,
+ action_454,
+ action_455,
+ action_456,
+ action_457,
+ action_458,
+ action_459,
+ action_460,
+ action_461,
+ action_462,
+ action_463,
+ action_464,
+ action_465,
+ action_466,
+ action_467,
+ action_468,
+ action_469,
+ action_470,
+ action_471,
+ action_472,
+ action_473,
+ action_474,
+ action_475,
+ action_476,
+ action_477,
+ action_478,
+ action_479,
+ action_480,
+ action_481,
+ action_482,
+ action_483,
+ action_484,
+ action_485,
+ action_486,
+ action_487,
+ action_488,
+ action_489,
+ action_490,
+ action_491,
+ action_492,
+ action_493,
+ action_494,
+ action_495,
+ action_496,
+ action_497,
+ action_498,
+ action_499,
+ action_500,
+ action_501,
+ action_502,
+ action_503,
+ action_504,
+ action_505,
+ action_506,
+ action_507,
+ action_508,
+ action_509,
+ action_510,
+ action_511,
+ action_512,
+ action_513,
+ action_514,
+ action_515,
+ action_516,
+ action_517,
+ action_518,
+ action_519,
+ action_520,
+ action_521,
+ action_522,
+ action_523,
+ action_524,
+ action_525,
+ action_526,
+ action_527,
+ action_528,
+ action_529,
+ action_530,
+ action_531,
+ action_532,
+ action_533,
+ action_534,
+ action_535,
+ action_536,
+ action_537,
+ action_538,
+ action_539,
+ action_540,
+ action_541,
+ action_542,
+ action_543,
+ action_544,
+ action_545,
+ action_546,
+ action_547 :: () => Int# -> HappyReduction (Err)
+
+happyReduce_5,
+ happyReduce_6,
+ happyReduce_7,
+ happyReduce_8,
+ happyReduce_9,
+ happyReduce_10,
+ happyReduce_11,
+ happyReduce_12,
+ happyReduce_13,
+ happyReduce_14,
+ happyReduce_15,
+ happyReduce_16,
+ happyReduce_17,
+ happyReduce_18,
+ happyReduce_19,
+ happyReduce_20,
+ happyReduce_21,
+ happyReduce_22,
+ happyReduce_23,
+ happyReduce_24,
+ happyReduce_25,
+ happyReduce_26,
+ happyReduce_27,
+ happyReduce_28,
+ happyReduce_29,
+ happyReduce_30,
+ happyReduce_31,
+ happyReduce_32,
+ happyReduce_33,
+ happyReduce_34,
+ happyReduce_35,
+ happyReduce_36,
+ happyReduce_37,
+ happyReduce_38,
+ happyReduce_39,
+ happyReduce_40,
+ happyReduce_41,
+ happyReduce_42,
+ happyReduce_43,
+ happyReduce_44,
+ happyReduce_45,
+ happyReduce_46,
+ happyReduce_47,
+ happyReduce_48,
+ happyReduce_49,
+ happyReduce_50,
+ happyReduce_51,
+ happyReduce_52,
+ happyReduce_53,
+ happyReduce_54,
+ happyReduce_55,
+ happyReduce_56,
+ happyReduce_57,
+ happyReduce_58,
+ happyReduce_59,
+ happyReduce_60,
+ happyReduce_61,
+ happyReduce_62,
+ happyReduce_63,
+ happyReduce_64,
+ happyReduce_65,
+ happyReduce_66,
+ happyReduce_67,
+ happyReduce_68,
+ happyReduce_69,
+ happyReduce_70,
+ happyReduce_71,
+ happyReduce_72,
+ happyReduce_73,
+ happyReduce_74,
+ happyReduce_75,
+ happyReduce_76,
+ happyReduce_77,
+ happyReduce_78,
+ happyReduce_79,
+ happyReduce_80,
+ happyReduce_81,
+ happyReduce_82,
+ happyReduce_83,
+ happyReduce_84,
+ happyReduce_85,
+ happyReduce_86,
+ happyReduce_87,
+ happyReduce_88,
+ happyReduce_89,
+ happyReduce_90,
+ happyReduce_91,
+ happyReduce_92,
+ happyReduce_93,
+ happyReduce_94,
+ happyReduce_95,
+ happyReduce_96,
+ happyReduce_97,
+ happyReduce_98,
+ happyReduce_99,
+ happyReduce_100,
+ happyReduce_101,
+ happyReduce_102,
+ happyReduce_103,
+ happyReduce_104,
+ happyReduce_105,
+ happyReduce_106,
+ happyReduce_107,
+ happyReduce_108,
+ happyReduce_109,
+ happyReduce_110,
+ happyReduce_111,
+ happyReduce_112,
+ happyReduce_113,
+ happyReduce_114,
+ happyReduce_115,
+ happyReduce_116,
+ happyReduce_117,
+ happyReduce_118,
+ happyReduce_119,
+ happyReduce_120,
+ happyReduce_121,
+ happyReduce_122,
+ happyReduce_123,
+ happyReduce_124,
+ happyReduce_125,
+ happyReduce_126,
+ happyReduce_127,
+ happyReduce_128,
+ happyReduce_129,
+ happyReduce_130,
+ happyReduce_131,
+ happyReduce_132,
+ happyReduce_133,
+ happyReduce_134,
+ happyReduce_135,
+ happyReduce_136,
+ happyReduce_137,
+ happyReduce_138,
+ happyReduce_139,
+ happyReduce_140,
+ happyReduce_141,
+ happyReduce_142,
+ happyReduce_143,
+ happyReduce_144,
+ happyReduce_145,
+ happyReduce_146,
+ happyReduce_147,
+ happyReduce_148,
+ happyReduce_149,
+ happyReduce_150,
+ happyReduce_151,
+ happyReduce_152,
+ happyReduce_153,
+ happyReduce_154,
+ happyReduce_155,
+ happyReduce_156,
+ happyReduce_157,
+ happyReduce_158,
+ happyReduce_159,
+ happyReduce_160,
+ happyReduce_161,
+ happyReduce_162,
+ happyReduce_163,
+ happyReduce_164,
+ happyReduce_165,
+ happyReduce_166,
+ happyReduce_167,
+ happyReduce_168,
+ happyReduce_169,
+ happyReduce_170,
+ happyReduce_171,
+ happyReduce_172,
+ happyReduce_173,
+ happyReduce_174,
+ happyReduce_175,
+ happyReduce_176,
+ happyReduce_177,
+ happyReduce_178,
+ happyReduce_179,
+ happyReduce_180,
+ happyReduce_181,
+ happyReduce_182,
+ happyReduce_183,
+ happyReduce_184,
+ happyReduce_185,
+ happyReduce_186,
+ happyReduce_187,
+ happyReduce_188,
+ happyReduce_189,
+ happyReduce_190,
+ happyReduce_191,
+ happyReduce_192,
+ happyReduce_193,
+ happyReduce_194,
+ happyReduce_195,
+ happyReduce_196,
+ happyReduce_197,
+ happyReduce_198,
+ happyReduce_199,
+ happyReduce_200,
+ happyReduce_201,
+ happyReduce_202,
+ happyReduce_203,
+ happyReduce_204,
+ happyReduce_205,
+ happyReduce_206,
+ happyReduce_207,
+ happyReduce_208,
+ happyReduce_209,
+ happyReduce_210,
+ happyReduce_211,
+ happyReduce_212,
+ happyReduce_213,
+ happyReduce_214,
+ happyReduce_215,
+ happyReduce_216,
+ happyReduce_217,
+ happyReduce_218,
+ happyReduce_219,
+ happyReduce_220,
+ happyReduce_221,
+ happyReduce_222,
+ happyReduce_223,
+ happyReduce_224,
+ happyReduce_225,
+ happyReduce_226,
+ happyReduce_227,
+ happyReduce_228,
+ happyReduce_229,
+ happyReduce_230,
+ happyReduce_231,
+ happyReduce_232,
+ happyReduce_233,
+ happyReduce_234,
+ happyReduce_235,
+ happyReduce_236,
+ happyReduce_237,
+ happyReduce_238,
+ happyReduce_239,
+ happyReduce_240,
+ happyReduce_241,
+ happyReduce_242,
+ happyReduce_243,
+ happyReduce_244,
+ happyReduce_245,
+ happyReduce_246,
+ happyReduce_247,
+ happyReduce_248,
+ happyReduce_249,
+ happyReduce_250,
+ happyReduce_251,
+ happyReduce_252,
+ happyReduce_253,
+ happyReduce_254,
+ happyReduce_255,
+ happyReduce_256,
+ happyReduce_257,
+ happyReduce_258,
+ happyReduce_259,
+ happyReduce_260,
+ happyReduce_261,
+ happyReduce_262,
+ happyReduce_263,
+ happyReduce_264,
+ happyReduce_265,
+ happyReduce_266,
+ happyReduce_267,
+ happyReduce_268,
+ happyReduce_269,
+ happyReduce_270,
+ happyReduce_271,
+ happyReduce_272,
+ happyReduce_273,
+ happyReduce_274 :: () => HappyReduction (Err)
+
+action_0 (13#) = happyGoto action_58
+action_0 (14#) = happyGoto action_59
+action_0 x = happyTcHack x happyReduce_11
+
+action_1 (139#) = happyShift action_57
+action_1 (142#) = happyShift action_9
+action_1 (15#) = happyGoto action_55
+action_1 (30#) = happyGoto action_56
+action_1 x = happyTcHack x happyReduce_60
+
+action_2 (141#) = happyShift action_54
+action_2 (90#) = happyGoto action_52
+action_2 (91#) = happyGoto action_53
+action_2 x = happyTcHack x happyReduce_265
+
+action_3 (96#) = happyShift action_24
+action_3 (98#) = happyShift action_25
+action_3 (104#) = happyShift action_26
+action_3 (109#) = happyShift action_27
+action_3 (110#) = happyShift action_28
+action_3 (111#) = happyShift action_29
+action_3 (114#) = happyShift action_30
+action_3 (119#) = happyShift action_31
+action_3 (124#) = happyShift action_32
+action_3 (125#) = happyShift action_33
+action_3 (126#) = happyShift action_34
+action_3 (127#) = happyShift action_35
+action_3 (128#) = happyShift action_36
+action_3 (129#) = happyShift action_37
+action_3 (131#) = happyShift action_38
+action_3 (134#) = happyShift action_39
+action_3 (137#) = happyShift action_40
+action_3 (140#) = happyShift action_41
+action_3 (145#) = happyShift action_42
+action_3 (156#) = happyShift action_43
+action_3 (157#) = happyShift action_44
+action_3 (161#) = happyShift action_45
+action_3 (162#) = happyShift action_46
+action_3 (167#) = happyShift action_47
+action_3 (170#) = happyShift action_6
+action_3 (171#) = happyShift action_48
+action_3 (172#) = happyShift action_49
+action_3 (173#) = happyShift action_50
+action_3 (174#) = happyShift action_51
+action_3 (8#) = happyGoto action_10
+action_3 (9#) = happyGoto action_11
+action_3 (10#) = happyGoto action_12
+action_3 (11#) = happyGoto action_13
+action_3 (12#) = happyGoto action_14
+action_3 (58#) = happyGoto action_15
+action_3 (59#) = happyGoto action_16
+action_3 (60#) = happyGoto action_17
+action_3 (61#) = happyGoto action_18
+action_3 (62#) = happyGoto action_19
+action_3 (63#) = happyGoto action_20
+action_3 (64#) = happyGoto action_21
+action_3 (72#) = happyGoto action_22
+action_3 (77#) = happyGoto action_23
+action_3 x = happyTcHack x happyFail
+
+action_4 (142#) = happyShift action_9
+action_4 (21#) = happyGoto action_7
+action_4 (30#) = happyGoto action_8
+action_4 x = happyTcHack x happyReduce_60
+
+action_5 (170#) = happyShift action_6
+action_5 x = happyTcHack x happyFail
+
+action_6 x = happyTcHack x happyReduce_5
+
+action_7 (1#) = happyAccept
+action_7 x = happyTcHack x happyFail
+
+action_8 (130#) = happyShift action_63
+action_8 (133#) = happyShift action_64
+action_8 (143#) = happyShift action_65
+action_8 (144#) = happyShift action_66
+action_8 (159#) = happyShift action_67
+action_8 (164#) = happyShift action_68
+action_8 (23#) = happyGoto action_137
+action_8 x = happyTcHack x happyFail
+
+action_9 x = happyTcHack x happyReduce_61
+
+action_10 x = happyTcHack x happyReduce_145
+
+action_11 x = happyTcHack x happyReduce_144
+
+action_12 x = happyTcHack x happyReduce_146
+
+action_13 x = happyTcHack x happyReduce_157
+
+action_14 (113#) = happyShift action_136
+action_14 x = happyTcHack x happyReduce_140
+
+action_15 x = happyTcHack x happyReduce_161
+
+action_16 (107#) = happyShift action_135
+action_16 x = happyTcHack x happyReduce_173
+
+action_17 (96#) = happyShift action_24
+action_17 (98#) = happyShift action_82
+action_17 (101#) = happyReduce_240
+action_17 (104#) = happyShift action_26
+action_17 (109#) = happyShift action_27
+action_17 (110#) = happyShift action_28
+action_17 (111#) = happyShift action_29
+action_17 (125#) = happyShift action_33
+action_17 (126#) = happyShift action_34
+action_17 (127#) = happyShift action_35
+action_17 (128#) = happyShift action_36
+action_17 (129#) = happyShift action_37
+action_17 (134#) = happyShift action_39
+action_17 (170#) = happyShift action_6
+action_17 (171#) = happyShift action_48
+action_17 (172#) = happyShift action_49
+action_17 (173#) = happyShift action_50
+action_17 (174#) = happyShift action_51
+action_17 (8#) = happyGoto action_10
+action_17 (9#) = happyGoto action_11
+action_17 (10#) = happyGoto action_12
+action_17 (11#) = happyGoto action_13
+action_17 (12#) = happyGoto action_79
+action_17 (58#) = happyGoto action_15
+action_17 (59#) = happyGoto action_134
+action_17 (72#) = happyGoto action_22
+action_17 x = happyTcHack x happyReduce_178
+
+action_18 (102#) = happyShift action_129
+action_18 (115#) = happyShift action_130
+action_18 (116#) = happyShift action_131
+action_18 (120#) = happyShift action_132
+action_18 (168#) = happyShift action_133
+action_18 x = happyTcHack x happyReduce_192
+
+action_19 (118#) = happyShift action_128
+action_19 x = happyTcHack x happyReduce_191
+
+action_20 (176#) = happyAccept
+action_20 x = happyTcHack x happyFail
+
+action_21 (117#) = happyShift action_127
+action_21 x = happyTcHack x happyReduce_180
+
+action_22 x = happyTcHack x happyReduce_143
+
+action_23 (101#) = happyShift action_126
+action_23 x = happyTcHack x happyFail
+
+action_24 (174#) = happyShift action_51
+action_24 (12#) = happyGoto action_124
+action_24 (53#) = happyGoto action_88
+action_24 (56#) = happyGoto action_89
+action_24 (57#) = happyGoto action_125
+action_24 x = happyTcHack x happyReduce_137
+
+action_25 (96#) = happyShift action_24
+action_25 (98#) = happyShift action_25
+action_25 (104#) = happyShift action_26
+action_25 (109#) = happyShift action_27
+action_25 (110#) = happyShift action_28
+action_25 (111#) = happyShift action_29
+action_25 (114#) = happyShift action_30
+action_25 (119#) = happyShift action_31
+action_25 (121#) = happyShift action_100
+action_25 (124#) = happyShift action_32
+action_25 (125#) = happyShift action_33
+action_25 (126#) = happyShift action_34
+action_25 (127#) = happyShift action_35
+action_25 (128#) = happyShift action_36
+action_25 (129#) = happyShift action_37
+action_25 (131#) = happyShift action_38
+action_25 (134#) = happyShift action_39
+action_25 (137#) = happyShift action_40
+action_25 (140#) = happyShift action_123
+action_25 (145#) = happyShift action_42
+action_25 (156#) = happyShift action_43
+action_25 (157#) = happyShift action_44
+action_25 (161#) = happyShift action_45
+action_25 (162#) = happyShift action_46
+action_25 (167#) = happyShift action_47
+action_25 (170#) = happyShift action_6
+action_25 (171#) = happyShift action_48
+action_25 (172#) = happyShift action_49
+action_25 (173#) = happyShift action_50
+action_25 (174#) = happyShift action_51
+action_25 (8#) = happyGoto action_10
+action_25 (9#) = happyGoto action_11
+action_25 (10#) = happyGoto action_12
+action_25 (11#) = happyGoto action_13
+action_25 (12#) = happyGoto action_120
+action_25 (58#) = happyGoto action_15
+action_25 (59#) = happyGoto action_16
+action_25 (60#) = happyGoto action_17
+action_25 (61#) = happyGoto action_18
+action_25 (62#) = happyGoto action_19
+action_25 (63#) = happyGoto action_121
+action_25 (64#) = happyGoto action_21
+action_25 (72#) = happyGoto action_22
+action_25 (75#) = happyGoto action_97
+action_25 (76#) = happyGoto action_122
+action_25 (77#) = happyGoto action_23
+action_25 x = happyTcHack x happyReduce_236
+
+action_26 (105#) = happyShift action_119
+action_26 (171#) = happyShift action_48
+action_26 (174#) = happyShift action_51
+action_26 (9#) = happyGoto action_117
+action_26 (12#) = happyGoto action_118
+action_26 x = happyTcHack x happyFail
+
+action_27 (174#) = happyShift action_51
+action_27 (12#) = happyGoto action_116
+action_27 x = happyTcHack x happyFail
+
+action_28 x = happyTcHack x happyReduce_147
+
+action_29 (96#) = happyShift action_24
+action_29 (98#) = happyShift action_25
+action_29 (104#) = happyShift action_26
+action_29 (109#) = happyShift action_27
+action_29 (110#) = happyShift action_28
+action_29 (111#) = happyShift action_29
+action_29 (114#) = happyShift action_30
+action_29 (119#) = happyShift action_31
+action_29 (124#) = happyShift action_32
+action_29 (125#) = happyShift action_33
+action_29 (126#) = happyShift action_34
+action_29 (127#) = happyShift action_35
+action_29 (128#) = happyShift action_36
+action_29 (129#) = happyShift action_37
+action_29 (131#) = happyShift action_38
+action_29 (134#) = happyShift action_39
+action_29 (137#) = happyShift action_40
+action_29 (140#) = happyShift action_41
+action_29 (145#) = happyShift action_42
+action_29 (156#) = happyShift action_43
+action_29 (157#) = happyShift action_44
+action_29 (161#) = happyShift action_45
+action_29 (162#) = happyShift action_46
+action_29 (167#) = happyShift action_47
+action_29 (170#) = happyShift action_6
+action_29 (171#) = happyShift action_48
+action_29 (172#) = happyShift action_49
+action_29 (173#) = happyShift action_50
+action_29 (174#) = happyShift action_51
+action_29 (8#) = happyGoto action_10
+action_29 (9#) = happyGoto action_11
+action_29 (10#) = happyGoto action_12
+action_29 (11#) = happyGoto action_13
+action_29 (12#) = happyGoto action_14
+action_29 (58#) = happyGoto action_15
+action_29 (59#) = happyGoto action_16
+action_29 (60#) = happyGoto action_17
+action_29 (61#) = happyGoto action_18
+action_29 (62#) = happyGoto action_19
+action_29 (63#) = happyGoto action_113
+action_29 (64#) = happyGoto action_21
+action_29 (72#) = happyGoto action_22
+action_29 (77#) = happyGoto action_23
+action_29 (78#) = happyGoto action_114
+action_29 (80#) = happyGoto action_115
+action_29 x = happyTcHack x happyReduce_243
+
+action_30 (96#) = happyShift action_106
+action_30 (98#) = happyShift action_107
+action_30 (104#) = happyShift action_108
+action_30 (110#) = happyShift action_109
+action_30 (111#) = happyShift action_110
+action_30 (114#) = happyShift action_111
+action_30 (121#) = happyShift action_112
+action_30 (170#) = happyShift action_6
+action_30 (171#) = happyShift action_48
+action_30 (172#) = happyShift action_49
+action_30 (174#) = happyShift action_51
+action_30 (8#) = happyGoto action_101
+action_30 (9#) = happyGoto action_102
+action_30 (10#) = happyGoto action_103
+action_30 (12#) = happyGoto action_104
+action_30 (67#) = happyGoto action_105
+action_30 x = happyTcHack x happyFail
+
+action_31 (119#) = happyShift action_99
+action_31 (121#) = happyShift action_100
+action_31 (174#) = happyShift action_51
+action_31 (12#) = happyGoto action_96
+action_31 (75#) = happyGoto action_97
+action_31 (76#) = happyGoto action_98
+action_31 x = happyTcHack x happyReduce_236
+
+action_32 (174#) = happyShift action_51
+action_32 (12#) = happyGoto action_95
+action_32 x = happyTcHack x happyFail
+
+action_33 x = happyTcHack x happyReduce_225
+
+action_34 x = happyTcHack x happyReduce_227
+
+action_35 x = happyTcHack x happyReduce_228
+
+action_36 x = happyTcHack x happyReduce_226
+
+action_37 x = happyTcHack x happyReduce_224
+
+action_38 (96#) = happyShift action_24
+action_38 (98#) = happyShift action_25
+action_38 (104#) = happyShift action_26
+action_38 (109#) = happyShift action_27
+action_38 (110#) = happyShift action_28
+action_38 (111#) = happyShift action_29
+action_38 (114#) = happyShift action_30
+action_38 (119#) = happyShift action_31
+action_38 (124#) = happyShift action_32
+action_38 (125#) = happyShift action_33
+action_38 (126#) = happyShift action_34
+action_38 (127#) = happyShift action_35
+action_38 (128#) = happyShift action_36
+action_38 (129#) = happyShift action_37
+action_38 (131#) = happyShift action_38
+action_38 (134#) = happyShift action_39
+action_38 (137#) = happyShift action_40
+action_38 (140#) = happyShift action_41
+action_38 (145#) = happyShift action_42
+action_38 (156#) = happyShift action_43
+action_38 (157#) = happyShift action_44
+action_38 (161#) = happyShift action_45
+action_38 (162#) = happyShift action_46
+action_38 (167#) = happyShift action_47
+action_38 (170#) = happyShift action_6
+action_38 (171#) = happyShift action_48
+action_38 (172#) = happyShift action_49
+action_38 (173#) = happyShift action_50
+action_38 (174#) = happyShift action_51
+action_38 (8#) = happyGoto action_10
+action_38 (9#) = happyGoto action_11
+action_38 (10#) = happyGoto action_12
+action_38 (11#) = happyGoto action_13
+action_38 (12#) = happyGoto action_14
+action_38 (58#) = happyGoto action_15
+action_38 (59#) = happyGoto action_16
+action_38 (60#) = happyGoto action_17
+action_38 (61#) = happyGoto action_18
+action_38 (62#) = happyGoto action_19
+action_38 (63#) = happyGoto action_94
+action_38 (64#) = happyGoto action_21
+action_38 (72#) = happyGoto action_22
+action_38 (77#) = happyGoto action_23
+action_38 x = happyTcHack x happyFail
+
+action_39 x = happyTcHack x happyReduce_149
+
+action_40 (96#) = happyShift action_93
+action_40 x = happyTcHack x happyFail
+
+action_41 (96#) = happyShift action_24
+action_41 (98#) = happyShift action_82
+action_41 (104#) = happyShift action_26
+action_41 (109#) = happyShift action_27
+action_41 (110#) = happyShift action_28
+action_41 (111#) = happyShift action_29
+action_41 (125#) = happyShift action_33
+action_41 (126#) = happyShift action_34
+action_41 (127#) = happyShift action_35
+action_41 (128#) = happyShift action_36
+action_41 (129#) = happyShift action_37
+action_41 (134#) = happyShift action_39
+action_41 (170#) = happyShift action_6
+action_41 (171#) = happyShift action_48
+action_41 (172#) = happyShift action_49
+action_41 (173#) = happyShift action_50
+action_41 (174#) = happyShift action_51
+action_41 (8#) = happyGoto action_10
+action_41 (9#) = happyGoto action_11
+action_41 (10#) = happyGoto action_12
+action_41 (11#) = happyGoto action_13
+action_41 (12#) = happyGoto action_79
+action_41 (58#) = happyGoto action_15
+action_41 (59#) = happyGoto action_92
+action_41 (72#) = happyGoto action_22
+action_41 x = happyTcHack x happyFail
+
+action_42 (96#) = happyShift action_91
+action_42 (174#) = happyShift action_51
+action_42 (12#) = happyGoto action_87
+action_42 (53#) = happyGoto action_88
+action_42 (56#) = happyGoto action_89
+action_42 (57#) = happyGoto action_90
+action_42 x = happyTcHack x happyReduce_137
+
+action_43 (96#) = happyShift action_24
+action_43 (98#) = happyShift action_82
+action_43 (104#) = happyShift action_26
+action_43 (109#) = happyShift action_27
+action_43 (110#) = happyShift action_28
+action_43 (111#) = happyShift action_29
+action_43 (125#) = happyShift action_33
+action_43 (126#) = happyShift action_34
+action_43 (127#) = happyShift action_35
+action_43 (128#) = happyShift action_36
+action_43 (129#) = happyShift action_37
+action_43 (134#) = happyShift action_39
+action_43 (170#) = happyShift action_6
+action_43 (171#) = happyShift action_48
+action_43 (172#) = happyShift action_49
+action_43 (173#) = happyShift action_50
+action_43 (174#) = happyShift action_51
+action_43 (8#) = happyGoto action_10
+action_43 (9#) = happyGoto action_11
+action_43 (10#) = happyGoto action_12
+action_43 (11#) = happyGoto action_13
+action_43 (12#) = happyGoto action_79
+action_43 (58#) = happyGoto action_15
+action_43 (59#) = happyGoto action_86
+action_43 (72#) = happyGoto action_22
+action_43 x = happyTcHack x happyFail
+
+action_44 (96#) = happyShift action_85
+action_44 x = happyTcHack x happyFail
+
+action_45 (96#) = happyShift action_84
+action_45 x = happyTcHack x happyFail
+
+action_46 (96#) = happyShift action_81
+action_46 (98#) = happyShift action_82
+action_46 (104#) = happyShift action_26
+action_46 (109#) = happyShift action_83
+action_46 (110#) = happyShift action_28
+action_46 (111#) = happyShift action_29
+action_46 (125#) = happyShift action_33
+action_46 (126#) = happyShift action_34
+action_46 (127#) = happyShift action_35
+action_46 (128#) = happyShift action_36
+action_46 (129#) = happyShift action_37
+action_46 (134#) = happyShift action_39
+action_46 (170#) = happyShift action_6
+action_46 (171#) = happyShift action_48
+action_46 (172#) = happyShift action_49
+action_46 (173#) = happyShift action_50
+action_46 (174#) = happyShift action_51
+action_46 (8#) = happyGoto action_10
+action_46 (9#) = happyGoto action_11
+action_46 (10#) = happyGoto action_12
+action_46 (11#) = happyGoto action_13
+action_46 (12#) = happyGoto action_79
+action_46 (58#) = happyGoto action_80
+action_46 (72#) = happyGoto action_22
+action_46 x = happyTcHack x happyFail
+
+action_47 (96#) = happyShift action_78
+action_47 x = happyTcHack x happyFail
+
+action_48 x = happyTcHack x happyReduce_6
+
+action_49 x = happyTcHack x happyReduce_7
+
+action_50 x = happyTcHack x happyReduce_8
+
+action_51 x = happyTcHack x happyReduce_9
+
+action_52 (176#) = happyAccept
+action_52 x = happyTcHack x happyFail
+
+action_53 (25#) = happyGoto action_77
+action_53 x = happyTcHack x happyReduce_48
+
+action_54 (106#) = happyShift action_74
+action_54 (107#) = happyShift action_75
+action_54 (123#) = happyShift action_76
+action_54 (171#) = happyShift action_48
+action_54 (174#) = happyShift action_51
+action_54 (9#) = happyGoto action_70
+action_54 (12#) = happyGoto action_71
+action_54 (92#) = happyGoto action_72
+action_54 (93#) = happyGoto action_73
+action_54 x = happyTcHack x happyFail
+
+action_55 (94#) = happyShift action_69
+action_55 (176#) = happyAccept
+action_55 x = happyTcHack x happyFail
+
+action_56 (130#) = happyShift action_63
+action_56 (133#) = happyShift action_64
+action_56 (143#) = happyShift action_65
+action_56 (144#) = happyShift action_66
+action_56 (159#) = happyShift action_67
+action_56 (164#) = happyShift action_68
+action_56 (23#) = happyGoto action_62
+action_56 x = happyTcHack x happyFail
+
+action_57 (174#) = happyShift action_51
+action_57 (12#) = happyGoto action_61
+action_57 x = happyTcHack x happyFail
+
+action_58 (176#) = happyAccept
+action_58 x = happyTcHack x happyFail
+
+action_59 (139#) = happyShift action_57
+action_59 (142#) = happyShift action_9
+action_59 (176#) = happyReduce_10
+action_59 (15#) = happyGoto action_60
+action_59 (30#) = happyGoto action_56
+action_59 x = happyTcHack x happyReduce_60
+
+action_60 (94#) = happyShift action_69
+action_60 x = happyTcHack x happyReduce_12
+
+action_61 (95#) = happyShift action_239
+action_61 x = happyTcHack x happyFail
+
+action_62 (95#) = happyShift action_238
+action_62 x = happyTcHack x happyFail
+
+action_63 (174#) = happyShift action_51
+action_63 (12#) = happyGoto action_237
+action_63 x = happyTcHack x happyFail
+
+action_64 (174#) = happyShift action_51
+action_64 (12#) = happyGoto action_236
+action_64 x = happyTcHack x happyFail
+
+action_65 (174#) = happyShift action_51
+action_65 (12#) = happyGoto action_235
+action_65 x = happyTcHack x happyFail
+
+action_66 (174#) = happyShift action_51
+action_66 (12#) = happyGoto action_234
+action_66 x = happyTcHack x happyFail
+
+action_67 (174#) = happyShift action_51
+action_67 (12#) = happyGoto action_233
+action_67 x = happyTcHack x happyFail
+
+action_68 (174#) = happyShift action_51
+action_68 (12#) = happyGoto action_232
+action_68 x = happyTcHack x happyFail
+
+action_69 x = happyTcHack x happyReduce_13
+
+action_70 x = happyTcHack x happyReduce_267
+
+action_71 (106#) = happyShift action_74
+action_71 (107#) = happyShift action_75
+action_71 (123#) = happyShift action_76
+action_71 (171#) = happyShift action_48
+action_71 (174#) = happyShift action_51
+action_71 (9#) = happyGoto action_70
+action_71 (12#) = happyGoto action_71
+action_71 (92#) = happyGoto action_231
+action_71 x = happyTcHack x happyReduce_268
+
+action_72 (94#) = happyShift action_230
+action_72 x = happyTcHack x happyFail
+
+action_73 x = happyTcHack x happyReduce_266
+
+action_74 (106#) = happyShift action_74
+action_74 (107#) = happyShift action_75
+action_74 (123#) = happyShift action_76
+action_74 (171#) = happyShift action_48
+action_74 (174#) = happyShift action_51
+action_74 (9#) = happyGoto action_70
+action_74 (12#) = happyGoto action_71
+action_74 (92#) = happyGoto action_229
+action_74 x = happyTcHack x happyFail
+
+action_75 (106#) = happyShift action_74
+action_75 (107#) = happyShift action_75
+action_75 (123#) = happyShift action_76
+action_75 (171#) = happyShift action_48
+action_75 (174#) = happyShift action_51
+action_75 (9#) = happyGoto action_70
+action_75 (12#) = happyGoto action_71
+action_75 (92#) = happyGoto action_228
+action_75 x = happyTcHack x happyFail
+
+action_76 (106#) = happyShift action_74
+action_76 (107#) = happyShift action_75
+action_76 (123#) = happyShift action_76
+action_76 (171#) = happyShift action_48
+action_76 (174#) = happyShift action_51
+action_76 (9#) = happyGoto action_70
+action_76 (12#) = happyGoto action_71
+action_76 (92#) = happyGoto action_227
+action_76 x = happyTcHack x happyFail
+
+action_77 (132#) = happyShift action_210
+action_77 (134#) = happyShift action_211
+action_77 (135#) = happyShift action_212
+action_77 (136#) = happyShift action_213
+action_77 (138#) = happyShift action_214
+action_77 (146#) = happyShift action_215
+action_77 (147#) = happyShift action_216
+action_77 (148#) = happyShift action_217
+action_77 (149#) = happyShift action_218
+action_77 (152#) = happyShift action_219
+action_77 (154#) = happyShift action_220
+action_77 (155#) = happyShift action_221
+action_77 (156#) = happyShift action_222
+action_77 (158#) = happyShift action_223
+action_77 (163#) = happyShift action_224
+action_77 (164#) = happyShift action_225
+action_77 (166#) = happyShift action_226
+action_77 (35#) = happyGoto action_209
+action_77 x = happyTcHack x happyReduce_264
+
+action_78 (96#) = happyShift action_24
+action_78 (98#) = happyShift action_25
+action_78 (104#) = happyShift action_26
+action_78 (109#) = happyShift action_27
+action_78 (110#) = happyShift action_28
+action_78 (111#) = happyShift action_29
+action_78 (114#) = happyShift action_30
+action_78 (119#) = happyShift action_31
+action_78 (124#) = happyShift action_32
+action_78 (125#) = happyShift action_33
+action_78 (126#) = happyShift action_34
+action_78 (127#) = happyShift action_35
+action_78 (128#) = happyShift action_36
+action_78 (129#) = happyShift action_37
+action_78 (131#) = happyShift action_38
+action_78 (134#) = happyShift action_39
+action_78 (137#) = happyShift action_40
+action_78 (140#) = happyShift action_41
+action_78 (145#) = happyShift action_42
+action_78 (156#) = happyShift action_43
+action_78 (157#) = happyShift action_44
+action_78 (161#) = happyShift action_45
+action_78 (162#) = happyShift action_46
+action_78 (167#) = happyShift action_47
+action_78 (170#) = happyShift action_6
+action_78 (171#) = happyShift action_48
+action_78 (172#) = happyShift action_49
+action_78 (173#) = happyShift action_50
+action_78 (174#) = happyShift action_51
+action_78 (8#) = happyGoto action_10
+action_78 (9#) = happyGoto action_11
+action_78 (10#) = happyGoto action_12
+action_78 (11#) = happyGoto action_13
+action_78 (12#) = happyGoto action_14
+action_78 (58#) = happyGoto action_15
+action_78 (59#) = happyGoto action_16
+action_78 (60#) = happyGoto action_17
+action_78 (61#) = happyGoto action_18
+action_78 (62#) = happyGoto action_19
+action_78 (63#) = happyGoto action_199
+action_78 (64#) = happyGoto action_21
+action_78 (65#) = happyGoto action_208
+action_78 (72#) = happyGoto action_22
+action_78 (77#) = happyGoto action_23
+action_78 x = happyTcHack x happyReduce_193
+
+action_79 x = happyTcHack x happyReduce_140
+
+action_80 (96#) = happyShift action_206
+action_80 (104#) = happyShift action_207
+action_80 x = happyTcHack x happyFail
+
+action_81 (96#) = happyShift action_106
+action_81 (98#) = happyShift action_107
+action_81 (104#) = happyShift action_108
+action_81 (106#) = happyShift action_176
+action_81 (110#) = happyShift action_109
+action_81 (111#) = happyShift action_110
+action_81 (114#) = happyShift action_111
+action_81 (121#) = happyShift action_112
+action_81 (170#) = happyShift action_6
+action_81 (171#) = happyShift action_48
+action_81 (172#) = happyShift action_49
+action_81 (174#) = happyShift action_51
+action_81 (8#) = happyGoto action_101
+action_81 (9#) = happyGoto action_102
+action_81 (10#) = happyGoto action_103
+action_81 (12#) = happyGoto action_202
+action_81 (53#) = happyGoto action_88
+action_81 (56#) = happyGoto action_89
+action_81 (57#) = happyGoto action_125
+action_81 (67#) = happyGoto action_171
+action_81 (68#) = happyGoto action_172
+action_81 (69#) = happyGoto action_203
+action_81 (82#) = happyGoto action_204
+action_81 (83#) = happyGoto action_205
+action_81 x = happyTcHack x happyReduce_137
+
+action_82 (96#) = happyShift action_24
+action_82 (98#) = happyShift action_25
+action_82 (104#) = happyShift action_26
+action_82 (109#) = happyShift action_27
+action_82 (110#) = happyShift action_28
+action_82 (111#) = happyShift action_29
+action_82 (114#) = happyShift action_30
+action_82 (119#) = happyShift action_31
+action_82 (124#) = happyShift action_32
+action_82 (125#) = happyShift action_33
+action_82 (126#) = happyShift action_34
+action_82 (127#) = happyShift action_35
+action_82 (128#) = happyShift action_36
+action_82 (129#) = happyShift action_37
+action_82 (131#) = happyShift action_38
+action_82 (134#) = happyShift action_39
+action_82 (137#) = happyShift action_40
+action_82 (140#) = happyShift action_123
+action_82 (145#) = happyShift action_42
+action_82 (156#) = happyShift action_43
+action_82 (157#) = happyShift action_44
+action_82 (161#) = happyShift action_45
+action_82 (162#) = happyShift action_46
+action_82 (167#) = happyShift action_47
+action_82 (170#) = happyShift action_6
+action_82 (171#) = happyShift action_48
+action_82 (172#) = happyShift action_49
+action_82 (173#) = happyShift action_50
+action_82 (174#) = happyShift action_51
+action_82 (8#) = happyGoto action_10
+action_82 (9#) = happyGoto action_11
+action_82 (10#) = happyGoto action_12
+action_82 (11#) = happyGoto action_13
+action_82 (12#) = happyGoto action_14
+action_82 (58#) = happyGoto action_15
+action_82 (59#) = happyGoto action_16
+action_82 (60#) = happyGoto action_17
+action_82 (61#) = happyGoto action_18
+action_82 (62#) = happyGoto action_19
+action_82 (63#) = happyGoto action_121
+action_82 (64#) = happyGoto action_21
+action_82 (72#) = happyGoto action_22
+action_82 (77#) = happyGoto action_23
+action_82 x = happyTcHack x happyFail
+
+action_83 (174#) = happyShift action_51
+action_83 (12#) = happyGoto action_201
+action_83 x = happyTcHack x happyFail
+
+action_84 (96#) = happyShift action_24
+action_84 (98#) = happyShift action_25
+action_84 (104#) = happyShift action_26
+action_84 (109#) = happyShift action_27
+action_84 (110#) = happyShift action_28
+action_84 (111#) = happyShift action_29
+action_84 (114#) = happyShift action_30
+action_84 (119#) = happyShift action_31
+action_84 (124#) = happyShift action_32
+action_84 (125#) = happyShift action_33
+action_84 (126#) = happyShift action_34
+action_84 (127#) = happyShift action_35
+action_84 (128#) = happyShift action_36
+action_84 (129#) = happyShift action_37
+action_84 (131#) = happyShift action_38
+action_84 (134#) = happyShift action_39
+action_84 (137#) = happyShift action_40
+action_84 (140#) = happyShift action_41
+action_84 (145#) = happyShift action_42
+action_84 (156#) = happyShift action_43
+action_84 (157#) = happyShift action_44
+action_84 (161#) = happyShift action_45
+action_84 (162#) = happyShift action_46
+action_84 (167#) = happyShift action_47
+action_84 (170#) = happyShift action_6
+action_84 (171#) = happyShift action_48
+action_84 (172#) = happyShift action_49
+action_84 (173#) = happyShift action_50
+action_84 (174#) = happyShift action_51
+action_84 (8#) = happyGoto action_10
+action_84 (9#) = happyGoto action_11
+action_84 (10#) = happyGoto action_12
+action_84 (11#) = happyGoto action_13
+action_84 (12#) = happyGoto action_14
+action_84 (58#) = happyGoto action_15
+action_84 (59#) = happyGoto action_16
+action_84 (60#) = happyGoto action_17
+action_84 (61#) = happyGoto action_18
+action_84 (62#) = happyGoto action_19
+action_84 (63#) = happyGoto action_199
+action_84 (64#) = happyGoto action_21
+action_84 (65#) = happyGoto action_200
+action_84 (72#) = happyGoto action_22
+action_84 (77#) = happyGoto action_23
+action_84 x = happyTcHack x happyReduce_193
+
+action_85 (96#) = happyShift action_24
+action_85 (98#) = happyShift action_25
+action_85 (104#) = happyShift action_26
+action_85 (109#) = happyShift action_27
+action_85 (110#) = happyShift action_28
+action_85 (111#) = happyShift action_29
+action_85 (114#) = happyShift action_30
+action_85 (119#) = happyShift action_31
+action_85 (124#) = happyShift action_32
+action_85 (125#) = happyShift action_33
+action_85 (126#) = happyShift action_34
+action_85 (127#) = happyShift action_35
+action_85 (128#) = happyShift action_36
+action_85 (129#) = happyShift action_37
+action_85 (131#) = happyShift action_38
+action_85 (134#) = happyShift action_39
+action_85 (137#) = happyShift action_40
+action_85 (140#) = happyShift action_41
+action_85 (145#) = happyShift action_42
+action_85 (156#) = happyShift action_43
+action_85 (157#) = happyShift action_44
+action_85 (161#) = happyShift action_45
+action_85 (162#) = happyShift action_46
+action_85 (167#) = happyShift action_47
+action_85 (170#) = happyShift action_6
+action_85 (171#) = happyShift action_48
+action_85 (172#) = happyShift action_49
+action_85 (173#) = happyShift action_50
+action_85 (174#) = happyShift action_51
+action_85 (8#) = happyGoto action_10
+action_85 (9#) = happyGoto action_11
+action_85 (10#) = happyGoto action_12
+action_85 (11#) = happyGoto action_13
+action_85 (12#) = happyGoto action_14
+action_85 (58#) = happyGoto action_15
+action_85 (59#) = happyGoto action_16
+action_85 (60#) = happyGoto action_17
+action_85 (61#) = happyGoto action_18
+action_85 (62#) = happyGoto action_19
+action_85 (63#) = happyGoto action_198
+action_85 (64#) = happyGoto action_21
+action_85 (72#) = happyGoto action_22
+action_85 (77#) = happyGoto action_23
+action_85 x = happyTcHack x happyFail
+
+action_86 (107#) = happyShift action_135
+action_86 x = happyTcHack x happyReduce_172
+
+action_87 (103#) = happyShift action_156
+action_87 x = happyTcHack x happyReduce_128
+
+action_88 (95#) = happyShift action_196
+action_88 (100#) = happyShift action_197
+action_88 x = happyTcHack x happyFail
+
+action_89 (94#) = happyShift action_195
+action_89 x = happyTcHack x happyReduce_138
+
+action_90 (140#) = happyShift action_194
+action_90 x = happyTcHack x happyFail
+
+action_91 (174#) = happyShift action_51
+action_91 (12#) = happyGoto action_87
+action_91 (53#) = happyGoto action_88
+action_91 (56#) = happyGoto action_89
+action_91 (57#) = happyGoto action_193
+action_91 x = happyTcHack x happyReduce_137
+
+action_92 (107#) = happyShift action_135
+action_92 (171#) = happyShift action_48
+action_92 (9#) = happyGoto action_192
+action_92 x = happyTcHack x happyFail
+
+action_93 (96#) = happyShift action_106
+action_93 (98#) = happyShift action_107
+action_93 (104#) = happyShift action_108
+action_93 (110#) = happyShift action_109
+action_93 (111#) = happyShift action_110
+action_93 (114#) = happyShift action_111
+action_93 (121#) = happyShift action_112
+action_93 (170#) = happyShift action_6
+action_93 (171#) = happyShift action_48
+action_93 (172#) = happyShift action_49
+action_93 (174#) = happyShift action_51
+action_93 (8#) = happyGoto action_101
+action_93 (9#) = happyGoto action_102
+action_93 (10#) = happyGoto action_103
+action_93 (12#) = happyGoto action_104
+action_93 (67#) = happyGoto action_188
+action_93 (74#) = happyGoto action_189
+action_93 (84#) = happyGoto action_190
+action_93 (85#) = happyGoto action_191
+action_93 x = happyTcHack x happyReduce_253
+
+action_94 (150#) = happyShift action_187
+action_94 x = happyTcHack x happyFail
+
+action_95 x = happyTcHack x happyReduce_174
+
+action_96 x = happyTcHack x happyReduce_234
+
+action_97 (103#) = happyShift action_186
+action_97 x = happyTcHack x happyReduce_237
+
+action_98 (101#) = happyShift action_185
+action_98 x = happyTcHack x happyFail
+
+action_99 (121#) = happyShift action_100
+action_99 (174#) = happyShift action_51
+action_99 (12#) = happyGoto action_96
+action_99 (75#) = happyGoto action_97
+action_99 (76#) = happyGoto action_184
+action_99 x = happyTcHack x happyReduce_236
+
+action_100 x = happyTcHack x happyReduce_235
+
+action_101 x = happyTcHack x happyReduce_206
+
+action_102 x = happyTcHack x happyReduce_208
+
+action_103 x = happyTcHack x happyReduce_207
+
+action_104 (107#) = happyShift action_183
+action_104 x = happyTcHack x happyReduce_203
+
+action_105 x = happyTcHack x happyReduce_171
+
+action_106 (174#) = happyShift action_51
+action_106 (12#) = happyGoto action_179
+action_106 (53#) = happyGoto action_180
+action_106 (70#) = happyGoto action_181
+action_106 (73#) = happyGoto action_182
+action_106 x = happyTcHack x happyReduce_229
+
+action_107 (96#) = happyShift action_106
+action_107 (98#) = happyShift action_107
+action_107 (104#) = happyShift action_108
+action_107 (106#) = happyShift action_176
+action_107 (110#) = happyShift action_109
+action_107 (111#) = happyShift action_110
+action_107 (114#) = happyShift action_111
+action_107 (121#) = happyShift action_112
+action_107 (170#) = happyShift action_6
+action_107 (171#) = happyShift action_48
+action_107 (172#) = happyShift action_49
+action_107 (174#) = happyShift action_51
+action_107 (8#) = happyGoto action_101
+action_107 (9#) = happyGoto action_102
+action_107 (10#) = happyGoto action_103
+action_107 (12#) = happyGoto action_170
+action_107 (67#) = happyGoto action_171
+action_107 (68#) = happyGoto action_172
+action_107 (69#) = happyGoto action_178
+action_107 x = happyTcHack x happyFail
+
+action_108 (171#) = happyShift action_48
+action_108 (9#) = happyGoto action_177
+action_108 x = happyTcHack x happyFail
+
+action_109 x = happyTcHack x happyReduce_198
+
+action_110 (96#) = happyShift action_106
+action_110 (98#) = happyShift action_107
+action_110 (104#) = happyShift action_108
+action_110 (106#) = happyShift action_176
+action_110 (110#) = happyShift action_109
+action_110 (111#) = happyShift action_110
+action_110 (114#) = happyShift action_111
+action_110 (121#) = happyShift action_112
+action_110 (170#) = happyShift action_6
+action_110 (171#) = happyShift action_48
+action_110 (172#) = happyShift action_49
+action_110 (174#) = happyShift action_51
+action_110 (8#) = happyGoto action_101
+action_110 (9#) = happyGoto action_102
+action_110 (10#) = happyGoto action_103
+action_110 (12#) = happyGoto action_170
+action_110 (67#) = happyGoto action_171
+action_110 (68#) = happyGoto action_172
+action_110 (69#) = happyGoto action_173
+action_110 (79#) = happyGoto action_174
+action_110 (81#) = happyGoto action_175
+action_110 x = happyTcHack x happyReduce_246
+
+action_111 (174#) = happyShift action_51
+action_111 (12#) = happyGoto action_169
+action_111 x = happyTcHack x happyFail
+
+action_112 x = happyTcHack x happyReduce_202
+
+action_113 (100#) = happyShift action_168
+action_113 x = happyTcHack x happyReduce_241
+
+action_114 (103#) = happyShift action_167
+action_114 x = happyTcHack x happyReduce_244
+
+action_115 (112#) = happyShift action_166
+action_115 x = happyTcHack x happyFail
+
+action_116 (107#) = happyShift action_164
+action_116 (109#) = happyShift action_165
+action_116 x = happyTcHack x happyFail
+
+action_117 (105#) = happyShift action_163
+action_117 x = happyTcHack x happyFail
+
+action_118 (96#) = happyShift action_140
+action_118 (98#) = happyShift action_82
+action_118 (104#) = happyShift action_26
+action_118 (109#) = happyShift action_83
+action_118 (110#) = happyShift action_28
+action_118 (111#) = happyShift action_29
+action_118 (125#) = happyShift action_33
+action_118 (126#) = happyShift action_34
+action_118 (127#) = happyShift action_35
+action_118 (128#) = happyShift action_36
+action_118 (129#) = happyShift action_37
+action_118 (134#) = happyShift action_39
+action_118 (170#) = happyShift action_6
+action_118 (171#) = happyShift action_48
+action_118 (172#) = happyShift action_49
+action_118 (173#) = happyShift action_50
+action_118 (174#) = happyShift action_51
+action_118 (8#) = happyGoto action_10
+action_118 (9#) = happyGoto action_11
+action_118 (10#) = happyGoto action_12
+action_118 (11#) = happyGoto action_13
+action_118 (12#) = happyGoto action_79
+action_118 (58#) = happyGoto action_161
+action_118 (66#) = happyGoto action_162
+action_118 (72#) = happyGoto action_22
+action_118 x = happyTcHack x happyReduce_196
+
+action_119 x = happyTcHack x happyReduce_148
+
+action_120 (100#) = happyReduce_234
+action_120 (103#) = happyReduce_234
+action_120 (113#) = happyShift action_136
+action_120 x = happyTcHack x happyReduce_140
+
+action_121 (99#) = happyShift action_160
+action_121 x = happyTcHack x happyFail
+
+action_122 (100#) = happyShift action_159
+action_122 x = happyTcHack x happyFail
+
+action_123 (96#) = happyShift action_24
+action_123 (98#) = happyShift action_82
+action_123 (104#) = happyShift action_26
+action_123 (109#) = happyShift action_27
+action_123 (110#) = happyShift action_28
+action_123 (111#) = happyShift action_29
+action_123 (125#) = happyShift action_33
+action_123 (126#) = happyShift action_34
+action_123 (127#) = happyShift action_35
+action_123 (128#) = happyShift action_36
+action_123 (129#) = happyShift action_37
+action_123 (134#) = happyShift action_39
+action_123 (170#) = happyShift action_6
+action_123 (171#) = happyShift action_48
+action_123 (172#) = happyShift action_49
+action_123 (173#) = happyShift action_50
+action_123 (174#) = happyShift action_51
+action_123 (8#) = happyGoto action_10
+action_123 (9#) = happyGoto action_11
+action_123 (10#) = happyGoto action_12
+action_123 (11#) = happyGoto action_13
+action_123 (12#) = happyGoto action_158
+action_123 (58#) = happyGoto action_15
+action_123 (59#) = happyGoto action_92
+action_123 (72#) = happyGoto action_22
+action_123 x = happyTcHack x happyFail
+
+action_124 (97#) = happyShift action_155
+action_124 (103#) = happyShift action_156
+action_124 (107#) = happyShift action_157
+action_124 x = happyTcHack x happyReduce_128
+
+action_125 (97#) = happyShift action_154
+action_125 x = happyTcHack x happyFail
+
+action_126 (96#) = happyShift action_24
+action_126 (98#) = happyShift action_25
+action_126 (104#) = happyShift action_26
+action_126 (109#) = happyShift action_27
+action_126 (110#) = happyShift action_28
+action_126 (111#) = happyShift action_29
+action_126 (114#) = happyShift action_30
+action_126 (119#) = happyShift action_31
+action_126 (124#) = happyShift action_32
+action_126 (125#) = happyShift action_33
+action_126 (126#) = happyShift action_34
+action_126 (127#) = happyShift action_35
+action_126 (128#) = happyShift action_36
+action_126 (129#) = happyShift action_37
+action_126 (131#) = happyShift action_38
+action_126 (134#) = happyShift action_39
+action_126 (137#) = happyShift action_40
+action_126 (140#) = happyShift action_41
+action_126 (145#) = happyShift action_42
+action_126 (156#) = happyShift action_43
+action_126 (157#) = happyShift action_44
+action_126 (161#) = happyShift action_45
+action_126 (162#) = happyShift action_46
+action_126 (167#) = happyShift action_47
+action_126 (170#) = happyShift action_6
+action_126 (171#) = happyShift action_48
+action_126 (172#) = happyShift action_49
+action_126 (173#) = happyShift action_50
+action_126 (174#) = happyShift action_51
+action_126 (8#) = happyGoto action_10
+action_126 (9#) = happyGoto action_11
+action_126 (10#) = happyGoto action_12
+action_126 (11#) = happyGoto action_13
+action_126 (12#) = happyGoto action_14
+action_126 (58#) = happyGoto action_15
+action_126 (59#) = happyGoto action_16
+action_126 (60#) = happyGoto action_17
+action_126 (61#) = happyGoto action_18
+action_126 (62#) = happyGoto action_19
+action_126 (63#) = happyGoto action_153
+action_126 (64#) = happyGoto action_21
+action_126 (72#) = happyGoto action_22
+action_126 (77#) = happyGoto action_23
+action_126 x = happyTcHack x happyFail
+
+action_127 (96#) = happyShift action_24
+action_127 (98#) = happyShift action_82
+action_127 (104#) = happyShift action_26
+action_127 (109#) = happyShift action_27
+action_127 (110#) = happyShift action_28
+action_127 (111#) = happyShift action_29
+action_127 (114#) = happyShift action_30
+action_127 (124#) = happyShift action_32
+action_127 (125#) = happyShift action_33
+action_127 (126#) = happyShift action_34
+action_127 (127#) = happyShift action_35
+action_127 (128#) = happyShift action_36
+action_127 (129#) = happyShift action_37
+action_127 (131#) = happyShift action_38
+action_127 (134#) = happyShift action_39
+action_127 (156#) = happyShift action_43
+action_127 (157#) = happyShift action_44
+action_127 (161#) = happyShift action_45
+action_127 (162#) = happyShift action_46
+action_127 (167#) = happyShift action_47
+action_127 (170#) = happyShift action_6
+action_127 (171#) = happyShift action_48
+action_127 (172#) = happyShift action_49
+action_127 (173#) = happyShift action_50
+action_127 (174#) = happyShift action_51
+action_127 (8#) = happyGoto action_10
+action_127 (9#) = happyGoto action_11
+action_127 (10#) = happyGoto action_12
+action_127 (11#) = happyGoto action_13
+action_127 (12#) = happyGoto action_14
+action_127 (58#) = happyGoto action_15
+action_127 (59#) = happyGoto action_16
+action_127 (60#) = happyGoto action_150
+action_127 (61#) = happyGoto action_151
+action_127 (62#) = happyGoto action_152
+action_127 (64#) = happyGoto action_21
+action_127 (72#) = happyGoto action_22
+action_127 x = happyTcHack x happyFail
+
+action_128 (96#) = happyShift action_24
+action_128 (98#) = happyShift action_25
+action_128 (104#) = happyShift action_26
+action_128 (109#) = happyShift action_27
+action_128 (110#) = happyShift action_28
+action_128 (111#) = happyShift action_29
+action_128 (114#) = happyShift action_30
+action_128 (119#) = happyShift action_31
+action_128 (124#) = happyShift action_32
+action_128 (125#) = happyShift action_33
+action_128 (126#) = happyShift action_34
+action_128 (127#) = happyShift action_35
+action_128 (128#) = happyShift action_36
+action_128 (129#) = happyShift action_37
+action_128 (131#) = happyShift action_38
+action_128 (134#) = happyShift action_39
+action_128 (137#) = happyShift action_40
+action_128 (140#) = happyShift action_41
+action_128 (145#) = happyShift action_42
+action_128 (156#) = happyShift action_43
+action_128 (157#) = happyShift action_44
+action_128 (161#) = happyShift action_45
+action_128 (162#) = happyShift action_46
+action_128 (167#) = happyShift action_47
+action_128 (170#) = happyShift action_6
+action_128 (171#) = happyShift action_48
+action_128 (172#) = happyShift action_49
+action_128 (173#) = happyShift action_50
+action_128 (174#) = happyShift action_51
+action_128 (8#) = happyGoto action_10
+action_128 (9#) = happyGoto action_11
+action_128 (10#) = happyGoto action_12
+action_128 (11#) = happyGoto action_13
+action_128 (12#) = happyGoto action_14
+action_128 (58#) = happyGoto action_15
+action_128 (59#) = happyGoto action_16
+action_128 (60#) = happyGoto action_17
+action_128 (61#) = happyGoto action_18
+action_128 (62#) = happyGoto action_19
+action_128 (63#) = happyGoto action_149
+action_128 (64#) = happyGoto action_21
+action_128 (72#) = happyGoto action_22
+action_128 (77#) = happyGoto action_23
+action_128 x = happyTcHack x happyFail
+
+action_129 (96#) = happyShift action_24
+action_129 (98#) = happyShift action_82
+action_129 (104#) = happyShift action_26
+action_129 (109#) = happyShift action_27
+action_129 (110#) = happyShift action_28
+action_129 (111#) = happyShift action_29
+action_129 (114#) = happyShift action_30
+action_129 (124#) = happyShift action_32
+action_129 (125#) = happyShift action_33
+action_129 (126#) = happyShift action_34
+action_129 (127#) = happyShift action_35
+action_129 (128#) = happyShift action_36
+action_129 (129#) = happyShift action_37
+action_129 (131#) = happyShift action_38
+action_129 (134#) = happyShift action_39
+action_129 (156#) = happyShift action_43
+action_129 (157#) = happyShift action_44
+action_129 (161#) = happyShift action_45
+action_129 (162#) = happyShift action_46
+action_129 (167#) = happyShift action_47
+action_129 (170#) = happyShift action_6
+action_129 (171#) = happyShift action_48
+action_129 (172#) = happyShift action_49
+action_129 (173#) = happyShift action_50
+action_129 (174#) = happyShift action_51
+action_129 (8#) = happyGoto action_10
+action_129 (9#) = happyGoto action_11
+action_129 (10#) = happyGoto action_12
+action_129 (11#) = happyGoto action_13
+action_129 (12#) = happyGoto action_14
+action_129 (58#) = happyGoto action_15
+action_129 (59#) = happyGoto action_16
+action_129 (60#) = happyGoto action_148
+action_129 (72#) = happyGoto action_22
+action_129 x = happyTcHack x happyFail
+
+action_130 (96#) = happyShift action_24
+action_130 (98#) = happyShift action_82
+action_130 (104#) = happyShift action_26
+action_130 (109#) = happyShift action_27
+action_130 (110#) = happyShift action_28
+action_130 (111#) = happyShift action_29
+action_130 (114#) = happyShift action_30
+action_130 (124#) = happyShift action_32
+action_130 (125#) = happyShift action_33
+action_130 (126#) = happyShift action_34
+action_130 (127#) = happyShift action_35
+action_130 (128#) = happyShift action_36
+action_130 (129#) = happyShift action_37
+action_130 (131#) = happyShift action_38
+action_130 (134#) = happyShift action_39
+action_130 (156#) = happyShift action_43
+action_130 (157#) = happyShift action_44
+action_130 (161#) = happyShift action_45
+action_130 (162#) = happyShift action_46
+action_130 (167#) = happyShift action_47
+action_130 (170#) = happyShift action_6
+action_130 (171#) = happyShift action_48
+action_130 (172#) = happyShift action_49
+action_130 (173#) = happyShift action_50
+action_130 (174#) = happyShift action_51
+action_130 (8#) = happyGoto action_10
+action_130 (9#) = happyGoto action_11
+action_130 (10#) = happyGoto action_12
+action_130 (11#) = happyGoto action_13
+action_130 (12#) = happyGoto action_14
+action_130 (58#) = happyGoto action_15
+action_130 (59#) = happyGoto action_16
+action_130 (60#) = happyGoto action_147
+action_130 (72#) = happyGoto action_22
+action_130 x = happyTcHack x happyFail
+
+action_131 (96#) = happyShift action_24
+action_131 (98#) = happyShift action_82
+action_131 (104#) = happyShift action_26
+action_131 (109#) = happyShift action_27
+action_131 (110#) = happyShift action_28
+action_131 (111#) = happyShift action_29
+action_131 (114#) = happyShift action_30
+action_131 (124#) = happyShift action_32
+action_131 (125#) = happyShift action_33
+action_131 (126#) = happyShift action_34
+action_131 (127#) = happyShift action_35
+action_131 (128#) = happyShift action_36
+action_131 (129#) = happyShift action_37
+action_131 (131#) = happyShift action_38
+action_131 (134#) = happyShift action_39
+action_131 (156#) = happyShift action_43
+action_131 (157#) = happyShift action_44
+action_131 (161#) = happyShift action_45
+action_131 (162#) = happyShift action_46
+action_131 (167#) = happyShift action_47
+action_131 (170#) = happyShift action_6
+action_131 (171#) = happyShift action_48
+action_131 (172#) = happyShift action_49
+action_131 (173#) = happyShift action_50
+action_131 (174#) = happyShift action_51
+action_131 (8#) = happyGoto action_10
+action_131 (9#) = happyGoto action_11
+action_131 (10#) = happyGoto action_12
+action_131 (11#) = happyGoto action_13
+action_131 (12#) = happyGoto action_14
+action_131 (58#) = happyGoto action_15
+action_131 (59#) = happyGoto action_16
+action_131 (60#) = happyGoto action_146
+action_131 (72#) = happyGoto action_22
+action_131 x = happyTcHack x happyFail
+
+action_132 (96#) = happyShift action_24
+action_132 (98#) = happyShift action_25
+action_132 (104#) = happyShift action_26
+action_132 (109#) = happyShift action_27
+action_132 (110#) = happyShift action_28
+action_132 (111#) = happyShift action_29
+action_132 (114#) = happyShift action_30
+action_132 (119#) = happyShift action_31
+action_132 (124#) = happyShift action_32
+action_132 (125#) = happyShift action_33
+action_132 (126#) = happyShift action_34
+action_132 (127#) = happyShift action_35
+action_132 (128#) = happyShift action_36
+action_132 (129#) = happyShift action_37
+action_132 (131#) = happyShift action_38
+action_132 (134#) = happyShift action_39
+action_132 (137#) = happyShift action_40
+action_132 (140#) = happyShift action_41
+action_132 (145#) = happyShift action_42
+action_132 (156#) = happyShift action_43
+action_132 (157#) = happyShift action_44
+action_132 (161#) = happyShift action_45
+action_132 (162#) = happyShift action_46
+action_132 (167#) = happyShift action_47
+action_132 (170#) = happyShift action_6
+action_132 (171#) = happyShift action_48
+action_132 (172#) = happyShift action_49
+action_132 (173#) = happyShift action_50
+action_132 (174#) = happyShift action_51
+action_132 (8#) = happyGoto action_10
+action_132 (9#) = happyGoto action_11
+action_132 (10#) = happyGoto action_12
+action_132 (11#) = happyGoto action_13
+action_132 (12#) = happyGoto action_14
+action_132 (58#) = happyGoto action_15
+action_132 (59#) = happyGoto action_16
+action_132 (60#) = happyGoto action_17
+action_132 (61#) = happyGoto action_18
+action_132 (62#) = happyGoto action_19
+action_132 (63#) = happyGoto action_145
+action_132 (64#) = happyGoto action_21
+action_132 (72#) = happyGoto action_22
+action_132 (77#) = happyGoto action_23
+action_132 x = happyTcHack x happyFail
+
+action_133 (96#) = happyShift action_144
+action_133 x = happyTcHack x happyFail
+
+action_134 (107#) = happyShift action_135
+action_134 x = happyTcHack x happyReduce_162
+
+action_135 (122#) = happyShift action_143
+action_135 (174#) = happyShift action_51
+action_135 (12#) = happyGoto action_141
+action_135 (71#) = happyGoto action_142
+action_135 x = happyTcHack x happyFail
+
+action_136 (96#) = happyShift action_140
+action_136 (98#) = happyShift action_82
+action_136 (104#) = happyShift action_26
+action_136 (109#) = happyShift action_83
+action_136 (110#) = happyShift action_28
+action_136 (111#) = happyShift action_29
+action_136 (125#) = happyShift action_33
+action_136 (126#) = happyShift action_34
+action_136 (127#) = happyShift action_35
+action_136 (128#) = happyShift action_36
+action_136 (129#) = happyShift action_37
+action_136 (134#) = happyShift action_39
+action_136 (170#) = happyShift action_6
+action_136 (171#) = happyShift action_48
+action_136 (172#) = happyShift action_49
+action_136 (173#) = happyShift action_50
+action_136 (174#) = happyShift action_51
+action_136 (8#) = happyGoto action_10
+action_136 (9#) = happyGoto action_11
+action_136 (10#) = happyGoto action_12
+action_136 (11#) = happyGoto action_13
+action_136 (12#) = happyGoto action_79
+action_136 (58#) = happyGoto action_139
+action_136 (72#) = happyGoto action_22
+action_136 x = happyTcHack x happyFail
+
+action_137 (95#) = happyShift action_138
+action_137 x = happyTcHack x happyFail
+
+action_138 (1#) = happyReduce_65
+action_138 (102#) = happyReduce_65
+action_138 (151#) = happyReduce_51
+action_138 (160#) = happyShift action_347
+action_138 (165#) = happyShift action_348
+action_138 (174#) = happyShift action_51
+action_138 (12#) = happyGoto action_241
+action_138 (22#) = happyGoto action_343
+action_138 (26#) = happyGoto action_344
+action_138 (32#) = happyGoto action_345
+action_138 (33#) = happyGoto action_346
+action_138 x = happyTcHack x happyReduce_65
+
+action_139 x = happyTcHack x happyReduce_170
+
+action_140 (174#) = happyShift action_51
+action_140 (12#) = happyGoto action_342
+action_140 (53#) = happyGoto action_88
+action_140 (56#) = happyGoto action_89
+action_140 (57#) = happyGoto action_125
+action_140 x = happyTcHack x happyReduce_137
+
+action_141 x = happyTcHack x happyReduce_222
+
+action_142 x = happyTcHack x happyReduce_158
+
+action_143 (170#) = happyShift action_6
+action_143 (8#) = happyGoto action_341
+action_143 x = happyTcHack x happyFail
+
+action_144 (174#) = happyShift action_51
+action_144 (12#) = happyGoto action_87
+action_144 (53#) = happyGoto action_88
+action_144 (56#) = happyGoto action_89
+action_144 (57#) = happyGoto action_340
+action_144 x = happyTcHack x happyReduce_137
+
+action_145 x = happyTcHack x happyReduce_185
+
+action_146 (96#) = happyShift action_24
+action_146 (98#) = happyShift action_82
+action_146 (104#) = happyShift action_26
+action_146 (109#) = happyShift action_27
+action_146 (110#) = happyShift action_28
+action_146 (111#) = happyShift action_29
+action_146 (125#) = happyShift action_33
+action_146 (126#) = happyShift action_34
+action_146 (127#) = happyShift action_35
+action_146 (128#) = happyShift action_36
+action_146 (129#) = happyShift action_37
+action_146 (134#) = happyShift action_39
+action_146 (170#) = happyShift action_6
+action_146 (171#) = happyShift action_48
+action_146 (172#) = happyShift action_49
+action_146 (173#) = happyShift action_50
+action_146 (174#) = happyShift action_51
+action_146 (8#) = happyGoto action_10
+action_146 (9#) = happyGoto action_11
+action_146 (10#) = happyGoto action_12
+action_146 (11#) = happyGoto action_13
+action_146 (12#) = happyGoto action_79
+action_146 (58#) = happyGoto action_15
+action_146 (59#) = happyGoto action_134
+action_146 (72#) = happyGoto action_22
+action_146 x = happyTcHack x happyReduce_176
+
+action_147 (96#) = happyShift action_24
+action_147 (98#) = happyShift action_82
+action_147 (104#) = happyShift action_26
+action_147 (109#) = happyShift action_27
+action_147 (110#) = happyShift action_28
+action_147 (111#) = happyShift action_29
+action_147 (125#) = happyShift action_33
+action_147 (126#) = happyShift action_34
+action_147 (127#) = happyShift action_35
+action_147 (128#) = happyShift action_36
+action_147 (129#) = happyShift action_37
+action_147 (134#) = happyShift action_39
+action_147 (170#) = happyShift action_6
+action_147 (171#) = happyShift action_48
+action_147 (172#) = happyShift action_49
+action_147 (173#) = happyShift action_50
+action_147 (174#) = happyShift action_51
+action_147 (8#) = happyGoto action_10
+action_147 (9#) = happyGoto action_11
+action_147 (10#) = happyGoto action_12
+action_147 (11#) = happyGoto action_13
+action_147 (12#) = happyGoto action_79
+action_147 (58#) = happyGoto action_15
+action_147 (59#) = happyGoto action_134
+action_147 (72#) = happyGoto action_22
+action_147 x = happyTcHack x happyReduce_175
+
+action_148 (96#) = happyShift action_24
+action_148 (98#) = happyShift action_82
+action_148 (104#) = happyShift action_26
+action_148 (109#) = happyShift action_27
+action_148 (110#) = happyShift action_28
+action_148 (111#) = happyShift action_29
+action_148 (125#) = happyShift action_33
+action_148 (126#) = happyShift action_34
+action_148 (127#) = happyShift action_35
+action_148 (128#) = happyShift action_36
+action_148 (129#) = happyShift action_37
+action_148 (134#) = happyShift action_39
+action_148 (170#) = happyShift action_6
+action_148 (171#) = happyShift action_48
+action_148 (172#) = happyShift action_49
+action_148 (173#) = happyShift action_50
+action_148 (174#) = happyShift action_51
+action_148 (8#) = happyGoto action_10
+action_148 (9#) = happyGoto action_11
+action_148 (10#) = happyGoto action_12
+action_148 (11#) = happyGoto action_13
+action_148 (12#) = happyGoto action_79
+action_148 (58#) = happyGoto action_15
+action_148 (59#) = happyGoto action_134
+action_148 (72#) = happyGoto action_22
+action_148 x = happyTcHack x happyReduce_177
+
+action_149 x = happyTcHack x happyReduce_181
+
+action_150 (96#) = happyShift action_24
+action_150 (98#) = happyShift action_82
+action_150 (104#) = happyShift action_26
+action_150 (109#) = happyShift action_27
+action_150 (110#) = happyShift action_28
+action_150 (111#) = happyShift action_29
+action_150 (125#) = happyShift action_33
+action_150 (126#) = happyShift action_34
+action_150 (127#) = happyShift action_35
+action_150 (128#) = happyShift action_36
+action_150 (129#) = happyShift action_37
+action_150 (134#) = happyShift action_39
+action_150 (170#) = happyShift action_6
+action_150 (171#) = happyShift action_48
+action_150 (172#) = happyShift action_49
+action_150 (173#) = happyShift action_50
+action_150 (174#) = happyShift action_51
+action_150 (8#) = happyGoto action_10
+action_150 (9#) = happyGoto action_11
+action_150 (10#) = happyGoto action_12
+action_150 (11#) = happyGoto action_13
+action_150 (12#) = happyGoto action_79
+action_150 (58#) = happyGoto action_15
+action_150 (59#) = happyGoto action_134
+action_150 (72#) = happyGoto action_22
+action_150 x = happyTcHack x happyReduce_178
+
+action_151 (102#) = happyShift action_129
+action_151 (115#) = happyShift action_130
+action_151 (116#) = happyShift action_131
+action_151 x = happyTcHack x happyReduce_192
+
+action_152 x = happyTcHack x happyReduce_179
+
+action_153 x = happyTcHack x happyReduce_184
+
+action_154 x = happyTcHack x happyReduce_152
+
+action_155 x = happyTcHack x happyReduce_141
+
+action_156 (174#) = happyShift action_51
+action_156 (12#) = happyGoto action_87
+action_156 (53#) = happyGoto action_339
+action_156 x = happyTcHack x happyFail
+
+action_157 (174#) = happyShift action_51
+action_157 (12#) = happyGoto action_338
+action_157 x = happyTcHack x happyFail
+
+action_158 (99#) = happyShift action_337
+action_158 x = happyTcHack x happyReduce_140
+
+action_159 (96#) = happyShift action_24
+action_159 (98#) = happyShift action_25
+action_159 (104#) = happyShift action_26
+action_159 (109#) = happyShift action_27
+action_159 (110#) = happyShift action_28
+action_159 (111#) = happyShift action_29
+action_159 (114#) = happyShift action_30
+action_159 (119#) = happyShift action_31
+action_159 (124#) = happyShift action_32
+action_159 (125#) = happyShift action_33
+action_159 (126#) = happyShift action_34
+action_159 (127#) = happyShift action_35
+action_159 (128#) = happyShift action_36
+action_159 (129#) = happyShift action_37
+action_159 (131#) = happyShift action_38
+action_159 (134#) = happyShift action_39
+action_159 (137#) = happyShift action_40
+action_159 (140#) = happyShift action_41
+action_159 (145#) = happyShift action_42
+action_159 (156#) = happyShift action_43
+action_159 (157#) = happyShift action_44
+action_159 (161#) = happyShift action_45
+action_159 (162#) = happyShift action_46
+action_159 (167#) = happyShift action_47
+action_159 (170#) = happyShift action_6
+action_159 (171#) = happyShift action_48
+action_159 (172#) = happyShift action_49
+action_159 (173#) = happyShift action_50
+action_159 (174#) = happyShift action_51
+action_159 (8#) = happyGoto action_10
+action_159 (9#) = happyGoto action_11
+action_159 (10#) = happyGoto action_12
+action_159 (11#) = happyGoto action_13
+action_159 (12#) = happyGoto action_14
+action_159 (58#) = happyGoto action_15
+action_159 (59#) = happyGoto action_16
+action_159 (60#) = happyGoto action_17
+action_159 (61#) = happyGoto action_18
+action_159 (62#) = happyGoto action_19
+action_159 (63#) = happyGoto action_336
+action_159 (64#) = happyGoto action_21
+action_159 (72#) = happyGoto action_22
+action_159 (77#) = happyGoto action_23
+action_159 x = happyTcHack x happyFail
+
+action_160 x = happyTcHack x happyReduce_156
+
+action_161 (96#) = happyShift action_140
+action_161 (98#) = happyShift action_82
+action_161 (104#) = happyShift action_26
+action_161 (109#) = happyShift action_83
+action_161 (110#) = happyShift action_28
+action_161 (111#) = happyShift action_29
+action_161 (125#) = happyShift action_33
+action_161 (126#) = happyShift action_34
+action_161 (127#) = happyShift action_35
+action_161 (128#) = happyShift action_36
+action_161 (129#) = happyShift action_37
+action_161 (134#) = happyShift action_39
+action_161 (170#) = happyShift action_6
+action_161 (171#) = happyShift action_48
+action_161 (172#) = happyShift action_49
+action_161 (173#) = happyShift action_50
+action_161 (174#) = happyShift action_51
+action_161 (8#) = happyGoto action_10
+action_161 (9#) = happyGoto action_11
+action_161 (10#) = happyGoto action_12
+action_161 (11#) = happyGoto action_13
+action_161 (12#) = happyGoto action_79
+action_161 (58#) = happyGoto action_161
+action_161 (66#) = happyGoto action_335
+action_161 (72#) = happyGoto action_22
+action_161 x = happyTcHack x happyReduce_196
+
+action_162 (105#) = happyShift action_334
+action_162 x = happyTcHack x happyFail
+
+action_163 x = happyTcHack x happyReduce_151
+
+action_164 (174#) = happyShift action_51
+action_164 (12#) = happyGoto action_333
+action_164 x = happyTcHack x happyFail
+
+action_165 x = happyTcHack x happyReduce_142
+
+action_166 x = happyTcHack x happyReduce_153
+
+action_167 (96#) = happyShift action_24
+action_167 (98#) = happyShift action_25
+action_167 (104#) = happyShift action_26
+action_167 (109#) = happyShift action_27
+action_167 (110#) = happyShift action_28
+action_167 (111#) = happyShift action_29
+action_167 (114#) = happyShift action_30
+action_167 (119#) = happyShift action_31
+action_167 (124#) = happyShift action_32
+action_167 (125#) = happyShift action_33
+action_167 (126#) = happyShift action_34
+action_167 (127#) = happyShift action_35
+action_167 (128#) = happyShift action_36
+action_167 (129#) = happyShift action_37
+action_167 (131#) = happyShift action_38
+action_167 (134#) = happyShift action_39
+action_167 (137#) = happyShift action_40
+action_167 (140#) = happyShift action_41
+action_167 (145#) = happyShift action_42
+action_167 (156#) = happyShift action_43
+action_167 (157#) = happyShift action_44
+action_167 (161#) = happyShift action_45
+action_167 (162#) = happyShift action_46
+action_167 (167#) = happyShift action_47
+action_167 (170#) = happyShift action_6
+action_167 (171#) = happyShift action_48
+action_167 (172#) = happyShift action_49
+action_167 (173#) = happyShift action_50
+action_167 (174#) = happyShift action_51
+action_167 (8#) = happyGoto action_10
+action_167 (9#) = happyGoto action_11
+action_167 (10#) = happyGoto action_12
+action_167 (11#) = happyGoto action_13
+action_167 (12#) = happyGoto action_14
+action_167 (58#) = happyGoto action_15
+action_167 (59#) = happyGoto action_16
+action_167 (60#) = happyGoto action_17
+action_167 (61#) = happyGoto action_18
+action_167 (62#) = happyGoto action_19
+action_167 (63#) = happyGoto action_331
+action_167 (64#) = happyGoto action_21
+action_167 (72#) = happyGoto action_22
+action_167 (77#) = happyGoto action_23
+action_167 (78#) = happyGoto action_114
+action_167 (80#) = happyGoto action_332
+action_167 x = happyTcHack x happyReduce_243
+
+action_168 (96#) = happyShift action_24
+action_168 (98#) = happyShift action_25
+action_168 (104#) = happyShift action_26
+action_168 (109#) = happyShift action_27
+action_168 (110#) = happyShift action_28
+action_168 (111#) = happyShift action_29
+action_168 (114#) = happyShift action_30
+action_168 (119#) = happyShift action_31
+action_168 (124#) = happyShift action_32
+action_168 (125#) = happyShift action_33
+action_168 (126#) = happyShift action_34
+action_168 (127#) = happyShift action_35
+action_168 (128#) = happyShift action_36
+action_168 (129#) = happyShift action_37
+action_168 (131#) = happyShift action_38
+action_168 (134#) = happyShift action_39
+action_168 (137#) = happyShift action_40
+action_168 (140#) = happyShift action_41
+action_168 (145#) = happyShift action_42
+action_168 (156#) = happyShift action_43
+action_168 (157#) = happyShift action_44
+action_168 (161#) = happyShift action_45
+action_168 (162#) = happyShift action_46
+action_168 (167#) = happyShift action_47
+action_168 (170#) = happyShift action_6
+action_168 (171#) = happyShift action_48
+action_168 (172#) = happyShift action_49
+action_168 (173#) = happyShift action_50
+action_168 (174#) = happyShift action_51
+action_168 (8#) = happyGoto action_10
+action_168 (9#) = happyGoto action_11
+action_168 (10#) = happyGoto action_12
+action_168 (11#) = happyGoto action_13
+action_168 (12#) = happyGoto action_14
+action_168 (58#) = happyGoto action_15
+action_168 (59#) = happyGoto action_16
+action_168 (60#) = happyGoto action_17
+action_168 (61#) = happyGoto action_18
+action_168 (62#) = happyGoto action_19
+action_168 (63#) = happyGoto action_330
+action_168 (64#) = happyGoto action_21
+action_168 (72#) = happyGoto action_22
+action_168 (77#) = happyGoto action_23
+action_168 x = happyTcHack x happyFail
+
+action_169 (107#) = happyShift action_329
+action_169 x = happyTcHack x happyReduce_200
+
+action_170 (96#) = happyShift action_106
+action_170 (98#) = happyShift action_107
+action_170 (104#) = happyShift action_108
+action_170 (107#) = happyShift action_300
+action_170 (110#) = happyShift action_109
+action_170 (111#) = happyShift action_110
+action_170 (113#) = happyShift action_301
+action_170 (114#) = happyShift action_111
+action_170 (121#) = happyShift action_112
+action_170 (170#) = happyShift action_6
+action_170 (171#) = happyShift action_48
+action_170 (172#) = happyShift action_49
+action_170 (174#) = happyShift action_51
+action_170 (8#) = happyGoto action_101
+action_170 (9#) = happyGoto action_102
+action_170 (10#) = happyGoto action_103
+action_170 (12#) = happyGoto action_104
+action_170 (67#) = happyGoto action_188
+action_170 (74#) = happyGoto action_299
+action_170 x = happyTcHack x happyReduce_203
+
+action_171 (116#) = happyShift action_328
+action_171 x = happyTcHack x happyReduce_217
+
+action_172 x = happyTcHack x happyReduce_220
+
+action_173 (108#) = happyShift action_296
+action_173 (117#) = happyShift action_297
+action_173 x = happyTcHack x happyReduce_242
+
+action_174 (103#) = happyShift action_327
+action_174 x = happyTcHack x happyReduce_247
+
+action_175 (112#) = happyShift action_326
+action_175 x = happyTcHack x happyFail
+
+action_176 (96#) = happyShift action_106
+action_176 (98#) = happyShift action_107
+action_176 (104#) = happyShift action_108
+action_176 (110#) = happyShift action_109
+action_176 (111#) = happyShift action_110
+action_176 (114#) = happyShift action_111
+action_176 (121#) = happyShift action_112
+action_176 (170#) = happyShift action_6
+action_176 (171#) = happyShift action_48
+action_176 (172#) = happyShift action_49
+action_176 (174#) = happyShift action_51
+action_176 (8#) = happyGoto action_101
+action_176 (9#) = happyGoto action_102
+action_176 (10#) = happyGoto action_103
+action_176 (12#) = happyGoto action_104
+action_176 (67#) = happyGoto action_325
+action_176 x = happyTcHack x happyFail
+
+action_177 (105#) = happyShift action_324
+action_177 x = happyTcHack x happyFail
+
+action_178 (99#) = happyShift action_323
+action_178 (108#) = happyShift action_296
+action_178 (117#) = happyShift action_297
+action_178 x = happyTcHack x happyFail
+
+action_179 (97#) = happyShift action_322
+action_179 (103#) = happyShift action_156
+action_179 x = happyTcHack x happyReduce_128
+
+action_180 (95#) = happyShift action_321
+action_180 x = happyTcHack x happyFail
+
+action_181 (94#) = happyShift action_320
+action_181 x = happyTcHack x happyReduce_230
+
+action_182 (97#) = happyShift action_319
+action_182 x = happyTcHack x happyFail
+
+action_183 (174#) = happyShift action_51
+action_183 (12#) = happyGoto action_318
+action_183 x = happyTcHack x happyFail
+
+action_184 (120#) = happyShift action_317
+action_184 x = happyTcHack x happyFail
+
+action_185 (96#) = happyShift action_24
+action_185 (98#) = happyShift action_25
+action_185 (104#) = happyShift action_26
+action_185 (109#) = happyShift action_27
+action_185 (110#) = happyShift action_28
+action_185 (111#) = happyShift action_29
+action_185 (114#) = happyShift action_30
+action_185 (119#) = happyShift action_31
+action_185 (124#) = happyShift action_32
+action_185 (125#) = happyShift action_33
+action_185 (126#) = happyShift action_34
+action_185 (127#) = happyShift action_35
+action_185 (128#) = happyShift action_36
+action_185 (129#) = happyShift action_37
+action_185 (131#) = happyShift action_38
+action_185 (134#) = happyShift action_39
+action_185 (137#) = happyShift action_40
+action_185 (140#) = happyShift action_41
+action_185 (145#) = happyShift action_42
+action_185 (156#) = happyShift action_43
+action_185 (157#) = happyShift action_44
+action_185 (161#) = happyShift action_45
+action_185 (162#) = happyShift action_46
+action_185 (167#) = happyShift action_47
+action_185 (170#) = happyShift action_6
+action_185 (171#) = happyShift action_48
+action_185 (172#) = happyShift action_49
+action_185 (173#) = happyShift action_50
+action_185 (174#) = happyShift action_51
+action_185 (8#) = happyGoto action_10
+action_185 (9#) = happyGoto action_11
+action_185 (10#) = happyGoto action_12
+action_185 (11#) = happyGoto action_13
+action_185 (12#) = happyGoto action_14
+action_185 (58#) = happyGoto action_15
+action_185 (59#) = happyGoto action_16
+action_185 (60#) = happyGoto action_17
+action_185 (61#) = happyGoto action_18
+action_185 (62#) = happyGoto action_19
+action_185 (63#) = happyGoto action_316
+action_185 (64#) = happyGoto action_21
+action_185 (72#) = happyGoto action_22
+action_185 (77#) = happyGoto action_23
+action_185 x = happyTcHack x happyFail
+
+action_186 (121#) = happyShift action_100
+action_186 (174#) = happyShift action_51
+action_186 (12#) = happyGoto action_96
+action_186 (75#) = happyGoto action_97
+action_186 (76#) = happyGoto action_315
+action_186 x = happyTcHack x happyReduce_236
+
+action_187 (96#) = happyShift action_314
+action_187 x = happyTcHack x happyFail
+
+action_188 (96#) = happyShift action_106
+action_188 (98#) = happyShift action_107
+action_188 (104#) = happyShift action_108
+action_188 (110#) = happyShift action_109
+action_188 (111#) = happyShift action_110
+action_188 (114#) = happyShift action_111
+action_188 (121#) = happyShift action_112
+action_188 (170#) = happyShift action_6
+action_188 (171#) = happyShift action_48
+action_188 (172#) = happyShift action_49
+action_188 (174#) = happyShift action_51
+action_188 (8#) = happyGoto action_101
+action_188 (9#) = happyGoto action_102
+action_188 (10#) = happyGoto action_103
+action_188 (12#) = happyGoto action_104
+action_188 (67#) = happyGoto action_188
+action_188 (74#) = happyGoto action_313
+action_188 x = happyTcHack x happyReduce_232
+
+action_189 (101#) = happyShift action_312
+action_189 x = happyTcHack x happyFail
+
+action_190 (94#) = happyShift action_311
+action_190 x = happyTcHack x happyReduce_254
+
+action_191 (97#) = happyShift action_310
+action_191 x = happyTcHack x happyFail
+
+action_192 x = happyTcHack x happyReduce_190
+
+action_193 (97#) = happyShift action_309
+action_193 x = happyTcHack x happyFail
+
+action_194 (96#) = happyShift action_24
+action_194 (98#) = happyShift action_25
+action_194 (104#) = happyShift action_26
+action_194 (109#) = happyShift action_27
+action_194 (110#) = happyShift action_28
+action_194 (111#) = happyShift action_29
+action_194 (114#) = happyShift action_30
+action_194 (119#) = happyShift action_31
+action_194 (124#) = happyShift action_32
+action_194 (125#) = happyShift action_33
+action_194 (126#) = happyShift action_34
+action_194 (127#) = happyShift action_35
+action_194 (128#) = happyShift action_36
+action_194 (129#) = happyShift action_37
+action_194 (131#) = happyShift action_38
+action_194 (134#) = happyShift action_39
+action_194 (137#) = happyShift action_40
+action_194 (140#) = happyShift action_41
+action_194 (145#) = happyShift action_42
+action_194 (156#) = happyShift action_43
+action_194 (157#) = happyShift action_44
+action_194 (161#) = happyShift action_45
+action_194 (162#) = happyShift action_46
+action_194 (167#) = happyShift action_47
+action_194 (170#) = happyShift action_6
+action_194 (171#) = happyShift action_48
+action_194 (172#) = happyShift action_49
+action_194 (173#) = happyShift action_50
+action_194 (174#) = happyShift action_51
+action_194 (8#) = happyGoto action_10
+action_194 (9#) = happyGoto action_11
+action_194 (10#) = happyGoto action_12
+action_194 (11#) = happyGoto action_13
+action_194 (12#) = happyGoto action_14
+action_194 (58#) = happyGoto action_15
+action_194 (59#) = happyGoto action_16
+action_194 (60#) = happyGoto action_17
+action_194 (61#) = happyGoto action_18
+action_194 (62#) = happyGoto action_19
+action_194 (63#) = happyGoto action_308
+action_194 (64#) = happyGoto action_21
+action_194 (72#) = happyGoto action_22
+action_194 (77#) = happyGoto action_23
+action_194 x = happyTcHack x happyFail
+
+action_195 (174#) = happyShift action_51
+action_195 (12#) = happyGoto action_87
+action_195 (53#) = happyGoto action_88
+action_195 (56#) = happyGoto action_89
+action_195 (57#) = happyGoto action_307
+action_195 x = happyTcHack x happyReduce_137
+
+action_196 (96#) = happyShift action_24
+action_196 (98#) = happyShift action_25
+action_196 (104#) = happyShift action_26
+action_196 (109#) = happyShift action_27
+action_196 (110#) = happyShift action_28
+action_196 (111#) = happyShift action_29
+action_196 (114#) = happyShift action_30
+action_196 (119#) = happyShift action_31
+action_196 (124#) = happyShift action_32
+action_196 (125#) = happyShift action_33
+action_196 (126#) = happyShift action_34
+action_196 (127#) = happyShift action_35
+action_196 (128#) = happyShift action_36
+action_196 (129#) = happyShift action_37
+action_196 (131#) = happyShift action_38
+action_196 (134#) = happyShift action_39
+action_196 (137#) = happyShift action_40
+action_196 (140#) = happyShift action_41
+action_196 (145#) = happyShift action_42
+action_196 (156#) = happyShift action_43
+action_196 (157#) = happyShift action_44
+action_196 (161#) = happyShift action_45
+action_196 (162#) = happyShift action_46
+action_196 (167#) = happyShift action_47
+action_196 (170#) = happyShift action_6
+action_196 (171#) = happyShift action_48
+action_196 (172#) = happyShift action_49
+action_196 (173#) = happyShift action_50
+action_196 (174#) = happyShift action_51
+action_196 (8#) = happyGoto action_10
+action_196 (9#) = happyGoto action_11
+action_196 (10#) = happyGoto action_12
+action_196 (11#) = happyGoto action_13
+action_196 (12#) = happyGoto action_14
+action_196 (58#) = happyGoto action_15
+action_196 (59#) = happyGoto action_16
+action_196 (60#) = happyGoto action_17
+action_196 (61#) = happyGoto action_18
+action_196 (62#) = happyGoto action_19
+action_196 (63#) = happyGoto action_306
+action_196 (64#) = happyGoto action_21
+action_196 (72#) = happyGoto action_22
+action_196 (77#) = happyGoto action_23
+action_196 x = happyTcHack x happyFail
+
+action_197 (96#) = happyShift action_24
+action_197 (98#) = happyShift action_25
+action_197 (104#) = happyShift action_26
+action_197 (109#) = happyShift action_27
+action_197 (110#) = happyShift action_28
+action_197 (111#) = happyShift action_29
+action_197 (114#) = happyShift action_30
+action_197 (119#) = happyShift action_31
+action_197 (124#) = happyShift action_32
+action_197 (125#) = happyShift action_33
+action_197 (126#) = happyShift action_34
+action_197 (127#) = happyShift action_35
+action_197 (128#) = happyShift action_36
+action_197 (129#) = happyShift action_37
+action_197 (131#) = happyShift action_38
+action_197 (134#) = happyShift action_39
+action_197 (137#) = happyShift action_40
+action_197 (140#) = happyShift action_41
+action_197 (145#) = happyShift action_42
+action_197 (156#) = happyShift action_43
+action_197 (157#) = happyShift action_44
+action_197 (161#) = happyShift action_45
+action_197 (162#) = happyShift action_46
+action_197 (167#) = happyShift action_47
+action_197 (170#) = happyShift action_6
+action_197 (171#) = happyShift action_48
+action_197 (172#) = happyShift action_49
+action_197 (173#) = happyShift action_50
+action_197 (174#) = happyShift action_51
+action_197 (8#) = happyGoto action_10
+action_197 (9#) = happyGoto action_11
+action_197 (10#) = happyGoto action_12
+action_197 (11#) = happyGoto action_13
+action_197 (12#) = happyGoto action_14
+action_197 (58#) = happyGoto action_15
+action_197 (59#) = happyGoto action_16
+action_197 (60#) = happyGoto action_17
+action_197 (61#) = happyGoto action_18
+action_197 (62#) = happyGoto action_19
+action_197 (63#) = happyGoto action_305
+action_197 (64#) = happyGoto action_21
+action_197 (72#) = happyGoto action_22
+action_197 (77#) = happyGoto action_23
+action_197 x = happyTcHack x happyFail
+
+action_198 (94#) = happyShift action_304
+action_198 x = happyTcHack x happyFail
+
+action_199 (94#) = happyShift action_303
+action_199 x = happyTcHack x happyReduce_194
+
+action_200 (97#) = happyShift action_302
+action_200 x = happyTcHack x happyFail
+
+action_201 (109#) = happyShift action_165
+action_201 x = happyTcHack x happyFail
+
+action_202 (96#) = happyShift action_106
+action_202 (97#) = happyShift action_155
+action_202 (98#) = happyShift action_107
+action_202 (103#) = happyShift action_156
+action_202 (104#) = happyShift action_108
+action_202 (107#) = happyShift action_300
+action_202 (108#) = happyReduce_203
+action_202 (110#) = happyShift action_109
+action_202 (111#) = happyShift action_110
+action_202 (113#) = happyShift action_301
+action_202 (114#) = happyShift action_111
+action_202 (116#) = happyReduce_203
+action_202 (117#) = happyReduce_203
+action_202 (120#) = happyReduce_203
+action_202 (121#) = happyShift action_112
+action_202 (170#) = happyShift action_6
+action_202 (171#) = happyShift action_48
+action_202 (172#) = happyShift action_49
+action_202 (174#) = happyShift action_51
+action_202 (8#) = happyGoto action_101
+action_202 (9#) = happyGoto action_102
+action_202 (10#) = happyGoto action_103
+action_202 (12#) = happyGoto action_104
+action_202 (67#) = happyGoto action_188
+action_202 (74#) = happyGoto action_299
+action_202 x = happyTcHack x happyReduce_128
+
+action_203 (108#) = happyShift action_296
+action_203 (117#) = happyShift action_297
+action_203 (120#) = happyShift action_298
+action_203 x = happyTcHack x happyFail
+
+action_204 (94#) = happyShift action_295
+action_204 x = happyTcHack x happyReduce_250
+
+action_205 (97#) = happyShift action_294
+action_205 x = happyTcHack x happyFail
+
+action_206 (96#) = happyShift action_106
+action_206 (98#) = happyShift action_107
+action_206 (104#) = happyShift action_108
+action_206 (106#) = happyShift action_176
+action_206 (110#) = happyShift action_109
+action_206 (111#) = happyShift action_110
+action_206 (114#) = happyShift action_111
+action_206 (121#) = happyShift action_112
+action_206 (170#) = happyShift action_6
+action_206 (171#) = happyShift action_48
+action_206 (172#) = happyShift action_49
+action_206 (174#) = happyShift action_51
+action_206 (8#) = happyGoto action_101
+action_206 (9#) = happyGoto action_102
+action_206 (10#) = happyGoto action_103
+action_206 (12#) = happyGoto action_170
+action_206 (67#) = happyGoto action_171
+action_206 (68#) = happyGoto action_172
+action_206 (69#) = happyGoto action_203
+action_206 (82#) = happyGoto action_204
+action_206 (83#) = happyGoto action_293
+action_206 x = happyTcHack x happyFail
+
+action_207 (96#) = happyShift action_24
+action_207 (98#) = happyShift action_25
+action_207 (104#) = happyShift action_26
+action_207 (109#) = happyShift action_27
+action_207 (110#) = happyShift action_28
+action_207 (111#) = happyShift action_29
+action_207 (114#) = happyShift action_30
+action_207 (119#) = happyShift action_31
+action_207 (124#) = happyShift action_32
+action_207 (125#) = happyShift action_33
+action_207 (126#) = happyShift action_34
+action_207 (127#) = happyShift action_35
+action_207 (128#) = happyShift action_36
+action_207 (129#) = happyShift action_37
+action_207 (131#) = happyShift action_38
+action_207 (134#) = happyShift action_39
+action_207 (137#) = happyShift action_40
+action_207 (140#) = happyShift action_41
+action_207 (145#) = happyShift action_42
+action_207 (156#) = happyShift action_43
+action_207 (157#) = happyShift action_44
+action_207 (161#) = happyShift action_45
+action_207 (162#) = happyShift action_46
+action_207 (167#) = happyShift action_47
+action_207 (170#) = happyShift action_6
+action_207 (171#) = happyShift action_48
+action_207 (172#) = happyShift action_49
+action_207 (173#) = happyShift action_50
+action_207 (174#) = happyShift action_51
+action_207 (8#) = happyGoto action_10
+action_207 (9#) = happyGoto action_11
+action_207 (10#) = happyGoto action_12
+action_207 (11#) = happyGoto action_13
+action_207 (12#) = happyGoto action_14
+action_207 (58#) = happyGoto action_15
+action_207 (59#) = happyGoto action_16
+action_207 (60#) = happyGoto action_17
+action_207 (61#) = happyGoto action_18
+action_207 (62#) = happyGoto action_19
+action_207 (63#) = happyGoto action_199
+action_207 (64#) = happyGoto action_21
+action_207 (65#) = happyGoto action_292
+action_207 (72#) = happyGoto action_22
+action_207 (77#) = happyGoto action_23
+action_207 x = happyTcHack x happyReduce_193
+
+action_208 (97#) = happyShift action_291
+action_208 x = happyTcHack x happyFail
+
+action_209 x = happyTcHack x happyReduce_49
+
+action_210 (104#) = happyShift action_290
+action_210 (174#) = happyShift action_51
+action_210 (12#) = happyGoto action_287
+action_210 (36#) = happyGoto action_288
+action_210 (46#) = happyGoto action_289
+action_210 x = happyTcHack x happyFail
+
+action_211 (174#) = happyShift action_51
+action_211 (12#) = happyGoto action_283
+action_211 (37#) = happyGoto action_276
+action_211 (38#) = happyGoto action_284
+action_211 (47#) = happyGoto action_285
+action_211 (48#) = happyGoto action_286
+action_211 (53#) = happyGoto action_278
+action_211 x = happyTcHack x happyFail
+
+action_212 (104#) = happyShift action_257
+action_212 (174#) = happyShift action_51
+action_212 (12#) = happyGoto action_252
+action_212 (34#) = happyGoto action_253
+action_212 (45#) = happyGoto action_282
+action_212 (54#) = happyGoto action_255
+action_212 (55#) = happyGoto action_256
+action_212 x = happyTcHack x happyFail
+
+action_213 (174#) = happyShift action_51
+action_213 (12#) = happyGoto action_279
+action_213 (44#) = happyGoto action_280
+action_213 (51#) = happyGoto action_281
+action_213 x = happyTcHack x happyFail
+
+action_214 (174#) = happyShift action_51
+action_214 (12#) = happyGoto action_87
+action_214 (37#) = happyGoto action_276
+action_214 (47#) = happyGoto action_277
+action_214 (53#) = happyGoto action_278
+action_214 x = happyTcHack x happyFail
+
+action_215 (104#) = happyShift action_257
+action_215 (174#) = happyShift action_51
+action_215 (12#) = happyGoto action_252
+action_215 (34#) = happyGoto action_253
+action_215 (45#) = happyGoto action_275
+action_215 (54#) = happyGoto action_255
+action_215 (55#) = happyGoto action_256
+action_215 x = happyTcHack x happyFail
+
+action_216 (104#) = happyShift action_257
+action_216 (174#) = happyShift action_51
+action_216 (12#) = happyGoto action_252
+action_216 (43#) = happyGoto action_260
+action_216 (50#) = happyGoto action_274
+action_216 (54#) = happyGoto action_262
+action_216 (55#) = happyGoto action_263
+action_216 x = happyTcHack x happyFail
+
+action_217 (104#) = happyShift action_257
+action_217 (174#) = happyShift action_51
+action_217 (12#) = happyGoto action_252
+action_217 (34#) = happyGoto action_253
+action_217 (45#) = happyGoto action_273
+action_217 (54#) = happyGoto action_255
+action_217 (55#) = happyGoto action_256
+action_217 x = happyTcHack x happyFail
+
+action_218 (104#) = happyShift action_257
+action_218 (174#) = happyShift action_51
+action_218 (12#) = happyGoto action_252
+action_218 (34#) = happyGoto action_253
+action_218 (45#) = happyGoto action_272
+action_218 (54#) = happyGoto action_255
+action_218 (55#) = happyGoto action_256
+action_218 x = happyTcHack x happyFail
+
+action_219 (104#) = happyShift action_257
+action_219 (174#) = happyShift action_51
+action_219 (12#) = happyGoto action_252
+action_219 (34#) = happyGoto action_253
+action_219 (45#) = happyGoto action_271
+action_219 (54#) = happyGoto action_255
+action_219 (55#) = happyGoto action_256
+action_219 x = happyTcHack x happyFail
+
+action_220 (174#) = happyShift action_51
+action_220 (12#) = happyGoto action_270
+action_220 x = happyTcHack x happyFail
+
+action_221 (174#) = happyShift action_51
+action_221 (12#) = happyGoto action_267
+action_221 (41#) = happyGoto action_268
+action_221 (49#) = happyGoto action_269
+action_221 x = happyTcHack x happyFail
+
+action_222 (104#) = happyShift action_257
+action_222 (174#) = happyShift action_51
+action_222 (12#) = happyGoto action_252
+action_222 (34#) = happyGoto action_253
+action_222 (45#) = happyGoto action_266
+action_222 (54#) = happyGoto action_255
+action_222 (55#) = happyGoto action_256
+action_222 x = happyTcHack x happyFail
+
+action_223 (104#) = happyShift action_257
+action_223 (132#) = happyShift action_264
+action_223 (138#) = happyShift action_265
+action_223 (174#) = happyShift action_51
+action_223 (12#) = happyGoto action_252
+action_223 (43#) = happyGoto action_260
+action_223 (50#) = happyGoto action_261
+action_223 (54#) = happyGoto action_262
+action_223 (55#) = happyGoto action_263
+action_223 x = happyTcHack x happyFail
+
+action_224 (174#) = happyShift action_51
+action_224 (12#) = happyGoto action_259
+action_224 x = happyTcHack x happyFail
+
+action_225 (104#) = happyShift action_257
+action_225 (174#) = happyShift action_51
+action_225 (12#) = happyGoto action_252
+action_225 (34#) = happyGoto action_253
+action_225 (45#) = happyGoto action_258
+action_225 (54#) = happyGoto action_255
+action_225 (55#) = happyGoto action_256
+action_225 x = happyTcHack x happyFail
+
+action_226 (104#) = happyShift action_257
+action_226 (174#) = happyShift action_51
+action_226 (12#) = happyGoto action_252
+action_226 (34#) = happyGoto action_253
+action_226 (45#) = happyGoto action_254
+action_226 (54#) = happyGoto action_255
+action_226 (55#) = happyGoto action_256
+action_226 x = happyTcHack x happyFail
+
+action_227 x = happyTcHack x happyReduce_269
+
+action_228 x = happyTcHack x happyReduce_270
+
+action_229 x = happyTcHack x happyReduce_271
+
+action_230 (106#) = happyShift action_74
+action_230 (107#) = happyShift action_75
+action_230 (123#) = happyShift action_76
+action_230 (171#) = happyShift action_48
+action_230 (174#) = happyShift action_51
+action_230 (9#) = happyGoto action_70
+action_230 (12#) = happyGoto action_71
+action_230 (92#) = happyGoto action_72
+action_230 (93#) = happyGoto action_251
+action_230 x = happyTcHack x happyReduce_273
+
+action_231 x = happyTcHack x happyReduce_272
+
+action_232 (100#) = happyShift action_250
+action_232 x = happyTcHack x happyFail
+
+action_233 x = happyTcHack x happyReduce_35
+
+action_234 x = happyTcHack x happyReduce_36
+
+action_235 (150#) = happyShift action_249
+action_235 x = happyTcHack x happyFail
+
+action_236 (150#) = happyShift action_248
+action_236 x = happyTcHack x happyFail
+
+action_237 x = happyTcHack x happyReduce_34
+
+action_238 (96#) = happyReduce_51
+action_238 (151#) = happyReduce_51
+action_238 (160#) = happyShift action_246
+action_238 (165#) = happyShift action_247
+action_238 (174#) = happyShift action_51
+action_238 (12#) = happyGoto action_241
+action_238 (24#) = happyGoto action_242
+action_238 (26#) = happyGoto action_243
+action_238 (32#) = happyGoto action_244
+action_238 (33#) = happyGoto action_245
+action_238 x = happyTcHack x happyReduce_65
+
+action_239 (96#) = happyShift action_240
+action_239 x = happyTcHack x happyFail
+
+action_240 (130#) = happyShift action_418
+action_240 x = happyTcHack x happyFail
+
+action_241 (104#) = happyShift action_416
+action_241 (106#) = happyShift action_417
+action_241 x = happyTcHack x happyReduce_68
+
+action_242 x = happyTcHack x happyReduce_15
+
+action_243 (151#) = happyShift action_356
+action_243 (28#) = happyGoto action_415
+action_243 x = happyTcHack x happyReduce_55
+
+action_244 (102#) = happyShift action_414
+action_244 x = happyTcHack x happyReduce_41
+
+action_245 (103#) = happyShift action_352
+action_245 (169#) = happyShift action_413
+action_245 x = happyTcHack x happyReduce_66
+
+action_246 (174#) = happyShift action_51
+action_246 (12#) = happyGoto action_412
+action_246 x = happyTcHack x happyFail
+
+action_247 (174#) = happyShift action_51
+action_247 (12#) = happyGoto action_241
+action_247 (32#) = happyGoto action_411
+action_247 (33#) = happyGoto action_350
+action_247 x = happyTcHack x happyReduce_65
+
+action_248 (174#) = happyShift action_51
+action_248 (12#) = happyGoto action_410
+action_248 x = happyTcHack x happyFail
+
+action_249 (174#) = happyShift action_51
+action_249 (12#) = happyGoto action_409
+action_249 x = happyTcHack x happyFail
+
+action_250 (98#) = happyShift action_408
+action_250 (174#) = happyShift action_51
+action_250 (12#) = happyGoto action_406
+action_250 (29#) = happyGoto action_407
+action_250 x = happyTcHack x happyFail
+
+action_251 x = happyTcHack x happyReduce_274
+
+action_252 x = happyTcHack x happyReduce_130
+
+action_253 (94#) = happyShift action_405
+action_253 x = happyTcHack x happyFail
+
+action_254 x = happyTcHack x happyReduce_93
+
+action_255 (96#) = happyShift action_106
+action_255 (98#) = happyShift action_107
+action_255 (103#) = happyShift action_398
+action_255 (104#) = happyShift action_108
+action_255 (110#) = happyShift action_109
+action_255 (111#) = happyShift action_110
+action_255 (114#) = happyShift action_111
+action_255 (121#) = happyShift action_112
+action_255 (170#) = happyShift action_6
+action_255 (171#) = happyShift action_48
+action_255 (172#) = happyShift action_49
+action_255 (174#) = happyShift action_51
+action_255 (8#) = happyGoto action_101
+action_255 (9#) = happyGoto action_102
+action_255 (10#) = happyGoto action_103
+action_255 (12#) = happyGoto action_104
+action_255 (67#) = happyGoto action_188
+action_255 (74#) = happyGoto action_404
+action_255 x = happyTcHack x happyReduce_132
+
+action_256 (95#) = happyShift action_402
+action_256 (100#) = happyShift action_403
+action_256 x = happyTcHack x happyFail
+
+action_257 (174#) = happyShift action_51
+action_257 (12#) = happyGoto action_401
+action_257 x = happyTcHack x happyFail
+
+action_258 x = happyTcHack x happyReduce_80
+
+action_259 (94#) = happyShift action_400
+action_259 x = happyTcHack x happyFail
+
+action_260 (94#) = happyShift action_399
+action_260 x = happyTcHack x happyFail
+
+action_261 x = happyTcHack x happyReduce_89
+
+action_262 (103#) = happyShift action_398
+action_262 x = happyTcHack x happyReduce_132
+
+action_263 (95#) = happyShift action_397
+action_263 x = happyTcHack x happyFail
+
+action_264 (104#) = happyShift action_257
+action_264 (174#) = happyShift action_51
+action_264 (12#) = happyGoto action_252
+action_264 (43#) = happyGoto action_260
+action_264 (50#) = happyGoto action_396
+action_264 (54#) = happyGoto action_262
+action_264 (55#) = happyGoto action_263
+action_264 x = happyTcHack x happyFail
+
+action_265 (104#) = happyShift action_257
+action_265 (174#) = happyShift action_51
+action_265 (12#) = happyGoto action_252
+action_265 (43#) = happyGoto action_260
+action_265 (50#) = happyGoto action_395
+action_265 (54#) = happyGoto action_262
+action_265 (55#) = happyGoto action_263
+action_265 x = happyTcHack x happyFail
+
+action_266 x = happyTcHack x happyReduce_91
+
+action_267 (95#) = happyShift action_394
+action_267 x = happyTcHack x happyReduce_107
+
+action_268 (94#) = happyShift action_393
+action_268 x = happyTcHack x happyFail
+
+action_269 x = happyTcHack x happyReduce_81
+
+action_270 (95#) = happyShift action_392
+action_270 x = happyTcHack x happyFail
+
+action_271 x = happyTcHack x happyReduce_82
+
+action_272 x = happyTcHack x happyReduce_90
+
+action_273 x = happyTcHack x happyReduce_84
+
+action_274 x = happyTcHack x happyReduce_83
+
+action_275 x = happyTcHack x happyReduce_85
+
+action_276 (94#) = happyShift action_391
+action_276 x = happyTcHack x happyFail
+
+action_277 x = happyTcHack x happyReduce_76
+
+action_278 (100#) = happyShift action_390
+action_278 x = happyTcHack x happyFail
+
+action_279 (95#) = happyShift action_389
+action_279 x = happyTcHack x happyFail
+
+action_280 (94#) = happyShift action_388
+action_280 x = happyTcHack x happyFail
+
+action_281 x = happyTcHack x happyReduce_88
+
+action_282 x = happyTcHack x happyReduce_78
+
+action_283 (95#) = happyShift action_387
+action_283 (103#) = happyShift action_156
+action_283 x = happyTcHack x happyReduce_128
+
+action_284 (94#) = happyShift action_386
+action_284 x = happyTcHack x happyFail
+
+action_285 x = happyTcHack x happyReduce_77
+
+action_286 x = happyTcHack x happyReduce_79
+
+action_287 (89#) = happyGoto action_385
+action_287 x = happyTcHack x happyReduce_262
+
+action_288 (94#) = happyShift action_384
+action_288 x = happyTcHack x happyFail
+
+action_289 x = happyTcHack x happyReduce_75
+
+action_290 (174#) = happyShift action_51
+action_290 (12#) = happyGoto action_383
+action_290 x = happyTcHack x happyFail
+
+action_291 x = happyTcHack x happyReduce_167
+
+action_292 (105#) = happyShift action_382
+action_292 x = happyTcHack x happyFail
+
+action_293 (97#) = happyShift action_381
+action_293 x = happyTcHack x happyFail
+
+action_294 x = happyTcHack x happyReduce_163
+
+action_295 (96#) = happyShift action_106
+action_295 (98#) = happyShift action_107
+action_295 (104#) = happyShift action_108
+action_295 (106#) = happyShift action_176
+action_295 (110#) = happyShift action_109
+action_295 (111#) = happyShift action_110
+action_295 (114#) = happyShift action_111
+action_295 (121#) = happyShift action_112
+action_295 (170#) = happyShift action_6
+action_295 (171#) = happyShift action_48
+action_295 (172#) = happyShift action_49
+action_295 (174#) = happyShift action_51
+action_295 (8#) = happyGoto action_101
+action_295 (9#) = happyGoto action_102
+action_295 (10#) = happyGoto action_103
+action_295 (12#) = happyGoto action_170
+action_295 (67#) = happyGoto action_171
+action_295 (68#) = happyGoto action_172
+action_295 (69#) = happyGoto action_203
+action_295 (82#) = happyGoto action_204
+action_295 (83#) = happyGoto action_380
+action_295 x = happyTcHack x happyFail
+
+action_296 (96#) = happyShift action_106
+action_296 (98#) = happyShift action_107
+action_296 (104#) = happyShift action_108
+action_296 (106#) = happyShift action_176
+action_296 (110#) = happyShift action_109
+action_296 (111#) = happyShift action_110
+action_296 (114#) = happyShift action_111
+action_296 (121#) = happyShift action_112
+action_296 (170#) = happyShift action_6
+action_296 (171#) = happyShift action_48
+action_296 (172#) = happyShift action_49
+action_296 (174#) = happyShift action_51
+action_296 (8#) = happyGoto action_101
+action_296 (9#) = happyGoto action_102
+action_296 (10#) = happyGoto action_103
+action_296 (12#) = happyGoto action_170
+action_296 (67#) = happyGoto action_171
+action_296 (68#) = happyGoto action_379
+action_296 x = happyTcHack x happyFail
+
+action_297 (96#) = happyShift action_106
+action_297 (98#) = happyShift action_107
+action_297 (104#) = happyShift action_108
+action_297 (106#) = happyShift action_176
+action_297 (110#) = happyShift action_109
+action_297 (111#) = happyShift action_110
+action_297 (114#) = happyShift action_111
+action_297 (121#) = happyShift action_112
+action_297 (170#) = happyShift action_6
+action_297 (171#) = happyShift action_48
+action_297 (172#) = happyShift action_49
+action_297 (174#) = happyShift action_51
+action_297 (8#) = happyGoto action_101
+action_297 (9#) = happyGoto action_102
+action_297 (10#) = happyGoto action_103
+action_297 (12#) = happyGoto action_170
+action_297 (67#) = happyGoto action_171
+action_297 (68#) = happyGoto action_378
+action_297 x = happyTcHack x happyFail
+
+action_298 (96#) = happyShift action_24
+action_298 (98#) = happyShift action_25
+action_298 (104#) = happyShift action_26
+action_298 (109#) = happyShift action_27
+action_298 (110#) = happyShift action_28
+action_298 (111#) = happyShift action_29
+action_298 (114#) = happyShift action_30
+action_298 (119#) = happyShift action_31
+action_298 (124#) = happyShift action_32
+action_298 (125#) = happyShift action_33
+action_298 (126#) = happyShift action_34
+action_298 (127#) = happyShift action_35
+action_298 (128#) = happyShift action_36
+action_298 (129#) = happyShift action_37
+action_298 (131#) = happyShift action_38
+action_298 (134#) = happyShift action_39
+action_298 (137#) = happyShift action_40
+action_298 (140#) = happyShift action_41
+action_298 (145#) = happyShift action_42
+action_298 (156#) = happyShift action_43
+action_298 (157#) = happyShift action_44
+action_298 (161#) = happyShift action_45
+action_298 (162#) = happyShift action_46
+action_298 (167#) = happyShift action_47
+action_298 (170#) = happyShift action_6
+action_298 (171#) = happyShift action_48
+action_298 (172#) = happyShift action_49
+action_298 (173#) = happyShift action_50
+action_298 (174#) = happyShift action_51
+action_298 (8#) = happyGoto action_10
+action_298 (9#) = happyGoto action_11
+action_298 (10#) = happyGoto action_12
+action_298 (11#) = happyGoto action_13
+action_298 (12#) = happyGoto action_14
+action_298 (58#) = happyGoto action_15
+action_298 (59#) = happyGoto action_16
+action_298 (60#) = happyGoto action_17
+action_298 (61#) = happyGoto action_18
+action_298 (62#) = happyGoto action_19
+action_298 (63#) = happyGoto action_377
+action_298 (64#) = happyGoto action_21
+action_298 (72#) = happyGoto action_22
+action_298 (77#) = happyGoto action_23
+action_298 x = happyTcHack x happyFail
+
+action_299 x = happyTcHack x happyReduce_212
+
+action_300 (174#) = happyShift action_51
+action_300 (12#) = happyGoto action_376
+action_300 x = happyTcHack x happyFail
+
+action_301 (96#) = happyShift action_106
+action_301 (98#) = happyShift action_107
+action_301 (104#) = happyShift action_108
+action_301 (110#) = happyShift action_109
+action_301 (111#) = happyShift action_110
+action_301 (114#) = happyShift action_111
+action_301 (121#) = happyShift action_112
+action_301 (170#) = happyShift action_6
+action_301 (171#) = happyShift action_48
+action_301 (172#) = happyShift action_49
+action_301 (174#) = happyShift action_51
+action_301 (8#) = happyGoto action_101
+action_301 (9#) = happyGoto action_102
+action_301 (10#) = happyGoto action_103
+action_301 (12#) = happyGoto action_104
+action_301 (67#) = happyGoto action_375
+action_301 x = happyTcHack x happyFail
+
+action_302 x = happyTcHack x happyReduce_169
+
+action_303 (96#) = happyShift action_24
+action_303 (98#) = happyShift action_25
+action_303 (104#) = happyShift action_26
+action_303 (109#) = happyShift action_27
+action_303 (110#) = happyShift action_28
+action_303 (111#) = happyShift action_29
+action_303 (114#) = happyShift action_30
+action_303 (119#) = happyShift action_31
+action_303 (124#) = happyShift action_32
+action_303 (125#) = happyShift action_33
+action_303 (126#) = happyShift action_34
+action_303 (127#) = happyShift action_35
+action_303 (128#) = happyShift action_36
+action_303 (129#) = happyShift action_37
+action_303 (131#) = happyShift action_38
+action_303 (134#) = happyShift action_39
+action_303 (137#) = happyShift action_40
+action_303 (140#) = happyShift action_41
+action_303 (145#) = happyShift action_42
+action_303 (156#) = happyShift action_43
+action_303 (157#) = happyShift action_44
+action_303 (161#) = happyShift action_45
+action_303 (162#) = happyShift action_46
+action_303 (167#) = happyShift action_47
+action_303 (170#) = happyShift action_6
+action_303 (171#) = happyShift action_48
+action_303 (172#) = happyShift action_49
+action_303 (173#) = happyShift action_50
+action_303 (174#) = happyShift action_51
+action_303 (8#) = happyGoto action_10
+action_303 (9#) = happyGoto action_11
+action_303 (10#) = happyGoto action_12
+action_303 (11#) = happyGoto action_13
+action_303 (12#) = happyGoto action_14
+action_303 (58#) = happyGoto action_15
+action_303 (59#) = happyGoto action_16
+action_303 (60#) = happyGoto action_17
+action_303 (61#) = happyGoto action_18
+action_303 (62#) = happyGoto action_19
+action_303 (63#) = happyGoto action_199
+action_303 (64#) = happyGoto action_21
+action_303 (65#) = happyGoto action_374
+action_303 (72#) = happyGoto action_22
+action_303 (77#) = happyGoto action_23
+action_303 x = happyTcHack x happyReduce_193
+
+action_304 (96#) = happyShift action_24
+action_304 (98#) = happyShift action_25
+action_304 (104#) = happyShift action_26
+action_304 (109#) = happyShift action_27
+action_304 (110#) = happyShift action_28
+action_304 (111#) = happyShift action_29
+action_304 (114#) = happyShift action_30
+action_304 (119#) = happyShift action_31
+action_304 (124#) = happyShift action_32
+action_304 (125#) = happyShift action_33
+action_304 (126#) = happyShift action_34
+action_304 (127#) = happyShift action_35
+action_304 (128#) = happyShift action_36
+action_304 (129#) = happyShift action_37
+action_304 (131#) = happyShift action_38
+action_304 (134#) = happyShift action_39
+action_304 (137#) = happyShift action_40
+action_304 (140#) = happyShift action_41
+action_304 (145#) = happyShift action_42
+action_304 (156#) = happyShift action_43
+action_304 (157#) = happyShift action_44
+action_304 (161#) = happyShift action_45
+action_304 (162#) = happyShift action_46
+action_304 (167#) = happyShift action_47
+action_304 (170#) = happyShift action_6
+action_304 (171#) = happyShift action_48
+action_304 (172#) = happyShift action_49
+action_304 (173#) = happyShift action_50
+action_304 (174#) = happyShift action_51
+action_304 (8#) = happyGoto action_10
+action_304 (9#) = happyGoto action_11
+action_304 (10#) = happyGoto action_12
+action_304 (11#) = happyGoto action_13
+action_304 (12#) = happyGoto action_14
+action_304 (58#) = happyGoto action_15
+action_304 (59#) = happyGoto action_16
+action_304 (60#) = happyGoto action_17
+action_304 (61#) = happyGoto action_18
+action_304 (62#) = happyGoto action_19
+action_304 (63#) = happyGoto action_371
+action_304 (64#) = happyGoto action_21
+action_304 (72#) = happyGoto action_22
+action_304 (77#) = happyGoto action_23
+action_304 (86#) = happyGoto action_372
+action_304 (87#) = happyGoto action_373
+action_304 x = happyTcHack x happyReduce_257
+
+action_305 (95#) = happyShift action_370
+action_305 x = happyTcHack x happyReduce_134
+
+action_306 x = happyTcHack x happyReduce_135
+
+action_307 x = happyTcHack x happyReduce_139
+
+action_308 x = happyTcHack x happyReduce_187
+
+action_309 (140#) = happyShift action_369
+action_309 x = happyTcHack x happyFail
+
+action_310 x = happyTcHack x happyReduce_189
+
+action_311 (96#) = happyShift action_106
+action_311 (98#) = happyShift action_107
+action_311 (104#) = happyShift action_108
+action_311 (110#) = happyShift action_109
+action_311 (111#) = happyShift action_110
+action_311 (114#) = happyShift action_111
+action_311 (121#) = happyShift action_112
+action_311 (170#) = happyShift action_6
+action_311 (171#) = happyShift action_48
+action_311 (172#) = happyShift action_49
+action_311 (174#) = happyShift action_51
+action_311 (8#) = happyGoto action_101
+action_311 (9#) = happyGoto action_102
+action_311 (10#) = happyGoto action_103
+action_311 (12#) = happyGoto action_104
+action_311 (67#) = happyGoto action_188
+action_311 (74#) = happyGoto action_189
+action_311 (84#) = happyGoto action_190
+action_311 (85#) = happyGoto action_368
+action_311 x = happyTcHack x happyReduce_253
+
+action_312 (96#) = happyShift action_24
+action_312 (98#) = happyShift action_25
+action_312 (104#) = happyShift action_26
+action_312 (109#) = happyShift action_27
+action_312 (110#) = happyShift action_28
+action_312 (111#) = happyShift action_29
+action_312 (114#) = happyShift action_30
+action_312 (119#) = happyShift action_31
+action_312 (124#) = happyShift action_32
+action_312 (125#) = happyShift action_33
+action_312 (126#) = happyShift action_34
+action_312 (127#) = happyShift action_35
+action_312 (128#) = happyShift action_36
+action_312 (129#) = happyShift action_37
+action_312 (131#) = happyShift action_38
+action_312 (134#) = happyShift action_39
+action_312 (137#) = happyShift action_40
+action_312 (140#) = happyShift action_41
+action_312 (145#) = happyShift action_42
+action_312 (156#) = happyShift action_43
+action_312 (157#) = happyShift action_44
+action_312 (161#) = happyShift action_45
+action_312 (162#) = happyShift action_46
+action_312 (167#) = happyShift action_47
+action_312 (170#) = happyShift action_6
+action_312 (171#) = happyShift action_48
+action_312 (172#) = happyShift action_49
+action_312 (173#) = happyShift action_50
+action_312 (174#) = happyShift action_51
+action_312 (8#) = happyGoto action_10
+action_312 (9#) = happyGoto action_11
+action_312 (10#) = happyGoto action_12
+action_312 (11#) = happyGoto action_13
+action_312 (12#) = happyGoto action_14
+action_312 (58#) = happyGoto action_15
+action_312 (59#) = happyGoto action_16
+action_312 (60#) = happyGoto action_17
+action_312 (61#) = happyGoto action_18
+action_312 (62#) = happyGoto action_19
+action_312 (63#) = happyGoto action_367
+action_312 (64#) = happyGoto action_21
+action_312 (72#) = happyGoto action_22
+action_312 (77#) = happyGoto action_23
+action_312 x = happyTcHack x happyFail
+
+action_313 x = happyTcHack x happyReduce_233
+
+action_314 (96#) = happyShift action_106
+action_314 (98#) = happyShift action_107
+action_314 (104#) = happyShift action_108
+action_314 (106#) = happyShift action_176
+action_314 (110#) = happyShift action_109
+action_314 (111#) = happyShift action_110
+action_314 (114#) = happyShift action_111
+action_314 (121#) = happyShift action_112
+action_314 (170#) = happyShift action_6
+action_314 (171#) = happyShift action_48
+action_314 (172#) = happyShift action_49
+action_314 (174#) = happyShift action_51
+action_314 (8#) = happyGoto action_101
+action_314 (9#) = happyGoto action_102
+action_314 (10#) = happyGoto action_103
+action_314 (12#) = happyGoto action_170
+action_314 (67#) = happyGoto action_171
+action_314 (68#) = happyGoto action_172
+action_314 (69#) = happyGoto action_203
+action_314 (82#) = happyGoto action_204
+action_314 (83#) = happyGoto action_366
+action_314 x = happyTcHack x happyFail
+
+action_315 x = happyTcHack x happyReduce_238
+
+action_316 x = happyTcHack x happyReduce_182
+
+action_317 (96#) = happyShift action_24
+action_317 (98#) = happyShift action_25
+action_317 (104#) = happyShift action_26
+action_317 (109#) = happyShift action_27
+action_317 (110#) = happyShift action_28
+action_317 (111#) = happyShift action_29
+action_317 (114#) = happyShift action_30
+action_317 (119#) = happyShift action_31
+action_317 (124#) = happyShift action_32
+action_317 (125#) = happyShift action_33
+action_317 (126#) = happyShift action_34
+action_317 (127#) = happyShift action_35
+action_317 (128#) = happyShift action_36
+action_317 (129#) = happyShift action_37
+action_317 (131#) = happyShift action_38
+action_317 (134#) = happyShift action_39
+action_317 (137#) = happyShift action_40
+action_317 (140#) = happyShift action_41
+action_317 (145#) = happyShift action_42
+action_317 (156#) = happyShift action_43
+action_317 (157#) = happyShift action_44
+action_317 (161#) = happyShift action_45
+action_317 (162#) = happyShift action_46
+action_317 (167#) = happyShift action_47
+action_317 (170#) = happyShift action_6
+action_317 (171#) = happyShift action_48
+action_317 (172#) = happyShift action_49
+action_317 (173#) = happyShift action_50
+action_317 (174#) = happyShift action_51
+action_317 (8#) = happyGoto action_10
+action_317 (9#) = happyGoto action_11
+action_317 (10#) = happyGoto action_12
+action_317 (11#) = happyGoto action_13
+action_317 (12#) = happyGoto action_14
+action_317 (58#) = happyGoto action_15
+action_317 (59#) = happyGoto action_16
+action_317 (60#) = happyGoto action_17
+action_317 (61#) = happyGoto action_18
+action_317 (62#) = happyGoto action_19
+action_317 (63#) = happyGoto action_365
+action_317 (64#) = happyGoto action_21
+action_317 (72#) = happyGoto action_22
+action_317 (77#) = happyGoto action_23
+action_317 x = happyTcHack x happyFail
+
+action_318 x = happyTcHack x happyReduce_205
+
+action_319 x = happyTcHack x happyReduce_209
+
+action_320 (174#) = happyShift action_51
+action_320 (12#) = happyGoto action_87
+action_320 (53#) = happyGoto action_180
+action_320 (70#) = happyGoto action_181
+action_320 (73#) = happyGoto action_364
+action_320 x = happyTcHack x happyReduce_229
+
+action_321 (96#) = happyShift action_106
+action_321 (98#) = happyShift action_107
+action_321 (104#) = happyShift action_108
+action_321 (106#) = happyShift action_176
+action_321 (110#) = happyShift action_109
+action_321 (111#) = happyShift action_110
+action_321 (114#) = happyShift action_111
+action_321 (121#) = happyShift action_112
+action_321 (170#) = happyShift action_6
+action_321 (171#) = happyShift action_48
+action_321 (172#) = happyShift action_49
+action_321 (174#) = happyShift action_51
+action_321 (8#) = happyGoto action_101
+action_321 (9#) = happyGoto action_102
+action_321 (10#) = happyGoto action_103
+action_321 (12#) = happyGoto action_170
+action_321 (67#) = happyGoto action_171
+action_321 (68#) = happyGoto action_172
+action_321 (69#) = happyGoto action_363
+action_321 x = happyTcHack x happyFail
+
+action_322 x = happyTcHack x happyReduce_204
+
+action_323 x = happyTcHack x happyReduce_211
+
+action_324 x = happyTcHack x happyReduce_199
+
+action_325 x = happyTcHack x happyReduce_216
+
+action_326 x = happyTcHack x happyReduce_210
+
+action_327 (96#) = happyShift action_106
+action_327 (98#) = happyShift action_107
+action_327 (104#) = happyShift action_108
+action_327 (106#) = happyShift action_176
+action_327 (110#) = happyShift action_109
+action_327 (111#) = happyShift action_110
+action_327 (114#) = happyShift action_111
+action_327 (121#) = happyShift action_112
+action_327 (170#) = happyShift action_6
+action_327 (171#) = happyShift action_48
+action_327 (172#) = happyShift action_49
+action_327 (174#) = happyShift action_51
+action_327 (8#) = happyGoto action_101
+action_327 (9#) = happyGoto action_102
+action_327 (10#) = happyGoto action_103
+action_327 (12#) = happyGoto action_170
+action_327 (67#) = happyGoto action_171
+action_327 (68#) = happyGoto action_172
+action_327 (69#) = happyGoto action_173
+action_327 (79#) = happyGoto action_174
+action_327 (81#) = happyGoto action_362
+action_327 x = happyTcHack x happyReduce_246
+
+action_328 x = happyTcHack x happyReduce_214
+
+action_329 (174#) = happyShift action_51
+action_329 (12#) = happyGoto action_361
+action_329 x = happyTcHack x happyFail
+
+action_330 (112#) = happyShift action_360
+action_330 x = happyTcHack x happyFail
+
+action_331 x = happyTcHack x happyReduce_241
+
+action_332 x = happyTcHack x happyReduce_245
+
+action_333 x = happyTcHack x happyReduce_160
+
+action_334 x = happyTcHack x happyReduce_150
+
+action_335 x = happyTcHack x happyReduce_197
+
+action_336 (99#) = happyShift action_359
+action_336 x = happyTcHack x happyFail
+
+action_337 x = happyTcHack x happyReduce_154
+
+action_338 (97#) = happyShift action_358
+action_338 x = happyTcHack x happyFail
+
+action_339 x = happyTcHack x happyReduce_129
+
+action_340 (97#) = happyShift action_357
+action_340 x = happyTcHack x happyFail
+
+action_341 x = happyTcHack x happyReduce_223
+
+action_342 (97#) = happyShift action_155
+action_342 (103#) = happyShift action_156
+action_342 x = happyTcHack x happyReduce_128
+
+action_343 x = happyTcHack x happyReduce_25
+
+action_344 (151#) = happyShift action_356
+action_344 (28#) = happyGoto action_355
+action_344 x = happyTcHack x happyReduce_55
+
+action_345 (102#) = happyShift action_354
+action_345 x = happyTcHack x happyReduce_27
+
+action_346 (103#) = happyShift action_352
+action_346 (169#) = happyShift action_353
+action_346 x = happyTcHack x happyReduce_66
+
+action_347 (174#) = happyShift action_51
+action_347 (12#) = happyGoto action_351
+action_347 x = happyTcHack x happyFail
+
+action_348 (174#) = happyShift action_51
+action_348 (12#) = happyGoto action_241
+action_348 (32#) = happyGoto action_349
+action_348 (33#) = happyGoto action_350
+action_348 x = happyTcHack x happyReduce_65
+
+action_349 x = happyTcHack x happyReduce_33
+
+action_350 (103#) = happyShift action_352
+action_350 x = happyTcHack x happyReduce_66
+
+action_351 x = happyTcHack x happyReduce_32
+
+action_352 (174#) = happyShift action_51
+action_352 (12#) = happyGoto action_241
+action_352 (32#) = happyGoto action_468
+action_352 (33#) = happyGoto action_350
+action_352 x = happyTcHack x happyReduce_65
+
+action_353 (98#) = happyShift action_408
+action_353 (174#) = happyShift action_51
+action_353 (12#) = happyGoto action_406
+action_353 (27#) = happyGoto action_467
+action_353 (29#) = happyGoto action_425
+action_353 x = happyTcHack x happyReduce_52
+
+action_354 (174#) = happyShift action_51
+action_354 (12#) = happyGoto action_241
+action_354 (33#) = happyGoto action_466
+action_354 x = happyTcHack x happyReduce_50
+
+action_355 x = happyTcHack x happyReduce_26
+
+action_356 (98#) = happyShift action_408
+action_356 (174#) = happyShift action_51
+action_356 (12#) = happyGoto action_406
+action_356 (27#) = happyGoto action_465
+action_356 (29#) = happyGoto action_425
+action_356 x = happyTcHack x happyReduce_52
+
+action_357 x = happyTcHack x happyReduce_188
+
+action_358 x = happyTcHack x happyReduce_159
+
+action_359 x = happyTcHack x happyReduce_239
+
+action_360 x = happyTcHack x happyReduce_155
+
+action_361 x = happyTcHack x happyReduce_201
+
+action_362 x = happyTcHack x happyReduce_248
+
+action_363 (108#) = happyShift action_296
+action_363 (117#) = happyShift action_297
+action_363 x = happyTcHack x happyReduce_221
+
+action_364 x = happyTcHack x happyReduce_231
+
+action_365 x = happyTcHack x happyReduce_183
+
+action_366 (97#) = happyShift action_464
+action_366 x = happyTcHack x happyFail
+
+action_367 x = happyTcHack x happyReduce_252
+
+action_368 x = happyTcHack x happyReduce_255
+
+action_369 (96#) = happyShift action_24
+action_369 (98#) = happyShift action_25
+action_369 (104#) = happyShift action_26
+action_369 (109#) = happyShift action_27
+action_369 (110#) = happyShift action_28
+action_369 (111#) = happyShift action_29
+action_369 (114#) = happyShift action_30
+action_369 (119#) = happyShift action_31
+action_369 (124#) = happyShift action_32
+action_369 (125#) = happyShift action_33
+action_369 (126#) = happyShift action_34
+action_369 (127#) = happyShift action_35
+action_369 (128#) = happyShift action_36
+action_369 (129#) = happyShift action_37
+action_369 (131#) = happyShift action_38
+action_369 (134#) = happyShift action_39
+action_369 (137#) = happyShift action_40
+action_369 (140#) = happyShift action_41
+action_369 (145#) = happyShift action_42
+action_369 (156#) = happyShift action_43
+action_369 (157#) = happyShift action_44
+action_369 (161#) = happyShift action_45
+action_369 (162#) = happyShift action_46
+action_369 (167#) = happyShift action_47
+action_369 (170#) = happyShift action_6
+action_369 (171#) = happyShift action_48
+action_369 (172#) = happyShift action_49
+action_369 (173#) = happyShift action_50
+action_369 (174#) = happyShift action_51
+action_369 (8#) = happyGoto action_10
+action_369 (9#) = happyGoto action_11
+action_369 (10#) = happyGoto action_12
+action_369 (11#) = happyGoto action_13
+action_369 (12#) = happyGoto action_14
+action_369 (58#) = happyGoto action_15
+action_369 (59#) = happyGoto action_16
+action_369 (60#) = happyGoto action_17
+action_369 (61#) = happyGoto action_18
+action_369 (62#) = happyGoto action_19
+action_369 (63#) = happyGoto action_463
+action_369 (64#) = happyGoto action_21
+action_369 (72#) = happyGoto action_22
+action_369 (77#) = happyGoto action_23
+action_369 x = happyTcHack x happyFail
+
+action_370 (96#) = happyShift action_24
+action_370 (98#) = happyShift action_25
+action_370 (104#) = happyShift action_26
+action_370 (109#) = happyShift action_27
+action_370 (110#) = happyShift action_28
+action_370 (111#) = happyShift action_29
+action_370 (114#) = happyShift action_30
+action_370 (119#) = happyShift action_31
+action_370 (124#) = happyShift action_32
+action_370 (125#) = happyShift action_33
+action_370 (126#) = happyShift action_34
+action_370 (127#) = happyShift action_35
+action_370 (128#) = happyShift action_36
+action_370 (129#) = happyShift action_37
+action_370 (131#) = happyShift action_38
+action_370 (134#) = happyShift action_39
+action_370 (137#) = happyShift action_40
+action_370 (140#) = happyShift action_41
+action_370 (145#) = happyShift action_42
+action_370 (156#) = happyShift action_43
+action_370 (157#) = happyShift action_44
+action_370 (161#) = happyShift action_45
+action_370 (162#) = happyShift action_46
+action_370 (167#) = happyShift action_47
+action_370 (170#) = happyShift action_6
+action_370 (171#) = happyShift action_48
+action_370 (172#) = happyShift action_49
+action_370 (173#) = happyShift action_50
+action_370 (174#) = happyShift action_51
+action_370 (8#) = happyGoto action_10
+action_370 (9#) = happyGoto action_11
+action_370 (10#) = happyGoto action_12
+action_370 (11#) = happyGoto action_13
+action_370 (12#) = happyGoto action_14
+action_370 (58#) = happyGoto action_15
+action_370 (59#) = happyGoto action_16
+action_370 (60#) = happyGoto action_17
+action_370 (61#) = happyGoto action_18
+action_370 (62#) = happyGoto action_19
+action_370 (63#) = happyGoto action_462
+action_370 (64#) = happyGoto action_21
+action_370 (72#) = happyGoto action_22
+action_370 (77#) = happyGoto action_23
+action_370 x = happyTcHack x happyFail
+
+action_371 (123#) = happyShift action_461
+action_371 x = happyTcHack x happyFail
+
+action_372 (94#) = happyShift action_460
+action_372 x = happyTcHack x happyReduce_258
+
+action_373 (97#) = happyShift action_459
+action_373 x = happyTcHack x happyFail
+
+action_374 x = happyTcHack x happyReduce_195
+
+action_375 x = happyTcHack x happyReduce_215
+
+action_376 (96#) = happyShift action_106
+action_376 (98#) = happyShift action_107
+action_376 (104#) = happyShift action_108
+action_376 (110#) = happyShift action_109
+action_376 (111#) = happyShift action_110
+action_376 (114#) = happyShift action_111
+action_376 (121#) = happyShift action_112
+action_376 (170#) = happyShift action_6
+action_376 (171#) = happyShift action_48
+action_376 (172#) = happyShift action_49
+action_376 (174#) = happyShift action_51
+action_376 (8#) = happyGoto action_101
+action_376 (9#) = happyGoto action_102
+action_376 (10#) = happyGoto action_103
+action_376 (12#) = happyGoto action_104
+action_376 (67#) = happyGoto action_188
+action_376 (74#) = happyGoto action_458
+action_376 x = happyTcHack x happyReduce_205
+
+action_377 x = happyTcHack x happyReduce_249
+
+action_378 x = happyTcHack x happyReduce_219
+
+action_379 x = happyTcHack x happyReduce_218
+
+action_380 x = happyTcHack x happyReduce_251
+
+action_381 x = happyTcHack x happyReduce_164
+
+action_382 x = happyTcHack x happyReduce_165
+
+action_383 (89#) = happyGoto action_457
+action_383 x = happyTcHack x happyReduce_262
+
+action_384 (104#) = happyShift action_290
+action_384 (174#) = happyShift action_51
+action_384 (12#) = happyGoto action_287
+action_384 (36#) = happyGoto action_288
+action_384 (46#) = happyGoto action_456
+action_384 x = happyTcHack x happyReduce_113
+
+action_385 (96#) = happyShift action_140
+action_385 (98#) = happyShift action_455
+action_385 (104#) = happyShift action_26
+action_385 (109#) = happyShift action_83
+action_385 (110#) = happyShift action_28
+action_385 (111#) = happyShift action_29
+action_385 (125#) = happyShift action_33
+action_385 (126#) = happyShift action_34
+action_385 (127#) = happyShift action_35
+action_385 (128#) = happyShift action_36
+action_385 (129#) = happyShift action_37
+action_385 (134#) = happyShift action_39
+action_385 (170#) = happyShift action_6
+action_385 (171#) = happyShift action_48
+action_385 (172#) = happyShift action_49
+action_385 (173#) = happyShift action_50
+action_385 (174#) = happyShift action_51
+action_385 (8#) = happyGoto action_10
+action_385 (9#) = happyGoto action_11
+action_385 (10#) = happyGoto action_12
+action_385 (11#) = happyGoto action_13
+action_385 (12#) = happyGoto action_79
+action_385 (58#) = happyGoto action_453
+action_385 (72#) = happyGoto action_22
+action_385 (88#) = happyGoto action_454
+action_385 x = happyTcHack x happyReduce_95
+
+action_386 (174#) = happyShift action_51
+action_386 (12#) = happyGoto action_451
+action_386 (38#) = happyGoto action_284
+action_386 (48#) = happyGoto action_452
+action_386 x = happyTcHack x happyReduce_117
+
+action_387 (174#) = happyShift action_51
+action_387 (12#) = happyGoto action_448
+action_387 (39#) = happyGoto action_449
+action_387 (40#) = happyGoto action_450
+action_387 x = happyTcHack x happyReduce_102
+
+action_388 (174#) = happyShift action_51
+action_388 (12#) = happyGoto action_279
+action_388 (44#) = happyGoto action_280
+action_388 (51#) = happyGoto action_447
+action_388 x = happyTcHack x happyReduce_123
+
+action_389 (174#) = happyShift action_51
+action_389 (12#) = happyGoto action_446
+action_389 x = happyTcHack x happyFail
+
+action_390 (96#) = happyShift action_24
+action_390 (98#) = happyShift action_25
+action_390 (104#) = happyShift action_26
+action_390 (109#) = happyShift action_27
+action_390 (110#) = happyShift action_28
+action_390 (111#) = happyShift action_29
+action_390 (114#) = happyShift action_30
+action_390 (119#) = happyShift action_31
+action_390 (124#) = happyShift action_32
+action_390 (125#) = happyShift action_33
+action_390 (126#) = happyShift action_34
+action_390 (127#) = happyShift action_35
+action_390 (128#) = happyShift action_36
+action_390 (129#) = happyShift action_37
+action_390 (131#) = happyShift action_38
+action_390 (134#) = happyShift action_39
+action_390 (137#) = happyShift action_40
+action_390 (140#) = happyShift action_41
+action_390 (145#) = happyShift action_42
+action_390 (156#) = happyShift action_43
+action_390 (157#) = happyShift action_44
+action_390 (161#) = happyShift action_45
+action_390 (162#) = happyShift action_46
+action_390 (167#) = happyShift action_47
+action_390 (170#) = happyShift action_6
+action_390 (171#) = happyShift action_48
+action_390 (172#) = happyShift action_49
+action_390 (173#) = happyShift action_50
+action_390 (174#) = happyShift action_51
+action_390 (8#) = happyGoto action_10
+action_390 (9#) = happyGoto action_11
+action_390 (10#) = happyGoto action_12
+action_390 (11#) = happyGoto action_13
+action_390 (12#) = happyGoto action_14
+action_390 (58#) = happyGoto action_15
+action_390 (59#) = happyGoto action_16
+action_390 (60#) = happyGoto action_17
+action_390 (61#) = happyGoto action_18
+action_390 (62#) = happyGoto action_19
+action_390 (63#) = happyGoto action_445
+action_390 (64#) = happyGoto action_21
+action_390 (72#) = happyGoto action_22
+action_390 (77#) = happyGoto action_23
+action_390 x = happyTcHack x happyFail
+
+action_391 (174#) = happyShift action_51
+action_391 (12#) = happyGoto action_87
+action_391 (37#) = happyGoto action_276
+action_391 (47#) = happyGoto action_444
+action_391 (53#) = happyGoto action_278
+action_391 x = happyTcHack x happyReduce_115
+
+action_392 (96#) = happyShift action_443
+action_392 x = happyTcHack x happyFail
+
+action_393 (174#) = happyShift action_51
+action_393 (12#) = happyGoto action_267
+action_393 (41#) = happyGoto action_268
+action_393 (49#) = happyGoto action_442
+action_393 x = happyTcHack x happyReduce_119
+
+action_394 (98#) = happyShift action_441
+action_394 (174#) = happyShift action_51
+action_394 (12#) = happyGoto action_438
+action_394 (42#) = happyGoto action_439
+action_394 (52#) = happyGoto action_440
+action_394 x = happyTcHack x happyReduce_125
+
+action_395 x = happyTcHack x happyReduce_87
+
+action_396 x = happyTcHack x happyReduce_86
+
+action_397 (96#) = happyShift action_24
+action_397 (98#) = happyShift action_25
+action_397 (104#) = happyShift action_26
+action_397 (109#) = happyShift action_27
+action_397 (110#) = happyShift action_28
+action_397 (111#) = happyShift action_29
+action_397 (114#) = happyShift action_30
+action_397 (119#) = happyShift action_31
+action_397 (124#) = happyShift action_32
+action_397 (125#) = happyShift action_33
+action_397 (126#) = happyShift action_34
+action_397 (127#) = happyShift action_35
+action_397 (128#) = happyShift action_36
+action_397 (129#) = happyShift action_37
+action_397 (131#) = happyShift action_38
+action_397 (134#) = happyShift action_39
+action_397 (137#) = happyShift action_40
+action_397 (140#) = happyShift action_41
+action_397 (145#) = happyShift action_42
+action_397 (156#) = happyShift action_43
+action_397 (157#) = happyShift action_44
+action_397 (161#) = happyShift action_45
+action_397 (162#) = happyShift action_46
+action_397 (167#) = happyShift action_47
+action_397 (170#) = happyShift action_6
+action_397 (171#) = happyShift action_48
+action_397 (172#) = happyShift action_49
+action_397 (173#) = happyShift action_50
+action_397 (174#) = happyShift action_51
+action_397 (8#) = happyGoto action_10
+action_397 (9#) = happyGoto action_11
+action_397 (10#) = happyGoto action_12
+action_397 (11#) = happyGoto action_13
+action_397 (12#) = happyGoto action_14
+action_397 (58#) = happyGoto action_15
+action_397 (59#) = happyGoto action_16
+action_397 (60#) = happyGoto action_17
+action_397 (61#) = happyGoto action_18
+action_397 (62#) = happyGoto action_19
+action_397 (63#) = happyGoto action_437
+action_397 (64#) = happyGoto action_21
+action_397 (72#) = happyGoto action_22
+action_397 (77#) = happyGoto action_23
+action_397 x = happyTcHack x happyFail
+
+action_398 (104#) = happyShift action_257
+action_398 (174#) = happyShift action_51
+action_398 (12#) = happyGoto action_252
+action_398 (54#) = happyGoto action_262
+action_398 (55#) = happyGoto action_436
+action_398 x = happyTcHack x happyFail
+
+action_399 (104#) = happyShift action_257
+action_399 (174#) = happyShift action_51
+action_399 (12#) = happyGoto action_252
+action_399 (43#) = happyGoto action_260
+action_399 (50#) = happyGoto action_435
+action_399 (54#) = happyGoto action_262
+action_399 (55#) = happyGoto action_263
+action_399 x = happyTcHack x happyReduce_121
+
+action_400 x = happyTcHack x happyReduce_94
+
+action_401 (105#) = happyShift action_434
+action_401 x = happyTcHack x happyFail
+
+action_402 (96#) = happyShift action_24
+action_402 (98#) = happyShift action_25
+action_402 (104#) = happyShift action_26
+action_402 (109#) = happyShift action_27
+action_402 (110#) = happyShift action_28
+action_402 (111#) = happyShift action_29
+action_402 (114#) = happyShift action_30
+action_402 (119#) = happyShift action_31
+action_402 (124#) = happyShift action_32
+action_402 (125#) = happyShift action_33
+action_402 (126#) = happyShift action_34
+action_402 (127#) = happyShift action_35
+action_402 (128#) = happyShift action_36
+action_402 (129#) = happyShift action_37
+action_402 (131#) = happyShift action_38
+action_402 (134#) = happyShift action_39
+action_402 (137#) = happyShift action_40
+action_402 (140#) = happyShift action_41
+action_402 (145#) = happyShift action_42
+action_402 (156#) = happyShift action_43
+action_402 (157#) = happyShift action_44
+action_402 (161#) = happyShift action_45
+action_402 (162#) = happyShift action_46
+action_402 (167#) = happyShift action_47
+action_402 (170#) = happyShift action_6
+action_402 (171#) = happyShift action_48
+action_402 (172#) = happyShift action_49
+action_402 (173#) = happyShift action_50
+action_402 (174#) = happyShift action_51
+action_402 (8#) = happyGoto action_10
+action_402 (9#) = happyGoto action_11
+action_402 (10#) = happyGoto action_12
+action_402 (11#) = happyGoto action_13
+action_402 (12#) = happyGoto action_14
+action_402 (58#) = happyGoto action_15
+action_402 (59#) = happyGoto action_16
+action_402 (60#) = happyGoto action_17
+action_402 (61#) = happyGoto action_18
+action_402 (62#) = happyGoto action_19
+action_402 (63#) = happyGoto action_433
+action_402 (64#) = happyGoto action_21
+action_402 (72#) = happyGoto action_22
+action_402 (77#) = happyGoto action_23
+action_402 x = happyTcHack x happyFail
+
+action_403 (96#) = happyShift action_24
+action_403 (98#) = happyShift action_25
+action_403 (104#) = happyShift action_26
+action_403 (109#) = happyShift action_27
+action_403 (110#) = happyShift action_28
+action_403 (111#) = happyShift action_29
+action_403 (114#) = happyShift action_30
+action_403 (119#) = happyShift action_31
+action_403 (124#) = happyShift action_32
+action_403 (125#) = happyShift action_33
+action_403 (126#) = happyShift action_34
+action_403 (127#) = happyShift action_35
+action_403 (128#) = happyShift action_36
+action_403 (129#) = happyShift action_37
+action_403 (131#) = happyShift action_38
+action_403 (134#) = happyShift action_39
+action_403 (137#) = happyShift action_40
+action_403 (140#) = happyShift action_41
+action_403 (145#) = happyShift action_42
+action_403 (156#) = happyShift action_43
+action_403 (157#) = happyShift action_44
+action_403 (161#) = happyShift action_45
+action_403 (162#) = happyShift action_46
+action_403 (167#) = happyShift action_47
+action_403 (170#) = happyShift action_6
+action_403 (171#) = happyShift action_48
+action_403 (172#) = happyShift action_49
+action_403 (173#) = happyShift action_50
+action_403 (174#) = happyShift action_51
+action_403 (8#) = happyGoto action_10
+action_403 (9#) = happyGoto action_11
+action_403 (10#) = happyGoto action_12
+action_403 (11#) = happyGoto action_13
+action_403 (12#) = happyGoto action_14
+action_403 (58#) = happyGoto action_15
+action_403 (59#) = happyGoto action_16
+action_403 (60#) = happyGoto action_17
+action_403 (61#) = happyGoto action_18
+action_403 (62#) = happyGoto action_19
+action_403 (63#) = happyGoto action_432
+action_403 (64#) = happyGoto action_21
+action_403 (72#) = happyGoto action_22
+action_403 (77#) = happyGoto action_23
+action_403 x = happyTcHack x happyFail
+
+action_404 (95#) = happyShift action_431
+action_404 x = happyTcHack x happyFail
+
+action_405 (104#) = happyShift action_257
+action_405 (174#) = happyShift action_51
+action_405 (12#) = happyGoto action_252
+action_405 (34#) = happyGoto action_253
+action_405 (45#) = happyGoto action_430
+action_405 (54#) = happyGoto action_255
+action_405 (55#) = happyGoto action_256
+action_405 x = happyTcHack x happyReduce_111
+
+action_406 x = happyTcHack x happyReduce_57
+
+action_407 (101#) = happyShift action_429
+action_407 x = happyTcHack x happyFail
+
+action_408 (142#) = happyShift action_427
+action_408 (144#) = happyShift action_428
+action_408 (31#) = happyGoto action_426
+action_408 x = happyTcHack x happyReduce_62
+
+action_409 x = happyTcHack x happyReduce_38
+
+action_410 x = happyTcHack x happyReduce_37
+
+action_411 x = happyTcHack x happyReduce_47
+
+action_412 x = happyTcHack x happyReduce_46
+
+action_413 (98#) = happyShift action_408
+action_413 (174#) = happyShift action_51
+action_413 (12#) = happyGoto action_406
+action_413 (27#) = happyGoto action_424
+action_413 (29#) = happyGoto action_425
+action_413 x = happyTcHack x happyReduce_52
+
+action_414 (174#) = happyShift action_51
+action_414 (12#) = happyGoto action_241
+action_414 (33#) = happyGoto action_423
+action_414 x = happyTcHack x happyReduce_50
+
+action_415 (96#) = happyShift action_422
+action_415 x = happyTcHack x happyFail
+
+action_416 (174#) = happyShift action_51
+action_416 (12#) = happyGoto action_87
+action_416 (53#) = happyGoto action_421
+action_416 x = happyTcHack x happyFail
+
+action_417 (104#) = happyShift action_420
+action_417 x = happyTcHack x happyFail
+
+action_418 (95#) = happyShift action_419
+action_418 x = happyTcHack x happyFail
+
+action_419 (174#) = happyShift action_51
+action_419 (12#) = happyGoto action_492
+action_419 x = happyTcHack x happyFail
+
+action_420 (174#) = happyShift action_51
+action_420 (12#) = happyGoto action_87
+action_420 (53#) = happyGoto action_491
+action_420 x = happyTcHack x happyFail
+
+action_421 (105#) = happyShift action_490
+action_421 x = happyTcHack x happyFail
+
+action_422 (25#) = happyGoto action_489
+action_422 x = happyTcHack x happyReduce_48
+
+action_423 (169#) = happyShift action_488
+action_423 x = happyTcHack x happyFail
+
+action_424 (102#) = happyShift action_487
+action_424 x = happyTcHack x happyReduce_42
+
+action_425 (103#) = happyShift action_486
+action_425 x = happyTcHack x happyReduce_53
+
+action_426 (174#) = happyShift action_51
+action_426 (12#) = happyGoto action_485
+action_426 x = happyTcHack x happyFail
+
+action_427 x = happyTcHack x happyReduce_63
+
+action_428 x = happyTcHack x happyReduce_64
+
+action_429 (98#) = happyShift action_408
+action_429 (174#) = happyShift action_51
+action_429 (12#) = happyGoto action_406
+action_429 (29#) = happyGoto action_484
+action_429 x = happyTcHack x happyFail
+
+action_430 x = happyTcHack x happyReduce_112
+
+action_431 (96#) = happyShift action_24
+action_431 (98#) = happyShift action_25
+action_431 (104#) = happyShift action_26
+action_431 (109#) = happyShift action_27
+action_431 (110#) = happyShift action_28
+action_431 (111#) = happyShift action_29
+action_431 (114#) = happyShift action_30
+action_431 (119#) = happyShift action_31
+action_431 (124#) = happyShift action_32
+action_431 (125#) = happyShift action_33
+action_431 (126#) = happyShift action_34
+action_431 (127#) = happyShift action_35
+action_431 (128#) = happyShift action_36
+action_431 (129#) = happyShift action_37
+action_431 (131#) = happyShift action_38
+action_431 (134#) = happyShift action_39
+action_431 (137#) = happyShift action_40
+action_431 (140#) = happyShift action_41
+action_431 (145#) = happyShift action_42
+action_431 (156#) = happyShift action_43
+action_431 (157#) = happyShift action_44
+action_431 (161#) = happyShift action_45
+action_431 (162#) = happyShift action_46
+action_431 (167#) = happyShift action_47
+action_431 (170#) = happyShift action_6
+action_431 (171#) = happyShift action_48
+action_431 (172#) = happyShift action_49
+action_431 (173#) = happyShift action_50
+action_431 (174#) = happyShift action_51
+action_431 (8#) = happyGoto action_10
+action_431 (9#) = happyGoto action_11
+action_431 (10#) = happyGoto action_12
+action_431 (11#) = happyGoto action_13
+action_431 (12#) = happyGoto action_14
+action_431 (58#) = happyGoto action_15
+action_431 (59#) = happyGoto action_16
+action_431 (60#) = happyGoto action_17
+action_431 (61#) = happyGoto action_18
+action_431 (62#) = happyGoto action_19
+action_431 (63#) = happyGoto action_483
+action_431 (64#) = happyGoto action_21
+action_431 (72#) = happyGoto action_22
+action_431 (77#) = happyGoto action_23
+action_431 x = happyTcHack x happyFail
+
+action_432 (95#) = happyShift action_482
+action_432 x = happyTcHack x happyReduce_71
+
+action_433 x = happyTcHack x happyReduce_72
+
+action_434 x = happyTcHack x happyReduce_131
+
+action_435 x = happyTcHack x happyReduce_122
+
+action_436 x = happyTcHack x happyReduce_133
+
+action_437 x = happyTcHack x happyReduce_109
+
+action_438 (89#) = happyGoto action_481
+action_438 x = happyTcHack x happyReduce_262
+
+action_439 (108#) = happyShift action_480
+action_439 x = happyTcHack x happyReduce_126
+
+action_440 x = happyTcHack x happyReduce_105
+
+action_441 (140#) = happyShift action_479
+action_441 x = happyTcHack x happyFail
+
+action_442 x = happyTcHack x happyReduce_120
+
+action_443 (25#) = happyGoto action_478
+action_443 x = happyTcHack x happyReduce_48
+
+action_444 x = happyTcHack x happyReduce_116
+
+action_445 x = happyTcHack x happyReduce_98
+
+action_446 x = happyTcHack x happyReduce_110
+
+action_447 x = happyTcHack x happyReduce_124
+
+action_448 (107#) = happyShift action_477
+action_448 x = happyTcHack x happyReduce_100
+
+action_449 (108#) = happyShift action_476
+action_449 x = happyTcHack x happyReduce_103
+
+action_450 x = happyTcHack x happyReduce_99
+
+action_451 (95#) = happyShift action_387
+action_451 x = happyTcHack x happyFail
+
+action_452 x = happyTcHack x happyReduce_118
+
+action_453 x = happyTcHack x happyReduce_261
+
+action_454 x = happyTcHack x happyReduce_263
+
+action_455 (96#) = happyShift action_24
+action_455 (98#) = happyShift action_25
+action_455 (104#) = happyShift action_26
+action_455 (109#) = happyShift action_27
+action_455 (110#) = happyShift action_28
+action_455 (111#) = happyShift action_29
+action_455 (114#) = happyShift action_30
+action_455 (119#) = happyShift action_31
+action_455 (121#) = happyShift action_100
+action_455 (124#) = happyShift action_32
+action_455 (125#) = happyShift action_33
+action_455 (126#) = happyShift action_34
+action_455 (127#) = happyShift action_35
+action_455 (128#) = happyShift action_36
+action_455 (129#) = happyShift action_37
+action_455 (131#) = happyShift action_38
+action_455 (134#) = happyShift action_39
+action_455 (137#) = happyShift action_40
+action_455 (140#) = happyShift action_123
+action_455 (145#) = happyShift action_42
+action_455 (156#) = happyShift action_43
+action_455 (157#) = happyShift action_44
+action_455 (161#) = happyShift action_45
+action_455 (162#) = happyShift action_46
+action_455 (167#) = happyShift action_47
+action_455 (170#) = happyShift action_6
+action_455 (171#) = happyShift action_48
+action_455 (172#) = happyShift action_49
+action_455 (173#) = happyShift action_50
+action_455 (174#) = happyShift action_51
+action_455 (8#) = happyGoto action_10
+action_455 (9#) = happyGoto action_11
+action_455 (10#) = happyGoto action_12
+action_455 (11#) = happyGoto action_13
+action_455 (12#) = happyGoto action_120
+action_455 (58#) = happyGoto action_15
+action_455 (59#) = happyGoto action_16
+action_455 (60#) = happyGoto action_17
+action_455 (61#) = happyGoto action_18
+action_455 (62#) = happyGoto action_19
+action_455 (63#) = happyGoto action_121
+action_455 (64#) = happyGoto action_21
+action_455 (72#) = happyGoto action_22
+action_455 (75#) = happyGoto action_97
+action_455 (76#) = happyGoto action_475
+action_455 (77#) = happyGoto action_23
+action_455 x = happyTcHack x happyReduce_236
+
+action_456 x = happyTcHack x happyReduce_114
+
+action_457 (96#) = happyShift action_140
+action_457 (98#) = happyShift action_455
+action_457 (104#) = happyShift action_26
+action_457 (105#) = happyShift action_474
+action_457 (109#) = happyShift action_83
+action_457 (110#) = happyShift action_28
+action_457 (111#) = happyShift action_29
+action_457 (125#) = happyShift action_33
+action_457 (126#) = happyShift action_34
+action_457 (127#) = happyShift action_35
+action_457 (128#) = happyShift action_36
+action_457 (129#) = happyShift action_37
+action_457 (134#) = happyShift action_39
+action_457 (170#) = happyShift action_6
+action_457 (171#) = happyShift action_48
+action_457 (172#) = happyShift action_49
+action_457 (173#) = happyShift action_50
+action_457 (174#) = happyShift action_51
+action_457 (8#) = happyGoto action_10
+action_457 (9#) = happyGoto action_11
+action_457 (10#) = happyGoto action_12
+action_457 (11#) = happyGoto action_13
+action_457 (12#) = happyGoto action_79
+action_457 (58#) = happyGoto action_453
+action_457 (72#) = happyGoto action_22
+action_457 (88#) = happyGoto action_454
+action_457 x = happyTcHack x happyFail
+
+action_458 x = happyTcHack x happyReduce_213
+
+action_459 x = happyTcHack x happyReduce_168
+
+action_460 (96#) = happyShift action_24
+action_460 (98#) = happyShift action_25
+action_460 (104#) = happyShift action_26
+action_460 (109#) = happyShift action_27
+action_460 (110#) = happyShift action_28
+action_460 (111#) = happyShift action_29
+action_460 (114#) = happyShift action_30
+action_460 (119#) = happyShift action_31
+action_460 (124#) = happyShift action_32
+action_460 (125#) = happyShift action_33
+action_460 (126#) = happyShift action_34
+action_460 (127#) = happyShift action_35
+action_460 (128#) = happyShift action_36
+action_460 (129#) = happyShift action_37
+action_460 (131#) = happyShift action_38
+action_460 (134#) = happyShift action_39
+action_460 (137#) = happyShift action_40
+action_460 (140#) = happyShift action_41
+action_460 (145#) = happyShift action_42
+action_460 (156#) = happyShift action_43
+action_460 (157#) = happyShift action_44
+action_460 (161#) = happyShift action_45
+action_460 (162#) = happyShift action_46
+action_460 (167#) = happyShift action_47
+action_460 (170#) = happyShift action_6
+action_460 (171#) = happyShift action_48
+action_460 (172#) = happyShift action_49
+action_460 (173#) = happyShift action_50
+action_460 (174#) = happyShift action_51
+action_460 (8#) = happyGoto action_10
+action_460 (9#) = happyGoto action_11
+action_460 (10#) = happyGoto action_12
+action_460 (11#) = happyGoto action_13
+action_460 (12#) = happyGoto action_14
+action_460 (58#) = happyGoto action_15
+action_460 (59#) = happyGoto action_16
+action_460 (60#) = happyGoto action_17
+action_460 (61#) = happyGoto action_18
+action_460 (62#) = happyGoto action_19
+action_460 (63#) = happyGoto action_371
+action_460 (64#) = happyGoto action_21
+action_460 (72#) = happyGoto action_22
+action_460 (77#) = happyGoto action_23
+action_460 (86#) = happyGoto action_372
+action_460 (87#) = happyGoto action_473
+action_460 x = happyTcHack x happyReduce_257
+
+action_461 (96#) = happyShift action_24
+action_461 (98#) = happyShift action_25
+action_461 (104#) = happyShift action_26
+action_461 (109#) = happyShift action_27
+action_461 (110#) = happyShift action_28
+action_461 (111#) = happyShift action_29
+action_461 (114#) = happyShift action_30
+action_461 (119#) = happyShift action_31
+action_461 (124#) = happyShift action_32
+action_461 (125#) = happyShift action_33
+action_461 (126#) = happyShift action_34
+action_461 (127#) = happyShift action_35
+action_461 (128#) = happyShift action_36
+action_461 (129#) = happyShift action_37
+action_461 (131#) = happyShift action_38
+action_461 (134#) = happyShift action_39
+action_461 (137#) = happyShift action_40
+action_461 (140#) = happyShift action_41
+action_461 (145#) = happyShift action_42
+action_461 (156#) = happyShift action_43
+action_461 (157#) = happyShift action_44
+action_461 (161#) = happyShift action_45
+action_461 (162#) = happyShift action_46
+action_461 (167#) = happyShift action_47
+action_461 (170#) = happyShift action_6
+action_461 (171#) = happyShift action_48
+action_461 (172#) = happyShift action_49
+action_461 (173#) = happyShift action_50
+action_461 (174#) = happyShift action_51
+action_461 (8#) = happyGoto action_10
+action_461 (9#) = happyGoto action_11
+action_461 (10#) = happyGoto action_12
+action_461 (11#) = happyGoto action_13
+action_461 (12#) = happyGoto action_14
+action_461 (58#) = happyGoto action_15
+action_461 (59#) = happyGoto action_16
+action_461 (60#) = happyGoto action_17
+action_461 (61#) = happyGoto action_18
+action_461 (62#) = happyGoto action_19
+action_461 (63#) = happyGoto action_472
+action_461 (64#) = happyGoto action_21
+action_461 (72#) = happyGoto action_22
+action_461 (77#) = happyGoto action_23
+action_461 x = happyTcHack x happyFail
+
+action_462 x = happyTcHack x happyReduce_136
+
+action_463 x = happyTcHack x happyReduce_186
+
+action_464 x = happyTcHack x happyReduce_166
+
+action_465 (140#) = happyShift action_471
+action_465 x = happyTcHack x happyFail
+
+action_466 (169#) = happyShift action_470
+action_466 x = happyTcHack x happyFail
+
+action_467 (102#) = happyShift action_469
+action_467 x = happyTcHack x happyReduce_28
+
+action_468 x = happyTcHack x happyReduce_67
+
+action_469 (151#) = happyShift action_356
+action_469 (28#) = happyGoto action_510
+action_469 x = happyTcHack x happyReduce_55
+
+action_470 (98#) = happyShift action_408
+action_470 (174#) = happyShift action_51
+action_470 (12#) = happyGoto action_406
+action_470 (27#) = happyGoto action_509
+action_470 (29#) = happyGoto action_425
+action_470 x = happyTcHack x happyReduce_52
+
+action_471 x = happyTcHack x happyReduce_56
+
+action_472 x = happyTcHack x happyReduce_256
+
+action_473 x = happyTcHack x happyReduce_259
+
+action_474 (96#) = happyShift action_508
+action_474 x = happyTcHack x happyReduce_96
+
+action_475 (100#) = happyShift action_507
+action_475 x = happyTcHack x happyFail
+
+action_476 (174#) = happyShift action_51
+action_476 (12#) = happyGoto action_448
+action_476 (39#) = happyGoto action_449
+action_476 (40#) = happyGoto action_506
+action_476 x = happyTcHack x happyReduce_102
+
+action_477 (174#) = happyShift action_51
+action_477 (12#) = happyGoto action_505
+action_477 x = happyTcHack x happyFail
+
+action_478 (97#) = happyShift action_504
+action_478 (132#) = happyShift action_210
+action_478 (134#) = happyShift action_211
+action_478 (135#) = happyShift action_212
+action_478 (136#) = happyShift action_213
+action_478 (138#) = happyShift action_214
+action_478 (146#) = happyShift action_215
+action_478 (147#) = happyShift action_216
+action_478 (148#) = happyShift action_217
+action_478 (149#) = happyShift action_218
+action_478 (152#) = happyShift action_219
+action_478 (154#) = happyShift action_220
+action_478 (155#) = happyShift action_221
+action_478 (156#) = happyShift action_222
+action_478 (158#) = happyShift action_223
+action_478 (163#) = happyShift action_224
+action_478 (164#) = happyShift action_225
+action_478 (166#) = happyShift action_226
+action_478 (35#) = happyGoto action_209
+action_478 x = happyTcHack x happyFail
+
+action_479 (174#) = happyShift action_51
+action_479 (12#) = happyGoto action_503
+action_479 x = happyTcHack x happyFail
+
+action_480 (174#) = happyShift action_51
+action_480 (12#) = happyGoto action_438
+action_480 (42#) = happyGoto action_439
+action_480 (52#) = happyGoto action_502
+action_480 x = happyTcHack x happyReduce_125
+
+action_481 (96#) = happyShift action_140
+action_481 (98#) = happyShift action_455
+action_481 (104#) = happyShift action_26
+action_481 (109#) = happyShift action_83
+action_481 (110#) = happyShift action_28
+action_481 (111#) = happyShift action_29
+action_481 (125#) = happyShift action_33
+action_481 (126#) = happyShift action_34
+action_481 (127#) = happyShift action_35
+action_481 (128#) = happyShift action_36
+action_481 (129#) = happyShift action_37
+action_481 (134#) = happyShift action_39
+action_481 (170#) = happyShift action_6
+action_481 (171#) = happyShift action_48
+action_481 (172#) = happyShift action_49
+action_481 (173#) = happyShift action_50
+action_481 (174#) = happyShift action_51
+action_481 (8#) = happyGoto action_10
+action_481 (9#) = happyGoto action_11
+action_481 (10#) = happyGoto action_12
+action_481 (11#) = happyGoto action_13
+action_481 (12#) = happyGoto action_79
+action_481 (58#) = happyGoto action_453
+action_481 (72#) = happyGoto action_22
+action_481 (88#) = happyGoto action_454
+action_481 x = happyTcHack x happyReduce_108
+
+action_482 (96#) = happyShift action_24
+action_482 (98#) = happyShift action_25
+action_482 (104#) = happyShift action_26
+action_482 (109#) = happyShift action_27
+action_482 (110#) = happyShift action_28
+action_482 (111#) = happyShift action_29
+action_482 (114#) = happyShift action_30
+action_482 (119#) = happyShift action_31
+action_482 (124#) = happyShift action_32
+action_482 (125#) = happyShift action_33
+action_482 (126#) = happyShift action_34
+action_482 (127#) = happyShift action_35
+action_482 (128#) = happyShift action_36
+action_482 (129#) = happyShift action_37
+action_482 (131#) = happyShift action_38
+action_482 (134#) = happyShift action_39
+action_482 (137#) = happyShift action_40
+action_482 (140#) = happyShift action_41
+action_482 (145#) = happyShift action_42
+action_482 (156#) = happyShift action_43
+action_482 (157#) = happyShift action_44
+action_482 (161#) = happyShift action_45
+action_482 (162#) = happyShift action_46
+action_482 (167#) = happyShift action_47
+action_482 (170#) = happyShift action_6
+action_482 (171#) = happyShift action_48
+action_482 (172#) = happyShift action_49
+action_482 (173#) = happyShift action_50
+action_482 (174#) = happyShift action_51
+action_482 (8#) = happyGoto action_10
+action_482 (9#) = happyGoto action_11
+action_482 (10#) = happyGoto action_12
+action_482 (11#) = happyGoto action_13
+action_482 (12#) = happyGoto action_14
+action_482 (58#) = happyGoto action_15
+action_482 (59#) = happyGoto action_16
+action_482 (60#) = happyGoto action_17
+action_482 (61#) = happyGoto action_18
+action_482 (62#) = happyGoto action_19
+action_482 (63#) = happyGoto action_501
+action_482 (64#) = happyGoto action_21
+action_482 (72#) = happyGoto action_22
+action_482 (77#) = happyGoto action_23
+action_482 x = happyTcHack x happyFail
+
+action_483 x = happyTcHack x happyReduce_73
+
+action_484 x = happyTcHack x happyReduce_39
+
+action_485 (95#) = happyShift action_499
+action_485 (99#) = happyShift action_500
+action_485 x = happyTcHack x happyFail
+
+action_486 (98#) = happyShift action_408
+action_486 (174#) = happyShift action_51
+action_486 (12#) = happyGoto action_406
+action_486 (27#) = happyGoto action_498
+action_486 (29#) = happyGoto action_425
+action_486 x = happyTcHack x happyReduce_52
+
+action_487 (151#) = happyShift action_356
+action_487 (28#) = happyGoto action_497
+action_487 x = happyTcHack x happyReduce_55
+
+action_488 (98#) = happyShift action_408
+action_488 (174#) = happyShift action_51
+action_488 (12#) = happyGoto action_406
+action_488 (27#) = happyGoto action_496
+action_488 (29#) = happyGoto action_425
+action_488 x = happyTcHack x happyReduce_52
+
+action_489 (97#) = happyShift action_495
+action_489 (132#) = happyShift action_210
+action_489 (134#) = happyShift action_211
+action_489 (135#) = happyShift action_212
+action_489 (136#) = happyShift action_213
+action_489 (138#) = happyShift action_214
+action_489 (146#) = happyShift action_215
+action_489 (147#) = happyShift action_216
+action_489 (148#) = happyShift action_217
+action_489 (149#) = happyShift action_218
+action_489 (152#) = happyShift action_219
+action_489 (154#) = happyShift action_220
+action_489 (155#) = happyShift action_221
+action_489 (156#) = happyShift action_222
+action_489 (158#) = happyShift action_223
+action_489 (163#) = happyShift action_224
+action_489 (164#) = happyShift action_225
+action_489 (166#) = happyShift action_226
+action_489 (35#) = happyGoto action_209
+action_489 x = happyTcHack x happyFail
+
+action_490 x = happyTcHack x happyReduce_69
+
+action_491 (105#) = happyShift action_494
+action_491 x = happyTcHack x happyFail
+
+action_492 (94#) = happyShift action_493
+action_492 x = happyTcHack x happyFail
+
+action_493 (174#) = happyShift action_51
+action_493 (12#) = happyGoto action_519
+action_493 (16#) = happyGoto action_520
+action_493 (17#) = happyGoto action_521
+action_493 x = happyTcHack x happyReduce_17
+
+action_494 x = happyTcHack x happyReduce_70
+
+action_495 x = happyTcHack x happyReduce_40
+
+action_496 (102#) = happyShift action_518
+action_496 x = happyTcHack x happyReduce_44
+
+action_497 (96#) = happyShift action_517
+action_497 x = happyTcHack x happyFail
+
+action_498 x = happyTcHack x happyReduce_54
+
+action_499 (174#) = happyShift action_51
+action_499 (12#) = happyGoto action_516
+action_499 x = happyTcHack x happyFail
+
+action_500 x = happyTcHack x happyReduce_58
+
+action_501 x = happyTcHack x happyReduce_74
+
+action_502 x = happyTcHack x happyReduce_127
+
+action_503 (99#) = happyShift action_515
+action_503 x = happyTcHack x happyFail
+
+action_504 (94#) = happyShift action_514
+action_504 x = happyTcHack x happyFail
+
+action_505 x = happyTcHack x happyReduce_101
+
+action_506 x = happyTcHack x happyReduce_104
+
+action_507 (96#) = happyShift action_24
+action_507 (98#) = happyShift action_25
+action_507 (104#) = happyShift action_26
+action_507 (109#) = happyShift action_27
+action_507 (110#) = happyShift action_28
+action_507 (111#) = happyShift action_29
+action_507 (114#) = happyShift action_30
+action_507 (119#) = happyShift action_31
+action_507 (124#) = happyShift action_32
+action_507 (125#) = happyShift action_33
+action_507 (126#) = happyShift action_34
+action_507 (127#) = happyShift action_35
+action_507 (128#) = happyShift action_36
+action_507 (129#) = happyShift action_37
+action_507 (131#) = happyShift action_38
+action_507 (134#) = happyShift action_39
+action_507 (137#) = happyShift action_40
+action_507 (140#) = happyShift action_41
+action_507 (145#) = happyShift action_42
+action_507 (156#) = happyShift action_43
+action_507 (157#) = happyShift action_44
+action_507 (161#) = happyShift action_45
+action_507 (162#) = happyShift action_46
+action_507 (167#) = happyShift action_47
+action_507 (170#) = happyShift action_6
+action_507 (171#) = happyShift action_48
+action_507 (172#) = happyShift action_49
+action_507 (173#) = happyShift action_50
+action_507 (174#) = happyShift action_51
+action_507 (8#) = happyGoto action_10
+action_507 (9#) = happyGoto action_11
+action_507 (10#) = happyGoto action_12
+action_507 (11#) = happyGoto action_13
+action_507 (12#) = happyGoto action_14
+action_507 (58#) = happyGoto action_15
+action_507 (59#) = happyGoto action_16
+action_507 (60#) = happyGoto action_17
+action_507 (61#) = happyGoto action_18
+action_507 (62#) = happyGoto action_19
+action_507 (63#) = happyGoto action_513
+action_507 (64#) = happyGoto action_21
+action_507 (72#) = happyGoto action_22
+action_507 (77#) = happyGoto action_23
+action_507 x = happyTcHack x happyFail
+
+action_508 (170#) = happyShift action_6
+action_508 (8#) = happyGoto action_512
+action_508 x = happyTcHack x happyFail
+
+action_509 (102#) = happyShift action_511
+action_509 x = happyTcHack x happyReduce_30
+
+action_510 x = happyTcHack x happyReduce_29
+
+action_511 (151#) = happyShift action_356
+action_511 (28#) = happyGoto action_530
+action_511 x = happyTcHack x happyReduce_55
+
+action_512 (97#) = happyShift action_529
+action_512 x = happyTcHack x happyFail
+
+action_513 (99#) = happyShift action_528
+action_513 x = happyTcHack x happyFail
+
+action_514 x = happyTcHack x happyReduce_92
+
+action_515 x = happyTcHack x happyReduce_106
+
+action_516 (99#) = happyShift action_527
+action_516 x = happyTcHack x happyFail
+
+action_517 (25#) = happyGoto action_526
+action_517 x = happyTcHack x happyReduce_48
+
+action_518 (151#) = happyShift action_356
+action_518 (28#) = happyGoto action_525
+action_518 x = happyTcHack x happyReduce_55
+
+action_519 (95#) = happyShift action_524
+action_519 x = happyTcHack x happyFail
+
+action_520 (94#) = happyShift action_523
+action_520 x = happyTcHack x happyReduce_18
+
+action_521 (97#) = happyShift action_522
+action_521 x = happyTcHack x happyFail
+
+action_522 x = happyTcHack x happyReduce_14
+
+action_523 (174#) = happyShift action_51
+action_523 (12#) = happyGoto action_519
+action_523 (16#) = happyGoto action_520
+action_523 (17#) = happyGoto action_535
+action_523 x = happyTcHack x happyReduce_17
+
+action_524 (174#) = happyShift action_51
+action_524 (12#) = happyGoto action_533
+action_524 (18#) = happyGoto action_534
+action_524 x = happyTcHack x happyFail
+
+action_525 (96#) = happyShift action_532
+action_525 x = happyTcHack x happyFail
+
+action_526 (97#) = happyShift action_531
+action_526 (132#) = happyShift action_210
+action_526 (134#) = happyShift action_211
+action_526 (135#) = happyShift action_212
+action_526 (136#) = happyShift action_213
+action_526 (138#) = happyShift action_214
+action_526 (146#) = happyShift action_215
+action_526 (147#) = happyShift action_216
+action_526 (148#) = happyShift action_217
+action_526 (149#) = happyShift action_218
+action_526 (152#) = happyShift action_219
+action_526 (154#) = happyShift action_220
+action_526 (155#) = happyShift action_221
+action_526 (156#) = happyShift action_222
+action_526 (158#) = happyShift action_223
+action_526 (163#) = happyShift action_224
+action_526 (164#) = happyShift action_225
+action_526 (166#) = happyShift action_226
+action_526 (35#) = happyGoto action_209
+action_526 x = happyTcHack x happyFail
+
+action_527 x = happyTcHack x happyReduce_59
+
+action_528 x = happyTcHack x happyReduce_260
+
+action_529 x = happyTcHack x happyReduce_97
+
+action_530 x = happyTcHack x happyReduce_31
+
+action_531 x = happyTcHack x happyReduce_43
+
+action_532 (25#) = happyGoto action_537
+action_532 x = happyTcHack x happyReduce_48
+
+action_533 (19#) = happyGoto action_536
+action_533 x = happyTcHack x happyReduce_21
+
+action_534 x = happyTcHack x happyReduce_16
+
+action_535 x = happyTcHack x happyReduce_19
+
+action_536 (98#) = happyShift action_540
+action_536 (20#) = happyGoto action_539
+action_536 x = happyTcHack x happyReduce_20
+
+action_537 (97#) = happyShift action_538
+action_537 (132#) = happyShift action_210
+action_537 (134#) = happyShift action_211
+action_537 (135#) = happyShift action_212
+action_537 (136#) = happyShift action_213
+action_537 (138#) = happyShift action_214
+action_537 (146#) = happyShift action_215
+action_537 (147#) = happyShift action_216
+action_537 (148#) = happyShift action_217
+action_537 (149#) = happyShift action_218
+action_537 (152#) = happyShift action_219
+action_537 (154#) = happyShift action_220
+action_537 (155#) = happyShift action_221
+action_537 (156#) = happyShift action_222
+action_537 (158#) = happyShift action_223
+action_537 (163#) = happyShift action_224
+action_537 (164#) = happyShift action_225
+action_537 (166#) = happyShift action_226
+action_537 (35#) = happyGoto action_209
+action_537 x = happyTcHack x happyFail
+
+action_538 x = happyTcHack x happyReduce_45
+
+action_539 x = happyTcHack x happyReduce_22
+
+action_540 (164#) = happyShift action_541
+action_540 x = happyTcHack x happyFail
+
+action_541 (140#) = happyShift action_542
+action_541 (153#) = happyShift action_543
+action_541 x = happyTcHack x happyFail
+
+action_542 (98#) = happyShift action_408
+action_542 (174#) = happyShift action_51
+action_542 (12#) = happyGoto action_406
+action_542 (29#) = happyGoto action_545
+action_542 x = happyTcHack x happyFail
+
+action_543 (98#) = happyShift action_408
+action_543 (174#) = happyShift action_51
+action_543 (12#) = happyGoto action_406
+action_543 (29#) = happyGoto action_544
+action_543 x = happyTcHack x happyFail
+
+action_544 (99#) = happyShift action_547
+action_544 x = happyTcHack x happyFail
+
+action_545 (99#) = happyShift action_546
+action_545 x = happyTcHack x happyFail
+
+action_546 x = happyTcHack x happyReduce_23
+
+action_547 x = happyTcHack x happyReduce_24
+
+happyReduce_5 = happySpecReduce_1 8# happyReduction_5
+happyReduction_5 (HappyTerminal (PT _ (TI happy_var_1)))
+ = HappyAbsSyn8
+ ((read happy_var_1) :: Integer
+ )
+happyReduction_5 _ = notHappyAtAll
+
+happyReduce_6 = happySpecReduce_1 9# happyReduction_6
+happyReduction_6 (HappyTerminal (PT _ (TL happy_var_1)))
+ = HappyAbsSyn9
+ (happy_var_1
+ )
+happyReduction_6 _ = notHappyAtAll
+
+happyReduce_7 = happySpecReduce_1 10# happyReduction_7
+happyReduction_7 (HappyTerminal (PT _ (TD happy_var_1)))
+ = HappyAbsSyn10
+ ((read happy_var_1) :: Double
+ )
+happyReduction_7 _ = notHappyAtAll
+
+happyReduce_8 = happySpecReduce_1 11# happyReduction_8
+happyReduction_8 (HappyTerminal (PT _ (T_LString happy_var_1)))
+ = HappyAbsSyn11
+ (LString (happy_var_1)
+ )
+happyReduction_8 _ = notHappyAtAll
+
+happyReduce_9 = happySpecReduce_1 12# happyReduction_9
+happyReduction_9 (HappyTerminal happy_var_1)
+ = HappyAbsSyn12
+ (PIdent (mkPosToken happy_var_1)
+ )
+happyReduction_9 _ = notHappyAtAll
+
+happyReduce_10 = happySpecReduce_1 13# happyReduction_10
+happyReduction_10 (HappyAbsSyn14 happy_var_1)
+ = HappyAbsSyn13
+ (Gr (reverse happy_var_1)
+ )
+happyReduction_10 _ = notHappyAtAll
+
+happyReduce_11 = happySpecReduce_0 14# happyReduction_11
+happyReduction_11 = HappyAbsSyn14
+ ([]
+ )
+
+happyReduce_12 = happySpecReduce_2 14# happyReduction_12
+happyReduction_12 (HappyAbsSyn15 happy_var_2)
+ (HappyAbsSyn14 happy_var_1)
+ = HappyAbsSyn14
+ (flip (:) happy_var_1 happy_var_2
+ )
+happyReduction_12 _ _ = notHappyAtAll
+
+happyReduce_13 = happySpecReduce_2 15# happyReduction_13
+happyReduction_13 _
+ (HappyAbsSyn15 happy_var_1)
+ = HappyAbsSyn15
+ (happy_var_1
+ )
+happyReduction_13 _ _ = notHappyAtAll
+
+happyReduce_14 = happyReduce 10# 15# happyReduction_14
+happyReduction_14 (_ `HappyStk`
+ (HappyAbsSyn17 happy_var_9) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_7) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn15
+ (MMain happy_var_2 happy_var_7 happy_var_9
+ ) `HappyStk` happyRest
+
+happyReduce_15 = happyReduce 4# 15# happyReduction_15
+happyReduction_15 ((HappyAbsSyn22 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn23 happy_var_2) `HappyStk`
+ (HappyAbsSyn30 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn15
+ (MModule happy_var_1 happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_16 = happySpecReduce_3 16# happyReduction_16
+happyReduction_16 (HappyAbsSyn18 happy_var_3)
+ _
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn16
+ (ConcSpec happy_var_1 happy_var_3
+ )
+happyReduction_16 _ _ _ = notHappyAtAll
+
+happyReduce_17 = happySpecReduce_0 17# happyReduction_17
+happyReduction_17 = HappyAbsSyn17
+ ([]
+ )
+
+happyReduce_18 = happySpecReduce_1 17# happyReduction_18
+happyReduction_18 (HappyAbsSyn16 happy_var_1)
+ = HappyAbsSyn17
+ ((:[]) happy_var_1
+ )
+happyReduction_18 _ = notHappyAtAll
+
+happyReduce_19 = happySpecReduce_3 17# happyReduction_19
+happyReduction_19 (HappyAbsSyn17 happy_var_3)
+ _
+ (HappyAbsSyn16 happy_var_1)
+ = HappyAbsSyn17
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_19 _ _ _ = notHappyAtAll
+
+happyReduce_20 = happySpecReduce_2 18# happyReduction_20
+happyReduction_20 (HappyAbsSyn19 happy_var_2)
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn18
+ (ConcExp happy_var_1 (reverse happy_var_2)
+ )
+happyReduction_20 _ _ = notHappyAtAll
+
+happyReduce_21 = happySpecReduce_0 19# happyReduction_21
+happyReduction_21 = HappyAbsSyn19
+ ([]
+ )
+
+happyReduce_22 = happySpecReduce_2 19# happyReduction_22
+happyReduction_22 (HappyAbsSyn20 happy_var_2)
+ (HappyAbsSyn19 happy_var_1)
+ = HappyAbsSyn19
+ (flip (:) happy_var_1 happy_var_2
+ )
+happyReduction_22 _ _ = notHappyAtAll
+
+happyReduce_23 = happyReduce 5# 20# happyReduction_23
+happyReduction_23 (_ `HappyStk`
+ (HappyAbsSyn29 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn20
+ (TransferIn happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_24 = happyReduce 5# 20# happyReduction_24
+happyReduction_24 (_ `HappyStk`
+ (HappyAbsSyn29 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn20
+ (TransferOut happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_25 = happyReduce 4# 21# happyReduction_25
+happyReduction_25 ((HappyAbsSyn22 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn23 happy_var_2) `HappyStk`
+ (HappyAbsSyn30 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn15
+ (MModule happy_var_1 happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_26 = happySpecReduce_2 22# happyReduction_26
+happyReduction_26 (HappyAbsSyn28 happy_var_2)
+ (HappyAbsSyn26 happy_var_1)
+ = HappyAbsSyn22
+ (MBody happy_var_1 happy_var_2 []
+ )
+happyReduction_26 _ _ = notHappyAtAll
+
+happyReduce_27 = happySpecReduce_1 22# happyReduction_27
+happyReduction_27 (HappyAbsSyn32 happy_var_1)
+ = HappyAbsSyn22
+ (MNoBody happy_var_1
+ )
+happyReduction_27 _ = notHappyAtAll
+
+happyReduce_28 = happySpecReduce_3 22# happyReduction_28
+happyReduction_28 (HappyAbsSyn27 happy_var_3)
+ _
+ (HappyAbsSyn33 happy_var_1)
+ = HappyAbsSyn22
+ (MWith happy_var_1 happy_var_3
+ )
+happyReduction_28 _ _ _ = notHappyAtAll
+
+happyReduce_29 = happyReduce 5# 22# happyReduction_29
+happyReduction_29 ((HappyAbsSyn28 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn27 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn33 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn22
+ (MWithBody happy_var_1 happy_var_3 happy_var_5 []
+ ) `HappyStk` happyRest
+
+happyReduce_30 = happyReduce 5# 22# happyReduction_30
+happyReduction_30 ((HappyAbsSyn27 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn33 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn32 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn22
+ (MWithE happy_var_1 happy_var_3 happy_var_5
+ ) `HappyStk` happyRest
+
+happyReduce_31 = happyReduce 7# 22# happyReduction_31
+happyReduction_31 ((HappyAbsSyn28 happy_var_7) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn27 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn33 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn32 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn22
+ (MWithEBody happy_var_1 happy_var_3 happy_var_5 happy_var_7 []
+ ) `HappyStk` happyRest
+
+happyReduce_32 = happySpecReduce_2 22# happyReduction_32
+happyReduction_32 (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn22
+ (MReuse happy_var_2
+ )
+happyReduction_32 _ _ = notHappyAtAll
+
+happyReduce_33 = happySpecReduce_2 22# happyReduction_33
+happyReduction_33 (HappyAbsSyn32 happy_var_2)
+ _
+ = HappyAbsSyn22
+ (MUnion happy_var_2
+ )
+happyReduction_33 _ _ = notHappyAtAll
+
+happyReduce_34 = happySpecReduce_2 23# happyReduction_34
+happyReduction_34 (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn23
+ (MTAbstract happy_var_2
+ )
+happyReduction_34 _ _ = notHappyAtAll
+
+happyReduce_35 = happySpecReduce_2 23# happyReduction_35
+happyReduction_35 (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn23
+ (MTResource happy_var_2
+ )
+happyReduction_35 _ _ = notHappyAtAll
+
+happyReduce_36 = happySpecReduce_2 23# happyReduction_36
+happyReduction_36 (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn23
+ (MTInterface happy_var_2
+ )
+happyReduction_36 _ _ = notHappyAtAll
+
+happyReduce_37 = happyReduce 4# 23# happyReduction_37
+happyReduction_37 ((HappyAbsSyn12 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn23
+ (MTConcrete happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_38 = happyReduce 4# 23# happyReduction_38
+happyReduction_38 ((HappyAbsSyn12 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn23
+ (MTInstance happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_39 = happyReduce 6# 23# happyReduction_39
+happyReduction_39 ((HappyAbsSyn29 happy_var_6) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn29 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn23
+ (MTTransfer happy_var_2 happy_var_4 happy_var_6
+ ) `HappyStk` happyRest
+
+happyReduce_40 = happyReduce 5# 24# happyReduction_40
+happyReduction_40 (_ `HappyStk`
+ (HappyAbsSyn25 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn28 happy_var_2) `HappyStk`
+ (HappyAbsSyn26 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn22
+ (MBody happy_var_1 happy_var_2 (reverse happy_var_4)
+ ) `HappyStk` happyRest
+
+happyReduce_41 = happySpecReduce_1 24# happyReduction_41
+happyReduction_41 (HappyAbsSyn32 happy_var_1)
+ = HappyAbsSyn22
+ (MNoBody happy_var_1
+ )
+happyReduction_41 _ = notHappyAtAll
+
+happyReduce_42 = happySpecReduce_3 24# happyReduction_42
+happyReduction_42 (HappyAbsSyn27 happy_var_3)
+ _
+ (HappyAbsSyn33 happy_var_1)
+ = HappyAbsSyn22
+ (MWith happy_var_1 happy_var_3
+ )
+happyReduction_42 _ _ _ = notHappyAtAll
+
+happyReduce_43 = happyReduce 8# 24# happyReduction_43
+happyReduction_43 (_ `HappyStk`
+ (HappyAbsSyn25 happy_var_7) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn28 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn27 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn33 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn22
+ (MWithBody happy_var_1 happy_var_3 happy_var_5 (reverse happy_var_7)
+ ) `HappyStk` happyRest
+
+happyReduce_44 = happyReduce 5# 24# happyReduction_44
+happyReduction_44 ((HappyAbsSyn27 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn33 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn32 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn22
+ (MWithE happy_var_1 happy_var_3 happy_var_5
+ ) `HappyStk` happyRest
+
+happyReduce_45 = happyReduce 10# 24# happyReduction_45
+happyReduction_45 (_ `HappyStk`
+ (HappyAbsSyn25 happy_var_9) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn28 happy_var_7) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn27 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn33 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn32 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn22
+ (MWithEBody happy_var_1 happy_var_3 happy_var_5 happy_var_7 (reverse happy_var_9)
+ ) `HappyStk` happyRest
+
+happyReduce_46 = happySpecReduce_2 24# happyReduction_46
+happyReduction_46 (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn22
+ (MReuse happy_var_2
+ )
+happyReduction_46 _ _ = notHappyAtAll
+
+happyReduce_47 = happySpecReduce_2 24# happyReduction_47
+happyReduction_47 (HappyAbsSyn32 happy_var_2)
+ _
+ = HappyAbsSyn22
+ (MUnion happy_var_2
+ )
+happyReduction_47 _ _ = notHappyAtAll
+
+happyReduce_48 = happySpecReduce_0 25# happyReduction_48
+happyReduction_48 = HappyAbsSyn25
+ ([]
+ )
+
+happyReduce_49 = happySpecReduce_2 25# happyReduction_49
+happyReduction_49 (HappyAbsSyn35 happy_var_2)
+ (HappyAbsSyn25 happy_var_1)
+ = HappyAbsSyn25
+ (flip (:) happy_var_1 happy_var_2
+ )
+happyReduction_49 _ _ = notHappyAtAll
+
+happyReduce_50 = happySpecReduce_2 26# happyReduction_50
+happyReduction_50 _
+ (HappyAbsSyn32 happy_var_1)
+ = HappyAbsSyn26
+ (Ext happy_var_1
+ )
+happyReduction_50 _ _ = notHappyAtAll
+
+happyReduce_51 = happySpecReduce_0 26# happyReduction_51
+happyReduction_51 = HappyAbsSyn26
+ (NoExt
+ )
+
+happyReduce_52 = happySpecReduce_0 27# happyReduction_52
+happyReduction_52 = HappyAbsSyn27
+ ([]
+ )
+
+happyReduce_53 = happySpecReduce_1 27# happyReduction_53
+happyReduction_53 (HappyAbsSyn29 happy_var_1)
+ = HappyAbsSyn27
+ ((:[]) happy_var_1
+ )
+happyReduction_53 _ = notHappyAtAll
+
+happyReduce_54 = happySpecReduce_3 27# happyReduction_54
+happyReduction_54 (HappyAbsSyn27 happy_var_3)
+ _
+ (HappyAbsSyn29 happy_var_1)
+ = HappyAbsSyn27
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_54 _ _ _ = notHappyAtAll
+
+happyReduce_55 = happySpecReduce_0 28# happyReduction_55
+happyReduction_55 = HappyAbsSyn28
+ (NoOpens
+ )
+
+happyReduce_56 = happySpecReduce_3 28# happyReduction_56
+happyReduction_56 _
+ (HappyAbsSyn27 happy_var_2)
+ _
+ = HappyAbsSyn28
+ (OpenIn happy_var_2
+ )
+happyReduction_56 _ _ _ = notHappyAtAll
+
+happyReduce_57 = happySpecReduce_1 29# happyReduction_57
+happyReduction_57 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn29
+ (OName happy_var_1
+ )
+happyReduction_57 _ = notHappyAtAll
+
+happyReduce_58 = happyReduce 4# 29# happyReduction_58
+happyReduction_58 (_ `HappyStk`
+ (HappyAbsSyn12 happy_var_3) `HappyStk`
+ (HappyAbsSyn31 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn29
+ (OQualQO happy_var_2 happy_var_3
+ ) `HappyStk` happyRest
+
+happyReduce_59 = happyReduce 6# 29# happyReduction_59
+happyReduction_59 (_ `HappyStk`
+ (HappyAbsSyn12 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_3) `HappyStk`
+ (HappyAbsSyn31 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn29
+ (OQual happy_var_2 happy_var_3 happy_var_5
+ ) `HappyStk` happyRest
+
+happyReduce_60 = happySpecReduce_0 30# happyReduction_60
+happyReduction_60 = HappyAbsSyn30
+ (CMCompl
+ )
+
+happyReduce_61 = happySpecReduce_1 30# happyReduction_61
+happyReduction_61 _
+ = HappyAbsSyn30
+ (CMIncompl
+ )
+
+happyReduce_62 = happySpecReduce_0 31# happyReduction_62
+happyReduction_62 = HappyAbsSyn31
+ (QOCompl
+ )
+
+happyReduce_63 = happySpecReduce_1 31# happyReduction_63
+happyReduction_63 _
+ = HappyAbsSyn31
+ (QOIncompl
+ )
+
+happyReduce_64 = happySpecReduce_1 31# happyReduction_64
+happyReduction_64 _
+ = HappyAbsSyn31
+ (QOInterface
+ )
+
+happyReduce_65 = happySpecReduce_0 32# happyReduction_65
+happyReduction_65 = HappyAbsSyn32
+ ([]
+ )
+
+happyReduce_66 = happySpecReduce_1 32# happyReduction_66
+happyReduction_66 (HappyAbsSyn33 happy_var_1)
+ = HappyAbsSyn32
+ ((:[]) happy_var_1
+ )
+happyReduction_66 _ = notHappyAtAll
+
+happyReduce_67 = happySpecReduce_3 32# happyReduction_67
+happyReduction_67 (HappyAbsSyn32 happy_var_3)
+ _
+ (HappyAbsSyn33 happy_var_1)
+ = HappyAbsSyn32
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_67 _ _ _ = notHappyAtAll
+
+happyReduce_68 = happySpecReduce_1 33# happyReduction_68
+happyReduction_68 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn33
+ (IAll happy_var_1
+ )
+happyReduction_68 _ = notHappyAtAll
+
+happyReduce_69 = happyReduce 4# 33# happyReduction_69
+happyReduction_69 (_ `HappyStk`
+ (HappyAbsSyn53 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn33
+ (ISome happy_var_1 happy_var_3
+ ) `HappyStk` happyRest
+
+happyReduce_70 = happyReduce 5# 33# happyReduction_70
+happyReduction_70 (_ `HappyStk`
+ (HappyAbsSyn53 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn33
+ (IMinus happy_var_1 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_71 = happySpecReduce_3 34# happyReduction_71
+happyReduction_71 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn55 happy_var_1)
+ = HappyAbsSyn34
+ (DDecl happy_var_1 happy_var_3
+ )
+happyReduction_71 _ _ _ = notHappyAtAll
+
+happyReduce_72 = happySpecReduce_3 34# happyReduction_72
+happyReduction_72 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn55 happy_var_1)
+ = HappyAbsSyn34
+ (DDef happy_var_1 happy_var_3
+ )
+happyReduction_72 _ _ _ = notHappyAtAll
+
+happyReduce_73 = happyReduce 4# 34# happyReduction_73
+happyReduction_73 ((HappyAbsSyn58 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn74 happy_var_2) `HappyStk`
+ (HappyAbsSyn54 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn34
+ (DPatt happy_var_1 happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_74 = happyReduce 5# 34# happyReduction_74
+happyReduction_74 ((HappyAbsSyn58 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn58 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn55 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn34
+ (DFull happy_var_1 happy_var_3 happy_var_5
+ ) `HappyStk` happyRest
+
+happyReduce_75 = happySpecReduce_2 35# happyReduction_75
+happyReduction_75 (HappyAbsSyn46 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefCat happy_var_2
+ )
+happyReduction_75 _ _ = notHappyAtAll
+
+happyReduce_76 = happySpecReduce_2 35# happyReduction_76
+happyReduction_76 (HappyAbsSyn47 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefFun happy_var_2
+ )
+happyReduction_76 _ _ = notHappyAtAll
+
+happyReduce_77 = happySpecReduce_2 35# happyReduction_77
+happyReduction_77 (HappyAbsSyn47 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefFunData happy_var_2
+ )
+happyReduction_77 _ _ = notHappyAtAll
+
+happyReduce_78 = happySpecReduce_2 35# happyReduction_78
+happyReduction_78 (HappyAbsSyn45 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefDef happy_var_2
+ )
+happyReduction_78 _ _ = notHappyAtAll
+
+happyReduce_79 = happySpecReduce_2 35# happyReduction_79
+happyReduction_79 (HappyAbsSyn48 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefData happy_var_2
+ )
+happyReduction_79 _ _ = notHappyAtAll
+
+happyReduce_80 = happySpecReduce_2 35# happyReduction_80
+happyReduction_80 (HappyAbsSyn45 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefTrans happy_var_2
+ )
+happyReduction_80 _ _ = notHappyAtAll
+
+happyReduce_81 = happySpecReduce_2 35# happyReduction_81
+happyReduction_81 (HappyAbsSyn49 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefPar happy_var_2
+ )
+happyReduction_81 _ _ = notHappyAtAll
+
+happyReduce_82 = happySpecReduce_2 35# happyReduction_82
+happyReduction_82 (HappyAbsSyn45 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefOper happy_var_2
+ )
+happyReduction_82 _ _ = notHappyAtAll
+
+happyReduce_83 = happySpecReduce_2 35# happyReduction_83
+happyReduction_83 (HappyAbsSyn50 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefLincat happy_var_2
+ )
+happyReduction_83 _ _ = notHappyAtAll
+
+happyReduce_84 = happySpecReduce_2 35# happyReduction_84
+happyReduction_84 (HappyAbsSyn45 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefLindef happy_var_2
+ )
+happyReduction_84 _ _ = notHappyAtAll
+
+happyReduce_85 = happySpecReduce_2 35# happyReduction_85
+happyReduction_85 (HappyAbsSyn45 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefLin happy_var_2
+ )
+happyReduction_85 _ _ = notHappyAtAll
+
+happyReduce_86 = happySpecReduce_3 35# happyReduction_86
+happyReduction_86 (HappyAbsSyn50 happy_var_3)
+ _
+ _
+ = HappyAbsSyn35
+ (DefPrintCat happy_var_3
+ )
+happyReduction_86 _ _ _ = notHappyAtAll
+
+happyReduce_87 = happySpecReduce_3 35# happyReduction_87
+happyReduction_87 (HappyAbsSyn50 happy_var_3)
+ _
+ _
+ = HappyAbsSyn35
+ (DefPrintFun happy_var_3
+ )
+happyReduction_87 _ _ _ = notHappyAtAll
+
+happyReduce_88 = happySpecReduce_2 35# happyReduction_88
+happyReduction_88 (HappyAbsSyn51 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefFlag happy_var_2
+ )
+happyReduction_88 _ _ = notHappyAtAll
+
+happyReduce_89 = happySpecReduce_2 35# happyReduction_89
+happyReduction_89 (HappyAbsSyn50 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefPrintOld happy_var_2
+ )
+happyReduction_89 _ _ = notHappyAtAll
+
+happyReduce_90 = happySpecReduce_2 35# happyReduction_90
+happyReduction_90 (HappyAbsSyn45 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefLintype happy_var_2
+ )
+happyReduction_90 _ _ = notHappyAtAll
+
+happyReduce_91 = happySpecReduce_2 35# happyReduction_91
+happyReduction_91 (HappyAbsSyn45 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefPattern happy_var_2
+ )
+happyReduction_91 _ _ = notHappyAtAll
+
+happyReduce_92 = happyReduce 7# 35# happyReduction_92
+happyReduction_92 (_ `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn25 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn35
+ (DefPackage happy_var_2 (reverse happy_var_5)
+ ) `HappyStk` happyRest
+
+happyReduce_93 = happySpecReduce_2 35# happyReduction_93
+happyReduction_93 (HappyAbsSyn45 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefVars happy_var_2
+ )
+happyReduction_93 _ _ = notHappyAtAll
+
+happyReduce_94 = happySpecReduce_3 35# happyReduction_94
+happyReduction_94 _
+ (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn35
+ (DefTokenizer happy_var_2
+ )
+happyReduction_94 _ _ _ = notHappyAtAll
+
+happyReduce_95 = happySpecReduce_2 36# happyReduction_95
+happyReduction_95 (HappyAbsSyn89 happy_var_2)
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn36
+ (SimpleCatDef happy_var_1 (reverse happy_var_2)
+ )
+happyReduction_95 _ _ = notHappyAtAll
+
+happyReduce_96 = happyReduce 4# 36# happyReduction_96
+happyReduction_96 (_ `HappyStk`
+ (HappyAbsSyn89 happy_var_3) `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn36
+ (ListCatDef happy_var_2 (reverse happy_var_3)
+ ) `HappyStk` happyRest
+
+happyReduce_97 = happyReduce 7# 36# happyReduction_97
+happyReduction_97 (_ `HappyStk`
+ (HappyAbsSyn8 happy_var_6) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn89 happy_var_3) `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn36
+ (ListSizeCatDef happy_var_2 (reverse happy_var_3) happy_var_6
+ ) `HappyStk` happyRest
+
+happyReduce_98 = happySpecReduce_3 37# happyReduction_98
+happyReduction_98 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn53 happy_var_1)
+ = HappyAbsSyn37
+ (FunDef happy_var_1 happy_var_3
+ )
+happyReduction_98 _ _ _ = notHappyAtAll
+
+happyReduce_99 = happySpecReduce_3 38# happyReduction_99
+happyReduction_99 (HappyAbsSyn40 happy_var_3)
+ _
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn38
+ (DataDef happy_var_1 happy_var_3
+ )
+happyReduction_99 _ _ _ = notHappyAtAll
+
+happyReduce_100 = happySpecReduce_1 39# happyReduction_100
+happyReduction_100 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn39
+ (DataId happy_var_1
+ )
+happyReduction_100 _ = notHappyAtAll
+
+happyReduce_101 = happySpecReduce_3 39# happyReduction_101
+happyReduction_101 (HappyAbsSyn12 happy_var_3)
+ _
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn39
+ (DataQId happy_var_1 happy_var_3
+ )
+happyReduction_101 _ _ _ = notHappyAtAll
+
+happyReduce_102 = happySpecReduce_0 40# happyReduction_102
+happyReduction_102 = HappyAbsSyn40
+ ([]
+ )
+
+happyReduce_103 = happySpecReduce_1 40# happyReduction_103
+happyReduction_103 (HappyAbsSyn39 happy_var_1)
+ = HappyAbsSyn40
+ ((:[]) happy_var_1
+ )
+happyReduction_103 _ = notHappyAtAll
+
+happyReduce_104 = happySpecReduce_3 40# happyReduction_104
+happyReduction_104 (HappyAbsSyn40 happy_var_3)
+ _
+ (HappyAbsSyn39 happy_var_1)
+ = HappyAbsSyn40
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_104 _ _ _ = notHappyAtAll
+
+happyReduce_105 = happySpecReduce_3 41# happyReduction_105
+happyReduction_105 (HappyAbsSyn52 happy_var_3)
+ _
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn41
+ (ParDefDir happy_var_1 happy_var_3
+ )
+happyReduction_105 _ _ _ = notHappyAtAll
+
+happyReduce_106 = happyReduce 6# 41# happyReduction_106
+happyReduction_106 (_ `HappyStk`
+ (HappyAbsSyn12 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn41
+ (ParDefIndir happy_var_1 happy_var_5
+ ) `HappyStk` happyRest
+
+happyReduce_107 = happySpecReduce_1 41# happyReduction_107
+happyReduction_107 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn41
+ (ParDefAbs happy_var_1
+ )
+happyReduction_107 _ = notHappyAtAll
+
+happyReduce_108 = happySpecReduce_2 42# happyReduction_108
+happyReduction_108 (HappyAbsSyn89 happy_var_2)
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn42
+ (ParConstr happy_var_1 (reverse happy_var_2)
+ )
+happyReduction_108 _ _ = notHappyAtAll
+
+happyReduce_109 = happySpecReduce_3 43# happyReduction_109
+happyReduction_109 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn55 happy_var_1)
+ = HappyAbsSyn43
+ (PrintDef happy_var_1 happy_var_3
+ )
+happyReduction_109 _ _ _ = notHappyAtAll
+
+happyReduce_110 = happySpecReduce_3 44# happyReduction_110
+happyReduction_110 (HappyAbsSyn12 happy_var_3)
+ _
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn44
+ (FlagDef happy_var_1 happy_var_3
+ )
+happyReduction_110 _ _ _ = notHappyAtAll
+
+happyReduce_111 = happySpecReduce_2 45# happyReduction_111
+happyReduction_111 _
+ (HappyAbsSyn34 happy_var_1)
+ = HappyAbsSyn45
+ ((:[]) happy_var_1
+ )
+happyReduction_111 _ _ = notHappyAtAll
+
+happyReduce_112 = happySpecReduce_3 45# happyReduction_112
+happyReduction_112 (HappyAbsSyn45 happy_var_3)
+ _
+ (HappyAbsSyn34 happy_var_1)
+ = HappyAbsSyn45
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_112 _ _ _ = notHappyAtAll
+
+happyReduce_113 = happySpecReduce_2 46# happyReduction_113
+happyReduction_113 _
+ (HappyAbsSyn36 happy_var_1)
+ = HappyAbsSyn46
+ ((:[]) happy_var_1
+ )
+happyReduction_113 _ _ = notHappyAtAll
+
+happyReduce_114 = happySpecReduce_3 46# happyReduction_114
+happyReduction_114 (HappyAbsSyn46 happy_var_3)
+ _
+ (HappyAbsSyn36 happy_var_1)
+ = HappyAbsSyn46
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_114 _ _ _ = notHappyAtAll
+
+happyReduce_115 = happySpecReduce_2 47# happyReduction_115
+happyReduction_115 _
+ (HappyAbsSyn37 happy_var_1)
+ = HappyAbsSyn47
+ ((:[]) happy_var_1
+ )
+happyReduction_115 _ _ = notHappyAtAll
+
+happyReduce_116 = happySpecReduce_3 47# happyReduction_116
+happyReduction_116 (HappyAbsSyn47 happy_var_3)
+ _
+ (HappyAbsSyn37 happy_var_1)
+ = HappyAbsSyn47
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_116 _ _ _ = notHappyAtAll
+
+happyReduce_117 = happySpecReduce_2 48# happyReduction_117
+happyReduction_117 _
+ (HappyAbsSyn38 happy_var_1)
+ = HappyAbsSyn48
+ ((:[]) happy_var_1
+ )
+happyReduction_117 _ _ = notHappyAtAll
+
+happyReduce_118 = happySpecReduce_3 48# happyReduction_118
+happyReduction_118 (HappyAbsSyn48 happy_var_3)
+ _
+ (HappyAbsSyn38 happy_var_1)
+ = HappyAbsSyn48
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_118 _ _ _ = notHappyAtAll
+
+happyReduce_119 = happySpecReduce_2 49# happyReduction_119
+happyReduction_119 _
+ (HappyAbsSyn41 happy_var_1)
+ = HappyAbsSyn49
+ ((:[]) happy_var_1
+ )
+happyReduction_119 _ _ = notHappyAtAll
+
+happyReduce_120 = happySpecReduce_3 49# happyReduction_120
+happyReduction_120 (HappyAbsSyn49 happy_var_3)
+ _
+ (HappyAbsSyn41 happy_var_1)
+ = HappyAbsSyn49
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_120 _ _ _ = notHappyAtAll
+
+happyReduce_121 = happySpecReduce_2 50# happyReduction_121
+happyReduction_121 _
+ (HappyAbsSyn43 happy_var_1)
+ = HappyAbsSyn50
+ ((:[]) happy_var_1
+ )
+happyReduction_121 _ _ = notHappyAtAll
+
+happyReduce_122 = happySpecReduce_3 50# happyReduction_122
+happyReduction_122 (HappyAbsSyn50 happy_var_3)
+ _
+ (HappyAbsSyn43 happy_var_1)
+ = HappyAbsSyn50
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_122 _ _ _ = notHappyAtAll
+
+happyReduce_123 = happySpecReduce_2 51# happyReduction_123
+happyReduction_123 _
+ (HappyAbsSyn44 happy_var_1)
+ = HappyAbsSyn51
+ ((:[]) happy_var_1
+ )
+happyReduction_123 _ _ = notHappyAtAll
+
+happyReduce_124 = happySpecReduce_3 51# happyReduction_124
+happyReduction_124 (HappyAbsSyn51 happy_var_3)
+ _
+ (HappyAbsSyn44 happy_var_1)
+ = HappyAbsSyn51
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_124 _ _ _ = notHappyAtAll
+
+happyReduce_125 = happySpecReduce_0 52# happyReduction_125
+happyReduction_125 = HappyAbsSyn52
+ ([]
+ )
+
+happyReduce_126 = happySpecReduce_1 52# happyReduction_126
+happyReduction_126 (HappyAbsSyn42 happy_var_1)
+ = HappyAbsSyn52
+ ((:[]) happy_var_1
+ )
+happyReduction_126 _ = notHappyAtAll
+
+happyReduce_127 = happySpecReduce_3 52# happyReduction_127
+happyReduction_127 (HappyAbsSyn52 happy_var_3)
+ _
+ (HappyAbsSyn42 happy_var_1)
+ = HappyAbsSyn52
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_127 _ _ _ = notHappyAtAll
+
+happyReduce_128 = happySpecReduce_1 53# happyReduction_128
+happyReduction_128 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn53
+ ((:[]) happy_var_1
+ )
+happyReduction_128 _ = notHappyAtAll
+
+happyReduce_129 = happySpecReduce_3 53# happyReduction_129
+happyReduction_129 (HappyAbsSyn53 happy_var_3)
+ _
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn53
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_129 _ _ _ = notHappyAtAll
+
+happyReduce_130 = happySpecReduce_1 54# happyReduction_130
+happyReduction_130 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn54
+ (IdentName happy_var_1
+ )
+happyReduction_130 _ = notHappyAtAll
+
+happyReduce_131 = happySpecReduce_3 54# happyReduction_131
+happyReduction_131 _
+ (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn54
+ (ListName happy_var_2
+ )
+happyReduction_131 _ _ _ = notHappyAtAll
+
+happyReduce_132 = happySpecReduce_1 55# happyReduction_132
+happyReduction_132 (HappyAbsSyn54 happy_var_1)
+ = HappyAbsSyn55
+ ((:[]) happy_var_1
+ )
+happyReduction_132 _ = notHappyAtAll
+
+happyReduce_133 = happySpecReduce_3 55# happyReduction_133
+happyReduction_133 (HappyAbsSyn55 happy_var_3)
+ _
+ (HappyAbsSyn54 happy_var_1)
+ = HappyAbsSyn55
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_133 _ _ _ = notHappyAtAll
+
+happyReduce_134 = happySpecReduce_3 56# happyReduction_134
+happyReduction_134 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn53 happy_var_1)
+ = HappyAbsSyn56
+ (LDDecl happy_var_1 happy_var_3
+ )
+happyReduction_134 _ _ _ = notHappyAtAll
+
+happyReduce_135 = happySpecReduce_3 56# happyReduction_135
+happyReduction_135 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn53 happy_var_1)
+ = HappyAbsSyn56
+ (LDDef happy_var_1 happy_var_3
+ )
+happyReduction_135 _ _ _ = notHappyAtAll
+
+happyReduce_136 = happyReduce 5# 56# happyReduction_136
+happyReduction_136 ((HappyAbsSyn58 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn58 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn53 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn56
+ (LDFull happy_var_1 happy_var_3 happy_var_5
+ ) `HappyStk` happyRest
+
+happyReduce_137 = happySpecReduce_0 57# happyReduction_137
+happyReduction_137 = HappyAbsSyn57
+ ([]
+ )
+
+happyReduce_138 = happySpecReduce_1 57# happyReduction_138
+happyReduction_138 (HappyAbsSyn56 happy_var_1)
+ = HappyAbsSyn57
+ ((:[]) happy_var_1
+ )
+happyReduction_138 _ = notHappyAtAll
+
+happyReduce_139 = happySpecReduce_3 57# happyReduction_139
+happyReduction_139 (HappyAbsSyn57 happy_var_3)
+ _
+ (HappyAbsSyn56 happy_var_1)
+ = HappyAbsSyn57
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_139 _ _ _ = notHappyAtAll
+
+happyReduce_140 = happySpecReduce_1 58# happyReduction_140
+happyReduction_140 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn58
+ (EIdent happy_var_1
+ )
+happyReduction_140 _ = notHappyAtAll
+
+happyReduce_141 = happySpecReduce_3 58# happyReduction_141
+happyReduction_141 _
+ (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (EConstr happy_var_2
+ )
+happyReduction_141 _ _ _ = notHappyAtAll
+
+happyReduce_142 = happySpecReduce_3 58# happyReduction_142
+happyReduction_142 _
+ (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (ECons happy_var_2
+ )
+happyReduction_142 _ _ _ = notHappyAtAll
+
+happyReduce_143 = happySpecReduce_1 58# happyReduction_143
+happyReduction_143 (HappyAbsSyn72 happy_var_1)
+ = HappyAbsSyn58
+ (ESort happy_var_1
+ )
+happyReduction_143 _ = notHappyAtAll
+
+happyReduce_144 = happySpecReduce_1 58# happyReduction_144
+happyReduction_144 (HappyAbsSyn9 happy_var_1)
+ = HappyAbsSyn58
+ (EString happy_var_1
+ )
+happyReduction_144 _ = notHappyAtAll
+
+happyReduce_145 = happySpecReduce_1 58# happyReduction_145
+happyReduction_145 (HappyAbsSyn8 happy_var_1)
+ = HappyAbsSyn58
+ (EInt happy_var_1
+ )
+happyReduction_145 _ = notHappyAtAll
+
+happyReduce_146 = happySpecReduce_1 58# happyReduction_146
+happyReduction_146 (HappyAbsSyn10 happy_var_1)
+ = HappyAbsSyn58
+ (EFloat happy_var_1
+ )
+happyReduction_146 _ = notHappyAtAll
+
+happyReduce_147 = happySpecReduce_1 58# happyReduction_147
+happyReduction_147 _
+ = HappyAbsSyn58
+ (EMeta
+ )
+
+happyReduce_148 = happySpecReduce_2 58# happyReduction_148
+happyReduction_148 _
+ _
+ = HappyAbsSyn58
+ (EEmpty
+ )
+
+happyReduce_149 = happySpecReduce_1 58# happyReduction_149
+happyReduction_149 _
+ = HappyAbsSyn58
+ (EData
+ )
+
+happyReduce_150 = happyReduce 4# 58# happyReduction_150
+happyReduction_150 (_ `HappyStk`
+ (HappyAbsSyn66 happy_var_3) `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EList happy_var_2 happy_var_3
+ ) `HappyStk` happyRest
+
+happyReduce_151 = happySpecReduce_3 58# happyReduction_151
+happyReduction_151 _
+ (HappyAbsSyn9 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (EStrings happy_var_2
+ )
+happyReduction_151 _ _ _ = notHappyAtAll
+
+happyReduce_152 = happySpecReduce_3 58# happyReduction_152
+happyReduction_152 _
+ (HappyAbsSyn57 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (ERecord happy_var_2
+ )
+happyReduction_152 _ _ _ = notHappyAtAll
+
+happyReduce_153 = happySpecReduce_3 58# happyReduction_153
+happyReduction_153 _
+ (HappyAbsSyn80 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (ETuple happy_var_2
+ )
+happyReduction_153 _ _ _ = notHappyAtAll
+
+happyReduce_154 = happyReduce 4# 58# happyReduction_154
+happyReduction_154 (_ `HappyStk`
+ (HappyAbsSyn12 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EIndir happy_var_3
+ ) `HappyStk` happyRest
+
+happyReduce_155 = happyReduce 5# 58# happyReduction_155
+happyReduction_155 (_ `HappyStk`
+ (HappyAbsSyn58 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn58 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (ETyped happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_156 = happySpecReduce_3 58# happyReduction_156
+happyReduction_156 _
+ (HappyAbsSyn58 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (happy_var_2
+ )
+happyReduction_156 _ _ _ = notHappyAtAll
+
+happyReduce_157 = happySpecReduce_1 58# happyReduction_157
+happyReduction_157 (HappyAbsSyn11 happy_var_1)
+ = HappyAbsSyn58
+ (ELString happy_var_1
+ )
+happyReduction_157 _ = notHappyAtAll
+
+happyReduce_158 = happySpecReduce_3 59# happyReduction_158
+happyReduction_158 (HappyAbsSyn71 happy_var_3)
+ _
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (EProj happy_var_1 happy_var_3
+ )
+happyReduction_158 _ _ _ = notHappyAtAll
+
+happyReduce_159 = happyReduce 5# 59# happyReduction_159
+happyReduction_159 (_ `HappyStk`
+ (HappyAbsSyn12 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EQConstr happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_160 = happyReduce 4# 59# happyReduction_160
+happyReduction_160 ((HappyAbsSyn12 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EQCons happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_161 = happySpecReduce_1 59# happyReduction_161
+happyReduction_161 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (happy_var_1
+ )
+happyReduction_161 _ = notHappyAtAll
+
+happyReduce_162 = happySpecReduce_2 60# happyReduction_162
+happyReduction_162 (HappyAbsSyn58 happy_var_2)
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (EApp happy_var_1 happy_var_2
+ )
+happyReduction_162 _ _ = notHappyAtAll
+
+happyReduce_163 = happyReduce 4# 60# happyReduction_163
+happyReduction_163 (_ `HappyStk`
+ (HappyAbsSyn83 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (ETable happy_var_3
+ ) `HappyStk` happyRest
+
+happyReduce_164 = happyReduce 5# 60# happyReduction_164
+happyReduction_164 (_ `HappyStk`
+ (HappyAbsSyn83 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn58 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (ETTable happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_165 = happyReduce 5# 60# happyReduction_165
+happyReduction_165 (_ `HappyStk`
+ (HappyAbsSyn65 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn58 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EVTable happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_166 = happyReduce 6# 60# happyReduction_166
+happyReduction_166 (_ `HappyStk`
+ (HappyAbsSyn83 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn58 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (ECase happy_var_2 happy_var_5
+ ) `HappyStk` happyRest
+
+happyReduce_167 = happyReduce 4# 60# happyReduction_167
+happyReduction_167 (_ `HappyStk`
+ (HappyAbsSyn65 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EVariants happy_var_3
+ ) `HappyStk` happyRest
+
+happyReduce_168 = happyReduce 6# 60# happyReduction_168
+happyReduction_168 (_ `HappyStk`
+ (HappyAbsSyn87 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn58 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EPre happy_var_3 happy_var_5
+ ) `HappyStk` happyRest
+
+happyReduce_169 = happyReduce 4# 60# happyReduction_169
+happyReduction_169 (_ `HappyStk`
+ (HappyAbsSyn65 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EStrs happy_var_3
+ ) `HappyStk` happyRest
+
+happyReduce_170 = happySpecReduce_3 60# happyReduction_170
+happyReduction_170 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn58
+ (EConAt happy_var_1 happy_var_3
+ )
+happyReduction_170 _ _ _ = notHappyAtAll
+
+happyReduce_171 = happySpecReduce_2 60# happyReduction_171
+happyReduction_171 (HappyAbsSyn67 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (EPatt happy_var_2
+ )
+happyReduction_171 _ _ = notHappyAtAll
+
+happyReduce_172 = happySpecReduce_2 60# happyReduction_172
+happyReduction_172 (HappyAbsSyn58 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (EPattType happy_var_2
+ )
+happyReduction_172 _ _ = notHappyAtAll
+
+happyReduce_173 = happySpecReduce_1 60# happyReduction_173
+happyReduction_173 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (happy_var_1
+ )
+happyReduction_173 _ = notHappyAtAll
+
+happyReduce_174 = happySpecReduce_2 60# happyReduction_174
+happyReduction_174 (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (ELin happy_var_2
+ )
+happyReduction_174 _ _ = notHappyAtAll
+
+happyReduce_175 = happySpecReduce_3 61# happyReduction_175
+happyReduction_175 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (ESelect happy_var_1 happy_var_3
+ )
+happyReduction_175 _ _ _ = notHappyAtAll
+
+happyReduce_176 = happySpecReduce_3 61# happyReduction_176
+happyReduction_176 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (ETupTyp happy_var_1 happy_var_3
+ )
+happyReduction_176 _ _ _ = notHappyAtAll
+
+happyReduce_177 = happySpecReduce_3 61# happyReduction_177
+happyReduction_177 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (EExtend happy_var_1 happy_var_3
+ )
+happyReduction_177 _ _ _ = notHappyAtAll
+
+happyReduce_178 = happySpecReduce_1 61# happyReduction_178
+happyReduction_178 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (happy_var_1
+ )
+happyReduction_178 _ = notHappyAtAll
+
+happyReduce_179 = happySpecReduce_3 62# happyReduction_179
+happyReduction_179 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (EGlue happy_var_1 happy_var_3
+ )
+happyReduction_179 _ _ _ = notHappyAtAll
+
+happyReduce_180 = happySpecReduce_1 62# happyReduction_180
+happyReduction_180 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (happy_var_1
+ )
+happyReduction_180 _ = notHappyAtAll
+
+happyReduce_181 = happySpecReduce_3 63# happyReduction_181
+happyReduction_181 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (EConcat happy_var_1 happy_var_3
+ )
+happyReduction_181 _ _ _ = notHappyAtAll
+
+happyReduce_182 = happyReduce 4# 63# happyReduction_182
+happyReduction_182 ((HappyAbsSyn58 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn76 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EAbstr happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_183 = happyReduce 5# 63# happyReduction_183
+happyReduction_183 ((HappyAbsSyn58 happy_var_5) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn76 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (ECTable happy_var_3 happy_var_5
+ ) `HappyStk` happyRest
+
+happyReduce_184 = happySpecReduce_3 63# happyReduction_184
+happyReduction_184 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn77 happy_var_1)
+ = HappyAbsSyn58
+ (EProd happy_var_1 happy_var_3
+ )
+happyReduction_184 _ _ _ = notHappyAtAll
+
+happyReduce_185 = happySpecReduce_3 63# happyReduction_185
+happyReduction_185 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (ETType happy_var_1 happy_var_3
+ )
+happyReduction_185 _ _ _ = notHappyAtAll
+
+happyReduce_186 = happyReduce 6# 63# happyReduction_186
+happyReduction_186 ((HappyAbsSyn58 happy_var_6) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn57 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (ELet happy_var_3 happy_var_6
+ ) `HappyStk` happyRest
+
+happyReduce_187 = happyReduce 4# 63# happyReduction_187
+happyReduction_187 ((HappyAbsSyn58 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn57 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (ELetb happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_188 = happyReduce 5# 63# happyReduction_188
+happyReduction_188 (_ `HappyStk`
+ (HappyAbsSyn57 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn58 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EWhere happy_var_1 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_189 = happyReduce 4# 63# happyReduction_189
+happyReduction_189 (_ `HappyStk`
+ (HappyAbsSyn85 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn58
+ (EEqs happy_var_3
+ ) `HappyStk` happyRest
+
+happyReduce_190 = happySpecReduce_3 63# happyReduction_190
+happyReduction_190 (HappyAbsSyn9 happy_var_3)
+ (HappyAbsSyn58 happy_var_2)
+ _
+ = HappyAbsSyn58
+ (EExample happy_var_2 happy_var_3
+ )
+happyReduction_190 _ _ _ = notHappyAtAll
+
+happyReduce_191 = happySpecReduce_1 63# happyReduction_191
+happyReduction_191 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (happy_var_1
+ )
+happyReduction_191 _ = notHappyAtAll
+
+happyReduce_192 = happySpecReduce_1 64# happyReduction_192
+happyReduction_192 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn58
+ (happy_var_1
+ )
+happyReduction_192 _ = notHappyAtAll
+
+happyReduce_193 = happySpecReduce_0 65# happyReduction_193
+happyReduction_193 = HappyAbsSyn65
+ ([]
+ )
+
+happyReduce_194 = happySpecReduce_1 65# happyReduction_194
+happyReduction_194 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn65
+ ((:[]) happy_var_1
+ )
+happyReduction_194 _ = notHappyAtAll
+
+happyReduce_195 = happySpecReduce_3 65# happyReduction_195
+happyReduction_195 (HappyAbsSyn65 happy_var_3)
+ _
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn65
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_195 _ _ _ = notHappyAtAll
+
+happyReduce_196 = happySpecReduce_0 66# happyReduction_196
+happyReduction_196 = HappyAbsSyn66
+ (NilExp
+ )
+
+happyReduce_197 = happySpecReduce_2 66# happyReduction_197
+happyReduction_197 (HappyAbsSyn66 happy_var_2)
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn66
+ (ConsExp happy_var_1 happy_var_2
+ )
+happyReduction_197 _ _ = notHappyAtAll
+
+happyReduce_198 = happySpecReduce_1 67# happyReduction_198
+happyReduction_198 _
+ = HappyAbsSyn67
+ (PChar
+ )
+
+happyReduce_199 = happySpecReduce_3 67# happyReduction_199
+happyReduction_199 _
+ (HappyAbsSyn9 happy_var_2)
+ _
+ = HappyAbsSyn67
+ (PChars happy_var_2
+ )
+happyReduction_199 _ _ _ = notHappyAtAll
+
+happyReduce_200 = happySpecReduce_2 67# happyReduction_200
+happyReduction_200 (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn67
+ (PMacro happy_var_2
+ )
+happyReduction_200 _ _ = notHappyAtAll
+
+happyReduce_201 = happyReduce 4# 67# happyReduction_201
+happyReduction_201 ((HappyAbsSyn12 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn67
+ (PM happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_202 = happySpecReduce_1 67# happyReduction_202
+happyReduction_202 _
+ = HappyAbsSyn67
+ (PW
+ )
+
+happyReduce_203 = happySpecReduce_1 67# happyReduction_203
+happyReduction_203 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn67
+ (PV happy_var_1
+ )
+happyReduction_203 _ = notHappyAtAll
+
+happyReduce_204 = happySpecReduce_3 67# happyReduction_204
+happyReduction_204 _
+ (HappyAbsSyn12 happy_var_2)
+ _
+ = HappyAbsSyn67
+ (PCon happy_var_2
+ )
+happyReduction_204 _ _ _ = notHappyAtAll
+
+happyReduce_205 = happySpecReduce_3 67# happyReduction_205
+happyReduction_205 (HappyAbsSyn12 happy_var_3)
+ _
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn67
+ (PQ happy_var_1 happy_var_3
+ )
+happyReduction_205 _ _ _ = notHappyAtAll
+
+happyReduce_206 = happySpecReduce_1 67# happyReduction_206
+happyReduction_206 (HappyAbsSyn8 happy_var_1)
+ = HappyAbsSyn67
+ (PInt happy_var_1
+ )
+happyReduction_206 _ = notHappyAtAll
+
+happyReduce_207 = happySpecReduce_1 67# happyReduction_207
+happyReduction_207 (HappyAbsSyn10 happy_var_1)
+ = HappyAbsSyn67
+ (PFloat happy_var_1
+ )
+happyReduction_207 _ = notHappyAtAll
+
+happyReduce_208 = happySpecReduce_1 67# happyReduction_208
+happyReduction_208 (HappyAbsSyn9 happy_var_1)
+ = HappyAbsSyn67
+ (PStr happy_var_1
+ )
+happyReduction_208 _ = notHappyAtAll
+
+happyReduce_209 = happySpecReduce_3 67# happyReduction_209
+happyReduction_209 _
+ (HappyAbsSyn73 happy_var_2)
+ _
+ = HappyAbsSyn67
+ (PR happy_var_2
+ )
+happyReduction_209 _ _ _ = notHappyAtAll
+
+happyReduce_210 = happySpecReduce_3 67# happyReduction_210
+happyReduction_210 _
+ (HappyAbsSyn81 happy_var_2)
+ _
+ = HappyAbsSyn67
+ (PTup happy_var_2
+ )
+happyReduction_210 _ _ _ = notHappyAtAll
+
+happyReduce_211 = happySpecReduce_3 67# happyReduction_211
+happyReduction_211 _
+ (HappyAbsSyn67 happy_var_2)
+ _
+ = HappyAbsSyn67
+ (happy_var_2
+ )
+happyReduction_211 _ _ _ = notHappyAtAll
+
+happyReduce_212 = happySpecReduce_2 68# happyReduction_212
+happyReduction_212 (HappyAbsSyn74 happy_var_2)
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn67
+ (PC happy_var_1 happy_var_2
+ )
+happyReduction_212 _ _ = notHappyAtAll
+
+happyReduce_213 = happyReduce 4# 68# happyReduction_213
+happyReduction_213 ((HappyAbsSyn74 happy_var_4) `HappyStk`
+ (HappyAbsSyn12 happy_var_3) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn12 happy_var_1) `HappyStk`
+ happyRest)
+ = HappyAbsSyn67
+ (PQC happy_var_1 happy_var_3 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_214 = happySpecReduce_2 68# happyReduction_214
+happyReduction_214 _
+ (HappyAbsSyn67 happy_var_1)
+ = HappyAbsSyn67
+ (PRep happy_var_1
+ )
+happyReduction_214 _ _ = notHappyAtAll
+
+happyReduce_215 = happySpecReduce_3 68# happyReduction_215
+happyReduction_215 (HappyAbsSyn67 happy_var_3)
+ _
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn67
+ (PAs happy_var_1 happy_var_3
+ )
+happyReduction_215 _ _ _ = notHappyAtAll
+
+happyReduce_216 = happySpecReduce_2 68# happyReduction_216
+happyReduction_216 (HappyAbsSyn67 happy_var_2)
+ _
+ = HappyAbsSyn67
+ (PNeg happy_var_2
+ )
+happyReduction_216 _ _ = notHappyAtAll
+
+happyReduce_217 = happySpecReduce_1 68# happyReduction_217
+happyReduction_217 (HappyAbsSyn67 happy_var_1)
+ = HappyAbsSyn67
+ (happy_var_1
+ )
+happyReduction_217 _ = notHappyAtAll
+
+happyReduce_218 = happySpecReduce_3 69# happyReduction_218
+happyReduction_218 (HappyAbsSyn67 happy_var_3)
+ _
+ (HappyAbsSyn67 happy_var_1)
+ = HappyAbsSyn67
+ (PDisj happy_var_1 happy_var_3
+ )
+happyReduction_218 _ _ _ = notHappyAtAll
+
+happyReduce_219 = happySpecReduce_3 69# happyReduction_219
+happyReduction_219 (HappyAbsSyn67 happy_var_3)
+ _
+ (HappyAbsSyn67 happy_var_1)
+ = HappyAbsSyn67
+ (PSeq happy_var_1 happy_var_3
+ )
+happyReduction_219 _ _ _ = notHappyAtAll
+
+happyReduce_220 = happySpecReduce_1 69# happyReduction_220
+happyReduction_220 (HappyAbsSyn67 happy_var_1)
+ = HappyAbsSyn67
+ (happy_var_1
+ )
+happyReduction_220 _ = notHappyAtAll
+
+happyReduce_221 = happySpecReduce_3 70# happyReduction_221
+happyReduction_221 (HappyAbsSyn67 happy_var_3)
+ _
+ (HappyAbsSyn53 happy_var_1)
+ = HappyAbsSyn70
+ (PA happy_var_1 happy_var_3
+ )
+happyReduction_221 _ _ _ = notHappyAtAll
+
+happyReduce_222 = happySpecReduce_1 71# happyReduction_222
+happyReduction_222 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn71
+ (LIdent happy_var_1
+ )
+happyReduction_222 _ = notHappyAtAll
+
+happyReduce_223 = happySpecReduce_2 71# happyReduction_223
+happyReduction_223 (HappyAbsSyn8 happy_var_2)
+ _
+ = HappyAbsSyn71
+ (LVar happy_var_2
+ )
+happyReduction_223 _ _ = notHappyAtAll
+
+happyReduce_224 = happySpecReduce_1 72# happyReduction_224
+happyReduction_224 _
+ = HappyAbsSyn72
+ (Sort_Type
+ )
+
+happyReduce_225 = happySpecReduce_1 72# happyReduction_225
+happyReduction_225 _
+ = HappyAbsSyn72
+ (Sort_PType
+ )
+
+happyReduce_226 = happySpecReduce_1 72# happyReduction_226
+happyReduction_226 _
+ = HappyAbsSyn72
+ (Sort_Tok
+ )
+
+happyReduce_227 = happySpecReduce_1 72# happyReduction_227
+happyReduction_227 _
+ = HappyAbsSyn72
+ (Sort_Str
+ )
+
+happyReduce_228 = happySpecReduce_1 72# happyReduction_228
+happyReduction_228 _
+ = HappyAbsSyn72
+ (Sort_Strs
+ )
+
+happyReduce_229 = happySpecReduce_0 73# happyReduction_229
+happyReduction_229 = HappyAbsSyn73
+ ([]
+ )
+
+happyReduce_230 = happySpecReduce_1 73# happyReduction_230
+happyReduction_230 (HappyAbsSyn70 happy_var_1)
+ = HappyAbsSyn73
+ ((:[]) happy_var_1
+ )
+happyReduction_230 _ = notHappyAtAll
+
+happyReduce_231 = happySpecReduce_3 73# happyReduction_231
+happyReduction_231 (HappyAbsSyn73 happy_var_3)
+ _
+ (HappyAbsSyn70 happy_var_1)
+ = HappyAbsSyn73
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_231 _ _ _ = notHappyAtAll
+
+happyReduce_232 = happySpecReduce_1 74# happyReduction_232
+happyReduction_232 (HappyAbsSyn67 happy_var_1)
+ = HappyAbsSyn74
+ ((:[]) happy_var_1
+ )
+happyReduction_232 _ = notHappyAtAll
+
+happyReduce_233 = happySpecReduce_2 74# happyReduction_233
+happyReduction_233 (HappyAbsSyn74 happy_var_2)
+ (HappyAbsSyn67 happy_var_1)
+ = HappyAbsSyn74
+ ((:) happy_var_1 happy_var_2
+ )
+happyReduction_233 _ _ = notHappyAtAll
+
+happyReduce_234 = happySpecReduce_1 75# happyReduction_234
+happyReduction_234 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn75
+ (BIdent happy_var_1
+ )
+happyReduction_234 _ = notHappyAtAll
+
+happyReduce_235 = happySpecReduce_1 75# happyReduction_235
+happyReduction_235 _
+ = HappyAbsSyn75
+ (BWild
+ )
+
+happyReduce_236 = happySpecReduce_0 76# happyReduction_236
+happyReduction_236 = HappyAbsSyn76
+ ([]
+ )
+
+happyReduce_237 = happySpecReduce_1 76# happyReduction_237
+happyReduction_237 (HappyAbsSyn75 happy_var_1)
+ = HappyAbsSyn76
+ ((:[]) happy_var_1
+ )
+happyReduction_237 _ = notHappyAtAll
+
+happyReduce_238 = happySpecReduce_3 76# happyReduction_238
+happyReduction_238 (HappyAbsSyn76 happy_var_3)
+ _
+ (HappyAbsSyn75 happy_var_1)
+ = HappyAbsSyn76
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_238 _ _ _ = notHappyAtAll
+
+happyReduce_239 = happyReduce 5# 77# happyReduction_239
+happyReduction_239 (_ `HappyStk`
+ (HappyAbsSyn58 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn76 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn77
+ (DDec happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_240 = happySpecReduce_1 77# happyReduction_240
+happyReduction_240 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn77
+ (DExp happy_var_1
+ )
+happyReduction_240 _ = notHappyAtAll
+
+happyReduce_241 = happySpecReduce_1 78# happyReduction_241
+happyReduction_241 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn78
+ (TComp happy_var_1
+ )
+happyReduction_241 _ = notHappyAtAll
+
+happyReduce_242 = happySpecReduce_1 79# happyReduction_242
+happyReduction_242 (HappyAbsSyn67 happy_var_1)
+ = HappyAbsSyn79
+ (PTComp happy_var_1
+ )
+happyReduction_242 _ = notHappyAtAll
+
+happyReduce_243 = happySpecReduce_0 80# happyReduction_243
+happyReduction_243 = HappyAbsSyn80
+ ([]
+ )
+
+happyReduce_244 = happySpecReduce_1 80# happyReduction_244
+happyReduction_244 (HappyAbsSyn78 happy_var_1)
+ = HappyAbsSyn80
+ ((:[]) happy_var_1
+ )
+happyReduction_244 _ = notHappyAtAll
+
+happyReduce_245 = happySpecReduce_3 80# happyReduction_245
+happyReduction_245 (HappyAbsSyn80 happy_var_3)
+ _
+ (HappyAbsSyn78 happy_var_1)
+ = HappyAbsSyn80
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_245 _ _ _ = notHappyAtAll
+
+happyReduce_246 = happySpecReduce_0 81# happyReduction_246
+happyReduction_246 = HappyAbsSyn81
+ ([]
+ )
+
+happyReduce_247 = happySpecReduce_1 81# happyReduction_247
+happyReduction_247 (HappyAbsSyn79 happy_var_1)
+ = HappyAbsSyn81
+ ((:[]) happy_var_1
+ )
+happyReduction_247 _ = notHappyAtAll
+
+happyReduce_248 = happySpecReduce_3 81# happyReduction_248
+happyReduction_248 (HappyAbsSyn81 happy_var_3)
+ _
+ (HappyAbsSyn79 happy_var_1)
+ = HappyAbsSyn81
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_248 _ _ _ = notHappyAtAll
+
+happyReduce_249 = happySpecReduce_3 82# happyReduction_249
+happyReduction_249 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn67 happy_var_1)
+ = HappyAbsSyn82
+ (Case happy_var_1 happy_var_3
+ )
+happyReduction_249 _ _ _ = notHappyAtAll
+
+happyReduce_250 = happySpecReduce_1 83# happyReduction_250
+happyReduction_250 (HappyAbsSyn82 happy_var_1)
+ = HappyAbsSyn83
+ ((:[]) happy_var_1
+ )
+happyReduction_250 _ = notHappyAtAll
+
+happyReduce_251 = happySpecReduce_3 83# happyReduction_251
+happyReduction_251 (HappyAbsSyn83 happy_var_3)
+ _
+ (HappyAbsSyn82 happy_var_1)
+ = HappyAbsSyn83
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_251 _ _ _ = notHappyAtAll
+
+happyReduce_252 = happySpecReduce_3 84# happyReduction_252
+happyReduction_252 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn74 happy_var_1)
+ = HappyAbsSyn84
+ (Equ happy_var_1 happy_var_3
+ )
+happyReduction_252 _ _ _ = notHappyAtAll
+
+happyReduce_253 = happySpecReduce_0 85# happyReduction_253
+happyReduction_253 = HappyAbsSyn85
+ ([]
+ )
+
+happyReduce_254 = happySpecReduce_1 85# happyReduction_254
+happyReduction_254 (HappyAbsSyn84 happy_var_1)
+ = HappyAbsSyn85
+ ((:[]) happy_var_1
+ )
+happyReduction_254 _ = notHappyAtAll
+
+happyReduce_255 = happySpecReduce_3 85# happyReduction_255
+happyReduction_255 (HappyAbsSyn85 happy_var_3)
+ _
+ (HappyAbsSyn84 happy_var_1)
+ = HappyAbsSyn85
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_255 _ _ _ = notHappyAtAll
+
+happyReduce_256 = happySpecReduce_3 86# happyReduction_256
+happyReduction_256 (HappyAbsSyn58 happy_var_3)
+ _
+ (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn86
+ (Alt happy_var_1 happy_var_3
+ )
+happyReduction_256 _ _ _ = notHappyAtAll
+
+happyReduce_257 = happySpecReduce_0 87# happyReduction_257
+happyReduction_257 = HappyAbsSyn87
+ ([]
+ )
+
+happyReduce_258 = happySpecReduce_1 87# happyReduction_258
+happyReduction_258 (HappyAbsSyn86 happy_var_1)
+ = HappyAbsSyn87
+ ((:[]) happy_var_1
+ )
+happyReduction_258 _ = notHappyAtAll
+
+happyReduce_259 = happySpecReduce_3 87# happyReduction_259
+happyReduction_259 (HappyAbsSyn87 happy_var_3)
+ _
+ (HappyAbsSyn86 happy_var_1)
+ = HappyAbsSyn87
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_259 _ _ _ = notHappyAtAll
+
+happyReduce_260 = happyReduce 5# 88# happyReduction_260
+happyReduction_260 (_ `HappyStk`
+ (HappyAbsSyn58 happy_var_4) `HappyStk`
+ _ `HappyStk`
+ (HappyAbsSyn76 happy_var_2) `HappyStk`
+ _ `HappyStk`
+ happyRest)
+ = HappyAbsSyn88
+ (DDDec happy_var_2 happy_var_4
+ ) `HappyStk` happyRest
+
+happyReduce_261 = happySpecReduce_1 88# happyReduction_261
+happyReduction_261 (HappyAbsSyn58 happy_var_1)
+ = HappyAbsSyn88
+ (DDExp happy_var_1
+ )
+happyReduction_261 _ = notHappyAtAll
+
+happyReduce_262 = happySpecReduce_0 89# happyReduction_262
+happyReduction_262 = HappyAbsSyn89
+ ([]
+ )
+
+happyReduce_263 = happySpecReduce_2 89# happyReduction_263
+happyReduction_263 (HappyAbsSyn88 happy_var_2)
+ (HappyAbsSyn89 happy_var_1)
+ = HappyAbsSyn89
+ (flip (:) happy_var_1 happy_var_2
+ )
+happyReduction_263 _ _ = notHappyAtAll
+
+happyReduce_264 = happySpecReduce_2 90# happyReduction_264
+happyReduction_264 (HappyAbsSyn25 happy_var_2)
+ (HappyAbsSyn91 happy_var_1)
+ = HappyAbsSyn90
+ (OldGr happy_var_1 (reverse happy_var_2)
+ )
+happyReduction_264 _ _ = notHappyAtAll
+
+happyReduce_265 = happySpecReduce_0 91# happyReduction_265
+happyReduction_265 = HappyAbsSyn91
+ (NoIncl
+ )
+
+happyReduce_266 = happySpecReduce_2 91# happyReduction_266
+happyReduction_266 (HappyAbsSyn93 happy_var_2)
+ _
+ = HappyAbsSyn91
+ (Incl happy_var_2
+ )
+happyReduction_266 _ _ = notHappyAtAll
+
+happyReduce_267 = happySpecReduce_1 92# happyReduction_267
+happyReduction_267 (HappyAbsSyn9 happy_var_1)
+ = HappyAbsSyn92
+ (FString happy_var_1
+ )
+happyReduction_267 _ = notHappyAtAll
+
+happyReduce_268 = happySpecReduce_1 92# happyReduction_268
+happyReduction_268 (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn92
+ (FIdent happy_var_1
+ )
+happyReduction_268 _ = notHappyAtAll
+
+happyReduce_269 = happySpecReduce_2 92# happyReduction_269
+happyReduction_269 (HappyAbsSyn92 happy_var_2)
+ _
+ = HappyAbsSyn92
+ (FSlash happy_var_2
+ )
+happyReduction_269 _ _ = notHappyAtAll
+
+happyReduce_270 = happySpecReduce_2 92# happyReduction_270
+happyReduction_270 (HappyAbsSyn92 happy_var_2)
+ _
+ = HappyAbsSyn92
+ (FDot happy_var_2
+ )
+happyReduction_270 _ _ = notHappyAtAll
+
+happyReduce_271 = happySpecReduce_2 92# happyReduction_271
+happyReduction_271 (HappyAbsSyn92 happy_var_2)
+ _
+ = HappyAbsSyn92
+ (FMinus happy_var_2
+ )
+happyReduction_271 _ _ = notHappyAtAll
+
+happyReduce_272 = happySpecReduce_2 92# happyReduction_272
+happyReduction_272 (HappyAbsSyn92 happy_var_2)
+ (HappyAbsSyn12 happy_var_1)
+ = HappyAbsSyn92
+ (FAddId happy_var_1 happy_var_2
+ )
+happyReduction_272 _ _ = notHappyAtAll
+
+happyReduce_273 = happySpecReduce_2 93# happyReduction_273
+happyReduction_273 _
+ (HappyAbsSyn92 happy_var_1)
+ = HappyAbsSyn93
+ ((:[]) happy_var_1
+ )
+happyReduction_273 _ _ = notHappyAtAll
+
+happyReduce_274 = happySpecReduce_3 93# happyReduction_274
+happyReduction_274 (HappyAbsSyn93 happy_var_3)
+ _
+ (HappyAbsSyn92 happy_var_1)
+ = HappyAbsSyn93
+ ((:) happy_var_1 happy_var_3
+ )
+happyReduction_274 _ _ _ = notHappyAtAll
+
+happyNewToken action sts stk [] =
+ action 176# 176# notHappyAtAll (HappyState action) sts stk []
+
+happyNewToken action sts stk (tk:tks) =
+ let cont i = action i i tk (HappyState action) sts stk tks in
+ case tk of {
+ PT _ (TS ";") -> cont 94#;
+ PT _ (TS "=") -> cont 95#;
+ PT _ (TS "{") -> cont 96#;
+ PT _ (TS "}") -> cont 97#;
+ PT _ (TS "(") -> cont 98#;
+ PT _ (TS ")") -> cont 99#;
+ PT _ (TS ":") -> cont 100#;
+ PT _ (TS "->") -> cont 101#;
+ PT _ (TS "**") -> cont 102#;
+ PT _ (TS ",") -> cont 103#;
+ PT _ (TS "[") -> cont 104#;
+ PT _ (TS "]") -> cont 105#;
+ PT _ (TS "-") -> cont 106#;
+ PT _ (TS ".") -> cont 107#;
+ PT _ (TS "|") -> cont 108#;
+ PT _ (TS "%") -> cont 109#;
+ PT _ (TS "?") -> cont 110#;
+ PT _ (TS "<") -> cont 111#;
+ PT _ (TS ">") -> cont 112#;
+ PT _ (TS "@") -> cont 113#;
+ PT _ (TS "#") -> cont 114#;
+ PT _ (TS "!") -> cont 115#;
+ PT _ (TS "*") -> cont 116#;
+ PT _ (TS "+") -> cont 117#;
+ PT _ (TS "++") -> cont 118#;
+ PT _ (TS "\\") -> cont 119#;
+ PT _ (TS "=>") -> cont 120#;
+ PT _ (TS "_") -> cont 121#;
+ PT _ (TS "$") -> cont 122#;
+ PT _ (TS "/") -> cont 123#;
+ PT _ (TS "Lin") -> cont 124#;
+ PT _ (TS "PType") -> cont 125#;
+ PT _ (TS "Str") -> cont 126#;
+ PT _ (TS "Strs") -> cont 127#;
+ PT _ (TS "Tok") -> cont 128#;
+ PT _ (TS "Type") -> cont 129#;
+ PT _ (TS "abstract") -> cont 130#;
+ PT _ (TS "case") -> cont 131#;
+ PT _ (TS "cat") -> cont 132#;
+ PT _ (TS "concrete") -> cont 133#;
+ PT _ (TS "data") -> cont 134#;
+ PT _ (TS "def") -> cont 135#;
+ PT _ (TS "flags") -> cont 136#;
+ PT _ (TS "fn") -> cont 137#;
+ PT _ (TS "fun") -> cont 138#;
+ PT _ (TS "grammar") -> cont 139#;
+ PT _ (TS "in") -> cont 140#;
+ PT _ (TS "include") -> cont 141#;
+ PT _ (TS "incomplete") -> cont 142#;
+ PT _ (TS "instance") -> cont 143#;
+ PT _ (TS "interface") -> cont 144#;
+ PT _ (TS "let") -> cont 145#;
+ PT _ (TS "lin") -> cont 146#;
+ PT _ (TS "lincat") -> cont 147#;
+ PT _ (TS "lindef") -> cont 148#;
+ PT _ (TS "lintype") -> cont 149#;
+ PT _ (TS "of") -> cont 150#;
+ PT _ (TS "open") -> cont 151#;
+ PT _ (TS "oper") -> cont 152#;
+ PT _ (TS "out") -> cont 153#;
+ PT _ (TS "package") -> cont 154#;
+ PT _ (TS "param") -> cont 155#;
+ PT _ (TS "pattern") -> cont 156#;
+ PT _ (TS "pre") -> cont 157#;
+ PT _ (TS "printname") -> cont 158#;
+ PT _ (TS "resource") -> cont 159#;
+ PT _ (TS "reuse") -> cont 160#;
+ PT _ (TS "strs") -> cont 161#;
+ PT _ (TS "table") -> cont 162#;
+ PT _ (TS "tokenizer") -> cont 163#;
+ PT _ (TS "transfer") -> cont 164#;
+ PT _ (TS "union") -> cont 165#;
+ PT _ (TS "var") -> cont 166#;
+ PT _ (TS "variants") -> cont 167#;
+ PT _ (TS "where") -> cont 168#;
+ PT _ (TS "with") -> cont 169#;
+ PT _ (TI happy_dollar_dollar) -> cont 170#;
+ PT _ (TL happy_dollar_dollar) -> cont 171#;
+ PT _ (TD happy_dollar_dollar) -> cont 172#;
+ PT _ (T_LString happy_dollar_dollar) -> cont 173#;
+ PT _ (T_PIdent _) -> cont 174#;
+ _ -> cont 175#;
+ _ -> happyError' (tk:tks)
+ }
+
+happyError_ tk tks = happyError' (tk:tks)
+
+happyThen :: () => Err a -> (a -> Err b) -> Err b
+happyThen = (thenM)
+happyReturn :: () => a -> Err a
+happyReturn = (returnM)
+happyThen1 m k tks = (thenM) m (\a -> k a tks)
+happyReturn1 :: () => a -> b -> Err a
+happyReturn1 = \a tks -> (returnM) a
+happyError' :: () => [Token] -> Err a
+happyError' = happyError
+
+pGrammar tks = happySomeParser where
+ happySomeParser = happyThen (happyParse action_0 tks) (\x -> case x of {HappyAbsSyn13 z -> happyReturn z; _other -> notHappyAtAll })
+
+pModDef tks = happySomeParser where
+ happySomeParser = happyThen (happyParse action_1 tks) (\x -> case x of {HappyAbsSyn15 z -> happyReturn z; _other -> notHappyAtAll })
+
+pOldGrammar tks = happySomeParser where
+ happySomeParser = happyThen (happyParse action_2 tks) (\x -> case x of {HappyAbsSyn90 z -> happyReturn z; _other -> notHappyAtAll })
+
+pExp tks = happySomeParser where
+ happySomeParser = happyThen (happyParse action_3 tks) (\x -> case x of {HappyAbsSyn58 z -> happyReturn z; _other -> notHappyAtAll })
+
+pModHeader tks = happySomeParser where
+ happySomeParser = happyThen (happyParse action_4 tks) (\x -> case x of {HappyAbsSyn15 z -> happyReturn z; _other -> notHappyAtAll })
+
+happySeq = happyDontSeq
+
+
+returnM :: a -> Err a
+returnM = return
+
+thenM :: Err a -> (a -> Err b) -> Err b
+thenM = (>>=)
+
+happyError :: [Token] -> Err a
+happyError ts =
+ Bad $ "syntax error at " ++ tokenPos ts ++
+ case ts of
+ [] -> []
+ [Err _] -> " due to lexer error"
+ _ -> " before " ++ unwords (map prToken (take 4 ts))
+
+myLexer = tokens
+{-# LINE 1 "templates/GenericTemplate.hs" #-}
+{-# LINE 1 "templates/GenericTemplate.hs" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "templates/GenericTemplate.hs" #-}
+-- Id: GenericTemplate.hs,v 1.26 2005/01/14 14:47:22 simonmar Exp
+
+{-# LINE 28 "templates/GenericTemplate.hs" #-}
+
+
+
+
+
+
+
+
+{-# LINE 49 "templates/GenericTemplate.hs" #-}
+
+{-# LINE 59 "templates/GenericTemplate.hs" #-}
+
+{-# LINE 68 "templates/GenericTemplate.hs" #-}
+
+infixr 9 `HappyStk`
+data HappyStk a = HappyStk a (HappyStk a)
+
+-----------------------------------------------------------------------------
+-- starting the parse
+
+happyParse start_state = happyNewToken start_state notHappyAtAll notHappyAtAll
+
+-----------------------------------------------------------------------------
+-- Accepting the parse
+
+-- If the current token is 1#, it means we've just accepted a partial
+-- parse (a %partial parser). We must ignore the saved token on the top of
+-- the stack in this case.
+happyAccept 1# tk st sts (_ `HappyStk` ans `HappyStk` _) =
+ happyReturn1 ans
+happyAccept j tk st sts (HappyStk ans _) =
+ (happyTcHack j ) (happyReturn1 ans)
+
+-----------------------------------------------------------------------------
+-- Arrays only: do the next action
+
+{-# LINE 155 "templates/GenericTemplate.hs" #-}
+
+-----------------------------------------------------------------------------
+-- HappyState data type (not arrays)
+
+
+
+newtype HappyState b c = HappyState
+ (Int# -> -- token number
+ Int# -> -- token number (yes, again)
+ b -> -- token semantic value
+ HappyState b c -> -- current state
+ [HappyState b c] -> -- state stack
+ c)
+
+
+
+-----------------------------------------------------------------------------
+-- Shifting a token
+
+happyShift new_state 1# tk st sts stk@(x `HappyStk` _) =
+ let i = (case x of { HappyErrorToken (I# (i)) -> i }) in
+-- trace "shifting the error token" $
+ new_state i i tk (HappyState (new_state)) ((st):(sts)) (stk)
+
+happyShift new_state i tk st sts stk =
+ happyNewToken new_state ((st):(sts)) ((HappyTerminal (tk))`HappyStk`stk)
+
+-- happyReduce is specialised for the common cases.
+
+happySpecReduce_0 i fn 1# tk st sts stk
+ = happyFail 1# tk st sts stk
+happySpecReduce_0 nt fn j tk st@((HappyState (action))) sts stk
+ = action nt j tk st ((st):(sts)) (fn `HappyStk` stk)
+
+happySpecReduce_1 i fn 1# tk st sts stk
+ = happyFail 1# tk st sts stk
+happySpecReduce_1 nt fn j tk _ sts@(((st@(HappyState (action))):(_))) (v1`HappyStk`stk')
+ = let r = fn v1 in
+ happySeq r (action nt j tk st sts (r `HappyStk` stk'))
+
+happySpecReduce_2 i fn 1# tk st sts stk
+ = happyFail 1# tk st sts stk
+happySpecReduce_2 nt fn j tk _ ((_):(sts@(((st@(HappyState (action))):(_))))) (v1`HappyStk`v2`HappyStk`stk')
+ = let r = fn v1 v2 in
+ happySeq r (action nt j tk st sts (r `HappyStk` stk'))
+
+happySpecReduce_3 i fn 1# tk st sts stk
+ = happyFail 1# tk st sts stk
+happySpecReduce_3 nt fn j tk _ ((_):(((_):(sts@(((st@(HappyState (action))):(_))))))) (v1`HappyStk`v2`HappyStk`v3`HappyStk`stk')
+ = let r = fn v1 v2 v3 in
+ happySeq r (action nt j tk st sts (r `HappyStk` stk'))
+
+happyReduce k i fn 1# tk st sts stk
+ = happyFail 1# tk st sts stk
+happyReduce k nt fn j tk st sts stk
+ = case happyDrop (k -# (1# :: Int#)) sts of
+ sts1@(((st1@(HappyState (action))):(_))) ->
+ let r = fn stk in -- it doesn't hurt to always seq here...
+ happyDoSeq r (action nt j tk st1 sts1 r)
+
+happyMonadReduce k nt fn 1# tk st sts stk
+ = happyFail 1# tk st sts stk
+happyMonadReduce k nt fn j tk st sts stk =
+ happyThen1 (fn stk tk) (\r -> action nt j tk st1 sts1 (r `HappyStk` drop_stk))
+ where sts1@(((st1@(HappyState (action))):(_))) = happyDrop k ((st):(sts))
+ drop_stk = happyDropStk k stk
+
+happyMonad2Reduce k nt fn 1# tk st sts stk
+ = happyFail 1# tk st sts stk
+happyMonad2Reduce k nt fn j tk st sts stk =
+ happyThen1 (fn stk tk) (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk))
+ where sts1@(((st1@(HappyState (action))):(_))) = happyDrop k ((st):(sts))
+ drop_stk = happyDropStk k stk
+
+
+
+
+
+ new_state = action
+
+
+happyDrop 0# l = l
+happyDrop n ((_):(t)) = happyDrop (n -# (1# :: Int#)) t
+
+happyDropStk 0# l = l
+happyDropStk n (x `HappyStk` xs) = happyDropStk (n -# (1#::Int#)) xs
+
+-----------------------------------------------------------------------------
+-- Moving to a new state after a reduction
+
+{-# LINE 253 "templates/GenericTemplate.hs" #-}
+happyGoto action j tk st = action j j tk (HappyState action)
+
+
+-----------------------------------------------------------------------------
+-- Error recovery (1# is the error token)
+
+-- parse error if we are in recovery and we fail again
+happyFail 1# tk old_st _ stk =
+-- trace "failing" $
+ happyError_ tk
+
+{- We don't need state discarding for our restricted implementation of
+ "error". In fact, it can cause some bogus parses, so I've disabled it
+ for now --SDM
+
+-- discard a state
+happyFail 1# tk old_st (((HappyState (action))):(sts))
+ (saved_tok `HappyStk` _ `HappyStk` stk) =
+-- trace ("discarding state, depth " ++ show (length stk)) $
+ action 1# 1# tk (HappyState (action)) sts ((saved_tok`HappyStk`stk))
+-}
+
+-- Enter error recovery: generate an error token,
+-- save the old token and carry on.
+happyFail i tk (HappyState (action)) sts stk =
+-- trace "entering error recovery" $
+ action 1# 1# tk (HappyState (action)) sts ( (HappyErrorToken (I# (i))) `HappyStk` stk)
+
+-- Internal happy errors:
+
+notHappyAtAll = error "Internal Happy error\n"
+
+-----------------------------------------------------------------------------
+-- Hack to get the typechecker to accept our action functions
+
+
+happyTcHack :: Int# -> a -> a
+happyTcHack x y = y
+{-# INLINE happyTcHack #-}
+
+
+-----------------------------------------------------------------------------
+-- Seq-ing. If the --strict flag is given, then Happy emits
+-- happySeq = happyDoSeq
+-- otherwise it emits
+-- happySeq = happyDontSeq
+
+happyDoSeq, happyDontSeq :: a -> b -> b
+happyDoSeq a b = a `seq` b
+happyDontSeq a b = b
+
+-----------------------------------------------------------------------------
+-- Don't inline any functions from the template. GHC has a nasty habit
+-- of deciding to inline happyGoto everywhere, which increases the size of
+-- the generated parser quite a bit.
+
+{-# LINE 317 "templates/GenericTemplate.hs" #-}
+{-# NOINLINE happyShift #-}
+{-# NOINLINE happySpecReduce_0 #-}
+{-# NOINLINE happySpecReduce_1 #-}
+{-# NOINLINE happySpecReduce_2 #-}
+{-# NOINLINE happySpecReduce_3 #-}
+{-# NOINLINE happyReduce #-}
+{-# NOINLINE happyMonadReduce #-}
+{-# NOINLINE happyGoto #-}
+{-# NOINLINE happyFail #-}
+
+-- end of Happy Template.
diff --git a/src-2.9/GF/Source/ParGF.y b/src-2.9/GF/Source/ParGF.y
new file mode 100644
index 000000000..2109434e5
--- /dev/null
+++ b/src-2.9/GF/Source/ParGF.y
@@ -0,0 +1,642 @@
+-- This Happy file was machine-generated by the BNF converter
+{
+{-# OPTIONS -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
+ module GF.Source.ParGF (pGrammar, pModDef, pOldGrammar, pExp, pModHeader, myLexer) where --H
+import GF.Source.AbsGF --H
+import GF.Source.LexGF --H
+import GF.Infra.Ident --H
+import GF.Data.ErrM --H
+}
+
+%name pGrammar Grammar
+%name pModDef ModDef
+%name pOldGrammar OldGrammar
+%name pExp Exp
+%partial pModHeader ModHeader
+
+-- no lexer declaration
+%monad { Err } { thenM } { returnM }
+%tokentype { Token }
+
+%token
+ ';' { PT _ (TS ";") }
+ '=' { PT _ (TS "=") }
+ '{' { PT _ (TS "{") }
+ '}' { PT _ (TS "}") }
+ '(' { PT _ (TS "(") }
+ ')' { PT _ (TS ")") }
+ ':' { PT _ (TS ":") }
+ '->' { PT _ (TS "->") }
+ '**' { PT _ (TS "**") }
+ ',' { PT _ (TS ",") }
+ '[' { PT _ (TS "[") }
+ ']' { PT _ (TS "]") }
+ '-' { PT _ (TS "-") }
+ '.' { PT _ (TS ".") }
+ '|' { PT _ (TS "|") }
+ '%' { PT _ (TS "%") }
+ '?' { PT _ (TS "?") }
+ '<' { PT _ (TS "<") }
+ '>' { PT _ (TS ">") }
+ '@' { PT _ (TS "@") }
+ '#' { PT _ (TS "#") }
+ '!' { PT _ (TS "!") }
+ '*' { PT _ (TS "*") }
+ '+' { PT _ (TS "+") }
+ '++' { PT _ (TS "++") }
+ '\\' { PT _ (TS "\\") }
+ '=>' { PT _ (TS "=>") }
+ '_' { PT _ (TS "_") }
+ '$' { PT _ (TS "$") }
+ '/' { PT _ (TS "/") }
+ 'Lin' { PT _ (TS "Lin") }
+ 'PType' { PT _ (TS "PType") }
+ 'Str' { PT _ (TS "Str") }
+ 'Strs' { PT _ (TS "Strs") }
+ 'Tok' { PT _ (TS "Tok") }
+ 'Type' { PT _ (TS "Type") }
+ 'abstract' { PT _ (TS "abstract") }
+ 'case' { PT _ (TS "case") }
+ 'cat' { PT _ (TS "cat") }
+ 'concrete' { PT _ (TS "concrete") }
+ 'data' { PT _ (TS "data") }
+ 'def' { PT _ (TS "def") }
+ 'flags' { PT _ (TS "flags") }
+ 'fn' { PT _ (TS "fn") }
+ 'fun' { PT _ (TS "fun") }
+ 'grammar' { PT _ (TS "grammar") }
+ 'in' { PT _ (TS "in") }
+ 'include' { PT _ (TS "include") }
+ 'incomplete' { PT _ (TS "incomplete") }
+ 'instance' { PT _ (TS "instance") }
+ 'interface' { PT _ (TS "interface") }
+ 'let' { PT _ (TS "let") }
+ 'lin' { PT _ (TS "lin") }
+ 'lincat' { PT _ (TS "lincat") }
+ 'lindef' { PT _ (TS "lindef") }
+ 'lintype' { PT _ (TS "lintype") }
+ 'of' { PT _ (TS "of") }
+ 'open' { PT _ (TS "open") }
+ 'oper' { PT _ (TS "oper") }
+ 'out' { PT _ (TS "out") }
+ 'package' { PT _ (TS "package") }
+ 'param' { PT _ (TS "param") }
+ 'pattern' { PT _ (TS "pattern") }
+ 'pre' { PT _ (TS "pre") }
+ 'printname' { PT _ (TS "printname") }
+ 'resource' { PT _ (TS "resource") }
+ 'reuse' { PT _ (TS "reuse") }
+ 'strs' { PT _ (TS "strs") }
+ 'table' { PT _ (TS "table") }
+ 'tokenizer' { PT _ (TS "tokenizer") }
+ 'transfer' { PT _ (TS "transfer") }
+ 'union' { PT _ (TS "union") }
+ 'var' { PT _ (TS "var") }
+ 'variants' { PT _ (TS "variants") }
+ 'where' { PT _ (TS "where") }
+ 'with' { PT _ (TS "with") }
+
+L_integ { PT _ (TI $$) }
+L_quoted { PT _ (TL $$) }
+L_doubl { PT _ (TD $$) }
+L_LString { PT _ (T_LString $$) }
+L_PIdent { PT _ (T_PIdent _) }
+L_err { _ }
+
+
+%%
+
+Integer :: { Integer } : L_integ { (read $1) :: Integer }
+String :: { String } : L_quoted { $1 }
+Double :: { Double } : L_doubl { (read $1) :: Double }
+LString :: { LString} : L_LString { LString ($1)}
+PIdent :: { PIdent} : L_PIdent { PIdent (mkPosToken $1)}
+
+Grammar :: { Grammar }
+Grammar : ListModDef { Gr (reverse $1) }
+
+
+ListModDef :: { [ModDef] }
+ListModDef : {- empty -} { [] }
+ | ListModDef ModDef { flip (:) $1 $2 }
+
+
+ModDef :: { ModDef }
+ModDef : ModDef ';' { $1 }
+ | 'grammar' PIdent '=' '{' 'abstract' '=' PIdent ';' ListConcSpec '}' { MMain $2 $7 $9 }
+ | ComplMod ModType '=' ModBody { MModule $1 $2 $4 }
+
+
+ConcSpec :: { ConcSpec }
+ConcSpec : PIdent '=' ConcExp { ConcSpec $1 $3 }
+
+
+ListConcSpec :: { [ConcSpec] }
+ListConcSpec : {- empty -} { [] }
+ | ConcSpec { (:[]) $1 }
+ | ConcSpec ';' ListConcSpec { (:) $1 $3 }
+
+
+ConcExp :: { ConcExp }
+ConcExp : PIdent ListTransfer { ConcExp $1 (reverse $2) }
+
+
+ListTransfer :: { [Transfer] }
+ListTransfer : {- empty -} { [] }
+ | ListTransfer Transfer { flip (:) $1 $2 }
+
+
+Transfer :: { Transfer }
+Transfer : '(' 'transfer' 'in' Open ')' { TransferIn $4 }
+ | '(' 'transfer' 'out' Open ')' { TransferOut $4 }
+
+
+ModHeader :: { ModDef }
+ModHeader : ComplMod ModType '=' ModHeaderBody { MModule $1 $2 $4 }
+
+
+ModHeaderBody :: { ModBody }
+ModHeaderBody : Extend Opens { MBody $1 $2 [] }
+ | ListIncluded { MNoBody $1 }
+ | Included 'with' ListOpen { MWith $1 $3 }
+ | Included 'with' ListOpen '**' Opens { MWithBody $1 $3 $5 [] }
+ | ListIncluded '**' Included 'with' ListOpen { MWithE $1 $3 $5 }
+ | ListIncluded '**' Included 'with' ListOpen '**' Opens { MWithEBody $1 $3 $5 $7 [] }
+ | 'reuse' PIdent { MReuse $2 }
+ | 'union' ListIncluded { MUnion $2 }
+
+
+ModType :: { ModType }
+ModType : 'abstract' PIdent { MTAbstract $2 }
+ | 'resource' PIdent { MTResource $2 }
+ | 'interface' PIdent { MTInterface $2 }
+ | 'concrete' PIdent 'of' PIdent { MTConcrete $2 $4 }
+ | 'instance' PIdent 'of' PIdent { MTInstance $2 $4 }
+ | 'transfer' PIdent ':' Open '->' Open { MTTransfer $2 $4 $6 }
+
+
+ModBody :: { ModBody }
+ModBody : Extend Opens '{' ListTopDef '}' { MBody $1 $2 (reverse $4) }
+ | ListIncluded { MNoBody $1 }
+ | Included 'with' ListOpen { MWith $1 $3 }
+ | Included 'with' ListOpen '**' Opens '{' ListTopDef '}' { MWithBody $1 $3 $5 (reverse $7) }
+ | ListIncluded '**' Included 'with' ListOpen { MWithE $1 $3 $5 }
+ | ListIncluded '**' Included 'with' ListOpen '**' Opens '{' ListTopDef '}' { MWithEBody $1 $3 $5 $7 (reverse $9) }
+ | 'reuse' PIdent { MReuse $2 }
+ | 'union' ListIncluded { MUnion $2 }
+
+
+ListTopDef :: { [TopDef] }
+ListTopDef : {- empty -} { [] }
+ | ListTopDef TopDef { flip (:) $1 $2 }
+
+
+Extend :: { Extend }
+Extend : ListIncluded '**' { Ext $1 }
+ | {- empty -} { NoExt }
+
+
+ListOpen :: { [Open] }
+ListOpen : {- empty -} { [] }
+ | Open { (:[]) $1 }
+ | Open ',' ListOpen { (:) $1 $3 }
+
+
+Opens :: { Opens }
+Opens : {- empty -} { NoOpens }
+ | 'open' ListOpen 'in' { OpenIn $2 }
+
+
+Open :: { Open }
+Open : PIdent { OName $1 }
+ | '(' QualOpen PIdent ')' { OQualQO $2 $3 }
+ | '(' QualOpen PIdent '=' PIdent ')' { OQual $2 $3 $5 }
+
+
+ComplMod :: { ComplMod }
+ComplMod : {- empty -} { CMCompl }
+ | 'incomplete' { CMIncompl }
+
+
+QualOpen :: { QualOpen }
+QualOpen : {- empty -} { QOCompl }
+ | 'incomplete' { QOIncompl }
+ | 'interface' { QOInterface }
+
+
+ListIncluded :: { [Included] }
+ListIncluded : {- empty -} { [] }
+ | Included { (:[]) $1 }
+ | Included ',' ListIncluded { (:) $1 $3 }
+
+
+Included :: { Included }
+Included : PIdent { IAll $1 }
+ | PIdent '[' ListPIdent ']' { ISome $1 $3 }
+ | PIdent '-' '[' ListPIdent ']' { IMinus $1 $4 }
+
+
+Def :: { Def }
+Def : ListName ':' Exp { DDecl $1 $3 }
+ | ListName '=' Exp { DDef $1 $3 }
+ | Name ListPatt '=' Exp { DPatt $1 $2 $4 }
+ | ListName ':' Exp '=' Exp { DFull $1 $3 $5 }
+
+
+TopDef :: { TopDef }
+TopDef : 'cat' ListCatDef { DefCat $2 }
+ | 'fun' ListFunDef { DefFun $2 }
+ | 'data' ListFunDef { DefFunData $2 }
+ | 'def' ListDef { DefDef $2 }
+ | 'data' ListDataDef { DefData $2 }
+ | 'transfer' ListDef { DefTrans $2 }
+ | 'param' ListParDef { DefPar $2 }
+ | 'oper' ListDef { DefOper $2 }
+ | 'lincat' ListPrintDef { DefLincat $2 }
+ | 'lindef' ListDef { DefLindef $2 }
+ | 'lin' ListDef { DefLin $2 }
+ | 'printname' 'cat' ListPrintDef { DefPrintCat $3 }
+ | 'printname' 'fun' ListPrintDef { DefPrintFun $3 }
+ | 'flags' ListFlagDef { DefFlag $2 }
+ | 'printname' ListPrintDef { DefPrintOld $2 }
+ | 'lintype' ListDef { DefLintype $2 }
+ | 'pattern' ListDef { DefPattern $2 }
+ | 'package' PIdent '=' '{' ListTopDef '}' ';' { DefPackage $2 (reverse $5) }
+ | 'var' ListDef { DefVars $2 }
+ | 'tokenizer' PIdent ';' { DefTokenizer $2 }
+
+
+CatDef :: { CatDef }
+CatDef : PIdent ListDDecl { SimpleCatDef $1 (reverse $2) }
+ | '[' PIdent ListDDecl ']' { ListCatDef $2 (reverse $3) }
+ | '[' PIdent ListDDecl ']' '{' Integer '}' { ListSizeCatDef $2 (reverse $3) $6 }
+
+
+FunDef :: { FunDef }
+FunDef : ListPIdent ':' Exp { FunDef $1 $3 }
+
+
+DataDef :: { DataDef }
+DataDef : PIdent '=' ListDataConstr { DataDef $1 $3 }
+
+
+DataConstr :: { DataConstr }
+DataConstr : PIdent { DataId $1 }
+ | PIdent '.' PIdent { DataQId $1 $3 }
+
+
+ListDataConstr :: { [DataConstr] }
+ListDataConstr : {- empty -} { [] }
+ | DataConstr { (:[]) $1 }
+ | DataConstr '|' ListDataConstr { (:) $1 $3 }
+
+
+ParDef :: { ParDef }
+ParDef : PIdent '=' ListParConstr { ParDefDir $1 $3 }
+ | PIdent '=' '(' 'in' PIdent ')' { ParDefIndir $1 $5 }
+ | PIdent { ParDefAbs $1 }
+
+
+ParConstr :: { ParConstr }
+ParConstr : PIdent ListDDecl { ParConstr $1 (reverse $2) }
+
+
+PrintDef :: { PrintDef }
+PrintDef : ListName '=' Exp { PrintDef $1 $3 }
+
+
+FlagDef :: { FlagDef }
+FlagDef : PIdent '=' PIdent { FlagDef $1 $3 }
+
+
+ListDef :: { [Def] }
+ListDef : Def ';' { (:[]) $1 }
+ | Def ';' ListDef { (:) $1 $3 }
+
+
+ListCatDef :: { [CatDef] }
+ListCatDef : CatDef ';' { (:[]) $1 }
+ | CatDef ';' ListCatDef { (:) $1 $3 }
+
+
+ListFunDef :: { [FunDef] }
+ListFunDef : FunDef ';' { (:[]) $1 }
+ | FunDef ';' ListFunDef { (:) $1 $3 }
+
+
+ListDataDef :: { [DataDef] }
+ListDataDef : DataDef ';' { (:[]) $1 }
+ | DataDef ';' ListDataDef { (:) $1 $3 }
+
+
+ListParDef :: { [ParDef] }
+ListParDef : ParDef ';' { (:[]) $1 }
+ | ParDef ';' ListParDef { (:) $1 $3 }
+
+
+ListPrintDef :: { [PrintDef] }
+ListPrintDef : PrintDef ';' { (:[]) $1 }
+ | PrintDef ';' ListPrintDef { (:) $1 $3 }
+
+
+ListFlagDef :: { [FlagDef] }
+ListFlagDef : FlagDef ';' { (:[]) $1 }
+ | FlagDef ';' ListFlagDef { (:) $1 $3 }
+
+
+ListParConstr :: { [ParConstr] }
+ListParConstr : {- empty -} { [] }
+ | ParConstr { (:[]) $1 }
+ | ParConstr '|' ListParConstr { (:) $1 $3 }
+
+
+ListPIdent :: { [PIdent] }
+ListPIdent : PIdent { (:[]) $1 }
+ | PIdent ',' ListPIdent { (:) $1 $3 }
+
+
+Name :: { Name }
+Name : PIdent { IdentName $1 }
+ | '[' PIdent ']' { ListName $2 }
+
+
+ListName :: { [Name] }
+ListName : Name { (:[]) $1 }
+ | Name ',' ListName { (:) $1 $3 }
+
+
+LocDef :: { LocDef }
+LocDef : ListPIdent ':' Exp { LDDecl $1 $3 }
+ | ListPIdent '=' Exp { LDDef $1 $3 }
+ | ListPIdent ':' Exp '=' Exp { LDFull $1 $3 $5 }
+
+
+ListLocDef :: { [LocDef] }
+ListLocDef : {- empty -} { [] }
+ | LocDef { (:[]) $1 }
+ | LocDef ';' ListLocDef { (:) $1 $3 }
+
+
+Exp6 :: { Exp }
+Exp6 : PIdent { EIdent $1 }
+ | '{' PIdent '}' { EConstr $2 }
+ | '%' PIdent '%' { ECons $2 }
+ | Sort { ESort $1 }
+ | String { EString $1 }
+ | Integer { EInt $1 }
+ | Double { EFloat $1 }
+ | '?' { EMeta }
+ | '[' ']' { EEmpty }
+ | 'data' { EData }
+ | '[' PIdent Exps ']' { EList $2 $3 }
+ | '[' String ']' { EStrings $2 }
+ | '{' ListLocDef '}' { ERecord $2 }
+ | '<' ListTupleComp '>' { ETuple $2 }
+ | '(' 'in' PIdent ')' { EIndir $3 }
+ | '<' Exp ':' Exp '>' { ETyped $2 $4 }
+ | '(' Exp ')' { $2 }
+ | LString { ELString $1 }
+
+
+Exp5 :: { Exp }
+Exp5 : Exp5 '.' Label { EProj $1 $3 }
+ | '{' PIdent '.' PIdent '}' { EQConstr $2 $4 }
+ | '%' PIdent '.' PIdent { EQCons $2 $4 }
+ | Exp6 { $1 }
+
+
+Exp4 :: { Exp }
+Exp4 : Exp4 Exp5 { EApp $1 $2 }
+ | 'table' '{' ListCase '}' { ETable $3 }
+ | 'table' Exp6 '{' ListCase '}' { ETTable $2 $4 }
+ | 'table' Exp6 '[' ListExp ']' { EVTable $2 $4 }
+ | 'case' Exp 'of' '{' ListCase '}' { ECase $2 $5 }
+ | 'variants' '{' ListExp '}' { EVariants $3 }
+ | 'pre' '{' Exp ';' ListAltern '}' { EPre $3 $5 }
+ | 'strs' '{' ListExp '}' { EStrs $3 }
+ | PIdent '@' Exp6 { EConAt $1 $3 }
+ | '#' Patt2 { EPatt $2 }
+ | 'pattern' Exp5 { EPattType $2 }
+ | Exp5 { $1 }
+ | 'Lin' PIdent { ELin $2 }
+
+
+Exp3 :: { Exp }
+Exp3 : Exp3 '!' Exp4 { ESelect $1 $3 }
+ | Exp3 '*' Exp4 { ETupTyp $1 $3 }
+ | Exp3 '**' Exp4 { EExtend $1 $3 }
+ | Exp4 { $1 }
+
+
+Exp1 :: { Exp }
+Exp1 : Exp2 '+' Exp1 { EGlue $1 $3 }
+ | Exp2 { $1 }
+
+
+Exp :: { Exp }
+Exp : Exp1 '++' Exp { EConcat $1 $3 }
+ | '\\' ListBind '->' Exp { EAbstr $2 $4 }
+ | '\\' '\\' ListBind '=>' Exp { ECTable $3 $5 }
+ | Decl '->' Exp { EProd $1 $3 }
+ | Exp3 '=>' Exp { ETType $1 $3 }
+ | 'let' '{' ListLocDef '}' 'in' Exp { ELet $3 $6 }
+ | 'let' ListLocDef 'in' Exp { ELetb $2 $4 }
+ | Exp3 'where' '{' ListLocDef '}' { EWhere $1 $4 }
+ | 'fn' '{' ListEquation '}' { EEqs $3 }
+ | 'in' Exp5 String { EExample $2 $3 }
+ | Exp1 { $1 }
+
+
+Exp2 :: { Exp }
+Exp2 : Exp3 { $1 }
+
+
+ListExp :: { [Exp] }
+ListExp : {- empty -} { [] }
+ | Exp { (:[]) $1 }
+ | Exp ';' ListExp { (:) $1 $3 }
+
+
+Exps :: { Exps }
+Exps : {- empty -} { NilExp }
+ | Exp6 Exps { ConsExp $1 $2 }
+
+
+Patt2 :: { Patt }
+Patt2 : '?' { PChar }
+ | '[' String ']' { PChars $2 }
+ | '#' PIdent { PMacro $2 }
+ | '#' PIdent '.' PIdent { PM $2 $4 }
+ | '_' { PW }
+ | PIdent { PV $1 }
+ | '{' PIdent '}' { PCon $2 }
+ | PIdent '.' PIdent { PQ $1 $3 }
+ | Integer { PInt $1 }
+ | Double { PFloat $1 }
+ | String { PStr $1 }
+ | '{' ListPattAss '}' { PR $2 }
+ | '<' ListPattTupleComp '>' { PTup $2 }
+ | '(' Patt ')' { $2 }
+
+
+Patt1 :: { Patt }
+Patt1 : PIdent ListPatt { PC $1 $2 }
+ | PIdent '.' PIdent ListPatt { PQC $1 $3 $4 }
+ | Patt2 '*' { PRep $1 }
+ | PIdent '@' Patt2 { PAs $1 $3 }
+ | '-' Patt2 { PNeg $2 }
+ | Patt2 { $1 }
+
+
+Patt :: { Patt }
+Patt : Patt '|' Patt1 { PDisj $1 $3 }
+ | Patt '+' Patt1 { PSeq $1 $3 }
+ | Patt1 { $1 }
+
+
+PattAss :: { PattAss }
+PattAss : ListPIdent '=' Patt { PA $1 $3 }
+
+
+Label :: { Label }
+Label : PIdent { LIdent $1 }
+ | '$' Integer { LVar $2 }
+
+
+Sort :: { Sort }
+Sort : 'Type' { Sort_Type }
+ | 'PType' { Sort_PType }
+ | 'Tok' { Sort_Tok }
+ | 'Str' { Sort_Str }
+ | 'Strs' { Sort_Strs }
+
+
+ListPattAss :: { [PattAss] }
+ListPattAss : {- empty -} { [] }
+ | PattAss { (:[]) $1 }
+ | PattAss ';' ListPattAss { (:) $1 $3 }
+
+
+ListPatt :: { [Patt] }
+ListPatt : Patt2 { (:[]) $1 }
+ | Patt2 ListPatt { (:) $1 $2 }
+
+
+Bind :: { Bind }
+Bind : PIdent { BIdent $1 }
+ | '_' { BWild }
+
+
+ListBind :: { [Bind] }
+ListBind : {- empty -} { [] }
+ | Bind { (:[]) $1 }
+ | Bind ',' ListBind { (:) $1 $3 }
+
+
+Decl :: { Decl }
+Decl : '(' ListBind ':' Exp ')' { DDec $2 $4 }
+ | Exp4 { DExp $1 }
+
+
+TupleComp :: { TupleComp }
+TupleComp : Exp { TComp $1 }
+
+
+PattTupleComp :: { PattTupleComp }
+PattTupleComp : Patt { PTComp $1 }
+
+
+ListTupleComp :: { [TupleComp] }
+ListTupleComp : {- empty -} { [] }
+ | TupleComp { (:[]) $1 }
+ | TupleComp ',' ListTupleComp { (:) $1 $3 }
+
+
+ListPattTupleComp :: { [PattTupleComp] }
+ListPattTupleComp : {- empty -} { [] }
+ | PattTupleComp { (:[]) $1 }
+ | PattTupleComp ',' ListPattTupleComp { (:) $1 $3 }
+
+
+Case :: { Case }
+Case : Patt '=>' Exp { Case $1 $3 }
+
+
+ListCase :: { [Case] }
+ListCase : Case { (:[]) $1 }
+ | Case ';' ListCase { (:) $1 $3 }
+
+
+Equation :: { Equation }
+Equation : ListPatt '->' Exp { Equ $1 $3 }
+
+
+ListEquation :: { [Equation] }
+ListEquation : {- empty -} { [] }
+ | Equation { (:[]) $1 }
+ | Equation ';' ListEquation { (:) $1 $3 }
+
+
+Altern :: { Altern }
+Altern : Exp '/' Exp { Alt $1 $3 }
+
+
+ListAltern :: { [Altern] }
+ListAltern : {- empty -} { [] }
+ | Altern { (:[]) $1 }
+ | Altern ';' ListAltern { (:) $1 $3 }
+
+
+DDecl :: { DDecl }
+DDecl : '(' ListBind ':' Exp ')' { DDDec $2 $4 }
+ | Exp6 { DDExp $1 }
+
+
+ListDDecl :: { [DDecl] }
+ListDDecl : {- empty -} { [] }
+ | ListDDecl DDecl { flip (:) $1 $2 }
+
+
+OldGrammar :: { OldGrammar }
+OldGrammar : Include ListTopDef { OldGr $1 (reverse $2) }
+
+
+Include :: { Include }
+Include : {- empty -} { NoIncl }
+ | 'include' ListFileName { Incl $2 }
+
+
+FileName :: { FileName }
+FileName : String { FString $1 }
+ | PIdent { FIdent $1 }
+ | '/' FileName { FSlash $2 }
+ | '.' FileName { FDot $2 }
+ | '-' FileName { FMinus $2 }
+ | PIdent FileName { FAddId $1 $2 }
+
+
+ListFileName :: { [FileName] }
+ListFileName : FileName ';' { (:[]) $1 }
+ | FileName ';' ListFileName { (:) $1 $3 }
+
+
+
+{
+
+returnM :: a -> Err a
+returnM = return
+
+thenM :: Err a -> (a -> Err b) -> Err b
+thenM = (>>=)
+
+happyError :: [Token] -> Err a
+happyError ts =
+ Bad $ "syntax error at " ++ tokenPos ts ++
+ case ts of
+ [] -> []
+ [Err _] -> " due to lexer error"
+ _ -> " before " ++ unwords (map prToken (take 4 ts))
+
+myLexer = tokens
+}
+
diff --git a/src-2.9/GF/Source/PrintGF.hs b/src-2.9/GF/Source/PrintGF.hs
new file mode 100644
index 000000000..0a260f5bf
--- /dev/null
+++ b/src-2.9/GF/Source/PrintGF.hs
@@ -0,0 +1,532 @@
+{-# OPTIONS -fno-warn-incomplete-patterns #-}
+module GF.Source.PrintGF where
+
+-- pretty-printer generated by the BNF converter
+
+import GF.Source.AbsGF
+import Char
+
+-- the top-level printing method
+printTree :: Print a => a -> String
+printTree = render . prt 0
+
+type Doc = [ShowS] -> [ShowS]
+
+doc :: ShowS -> Doc
+doc = (:)
+
+render :: Doc -> String
+render d = rend 0 (map ($ "") $ d []) "" where
+ rend i ss = case ss of
+ "[" :ts -> showChar '[' . rend i ts
+ "(" :ts -> showChar '(' . rend i ts
+ "{" :ts -> showChar '{' . new (i+1) . rend (i+1) ts
+ "}" : ";":ts -> new (i-1) . space "}" . showChar ';' . new (i-1) . rend (i-1) ts
+ "}" :ts -> new (i-1) . showChar '}' . new (i-1) . rend (i-1) ts
+ ";" :ts -> showChar ';' . new i . rend i ts
+ t : "," :ts -> showString t . space "," . rend i ts
+ t : ")" :ts -> showString t . showChar ')' . rend i ts
+ t : "]" :ts -> showString t . showChar ']' . rend i ts
+ t :ts -> space t . rend i ts
+ _ -> id
+ new i = showChar '\n' . replicateS (2*i) (showChar ' ') . dropWhile isSpace
+ space t = showString t . (\s -> if null s then "" else (' ':s))
+
+parenth :: Doc -> Doc
+parenth ss = doc (showChar '(') . ss . doc (showChar ')')
+
+concatS :: [ShowS] -> ShowS
+concatS = foldr (.) id
+
+concatD :: [Doc] -> Doc
+concatD = foldr (.) id
+
+replicateS :: Int -> ShowS -> ShowS
+replicateS n f = concatS (replicate n f)
+
+-- the printer class does the job
+class Print a where
+ prt :: Int -> a -> Doc
+ prtList :: [a] -> Doc
+ prtList = concatD . map (prt 0)
+
+instance Print a => Print [a] where
+ prt _ = prtList
+
+instance Print Char where
+ prt _ s = doc (showChar '\'' . mkEsc '\'' s . showChar '\'')
+ prtList s = doc (showChar '"' . concatS (map (mkEsc '"') s) . showChar '"')
+
+mkEsc :: Char -> Char -> ShowS
+mkEsc q s = case s of
+ _ | s == q -> showChar '\\' . showChar s
+ '\\'-> showString "\\\\"
+ '\n' -> showString "\\n"
+ '\t' -> showString "\\t"
+ _ -> showChar s
+
+prPrec :: Int -> Int -> Doc -> Doc
+prPrec i j = if j (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+
+
+
+instance Print Grammar where
+ prt i e = case e of
+ Gr moddefs -> prPrec i 0 (concatD [prt 0 moddefs])
+
+
+instance Print ModDef where
+ prt i e = case e of
+ MMain pident0 pident concspecs -> prPrec i 0 (concatD [doc (showString "grammar") , prt 0 pident0 , doc (showString "=") , doc (showString "{") , doc (showString "abstract") , doc (showString "=") , prt 0 pident , doc (showString ";") , prt 0 concspecs , doc (showString "}")])
+ MModule complmod modtype modbody -> prPrec i 0 (concatD [prt 0 complmod , prt 0 modtype , doc (showString "=") , prt 0 modbody])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ x:xs -> (concatD [prt 0 x , prt 0 xs])
+
+instance Print ConcSpec where
+ prt i e = case e of
+ ConcSpec pident concexp -> prPrec i 0 (concatD [prt 0 pident , doc (showString "=") , prt 0 concexp])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print ConcExp where
+ prt i e = case e of
+ ConcExp pident transfers -> prPrec i 0 (concatD [prt 0 pident , prt 0 transfers])
+
+
+instance Print Transfer where
+ prt i e = case e of
+ TransferIn open -> prPrec i 0 (concatD [doc (showString "(") , doc (showString "transfer") , doc (showString "in") , prt 0 open , doc (showString ")")])
+ TransferOut open -> prPrec i 0 (concatD [doc (showString "(") , doc (showString "transfer") , doc (showString "out") , prt 0 open , doc (showString ")")])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ x:xs -> (concatD [prt 0 x , prt 0 xs])
+
+instance Print ModType where
+ prt i e = case e of
+ MTAbstract pident -> prPrec i 0 (concatD [doc (showString "abstract") , prt 0 pident])
+ MTResource pident -> prPrec i 0 (concatD [doc (showString "resource") , prt 0 pident])
+ MTInterface pident -> prPrec i 0 (concatD [doc (showString "interface") , prt 0 pident])
+ MTConcrete pident0 pident -> prPrec i 0 (concatD [doc (showString "concrete") , prt 0 pident0 , doc (showString "of") , prt 0 pident])
+ MTInstance pident0 pident -> prPrec i 0 (concatD [doc (showString "instance") , prt 0 pident0 , doc (showString "of") , prt 0 pident])
+ MTTransfer pident open0 open -> prPrec i 0 (concatD [doc (showString "transfer") , prt 0 pident , doc (showString ":") , prt 0 open0 , doc (showString "->") , prt 0 open])
+
+
+instance Print ModBody where
+ prt i e = case e of
+ MBody extend opens topdefs -> prPrec i 0 (concatD [prt 0 extend , prt 0 opens , doc (showString "{") , prt 0 topdefs , doc (showString "}")])
+ MNoBody includeds -> prPrec i 0 (concatD [prt 0 includeds])
+ MWith included opens -> prPrec i 0 (concatD [prt 0 included , doc (showString "with") , prt 0 opens])
+ MWithBody included opens0 opens topdefs -> prPrec i 0 (concatD [prt 0 included , doc (showString "with") , prt 0 opens0 , doc (showString "**") , prt 0 opens , doc (showString "{") , prt 0 topdefs , doc (showString "}")])
+ MWithE includeds included opens -> prPrec i 0 (concatD [prt 0 includeds , doc (showString "**") , prt 0 included , doc (showString "with") , prt 0 opens])
+ MWithEBody includeds included opens0 opens topdefs -> prPrec i 0 (concatD [prt 0 includeds , doc (showString "**") , prt 0 included , doc (showString "with") , prt 0 opens0 , doc (showString "**") , prt 0 opens , doc (showString "{") , prt 0 topdefs , doc (showString "}")])
+ MReuse pident -> prPrec i 0 (concatD [doc (showString "reuse") , prt 0 pident])
+ MUnion includeds -> prPrec i 0 (concatD [doc (showString "union") , prt 0 includeds])
+
+
+instance Print Extend where
+ prt i e = case e of
+ Ext includeds -> prPrec i 0 (concatD [prt 0 includeds , doc (showString "**")])
+ NoExt -> prPrec i 0 (concatD [])
+
+
+instance Print Opens where
+ prt i e = case e of
+ NoOpens -> prPrec i 0 (concatD [])
+ OpenIn opens -> prPrec i 0 (concatD [doc (showString "open") , prt 0 opens , doc (showString "in")])
+
+
+instance Print Open where
+ prt i e = case e of
+ OName pident -> prPrec i 0 (concatD [prt 0 pident])
+ OQualQO qualopen pident -> prPrec i 0 (concatD [doc (showString "(") , prt 0 qualopen , prt 0 pident , doc (showString ")")])
+ OQual qualopen pident0 pident -> prPrec i 0 (concatD [doc (showString "(") , prt 0 qualopen , prt 0 pident0 , doc (showString "=") , prt 0 pident , doc (showString ")")])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+
+instance Print ComplMod where
+ prt i e = case e of
+ CMCompl -> prPrec i 0 (concatD [])
+ CMIncompl -> prPrec i 0 (concatD [doc (showString "incomplete")])
+
+
+instance Print QualOpen where
+ prt i e = case e of
+ QOCompl -> prPrec i 0 (concatD [])
+ QOIncompl -> prPrec i 0 (concatD [doc (showString "incomplete")])
+ QOInterface -> prPrec i 0 (concatD [doc (showString "interface")])
+
+
+instance Print Included where
+ prt i e = case e of
+ IAll pident -> prPrec i 0 (concatD [prt 0 pident])
+ ISome pident pidents -> prPrec i 0 (concatD [prt 0 pident , doc (showString "[") , prt 0 pidents , doc (showString "]")])
+ IMinus pident pidents -> prPrec i 0 (concatD [prt 0 pident , doc (showString "-") , doc (showString "[") , prt 0 pidents , doc (showString "]")])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+
+instance Print Def where
+ prt i e = case e of
+ DDecl names exp -> prPrec i 0 (concatD [prt 0 names , doc (showString ":") , prt 0 exp])
+ DDef names exp -> prPrec i 0 (concatD [prt 0 names , doc (showString "=") , prt 0 exp])
+ DPatt name patts exp -> prPrec i 0 (concatD [prt 0 name , prt 0 patts , doc (showString "=") , prt 0 exp])
+ DFull names exp0 exp -> prPrec i 0 (concatD [prt 0 names , doc (showString ":") , prt 0 exp0 , doc (showString "=") , prt 0 exp])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x , doc (showString ";")])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print TopDef where
+ prt i e = case e of
+ DefCat catdefs -> prPrec i 0 (concatD [doc (showString "cat") , prt 0 catdefs])
+ DefFun fundefs -> prPrec i 0 (concatD [doc (showString "fun") , prt 0 fundefs])
+ DefFunData fundefs -> prPrec i 0 (concatD [doc (showString "data") , prt 0 fundefs])
+ DefDef defs -> prPrec i 0 (concatD [doc (showString "def") , prt 0 defs])
+ DefData datadefs -> prPrec i 0 (concatD [doc (showString "data") , prt 0 datadefs])
+ DefTrans defs -> prPrec i 0 (concatD [doc (showString "transfer") , prt 0 defs])
+ DefPar pardefs -> prPrec i 0 (concatD [doc (showString "param") , prt 0 pardefs])
+ DefOper defs -> prPrec i 0 (concatD [doc (showString "oper") , prt 0 defs])
+ DefLincat printdefs -> prPrec i 0 (concatD [doc (showString "lincat") , prt 0 printdefs])
+ DefLindef defs -> prPrec i 0 (concatD [doc (showString "lindef") , prt 0 defs])
+ DefLin defs -> prPrec i 0 (concatD [doc (showString "lin") , prt 0 defs])
+ DefPrintCat printdefs -> prPrec i 0 (concatD [doc (showString "printname") , doc (showString "cat") , prt 0 printdefs])
+ DefPrintFun printdefs -> prPrec i 0 (concatD [doc (showString "printname") , doc (showString "fun") , prt 0 printdefs])
+ DefFlag flagdefs -> prPrec i 0 (concatD [doc (showString "flags") , prt 0 flagdefs])
+ DefPrintOld printdefs -> prPrec i 0 (concatD [doc (showString "printname") , prt 0 printdefs])
+ DefLintype defs -> prPrec i 0 (concatD [doc (showString "lintype") , prt 0 defs])
+ DefPattern defs -> prPrec i 0 (concatD [doc (showString "pattern") , prt 0 defs])
+ DefPackage pident topdefs -> prPrec i 0 (concatD [doc (showString "package") , prt 0 pident , doc (showString "=") , doc (showString "{") , prt 0 topdefs , doc (showString "}") , doc (showString ";")])
+ DefVars defs -> prPrec i 0 (concatD [doc (showString "var") , prt 0 defs])
+ DefTokenizer pident -> prPrec i 0 (concatD [doc (showString "tokenizer") , prt 0 pident , doc (showString ";")])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ x:xs -> (concatD [prt 0 x , prt 0 xs])
+
+instance Print CatDef where
+ prt i e = case e of
+ SimpleCatDef pident ddecls -> prPrec i 0 (concatD [prt 0 pident , prt 0 ddecls])
+ ListCatDef pident ddecls -> prPrec i 0 (concatD [doc (showString "[") , prt 0 pident , prt 0 ddecls , doc (showString "]")])
+ ListSizeCatDef pident ddecls n -> prPrec i 0 (concatD [doc (showString "[") , prt 0 pident , prt 0 ddecls , doc (showString "]") , doc (showString "{") , prt 0 n , doc (showString "}")])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x , doc (showString ";")])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print FunDef where
+ prt i e = case e of
+ FunDef pidents exp -> prPrec i 0 (concatD [prt 0 pidents , doc (showString ":") , prt 0 exp])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x , doc (showString ";")])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print DataDef where
+ prt i e = case e of
+ DataDef pident dataconstrs -> prPrec i 0 (concatD [prt 0 pident , doc (showString "=") , prt 0 dataconstrs])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x , doc (showString ";")])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print DataConstr where
+ prt i e = case e of
+ DataId pident -> prPrec i 0 (concatD [prt 0 pident])
+ DataQId pident0 pident -> prPrec i 0 (concatD [prt 0 pident0 , doc (showString ".") , prt 0 pident])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString "|") , prt 0 xs])
+
+instance Print ParDef where
+ prt i e = case e of
+ ParDefDir pident parconstrs -> prPrec i 0 (concatD [prt 0 pident , doc (showString "=") , prt 0 parconstrs])
+ ParDefIndir pident0 pident -> prPrec i 0 (concatD [prt 0 pident0 , doc (showString "=") , doc (showString "(") , doc (showString "in") , prt 0 pident , doc (showString ")")])
+ ParDefAbs pident -> prPrec i 0 (concatD [prt 0 pident])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x , doc (showString ";")])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print ParConstr where
+ prt i e = case e of
+ ParConstr pident ddecls -> prPrec i 0 (concatD [prt 0 pident , prt 0 ddecls])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString "|") , prt 0 xs])
+
+instance Print PrintDef where
+ prt i e = case e of
+ PrintDef names exp -> prPrec i 0 (concatD [prt 0 names , doc (showString "=") , prt 0 exp])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x , doc (showString ";")])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print FlagDef where
+ prt i e = case e of
+ FlagDef pident0 pident -> prPrec i 0 (concatD [prt 0 pident0 , doc (showString "=") , prt 0 pident])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x , doc (showString ";")])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print Name where
+ prt i e = case e of
+ IdentName pident -> prPrec i 0 (concatD [prt 0 pident])
+ ListName pident -> prPrec i 0 (concatD [doc (showString "[") , prt 0 pident , doc (showString "]")])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+
+instance Print LocDef where
+ prt i e = case e of
+ LDDecl pidents exp -> prPrec i 0 (concatD [prt 0 pidents , doc (showString ":") , prt 0 exp])
+ LDDef pidents exp -> prPrec i 0 (concatD [prt 0 pidents , doc (showString "=") , prt 0 exp])
+ LDFull pidents exp0 exp -> prPrec i 0 (concatD [prt 0 pidents , doc (showString ":") , prt 0 exp0 , doc (showString "=") , prt 0 exp])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print Exp where
+ prt i e = case e of
+ EIdent pident -> prPrec i 6 (concatD [prt 0 pident])
+ EConstr pident -> prPrec i 6 (concatD [doc (showString "{") , prt 0 pident , doc (showString "}")])
+ ECons pident -> prPrec i 6 (concatD [doc (showString "%") , prt 0 pident , doc (showString "%")])
+ ESort sort -> prPrec i 6 (concatD [prt 0 sort])
+ EString str -> prPrec i 6 (concatD [prt 0 str])
+ EInt n -> prPrec i 6 (concatD [prt 0 n])
+ EFloat d -> prPrec i 6 (concatD [prt 0 d])
+ EMeta -> prPrec i 6 (concatD [doc (showString "?")])
+ EEmpty -> prPrec i 6 (concatD [doc (showString "[") , doc (showString "]")])
+ EData -> prPrec i 6 (concatD [doc (showString "data")])
+ EList pident exps -> prPrec i 6 (concatD [doc (showString "[") , prt 0 pident , prt 0 exps , doc (showString "]")])
+ EStrings str -> prPrec i 6 (concatD [doc (showString "[") , prt 0 str , doc (showString "]")])
+ ERecord locdefs -> prPrec i 6 (concatD [doc (showString "{") , prt 0 locdefs , doc (showString "}")])
+ ETuple tuplecomps -> prPrec i 6 (concatD [doc (showString "<") , prt 0 tuplecomps , doc (showString ">")])
+ EIndir pident -> prPrec i 6 (concatD [doc (showString "(") , doc (showString "in") , prt 0 pident , doc (showString ")")])
+ ETyped exp0 exp -> prPrec i 6 (concatD [doc (showString "<") , prt 0 exp0 , doc (showString ":") , prt 0 exp , doc (showString ">")])
+ EProj exp label -> prPrec i 5 (concatD [prt 5 exp , doc (showString ".") , prt 0 label])
+ EQConstr pident0 pident -> prPrec i 5 (concatD [doc (showString "{") , prt 0 pident0 , doc (showString ".") , prt 0 pident , doc (showString "}")])
+ EQCons pident0 pident -> prPrec i 5 (concatD [doc (showString "%") , prt 0 pident0 , doc (showString ".") , prt 0 pident])
+ EApp exp0 exp -> prPrec i 4 (concatD [prt 4 exp0 , prt 5 exp])
+ ETable cases -> prPrec i 4 (concatD [doc (showString "table") , doc (showString "{") , prt 0 cases , doc (showString "}")])
+ ETTable exp cases -> prPrec i 4 (concatD [doc (showString "table") , prt 6 exp , doc (showString "{") , prt 0 cases , doc (showString "}")])
+ EVTable exp exps -> prPrec i 4 (concatD [doc (showString "table") , prt 6 exp , doc (showString "[") , prt 0 exps , doc (showString "]")])
+ ECase exp cases -> prPrec i 4 (concatD [doc (showString "case") , prt 0 exp , doc (showString "of") , doc (showString "{") , prt 0 cases , doc (showString "}")])
+ EVariants exps -> prPrec i 4 (concatD [doc (showString "variants") , doc (showString "{") , prt 0 exps , doc (showString "}")])
+ EPre exp alterns -> prPrec i 4 (concatD [doc (showString "pre") , doc (showString "{") , prt 0 exp , doc (showString ";") , prt 0 alterns , doc (showString "}")])
+ EStrs exps -> prPrec i 4 (concatD [doc (showString "strs") , doc (showString "{") , prt 0 exps , doc (showString "}")])
+ EConAt pident exp -> prPrec i 4 (concatD [prt 0 pident , doc (showString "@") , prt 6 exp])
+ EPatt patt -> prPrec i 4 (concatD [doc (showString "#") , prt 2 patt])
+ EPattType exp -> prPrec i 4 (concatD [doc (showString "pattern") , prt 5 exp])
+ ESelect exp0 exp -> prPrec i 3 (concatD [prt 3 exp0 , doc (showString "!") , prt 4 exp])
+ ETupTyp exp0 exp -> prPrec i 3 (concatD [prt 3 exp0 , doc (showString "*") , prt 4 exp])
+ EExtend exp0 exp -> prPrec i 3 (concatD [prt 3 exp0 , doc (showString "**") , prt 4 exp])
+ EGlue exp0 exp -> prPrec i 1 (concatD [prt 2 exp0 , doc (showString "+") , prt 1 exp])
+ EConcat exp0 exp -> prPrec i 0 (concatD [prt 1 exp0 , doc (showString "++") , prt 0 exp])
+ EAbstr binds exp -> prPrec i 0 (concatD [doc (showString "\\") , prt 0 binds , doc (showString "->") , prt 0 exp])
+ ECTable binds exp -> prPrec i 0 (concatD [doc (showString "\\") , doc (showString "\\") , prt 0 binds , doc (showString "=>") , prt 0 exp])
+ EProd decl exp -> prPrec i 0 (concatD [prt 0 decl , doc (showString "->") , prt 0 exp])
+ ETType exp0 exp -> prPrec i 0 (concatD [prt 3 exp0 , doc (showString "=>") , prt 0 exp])
+ ELet locdefs exp -> prPrec i 0 (concatD [doc (showString "let") , doc (showString "{") , prt 0 locdefs , doc (showString "}") , doc (showString "in") , prt 0 exp])
+ ELetb locdefs exp -> prPrec i 0 (concatD [doc (showString "let") , prt 0 locdefs , doc (showString "in") , prt 0 exp])
+ EWhere exp locdefs -> prPrec i 0 (concatD [prt 3 exp , doc (showString "where") , doc (showString "{") , prt 0 locdefs , doc (showString "}")])
+ EEqs equations -> prPrec i 0 (concatD [doc (showString "fn") , doc (showString "{") , prt 0 equations , doc (showString "}")])
+ EExample exp str -> prPrec i 0 (concatD [doc (showString "in") , prt 5 exp , prt 0 str])
+ ELString lstring -> prPrec i 6 (concatD [prt 0 lstring])
+ ELin pident -> prPrec i 4 (concatD [doc (showString "Lin") , prt 0 pident])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print Exps where
+ prt i e = case e of
+ NilExp -> prPrec i 0 (concatD [])
+ ConsExp exp exps -> prPrec i 0 (concatD [prt 6 exp , prt 0 exps])
+
+
+instance Print Patt where
+ prt i e = case e of
+ PChar -> prPrec i 2 (concatD [doc (showString "?")])
+ PChars str -> prPrec i 2 (concatD [doc (showString "[") , prt 0 str , doc (showString "]")])
+ PMacro pident -> prPrec i 2 (concatD [doc (showString "#") , prt 0 pident])
+ PM pident0 pident -> prPrec i 2 (concatD [doc (showString "#") , prt 0 pident0 , doc (showString ".") , prt 0 pident])
+ PW -> prPrec i 2 (concatD [doc (showString "_")])
+ PV pident -> prPrec i 2 (concatD [prt 0 pident])
+ PCon pident -> prPrec i 2 (concatD [doc (showString "{") , prt 0 pident , doc (showString "}")])
+ PQ pident0 pident -> prPrec i 2 (concatD [prt 0 pident0 , doc (showString ".") , prt 0 pident])
+ PInt n -> prPrec i 2 (concatD [prt 0 n])
+ PFloat d -> prPrec i 2 (concatD [prt 0 d])
+ PStr str -> prPrec i 2 (concatD [prt 0 str])
+ PR pattasss -> prPrec i 2 (concatD [doc (showString "{") , prt 0 pattasss , doc (showString "}")])
+ PTup patttuplecomps -> prPrec i 2 (concatD [doc (showString "<") , prt 0 patttuplecomps , doc (showString ">")])
+ PC pident patts -> prPrec i 1 (concatD [prt 0 pident , prt 0 patts])
+ PQC pident0 pident patts -> prPrec i 1 (concatD [prt 0 pident0 , doc (showString ".") , prt 0 pident , prt 0 patts])
+ PDisj patt0 patt -> prPrec i 0 (concatD [prt 0 patt0 , doc (showString "|") , prt 1 patt])
+ PSeq patt0 patt -> prPrec i 0 (concatD [prt 0 patt0 , doc (showString "+") , prt 1 patt])
+ PRep patt -> prPrec i 1 (concatD [prt 2 patt , doc (showString "*")])
+ PAs pident patt -> prPrec i 1 (concatD [prt 0 pident , doc (showString "@") , prt 2 patt])
+ PNeg patt -> prPrec i 1 (concatD [doc (showString "-") , prt 2 patt])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 2 x])
+ x:xs -> (concatD [prt 2 x , prt 0 xs])
+
+instance Print PattAss where
+ prt i e = case e of
+ PA pidents patt -> prPrec i 0 (concatD [prt 0 pidents , doc (showString "=") , prt 0 patt])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print Label where
+ prt i e = case e of
+ LIdent pident -> prPrec i 0 (concatD [prt 0 pident])
+ LVar n -> prPrec i 0 (concatD [doc (showString "$") , prt 0 n])
+
+
+instance Print Sort where
+ prt i e = case e of
+ Sort_Type -> prPrec i 0 (concatD [doc (showString "Type")])
+ Sort_PType -> prPrec i 0 (concatD [doc (showString "PType")])
+ Sort_Tok -> prPrec i 0 (concatD [doc (showString "Tok")])
+ Sort_Str -> prPrec i 0 (concatD [doc (showString "Str")])
+ Sort_Strs -> prPrec i 0 (concatD [doc (showString "Strs")])
+
+
+instance Print Bind where
+ prt i e = case e of
+ BIdent pident -> prPrec i 0 (concatD [prt 0 pident])
+ BWild -> prPrec i 0 (concatD [doc (showString "_")])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+
+instance Print Decl where
+ prt i e = case e of
+ DDec binds exp -> prPrec i 0 (concatD [doc (showString "(") , prt 0 binds , doc (showString ":") , prt 0 exp , doc (showString ")")])
+ DExp exp -> prPrec i 0 (concatD [prt 4 exp])
+
+
+instance Print TupleComp where
+ prt i e = case e of
+ TComp exp -> prPrec i 0 (concatD [prt 0 exp])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+
+instance Print PattTupleComp where
+ prt i e = case e of
+ PTComp patt -> prPrec i 0 (concatD [prt 0 patt])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+
+instance Print Case where
+ prt i e = case e of
+ Case patt exp -> prPrec i 0 (concatD [prt 0 patt , doc (showString "=>") , prt 0 exp])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print Equation where
+ prt i e = case e of
+ Equ patts exp -> prPrec i 0 (concatD [prt 0 patts , doc (showString "->") , prt 0 exp])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print Altern where
+ prt i e = case e of
+ Alt exp0 exp -> prPrec i 0 (concatD [prt 0 exp0 , doc (showString "/") , prt 0 exp])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+instance Print DDecl where
+ prt i e = case e of
+ DDDec binds exp -> prPrec i 0 (concatD [doc (showString "(") , prt 0 binds , doc (showString ":") , prt 0 exp , doc (showString ")")])
+ DDExp exp -> prPrec i 0 (concatD [prt 6 exp])
+
+ prtList es = case es of
+ [] -> (concatD [])
+ x:xs -> (concatD [prt 0 x , prt 0 xs])
+
+instance Print OldGrammar where
+ prt i e = case e of
+ OldGr include topdefs -> prPrec i 0 (concatD [prt 0 include , prt 0 topdefs])
+
+
+instance Print Include where
+ prt i e = case e of
+ NoIncl -> prPrec i 0 (concatD [])
+ Incl filenames -> prPrec i 0 (concatD [doc (showString "include") , prt 0 filenames])
+
+
+instance Print FileName where
+ prt i e = case e of
+ FString str -> prPrec i 0 (concatD [prt 0 str])
+ FIdent pident -> prPrec i 0 (concatD [prt 0 pident])
+ FSlash filename -> prPrec i 0 (concatD [doc (showString "/") , prt 0 filename])
+ FDot filename -> prPrec i 0 (concatD [doc (showString ".") , prt 0 filename])
+ FMinus filename -> prPrec i 0 (concatD [doc (showString "-") , prt 0 filename])
+ FAddId pident filename -> prPrec i 0 (concatD [prt 0 pident , prt 0 filename])
+
+ prtList es = case es of
+ [x] -> (concatD [prt 0 x , doc (showString ";")])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+
+
diff --git a/src-2.9/GF/Source/SkelGF.hs b/src-2.9/GF/Source/SkelGF.hs
new file mode 100644
index 000000000..3bd192f9d
--- /dev/null
+++ b/src-2.9/GF/Source/SkelGF.hs
@@ -0,0 +1,364 @@
+module GF.Source.SkelGF where
+
+-- Haskell module generated by the BNF converter
+
+import GF.Source.AbsGF
+import GF.Source.ErrM
+type Result = Err String
+
+failure :: Show a => a -> Result
+failure x = Bad $ "Undefined case: " ++ show x
+
+transLString :: LString -> Result
+transLString x = case x of
+ LString str -> failure x
+
+
+transPIdent :: PIdent -> Result
+transPIdent x = case x of
+ PIdent str -> failure x
+
+
+transGrammar :: Grammar -> Result
+transGrammar x = case x of
+ Gr moddefs -> failure x
+
+
+transModDef :: ModDef -> Result
+transModDef x = case x of
+ MMain pident0 pident concspecs -> failure x
+ MModule complmod modtype modbody -> failure x
+
+
+transConcSpec :: ConcSpec -> Result
+transConcSpec x = case x of
+ ConcSpec pident concexp -> failure x
+
+
+transConcExp :: ConcExp -> Result
+transConcExp x = case x of
+ ConcExp pident transfers -> failure x
+
+
+transTransfer :: Transfer -> Result
+transTransfer x = case x of
+ TransferIn open -> failure x
+ TransferOut open -> failure x
+
+
+transModType :: ModType -> Result
+transModType x = case x of
+ MTAbstract pident -> failure x
+ MTResource pident -> failure x
+ MTInterface pident -> failure x
+ MTConcrete pident0 pident -> failure x
+ MTInstance pident0 pident -> failure x
+ MTTransfer pident open0 open -> failure x
+
+
+transModBody :: ModBody -> Result
+transModBody x = case x of
+ MBody extend opens topdefs -> failure x
+ MNoBody includeds -> failure x
+ MWith included opens -> failure x
+ MWithBody included opens0 opens topdefs -> failure x
+ MWithE includeds included opens -> failure x
+ MWithEBody includeds included opens0 opens topdefs -> failure x
+ MReuse pident -> failure x
+ MUnion includeds -> failure x
+
+
+transExtend :: Extend -> Result
+transExtend x = case x of
+ Ext includeds -> failure x
+ NoExt -> failure x
+
+
+transOpens :: Opens -> Result
+transOpens x = case x of
+ NoOpens -> failure x
+ OpenIn opens -> failure x
+
+
+transOpen :: Open -> Result
+transOpen x = case x of
+ OName pident -> failure x
+ OQualQO qualopen pident -> failure x
+ OQual qualopen pident0 pident -> failure x
+
+
+transComplMod :: ComplMod -> Result
+transComplMod x = case x of
+ CMCompl -> failure x
+ CMIncompl -> failure x
+
+
+transQualOpen :: QualOpen -> Result
+transQualOpen x = case x of
+ QOCompl -> failure x
+ QOIncompl -> failure x
+ QOInterface -> failure x
+
+
+transIncluded :: Included -> Result
+transIncluded x = case x of
+ IAll pident -> failure x
+ ISome pident pidents -> failure x
+ IMinus pident pidents -> failure x
+
+
+transDef :: Def -> Result
+transDef x = case x of
+ DDecl names exp -> failure x
+ DDef names exp -> failure x
+ DPatt name patts exp -> failure x
+ DFull names exp0 exp -> failure x
+
+
+transTopDef :: TopDef -> Result
+transTopDef x = case x of
+ DefCat catdefs -> failure x
+ DefFun fundefs -> failure x
+ DefFunData fundefs -> failure x
+ DefDef defs -> failure x
+ DefData datadefs -> failure x
+ DefTrans defs -> failure x
+ DefPar pardefs -> failure x
+ DefOper defs -> failure x
+ DefLincat printdefs -> failure x
+ DefLindef defs -> failure x
+ DefLin defs -> failure x
+ DefPrintCat printdefs -> failure x
+ DefPrintFun printdefs -> failure x
+ DefFlag flagdefs -> failure x
+ DefPrintOld printdefs -> failure x
+ DefLintype defs -> failure x
+ DefPattern defs -> failure x
+ DefPackage pident topdefs -> failure x
+ DefVars defs -> failure x
+ DefTokenizer pident -> failure x
+
+
+transCatDef :: CatDef -> Result
+transCatDef x = case x of
+ SimpleCatDef pident ddecls -> failure x
+ ListCatDef pident ddecls -> failure x
+ ListSizeCatDef pident ddecls n -> failure x
+
+
+transFunDef :: FunDef -> Result
+transFunDef x = case x of
+ FunDef pidents exp -> failure x
+
+
+transDataDef :: DataDef -> Result
+transDataDef x = case x of
+ DataDef pident dataconstrs -> failure x
+
+
+transDataConstr :: DataConstr -> Result
+transDataConstr x = case x of
+ DataId pident -> failure x
+ DataQId pident0 pident -> failure x
+
+
+transParDef :: ParDef -> Result
+transParDef x = case x of
+ ParDefDir pident parconstrs -> failure x
+ ParDefIndir pident0 pident -> failure x
+ ParDefAbs pident -> failure x
+
+
+transParConstr :: ParConstr -> Result
+transParConstr x = case x of
+ ParConstr pident ddecls -> failure x
+
+
+transPrintDef :: PrintDef -> Result
+transPrintDef x = case x of
+ PrintDef names exp -> failure x
+
+
+transFlagDef :: FlagDef -> Result
+transFlagDef x = case x of
+ FlagDef pident0 pident -> failure x
+
+
+transName :: Name -> Result
+transName x = case x of
+ IdentName pident -> failure x
+ ListName pident -> failure x
+
+
+transLocDef :: LocDef -> Result
+transLocDef x = case x of
+ LDDecl pidents exp -> failure x
+ LDDef pidents exp -> failure x
+ LDFull pidents exp0 exp -> failure x
+
+
+transExp :: Exp -> Result
+transExp x = case x of
+ EIdent pident -> failure x
+ EConstr pident -> failure x
+ ECons pident -> failure x
+ ESort sort -> failure x
+ EString str -> failure x
+ EInt n -> failure x
+ EFloat d -> failure x
+ EMeta -> failure x
+ EEmpty -> failure x
+ EData -> failure x
+ EList pident exps -> failure x
+ EStrings str -> failure x
+ ERecord locdefs -> failure x
+ ETuple tuplecomps -> failure x
+ EIndir pident -> failure x
+ ETyped exp0 exp -> failure x
+ EProj exp label -> failure x
+ EQConstr pident0 pident -> failure x
+ EQCons pident0 pident -> failure x
+ EApp exp0 exp -> failure x
+ ETable cases -> failure x
+ ETTable exp cases -> failure x
+ EVTable exp exps -> failure x
+ ECase exp cases -> failure x
+ EVariants exps -> failure x
+ EPre exp alterns -> failure x
+ EStrs exps -> failure x
+ EConAt pident exp -> failure x
+ EPatt patt -> failure x
+ EPattType exp -> failure x
+ ESelect exp0 exp -> failure x
+ ETupTyp exp0 exp -> failure x
+ EExtend exp0 exp -> failure x
+ EGlue exp0 exp -> failure x
+ EConcat exp0 exp -> failure x
+ EAbstr binds exp -> failure x
+ ECTable binds exp -> failure x
+ EProd decl exp -> failure x
+ ETType exp0 exp -> failure x
+ ELet locdefs exp -> failure x
+ ELetb locdefs exp -> failure x
+ EWhere exp locdefs -> failure x
+ EEqs equations -> failure x
+ EExample exp str -> failure x
+ ELString lstring -> failure x
+ ELin pident -> failure x
+
+
+transExps :: Exps -> Result
+transExps x = case x of
+ NilExp -> failure x
+ ConsExp exp exps -> failure x
+
+
+transPatt :: Patt -> Result
+transPatt x = case x of
+ PChar -> failure x
+ PChars str -> failure x
+ PMacro pident -> failure x
+ PM pident0 pident -> failure x
+ PW -> failure x
+ PV pident -> failure x
+ PCon pident -> failure x
+ PQ pident0 pident -> failure x
+ PInt n -> failure x
+ PFloat d -> failure x
+ PStr str -> failure x
+ PR pattasss -> failure x
+ PTup patttuplecomps -> failure x
+ PC pident patts -> failure x
+ PQC pident0 pident patts -> failure x
+ PDisj patt0 patt -> failure x
+ PSeq patt0 patt -> failure x
+ PRep patt -> failure x
+ PAs pident patt -> failure x
+ PNeg patt -> failure x
+
+
+transPattAss :: PattAss -> Result
+transPattAss x = case x of
+ PA pidents patt -> failure x
+
+
+transLabel :: Label -> Result
+transLabel x = case x of
+ LIdent pident -> failure x
+ LVar n -> failure x
+
+
+transSort :: Sort -> Result
+transSort x = case x of
+ Sort_Type -> failure x
+ Sort_PType -> failure x
+ Sort_Tok -> failure x
+ Sort_Str -> failure x
+ Sort_Strs -> failure x
+
+
+transBind :: Bind -> Result
+transBind x = case x of
+ BIdent pident -> failure x
+ BWild -> failure x
+
+
+transDecl :: Decl -> Result
+transDecl x = case x of
+ DDec binds exp -> failure x
+ DExp exp -> failure x
+
+
+transTupleComp :: TupleComp -> Result
+transTupleComp x = case x of
+ TComp exp -> failure x
+
+
+transPattTupleComp :: PattTupleComp -> Result
+transPattTupleComp x = case x of
+ PTComp patt -> failure x
+
+
+transCase :: Case -> Result
+transCase x = case x of
+ Case patt exp -> failure x
+
+
+transEquation :: Equation -> Result
+transEquation x = case x of
+ Equ patts exp -> failure x
+
+
+transAltern :: Altern -> Result
+transAltern x = case x of
+ Alt exp0 exp -> failure x
+
+
+transDDecl :: DDecl -> Result
+transDDecl x = case x of
+ DDDec binds exp -> failure x
+ DDExp exp -> failure x
+
+
+transOldGrammar :: OldGrammar -> Result
+transOldGrammar x = case x of
+ OldGr include topdefs -> failure x
+
+
+transInclude :: Include -> Result
+transInclude x = case x of
+ NoIncl -> failure x
+ Incl filenames -> failure x
+
+
+transFileName :: FileName -> Result
+transFileName x = case x of
+ FString str -> failure x
+ FIdent pident -> failure x
+ FSlash filename -> failure x
+ FDot filename -> failure x
+ FMinus filename -> failure x
+ FAddId pident filename -> failure x
+
+
+
diff --git a/src-2.9/GF/Source/SourceToGrammar.hs b/src-2.9/GF/Source/SourceToGrammar.hs
new file mode 100644
index 000000000..132bd4704
--- /dev/null
+++ b/src-2.9/GF/Source/SourceToGrammar.hs
@@ -0,0 +1,755 @@
+----------------------------------------------------------------------
+-- |
+-- Module : SourceToGrammar
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/10/04 11:05:07 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.28 $
+--
+-- based on the skeleton Haskell module generated by the BNF converter
+-----------------------------------------------------------------------------
+
+module GF.Source.SourceToGrammar ( transGrammar,
+ transInclude,
+ transModDef,
+ transOldGrammar,
+ transExp,
+ newReservedWords
+ ) where
+
+import qualified GF.Grammar.Grammar as G
+import qualified GF.Grammar.PrGrammar as GP
+import qualified GF.Infra.Modules as GM
+import qualified GF.Grammar.Macros as M
+import qualified GF.Compile.Update as U
+import qualified GF.Infra.Option as GO
+import qualified GF.Compile.ModDeps as GD
+import GF.Infra.Ident
+import GF.Source.AbsGF
+import GF.Source.PrintGF
+import GF.Compile.RemoveLiT --- for bw compat
+import GF.Data.Operations
+import GF.Infra.Option
+
+import Control.Monad
+import Data.Char
+import Data.List (genericReplicate)
+
+-- based on the skeleton Haskell module generated by the BNF converter
+
+type Result = Err String
+
+failure :: Show a => a -> Err b
+failure x = Bad $ "Undefined case: " ++ show x
+
+prPIdent :: PIdent -> String
+prPIdent (PIdent (_,c)) = c
+
+getIdentPos :: PIdent -> Err (Ident,Int)
+getIdentPos x = case x of
+ PIdent ((line,_),c) -> return (IC c,line)
+
+transIdent :: PIdent -> Err Ident
+transIdent = liftM fst . getIdentPos
+
+transName :: Name -> Err Ident
+transName n = case n of
+ IdentName i -> transIdent i
+ ListName i -> liftM mkListId (transIdent i)
+
+transGrammar :: Grammar -> Err G.SourceGrammar
+transGrammar x = case x of
+ Gr moddefs -> do
+ moddefs' <- mapM transModDef moddefs
+ GD.mkSourceGrammar moddefs'
+
+transModDef :: ModDef -> Err (Ident, G.SourceModInfo)
+transModDef x = case x of
+
+ MMain id0 id concspecs -> do
+ id0' <- transIdent id0
+ id' <- transIdent id
+ concspecs' <- mapM transConcSpec concspecs
+ return $ (id0', GM.ModMainGrammar (GM.MainGrammar id' concspecs'))
+
+ MModule compl mtyp body -> do
+
+ let mstat' = transComplMod compl
+
+ (trDef, mtyp', id') <- case mtyp of
+ MTAbstract id -> do
+ id' <- transIdent id
+ return (transAbsDef, GM.MTAbstract, id')
+ MTResource id -> mkModRes id GM.MTResource body
+ MTConcrete id open -> do
+ id' <- transIdent id
+ open' <- transIdent open
+ return (transCncDef, GM.MTConcrete open', id')
+ MTTransfer id a b -> do
+ id' <- transIdent id
+ a' <- transOpen a
+ b' <- transOpen a
+ return (transAbsDef, GM.MTTransfer a' b', id')
+ MTInterface id -> mkModRes id GM.MTInterface body
+ MTInstance id open -> do
+ open' <- transIdent open
+ mkModRes id (GM.MTInstance open') body
+
+ mkBody (mstat', trDef, mtyp', id') body
+ where
+ mkBody xx@(mstat', trDef, mtyp', id') bod = case bod of
+ MNoBody incls -> do
+ mkBody xx $ MBody (Ext incls) NoOpens []
+ MBody extends opens defs -> do
+ extends' <- transExtend extends
+ opens' <- transOpens opens
+ defs0 <- mapM trDef $ getTopDefs defs
+ defs' <- U.buildAnyTree [d | Left ds <- defs0, d <- ds]
+ flags' <- return [f | Right fs <- defs0, f <- fs]
+ return (id',GM.ModMod (GM.Module mtyp' mstat' flags' extends' opens' defs'))
+ MReuse _ -> do
+ return (id', GM.ModMod (GM.Module mtyp' mstat' [] [] [] emptyBinTree))
+ MUnion imps -> do
+ imps' <- mapM transIncluded imps
+ return (id',
+ GM.ModMod (GM.Module (GM.MTUnion mtyp' imps') mstat' [] [] [] emptyBinTree))
+
+ MWith m insts -> mkBody xx $ MWithEBody [] m insts NoOpens []
+ MWithBody m insts opens defs -> mkBody xx $ MWithEBody [] m insts opens defs
+ MWithE extends m insts -> mkBody xx $ MWithEBody extends m insts NoOpens []
+ MWithEBody extends m insts opens defs -> do
+ extends' <- mapM transIncludedExt extends
+ m' <- transIncludedExt m
+ insts' <- mapM transOpen insts
+ opens' <- transOpens opens
+ defs0 <- mapM trDef $ getTopDefs defs
+ defs' <- U.buildAnyTree [d | Left ds <- defs0, d <- ds]
+ flags' <- return [f | Right fs <- defs0, f <- fs]
+ return (id',
+ GM.ModWith (GM.Module mtyp' mstat' flags' extends' opens' defs') m' insts')
+
+ mkModRes id mtyp body = do
+ id' <- transIdent id
+ case body of
+ MReuse c -> do
+ c' <- transIdent c
+ mtyp' <- trMReuseType mtyp c'
+ return (transResDef, GM.MTReuse mtyp', id')
+ _ -> return (transResDef, mtyp, id')
+ trMReuseType mtyp c = case mtyp of
+ GM.MTInterface -> return $ GM.MRInterface c
+ GM.MTInstance op -> return $ GM.MRInstance c op
+ GM.MTResource -> return $ GM.MRResource c
+
+
+transComplMod :: ComplMod -> GM.ModuleStatus
+transComplMod x = case x of
+ CMCompl -> GM.MSComplete
+ CMIncompl -> GM.MSIncomplete
+
+getTopDefs :: [TopDef] -> [TopDef]
+getTopDefs x = x
+
+transConcSpec :: ConcSpec -> Err (GM.MainConcreteSpec Ident)
+transConcSpec x = case x of
+ ConcSpec id concexp -> do
+ id' <- transIdent id
+ (m,mi,mo) <- transConcExp concexp
+ return $ GM.MainConcreteSpec id' m mi mo
+
+transConcExp :: ConcExp ->
+ Err (Ident, Maybe (GM.OpenSpec Ident),Maybe (GM.OpenSpec Ident))
+transConcExp x = case x of
+ ConcExp id transfers -> do
+ id' <- transIdent id
+ trs <- mapM transTransfer transfers
+ tin <- case [o | Left o <- trs] of
+ [o] -> return $ Just o
+ [] -> return $ Nothing
+ _ -> Bad "ambiguous transfer in"
+ tout <- case [o | Right o <- trs] of
+ [o] -> return $ Just o
+ [] -> return $ Nothing
+ _ -> Bad "ambiguous transfer out"
+ return (id',tin,tout)
+
+transTransfer :: Transfer ->
+ Err (Either (GM.OpenSpec Ident)(GM.OpenSpec Ident))
+transTransfer x = case x of
+ TransferIn open -> liftM Left $ transOpen open
+ TransferOut open -> liftM Right $ transOpen open
+
+transExtend :: Extend -> Err [(Ident,GM.MInclude Ident)]
+transExtend x = case x of
+ Ext ids -> mapM transIncludedExt ids
+ NoExt -> return []
+
+transOpens :: Opens -> Err [GM.OpenSpec Ident]
+transOpens x = case x of
+ NoOpens -> return []
+ OpenIn opens -> mapM transOpen opens
+
+transOpen :: Open -> Err (GM.OpenSpec Ident)
+transOpen x = case x of
+ OName id -> liftM (GM.OSimple GM.OQNormal) $ transIdent id
+ OQualQO q id -> liftM2 GM.OSimple (transQualOpen q) (transIdent id)
+ OQual q id m -> liftM3 GM.OQualif (transQualOpen q) (transIdent id) (transIdent m)
+
+transQualOpen :: QualOpen -> Err GM.OpenQualif
+transQualOpen x = case x of
+ QOCompl -> return GM.OQNormal
+ QOInterface -> return GM.OQInterface
+ QOIncompl -> return GM.OQIncomplete
+
+transIncluded :: Included -> Err (Ident,[Ident])
+transIncluded x = case x of
+ IAll i -> liftM (flip (curry id) []) $ transIdent i
+ ISome i ids -> liftM2 (curry id) (transIdent i) (mapM transIdent ids)
+ IMinus i ids -> liftM2 (curry id) (transIdent i) (mapM transIdent ids) ----
+
+transIncludedExt :: Included -> Err (Ident, GM.MInclude Ident)
+transIncludedExt x = case x of
+ IAll i -> liftM2 (,) (transIdent i) (return GM.MIAll)
+ ISome i ids -> liftM2 (,) (transIdent i) (liftM GM.MIOnly $ mapM transIdent ids)
+ IMinus i ids -> liftM2 (,) (transIdent i) (liftM GM.MIExcept $ mapM transIdent ids)
+
+transAbsDef :: TopDef -> Err (Either [(Ident, G.Info)] [GO.Option])
+transAbsDef x = case x of
+ DefCat catdefs -> liftM (Left . concat) $ mapM transCatDef catdefs
+ DefFun fundefs -> do
+ fundefs' <- mapM transFunDef fundefs
+ returnl [(fun, G.AbsFun (yes typ) nope) | (funs,typ) <- fundefs', fun <- funs]
+ DefFunData fundefs -> do
+ fundefs' <- mapM transFunDef fundefs
+ returnl $
+ [(cat, G.AbsCat nope (yes [M.cn fun])) | (funs,typ) <- fundefs',
+ fun <- funs,
+ Ok (_,cat) <- [M.valCat typ]
+ ] ++
+ [(fun, G.AbsFun (yes typ) (yes G.EData)) | (funs,typ) <- fundefs', fun <- funs]
+ DefDef defs -> do
+ defs' <- liftM concat $ mapM getDefsGen defs
+ returnl [(c, G.AbsFun nope pe) | (c,(_,pe)) <- defs']
+ DefData ds -> do
+ ds' <- mapM transDataDef ds
+ returnl $
+ [(c, G.AbsCat nope (yes ps)) | (c,ps) <- ds'] ++
+ [(f, G.AbsFun nope (yes G.EData)) | (_,fs) <- ds', tf <- fs, f <- funs tf]
+ DefTrans defs -> do
+ defs' <- liftM concat $ mapM getDefsGen defs
+ returnl [(c, G.AbsTrans f) | (c,(_,Yes f)) <- defs']
+ DefFlag defs -> liftM Right $ mapM transFlagDef defs
+ _ -> Bad $ "illegal definition in abstract module:" ++++ printTree x
+ where
+ -- to get data constructors as terms
+ funs t = case t of
+ G.Cn f -> [f]
+ G.Q _ f -> [f]
+ G.QC _ f -> [f]
+ _ -> []
+
+returnl :: a -> Err (Either a b)
+returnl = return . Left
+
+transFlagDef :: FlagDef -> Err GO.Option
+transFlagDef x = case x of
+ FlagDef f x -> return $ GO.Opt (prPIdent f,[prPIdent x])
+
+-- | Cat definitions can also return some fun defs
+-- if it is a list category definition
+transCatDef :: CatDef -> Err [(Ident, G.Info)]
+transCatDef x = case x of
+ SimpleCatDef id ddecls -> do
+ id' <- transIdent id
+ liftM (:[]) $ cat id' ddecls
+ ListCatDef id ddecls -> listCat id ddecls 0
+ ListSizeCatDef id ddecls size -> listCat id ddecls size
+ where
+ cat i ddecls = do
+ -- i <- transIdent id
+ cont <- liftM concat $ mapM transDDecl ddecls
+ return (i, G.AbsCat (yes cont) nope)
+ listCat id ddecls size = do
+ id' <- transIdent id
+ let
+ li = mkListId id'
+ baseId = mkBaseId id'
+ consId = mkConsId id'
+ catd0@(c,G.AbsCat (Yes cont0) _) <- cat li ddecls
+ let
+ catd = (c,G.AbsCat (Yes cont0) (Yes [M.cn baseId,M.cn consId]))
+ cont = [(mkId x i,ty) | (i,(x,ty)) <- zip [0..] cont0]
+ xs = map (G.Vr . fst) cont
+ cd = M.mkDecl (M.mkApp (G.Vr id') xs)
+ lc = M.mkApp (G.Vr li) xs
+ niltyp = M.mkProdSimple (cont ++ genericReplicate size cd) lc
+ nilfund = (baseId, G.AbsFun (yes niltyp) (yes G.EData))
+ constyp = M.mkProdSimple (cont ++ [cd, M.mkDecl lc]) lc
+ consfund = (consId, G.AbsFun (yes constyp) (yes G.EData))
+ return [catd,nilfund,consfund]
+ mkId x i = if isWildIdent x then (mkIdent "x" i) else x
+
+transFunDef :: FunDef -> Err ([Ident], G.Type)
+transFunDef x = case x of
+ FunDef ids typ -> liftM2 (,) (mapM transIdent ids) (transExp typ)
+
+transDataDef :: DataDef -> Err (Ident,[G.Term])
+transDataDef x = case x of
+ DataDef id ds -> liftM2 (,) (transIdent id) (mapM transData ds)
+ where
+ transData d = case d of
+ DataId id -> liftM G.Cn $ transIdent id
+ DataQId id0 id -> liftM2 G.QC (transIdent id0) (transIdent id)
+
+transResDef :: TopDef -> Err (Either [(Ident, G.Info)] [GO.Option])
+transResDef x = case x of
+ DefPar pardefs -> do
+ pardefs' <- mapM transParDef pardefs
+ returnl $ [(p, G.ResParam (if null pars
+ then nope -- abstract param type
+ else (yes (pars,Nothing))))
+ | (p,pars) <- pardefs']
+ ++ [(f, G.ResValue (yes (M.mkProdSimple co (G.Cn p),Nothing))) |
+ (p,pars) <- pardefs', (f,co) <- pars]
+
+{-
+ ---- encoding of AnyInd without changing syntax. AR 20/9/2007
+ DefOper [DDef [c] (EApp (EInt status) (EIdent mo))] -> do
+ c' <- transName c
+ mo' <- transIdent mo
+ return $ Left [(c',G.AnyInd (status==1) mo')]
+-}
+ DefOper defs -> do
+ defs' <- liftM concat $ mapM getDefs defs
+ returnl $ concatMap mkOverload [(f, G.ResOper pt pe) | (f,(pt,pe)) <- defs']
+
+ DefLintype defs -> do
+ defs' <- liftM concat $ mapM getDefs defs
+ returnl [(f, G.ResOper pt pe) | (f,(pt,pe)) <- defs']
+
+ DefFlag defs -> liftM Right $ mapM transFlagDef defs
+ _ -> Bad $ "illegal definition form in resource" +++ printTree x
+ where
+ mkOverload (c,j) = case j of
+ G.ResOper _ (Yes (G.App keyw (G.R fs@(_:_:_)))) |
+ isOverloading keyw c fs ->
+ [(c,G.ResOverload [(ty,fu) | (_,(Just ty,fu)) <- fs])]
+
+ -- to enable separare type signature --- not type-checked
+ G.ResOper (Yes (G.App keyw (G.RecType fs@(_:_:_)))) _ |
+ isOverloading keyw c fs -> []
+ _ -> [(c,j)]
+ isOverloading keyw c fs =
+ GP.prt keyw == "overload" && -- overload is a "soft keyword"
+ all (== GP.prt c) (map (GP.prt . fst) fs)
+
+transParDef :: ParDef -> Err (Ident, [G.Param])
+transParDef x = case x of
+ ParDefDir id params -> liftM2 (,) (transIdent id) (mapM transParConstr params)
+ ParDefAbs id -> liftM2 (,) (transIdent id) (return [])
+ _ -> Bad $ "illegal definition in resource:" ++++ printTree x
+
+transCncDef :: TopDef -> Err (Either [(Ident, G.Info)] [GO.Option])
+transCncDef x = case x of
+ DefLincat defs -> do
+ defs' <- liftM concat $ mapM transPrintDef defs
+ returnl [(f, G.CncCat (yes t) nope nope) | (f,t) <- defs']
+ DefLindef defs -> do
+ defs' <- liftM concat $ mapM getDefs defs
+ returnl [(f, G.CncCat pt pe nope) | (f,(pt,pe)) <- defs']
+ DefLin defs -> do
+ defs' <- liftM concat $ mapM getDefs defs
+ returnl [(f, G.CncFun Nothing pe nope) | (f,(_,pe)) <- defs']
+ DefPrintCat defs -> do
+ defs' <- liftM concat $ mapM transPrintDef defs
+ returnl [(f, G.CncCat nope nope (yes e)) | (f,e) <- defs']
+ DefPrintFun defs -> do
+ defs' <- liftM concat $ mapM transPrintDef defs
+ returnl [(f, G.CncFun Nothing nope (yes e)) | (f,e) <- defs']
+ DefPrintOld defs -> do --- a guess, for backward compatibility
+ defs' <- liftM concat $ mapM transPrintDef defs
+ returnl [(f, G.CncFun Nothing nope (yes e)) | (f,e) <- defs']
+ DefFlag defs -> liftM Right $ mapM transFlagDef defs
+ DefPattern defs -> do
+ defs' <- liftM concat $ mapM getDefs defs
+ let defs2 = [(f, termInPattern t) | (f,(_,Yes t)) <- defs']
+ returnl [(f, G.CncFun Nothing (yes t) nope) | (f,t) <- defs2]
+
+ _ -> errIn ("illegal definition in concrete syntax:") $ transResDef x
+
+transPrintDef :: PrintDef -> Err [(Ident,G.Term)]
+transPrintDef x = case x of
+ PrintDef ids exp -> do
+ (ids,e) <- liftM2 (,) (mapM transName ids) (transExp exp)
+ return $ [(i,e) | i <- ids]
+
+getDefsGen :: Def -> Err [(Ident, (G.Perh G.Type, G.Perh G.Term))]
+getDefsGen d = case d of
+ DDecl ids t -> do
+ ids' <- mapM transName ids
+ t' <- transExp t
+ return [(i,(yes t', nope)) | i <- ids']
+ DDef ids e -> do
+ ids' <- mapM transName ids
+ e' <- transExp e
+ return [(i,(nope, yes e')) | i <- ids']
+ DFull ids t e -> do
+ ids' <- mapM transName ids
+ t' <- transExp t
+ e' <- transExp e
+ return [(i,(yes t', yes e')) | i <- ids']
+ DPatt id patts e -> do
+ id' <- transName id
+ ps' <- mapM transPatt patts
+ e' <- transExp e
+ return [(id',(nope, yes (G.Eqs [(ps',e')])))]
+
+-- | sometimes you need this special case, e.g. in linearization rules
+getDefs :: Def -> Err [(Ident, (G.Perh G.Type, G.Perh G.Term))]
+getDefs d = case d of
+ DPatt id patts e -> do
+ id' <- transName id
+ xs <- mapM tryMakeVar patts
+ e' <- transExp e
+ return [(id',(nope, yes (M.mkAbs xs e')))]
+ _ -> getDefsGen d
+
+-- | accepts a pattern that is either a variable or a wild card
+tryMakeVar :: Patt -> Err Ident
+tryMakeVar p = do
+ p' <- transPatt p
+ case p' of
+ G.PV i -> return i
+ G.PW -> return identW
+ _ -> Bad $ "not a legal pattern in lambda binding" +++ GP.prt p'
+
+transExp :: Exp -> Err G.Term
+transExp x = case x of
+ EIdent id -> liftM G.Vr $ transIdent id
+ EConstr id -> liftM G.Con $ transIdent id
+ ECons id -> liftM G.Cn $ transIdent id
+ EQConstr m c -> liftM2 G.QC (transIdent m) (transIdent c)
+ EQCons m c -> liftM2 G.Q (transIdent m) (transIdent c)
+ EString str -> return $ G.K str
+ ESort sort -> liftM G.Sort $ transSort sort
+ EInt n -> return $ G.EInt n
+ EFloat n -> return $ G.EFloat n
+ EMeta -> return $ M.meta $ M.int2meta 0
+ EEmpty -> return G.Empty
+ -- [ C x_1 ... x_n ] becomes (ListC x_1 ... x_n)
+ EList i es -> do
+ i' <- transIdent i
+ es' <- mapM transExp (exps2list es)
+ return $ foldl G.App (G.Vr (mkListId i')) es'
+ EStrings [] -> return G.Empty
+ EStrings str -> return $ foldr1 G.C $ map G.K $ words str
+ ERecord defs -> erecord2term defs
+ ETupTyp _ _ -> do
+ let tups t = case t of
+ ETupTyp x y -> tups x ++ [y] -- right-associative parsing
+ _ -> [t]
+ es <- mapM transExp $ tups x
+ return $ G.RecType $ M.tuple2recordType es
+ ETuple tuplecomps -> do
+ es <- mapM transExp [e | TComp e <- tuplecomps]
+ return $ G.R $ M.tuple2record es
+ EProj exp id -> liftM2 G.P (transExp exp) (trLabel id)
+ EApp exp0 exp -> liftM2 G.App (transExp exp0) (transExp exp)
+ ETable cases -> liftM (G.T G.TRaw) (transCases cases)
+ ETTable exp cases ->
+ liftM2 (\t c -> G.T (G.TTyped t) c) (transExp exp) (transCases cases)
+ EVTable exp cases ->
+ liftM2 (\t c -> G.V t c) (transExp exp) (mapM transExp cases)
+ ECase exp cases -> do
+ exp' <- transExp exp
+ cases' <- transCases cases
+ let annot = case exp' of
+ G.Typed _ t -> G.TTyped t
+ _ -> G.TRaw
+ return $ G.S (G.T annot cases') exp'
+ ECTable binds exp -> liftM2 M.mkCTable (mapM transBind binds) (transExp exp)
+
+ EVariants exps -> liftM G.FV $ mapM transExp exps
+ EPre exp alts -> liftM2 (curry G.Alts) (transExp exp) (mapM transAltern alts)
+ EStrs exps -> liftM G.Strs $ mapM transExp exps
+ ESelect exp0 exp -> liftM2 G.S (transExp exp0) (transExp exp)
+ EExtend exp0 exp -> liftM2 G.ExtR (transExp exp0) (transExp exp)
+ EAbstr binds exp -> liftM2 M.mkAbs (mapM transBind binds) (transExp exp)
+ ETyped exp0 exp -> liftM2 G.Typed (transExp exp0) (transExp exp)
+ EExample exp str -> liftM2 G.Example (transExp exp) (return str)
+
+ EProd decl exp -> liftM2 M.mkProdSimple (transDecl decl) (transExp exp)
+ ETType exp0 exp -> liftM2 G.Table (transExp exp0) (transExp exp)
+ EConcat exp0 exp -> liftM2 G.C (transExp exp0) (transExp exp)
+ EGlue exp0 exp -> liftM2 G.Glue (transExp exp0) (transExp exp)
+ ELet defs exp -> do
+ exp' <- transExp exp
+ defs0 <- mapM locdef2fields defs
+ defs' <- mapM tryLoc $ concat defs0
+ return $ M.mkLet defs' exp'
+ where
+ tryLoc (c,(mty,Just e)) = return (c,(mty,e))
+ tryLoc (c,_) = Bad $ "local definition of" +++ GP.prt c +++ "without value"
+ ELetb defs exp -> transExp $ ELet defs exp
+ EWhere exp defs -> transExp $ ELet defs exp
+
+ EPattType typ -> liftM G.EPattType (transExp typ)
+ EPatt patt -> liftM G.EPatt (transPatt patt)
+
+ ELString (LString str) -> return $ G.K str
+ ELin id -> liftM G.LiT $ transIdent id
+
+ EEqs eqs -> liftM G.Eqs $ mapM transEquation eqs
+
+ _ -> Bad $ "translation not yet defined for" +++ printTree x ----
+
+exps2list :: Exps -> [Exp]
+exps2list NilExp = []
+exps2list (ConsExp e es) = e : exps2list es
+
+--- this is complicated: should we change Exp or G.Term ?
+
+erecord2term :: [LocDef] -> Err G.Term
+erecord2term ds = do
+ ds' <- mapM locdef2fields ds
+ mkR $ concat ds'
+ where
+ mkR fs = do
+ fs' <- transF fs
+ return $ case fs' of
+ Left ts -> G.RecType ts
+ Right ds -> G.R ds
+ transF [] = return $ Left [] --- empty record always interpreted as record type
+ transF fs@(f:_) = case f of
+ (lab,(Just ty,Nothing)) -> mapM tryRT fs >>= return . Left
+ _ -> mapM tryR fs >>= return . Right
+ tryRT f = case f of
+ (lab,(Just ty,Nothing)) -> return (M.ident2label lab,ty)
+ _ -> Bad $ "illegal record type field" +++ GP.prt (fst f) --- manifest fields ?!
+ tryR f = case f of
+ (lab,(mty, Just t)) -> return (M.ident2label lab,(mty,t))
+ _ -> Bad $ "illegal record field" +++ GP.prt (fst f)
+
+
+locdef2fields :: LocDef -> Err [(Ident, (Maybe G.Type, Maybe G.Type))]
+locdef2fields d = case d of
+ LDDecl ids t -> do
+ labs <- mapM transIdent ids
+ t' <- transExp t
+ return [(lab,(Just t',Nothing)) | lab <- labs]
+ LDDef ids e -> do
+ labs <- mapM transIdent ids
+ e' <- transExp e
+ return [(lab,(Nothing, Just e')) | lab <- labs]
+ LDFull ids t e -> do
+ labs <- mapM transIdent ids
+ t' <- transExp t
+ e' <- transExp e
+ return [(lab,(Just t', Just e')) | lab <- labs]
+
+trLabel :: Label -> Err G.Label
+trLabel x = case x of
+
+ -- this case is for bward compatibility and should be removed
+ LIdent (PIdent (_,'v':ds@(_:_))) | all isDigit ds -> return $ G.LVar $ readIntArg ds
+
+ LIdent (PIdent (_, s)) -> return $ G.LIdent s
+ LVar x -> return $ G.LVar $ fromInteger x
+
+transSort :: Sort -> Err String
+transSort x = case x of
+ _ -> return $ printTree x
+
+{-
+--- no more used 7/1/2006 AR
+transPatts :: Patt -> Err [G.Patt]
+transPatts p = case p of
+ PDisj p1 p2 -> liftM2 (++) (transPatts p1) (transPatts p2)
+ PC id patts -> liftM (map (G.PC id) . combinations) $ mapM transPatts patts
+ PQC q id patts -> liftM (map (G.PP q id) . combinations) (mapM transPatts patts)
+
+ PR pattasss -> do
+ let (lss,ps) = unzip [(ls,p) | PA ls p <- pattasss]
+ ls = map LIdent $ concat lss
+ ps0 <- mapM transPatts ps
+ let ps' = combinations ps0
+ lss' <- mapM trLabel ls
+ let rss = map (zip lss') ps'
+ return $ map G.PR rss
+ PTup pcs -> do
+ ps0 <- mapM transPatts [e | PTComp e <- pcs]
+ let ps' = combinations ps0
+ return $ map (G.PR . M.tuple2recordPatt) ps'
+ _ -> liftM singleton $ transPatt p
+-}
+
+transPatt :: Patt -> Err G.Patt
+transPatt x = case x of
+ PW -> return G.wildPatt
+ PV id -> liftM G.PV $ transIdent id
+ PC id patts -> liftM2 G.PC (transIdent id) (mapM transPatt patts)
+ PCon id -> liftM2 G.PC (transIdent id) (return [])
+ PInt n -> return $ G.PInt n
+ PFloat n -> return $ G.PFloat n
+ PStr str -> return $ G.PString str
+ PR pattasss -> do
+ let (lss,ps) = unzip [(ls,p) | PA ls p <- pattasss]
+ ls = map LIdent $ concat lss
+ liftM G.PR $ liftM2 zip (mapM trLabel ls) (mapM transPatt ps)
+ PTup pcs ->
+ liftM (G.PR . M.tuple2recordPatt) (mapM transPatt [e | PTComp e <- pcs])
+ PQ id0 id -> liftM3 G.PP (transIdent id0) (transIdent id) (return [])
+ PQC id0 id patts ->
+ liftM3 G.PP (transIdent id0) (transIdent id) (mapM transPatt patts)
+ PDisj p1 p2 -> liftM2 G.PAlt (transPatt p1) (transPatt p2)
+ PSeq p1 p2 -> liftM2 G.PSeq (transPatt p1) (transPatt p2)
+ PRep p -> liftM G.PRep (transPatt p)
+ PNeg p -> liftM G.PNeg (transPatt p)
+ PAs x p -> liftM2 G.PAs (transIdent x) (transPatt p)
+ PChar -> return G.PChar
+ PChars s -> return $ G.PChars s
+ PMacro c -> liftM G.PMacro $ transIdent c
+ PM m c -> liftM2 G.PM (transIdent m) (transIdent c)
+
+transBind :: Bind -> Err Ident
+transBind x = case x of
+ BIdent id -> transIdent id
+ BWild -> return identW
+
+transDecl :: Decl -> Err [G.Decl]
+transDecl x = case x of
+ DDec binds exp -> do
+ xs <- mapM transBind binds
+ exp' <- transExp exp
+ return [(x,exp') | x <- xs]
+ DExp exp -> liftM (return . M.mkDecl) $ transExp exp
+
+transCases :: [Case] -> Err [G.Case]
+transCases = mapM transCase
+
+transCase :: Case -> Err G.Case
+transCase (Case p exp) = do
+ patt <- transPatt p
+ exp' <- transExp exp
+ return (patt,exp')
+
+transEquation :: Equation -> Err G.Equation
+transEquation x = case x of
+ Equ apatts exp -> liftM2 (,) (mapM transPatt apatts) (transExp exp)
+
+transAltern :: Altern -> Err (G.Term, G.Term)
+transAltern x = case x of
+ Alt exp0 exp -> liftM2 (,) (transExp exp0) (transExp exp)
+
+transParConstr :: ParConstr -> Err G.Param
+transParConstr x = case x of
+ ParConstr id ddecls -> do
+ id' <- transIdent id
+ ddecls' <- mapM transDDecl ddecls
+ return (id',concat ddecls')
+
+transDDecl :: DDecl -> Err [G.Decl]
+transDDecl x = case x of
+ DDDec binds exp -> transDecl $ DDec binds exp
+ DDExp exp -> transDecl $ DExp exp
+
+-- | to deal with the old format, sort judgements in three modules, forming
+-- their names from a given string, e.g. file name or overriding user-given string
+transOldGrammar :: Options -> FilePath -> OldGrammar -> Err G.SourceGrammar
+transOldGrammar opts name0 x = case x of
+ OldGr includes topdefs -> do --- includes must be collected separately
+ let moddefs = sortTopDefs topdefs
+ g1 <- transGrammar $ Gr moddefs
+ removeLiT g1 --- needed for bw compatibility with an obsolete feature
+ where
+ sortTopDefs ds = [mkAbs a,mkRes ops r,mkCnc ops c] ++ map mkPack ps
+ where
+ ops = map fst ps
+ (a,r,c,ps) = foldr srt ([],[],[],[]) ds
+ srt d (a,r,c,ps) = case d of
+ DefCat catdefs -> (d:a,r,c,ps)
+ DefFun fundefs -> (d:a,r,c,ps)
+ DefFunData fundefs -> (d:a,r,c,ps)
+ DefDef defs -> (d:a,r,c,ps)
+ DefData pardefs -> (d:a,r,c,ps)
+ DefPar pardefs -> (a,d:r,c,ps)
+ DefOper defs -> (a,d:r,c,ps)
+ DefLintype defs -> (a,d:r,c,ps)
+ DefLincat defs -> (a,r,d:c,ps)
+ DefLindef defs -> (a,r,d:c,ps)
+ DefLin defs -> (a,r,d:c,ps)
+ DefPattern defs -> (a,r,d:c,ps)
+ DefFlag defs -> (a,r,d:c,ps) --- a guess
+ DefPrintCat printdefs -> (a,r,d:c,ps)
+ DefPrintFun printdefs -> (a,r,d:c,ps)
+ DefPrintOld printdefs -> (a,r,d:c,ps)
+ DefPackage m ds -> (a,r,c,(m,ds):ps)
+ _ -> (a,r,c,ps)
+ mkAbs a = MModule q (MTAbstract absName) (MBody ne (OpenIn []) (topDefs a))
+ mkRes ps r = MModule q (MTResource resName) (MBody ne (OpenIn ops) (topDefs r))
+ where ops = map OName ps
+ mkCnc ps r = MModule q (MTConcrete cncName absName)
+ (MBody ne (OpenIn (map OName (resName:ps))) (topDefs r))
+ mkPack (m, ds) = MModule q (MTResource m) (MBody ne (OpenIn []) (topDefs ds))
+ topDefs t = t
+ ne = NoExt
+ q = CMCompl
+
+ name = maybe name0 (++ ".gf") $ getOptVal opts useName
+ absName = identPI $ maybe topic id $ getOptVal opts useAbsName
+ resName = identPI $ maybe ("Res" ++ lang) id $ getOptVal opts useResName
+ cncName = identPI $ maybe lang id $ getOptVal opts useCncName
+
+ identPI s = PIdent ((0,0),s)
+
+ (beg,rest) = span (/='.') name
+ (topic,lang) = case rest of -- to avoid overwriting old files
+ ".gf" -> ("Abs" ++ beg,"Cnc" ++ beg)
+ ".cf" -> ("Abs" ++ beg,"Cnc" ++ beg)
+ ".ebnf" -> ("Abs" ++ beg,"Cnc" ++ beg)
+ [] -> ("Abs" ++ beg,"Cnc" ++ beg)
+ _:s -> (beg, takeWhile (/='.') s)
+
+transInclude :: Include -> Err [FilePath]
+transInclude x = case x of
+ NoIncl -> return []
+ Incl filenames -> return $ map trans filenames
+ where
+ trans f = case f of
+ FString s -> s
+ FIdent (PIdent (_, s)) -> modif s
+ FSlash filename -> '/' : trans filename
+ FDot filename -> '.' : trans filename
+ FMinus filename -> '-' : trans filename
+ FAddId (PIdent (_, s)) filename -> modif s ++ trans filename
+ modif s = let s' = init s ++ [toLower (last s)] in
+ if elem s' newReservedWords then s' else s
+ --- unsafe hack ; cf. GetGrammar.oldLexer
+
+
+newReservedWords :: [String]
+newReservedWords =
+ words $ "abstract concrete interface incomplete " ++
+ "instance out open resource reuse transfer union with where"
+
+termInPattern :: G.Term -> G.Term
+termInPattern t = M.mkAbs xx $ G.R [(s, (Nothing, toP body))] where
+ toP t = case t of
+ G.Vr x -> G.P t s
+ _ -> M.composSafeOp toP t
+ s = G.LIdent "s"
+ (xx,body) = abss [] t
+ abss xs t = case t of
+ G.Abs x b -> abss (x:xs) b
+ _ -> (reverse xs,t)
+
+mkListId,mkConsId,mkBaseId :: Ident -> Ident
+mkListId = prefixId "List"
+mkConsId = prefixId "Cons"
+mkBaseId = prefixId "Base"
+
+prefixId :: String -> Ident -> Ident
+prefixId pref id = IC (pref ++ prIdent id)
diff --git a/src-2.9/GF/Source/TestGF.hs b/src-2.9/GF/Source/TestGF.hs
new file mode 100644
index 000000000..e4c072467
--- /dev/null
+++ b/src-2.9/GF/Source/TestGF.hs
@@ -0,0 +1,58 @@
+-- automatically generated by BNF Converter
+module Main where
+
+
+import IO ( stdin, hGetContents )
+import System ( getArgs, getProgName )
+
+import GF.Source.LexGF
+import GF.Source.ParGF
+import GF.Source.SkelGF
+import GF.Source.PrintGF
+import GF.Source.AbsGF
+
+
+
+
+import GF.Source.ErrM
+
+type ParseFun a = [Token] -> Err a
+
+myLLexer = myLexer
+
+type Verbosity = Int
+
+putStrV :: Verbosity -> String -> IO ()
+putStrV v s = if v > 1 then putStrLn s else return ()
+
+runFile :: (Print a, Show a) => Verbosity -> ParseFun a -> FilePath -> IO ()
+runFile v p f = putStrLn f >> readFile f >>= run v p
+
+run :: (Print a, Show a) => Verbosity -> ParseFun a -> String -> IO ()
+run v p s = let ts = myLLexer s in case p ts of
+ Bad s -> do putStrLn "\nParse Failed...\n"
+ putStrV v "Tokens:"
+ putStrV v $ show ts
+ putStrLn s
+ Ok tree -> do putStrLn "\nParse Successful!"
+ showTree v tree
+
+
+
+showTree :: (Show a, Print a) => Int -> a -> IO ()
+showTree v tree
+ = do
+ putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
+ putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
+
+main :: IO ()
+main = do args <- getArgs
+ case args of
+ [] -> hGetContents stdin >>= run 2 pGrammar
+ "-s":fs -> mapM_ (runFile 0 pGrammar) fs
+ fs -> mapM_ (runFile 2 pGrammar) fs
+
+
+
+
+
diff --git a/src-2.9/GF/Speech/CFGToFiniteState.hs b/src-2.9/GF/Speech/CFGToFiniteState.hs
new file mode 100644
index 000000000..7e6f80ba1
--- /dev/null
+++ b/src-2.9/GF/Speech/CFGToFiniteState.hs
@@ -0,0 +1,265 @@
+----------------------------------------------------------------------
+-- |
+-- Module : CFGToFiniteState
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/10 16:43:44 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.6 $
+--
+-- Approximates CFGs with finite state networks.
+-----------------------------------------------------------------------------
+
+module GF.Speech.CFGToFiniteState (cfgToFA, makeSimpleRegular,
+ MFA(..), MFALabel, cfgToMFA,cfgToFA') where
+
+import Data.List
+import Data.Maybe
+import Data.Map (Map)
+import qualified Data.Map as Map
+import Data.Set (Set)
+import qualified Data.Set as Set
+
+import GF.Data.Utilities
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..), mapSymbol, filterCats, symbol, NameProfile(..))
+import GF.Conversion.Types
+import GF.Infra.Ident (Ident)
+import GF.Infra.Option (Options)
+import GF.Compile.ShellState (StateGrammar)
+
+import GF.Speech.FiniteState
+import GF.Speech.Graph
+import GF.Speech.Relation
+import GF.Speech.TransformCFG
+
+data Recursivity = RightR | LeftR | NotR
+
+data MutRecSet = MutRecSet {
+ mrCats :: Set Cat_,
+ mrNonRecRules :: [CFRule_],
+ mrRecRules :: [CFRule_],
+ mrRec :: Recursivity
+ }
+
+
+type MutRecSets = Map Cat_ MutRecSet
+
+--
+-- * Multiple DFA type
+--
+
+type MFALabel a = Symbol String a
+
+data MFA a = MFA String [(String,DFA (MFALabel a))]
+
+
+
+cfgToFA :: Options -> StateGrammar -> DFA Token
+cfgToFA opts s = minimize $ compileAutomaton start $ makeSimpleRegular opts s
+ where start = getStartCatCF opts s
+
+makeSimpleRegular :: Options -> StateGrammar -> CFRules
+makeSimpleRegular opts s = makeRegular $ preprocess $ cfgToCFRules s
+ where start = getStartCatCF opts s
+ preprocess = topDownFilter start . bottomUpFilter
+ . removeCycles
+
+
+--
+-- * Compile strongly regular grammars to NFAs
+--
+
+-- Convert a strongly regular grammar to a finite automaton.
+compileAutomaton :: Cat_ -- ^ Start category
+ -> CFRules
+ -> NFA Token
+compileAutomaton start g = make_fa (g,ns) s [Cat start] f fa
+ where
+ (fa,s,f) = newFA_
+ ns = mutRecSets g $ mutRecCats False g
+
+-- | The make_fa algorithm from \"Regular approximation of CFLs: a grammatical view\",
+-- Mark-Jan Nederhof, Advances in Probabilistic and other Parsing Technologies, 2000.
+make_fa :: (CFRules,MutRecSets) -> State -> [Symbol Cat_ Token] -> State
+ -> NFA Token -> NFA Token
+make_fa c@(g,ns) q0 alpha q1 fa =
+ case alpha of
+ [] -> newTransition q0 q1 Nothing fa
+ [Tok t] -> newTransition q0 q1 (Just t) fa
+ [Cat a] -> case Map.lookup a ns of
+ -- a is recursive
+ Just n@(MutRecSet { mrCats = ni, mrNonRecRules = nrs, mrRecRules = rs} ) ->
+ case mrRec n of
+ RightR ->
+ -- the set Ni is right-recursive or cyclic
+ let new = [(getState c, xs, q1) | CFRule c xs _ <- nrs]
+ ++ [(getState c, xs, getState d) | CFRule c ss _ <- rs,
+ let (xs,Cat d) = (init ss,last ss)]
+ in make_fas new $ newTransition q0 (getState a) Nothing fa'
+ LeftR ->
+ -- the set Ni is left-recursive
+ let new = [(q0, xs, getState c) | CFRule c xs _ <- nrs]
+ ++ [(getState d, xs, getState c) | CFRule c (Cat d:xs) _ <- rs]
+ in make_fas new $ newTransition (getState a) q1 Nothing fa'
+ where
+ (fa',stateMap) = addStatesForCats ni fa
+ getState x = Map.findWithDefault
+ (error $ "CFGToFiniteState: No state for " ++ x)
+ x stateMap
+ -- a is not recursive
+ Nothing -> let rs = catRules g a
+ in foldl' (\f (CFRule _ b _) -> make_fa_ q0 b q1 f) fa rs
+ (x:beta) -> let (fa',q) = newState () fa
+ in make_fa_ q beta q1 $ make_fa_ q0 [x] q fa'
+ where
+ make_fa_ = make_fa c
+ make_fas xs fa = foldl' (\f' (s1,xs,s2) -> make_fa_ s1 xs s2 f') fa xs
+
+--
+-- * Compile a strongly regular grammar to a DFA with sub-automata
+--
+
+cfgToMFA :: Options -> StateGrammar -> MFA Token
+cfgToMFA opts s = buildMFA start $ makeSimpleRegular opts s
+ where start = getStartCatCF opts s
+
+-- | Build a DFA by building and expanding an MFA
+cfgToFA' :: Options -> StateGrammar -> DFA Token
+cfgToFA' opts s = mfaToDFA $ cfgToMFA opts s
+
+buildMFA :: Cat_ -- ^ Start category
+ -> CFRules -> MFA Token
+buildMFA start g = sortSubLats $ removeUnusedSubLats mfa
+ where fas = compileAutomata g
+ mfa = MFA start [(c, minimize fa) | (c,fa) <- fas]
+
+mfaStartDFA :: MFA a -> DFA (MFALabel a)
+mfaStartDFA (MFA start subs) =
+ fromMaybe (error $ "Bad start MFA: " ++ start) $ lookup start subs
+
+mfaToDFA :: Ord a => MFA a -> DFA a
+mfaToDFA mfa@(MFA _ subs) = minimize $ expand $ dfa2nfa $ mfaStartDFA mfa
+ where
+ subs' = Map.fromList [(c, dfa2nfa n) | (c,n) <- subs]
+ getSub l = fromJust $ Map.lookup l subs'
+ expand (FA (Graph c ns es) s f)
+ = foldl' expandEdge (FA (Graph c ns []) s f) es
+ expandEdge fa (f,t,x) =
+ case x of
+ Nothing -> newTransition f t Nothing fa
+ Just (Tok s) -> newTransition f t (Just s) fa
+ Just (Cat l) -> insertNFA fa (f,t) (expand $ getSub l)
+
+removeUnusedSubLats :: MFA a -> MFA a
+removeUnusedSubLats mfa@(MFA start subs) = MFA start [(c,s) | (c,s) <- subs, isUsed c]
+ where
+ usedMap = subLatUseMap mfa
+ used = growUsedSet (Set.singleton start)
+ isUsed c = c `Set.member` used
+ growUsedSet = fix (\s -> foldl Set.union s $ mapMaybe (flip Map.lookup usedMap) $ Set.toList s)
+
+subLatUseMap :: MFA a -> Map String (Set String)
+subLatUseMap (MFA _ subs) = Map.fromList [(c,usedSubLats n) | (c,n) <- subs]
+
+usedSubLats :: DFA (MFALabel a) -> Set String
+usedSubLats fa = Set.fromList [s | (_,_,Cat s) <- transitions fa]
+
+revMultiMap :: (Ord a, Ord b) => Map a (Set b) -> Map b (Set a)
+revMultiMap m = Map.fromListWith Set.union [ (y,Set.singleton x) | (x,s) <- Map.toList m, y <- Set.toList s]
+
+-- | Sort sub-networks topologically.
+sortSubLats :: MFA a -> MFA a
+sortSubLats mfa@(MFA main subs) = MFA main (reverse $ sortLats usedByMap subs)
+ where
+ usedByMap = revMultiMap (subLatUseMap mfa)
+ sortLats _ [] = []
+ sortLats ub ls = xs ++ sortLats ub' ys
+ where (xs,ys) = partition ((==0) . indeg) ls
+ ub' = Map.map (Set.\\ Set.fromList (map fst xs)) ub
+ indeg (c,_) = maybe 0 Set.size $ Map.lookup c ub
+
+-- | Convert a strongly regular grammar to a number of finite automata,
+-- one for each non-terminal.
+-- The edges in the automata accept tokens, or name another automaton to use.
+compileAutomata :: CFRules
+ -> [(Cat_,NFA (Symbol Cat_ Token))]
+ -- ^ A map of non-terminals and their automata.
+compileAutomata g = [(c, makeOneFA c) | c <- allCats g]
+ where
+ mrs = mutRecSets g $ mutRecCats True g
+ makeOneFA c = make_fa1 mr s [Cat c] f fa
+ where (fa,s,f) = newFA_
+ mr = fromJust (Map.lookup c mrs)
+
+
+-- | The make_fa algorithm from \"Regular approximation of CFLs: a grammatical view\",
+-- Mark-Jan Nederhof, Advances in Probabilistic and other Parsing Technologies, 2000,
+-- adapted to build a finite automaton for a single (mutually recursive) set only.
+-- Categories not in the set will result in category-labelled edges.
+make_fa1 :: MutRecSet -- ^ The set of (mutually recursive) categories for which
+ -- we are building the automaton.
+ -> State -- ^ State to come from
+ -> [Symbol Cat_ Token] -- ^ Symbols to accept
+ -> State -- ^ State to end up in
+ -> NFA (Symbol Cat_ Token) -- ^ FA to add to.
+ -> NFA (Symbol Cat_ Token)
+make_fa1 mr q0 alpha q1 fa =
+ case alpha of
+ [] -> newTransition q0 q1 Nothing fa
+ [t@(Tok _)] -> newTransition q0 q1 (Just t) fa
+ [c@(Cat a)] | not (a `Set.member` mrCats mr) -> newTransition q0 q1 (Just c) fa
+ [Cat a] ->
+ case mrRec mr of
+ NotR -> -- the set is a non-recursive (always singleton) set of categories
+ -- so the set of category rules is the set of rules for the whole set
+ make_fas [(q0, b, q1) | CFRule _ b _ <- mrNonRecRules mr] fa
+ RightR -> -- the set is right-recursive or cyclic
+ let new = [(getState c, xs, q1) | CFRule c xs _ <- mrNonRecRules mr]
+ ++ [(getState c, xs, getState d) | CFRule c ss _ <- mrRecRules mr,
+ let (xs,Cat d) = (init ss,last ss)]
+ in make_fas new $ newTransition q0 (getState a) Nothing fa'
+ LeftR -> -- the set is left-recursive
+ let new = [(q0, xs, getState c) | CFRule c xs _ <- mrNonRecRules mr]
+ ++ [(getState d, xs, getState c) | CFRule c (Cat d:xs) _ <- mrRecRules mr]
+ in make_fas new $ newTransition (getState a) q1 Nothing fa'
+ where
+ (fa',stateMap) = addStatesForCats (mrCats mr) fa
+ getState x = Map.findWithDefault
+ (error $ "CFGToFiniteState: No state for " ++ x)
+ x stateMap
+ (x:beta) -> let (fa',q) = newState () fa
+ in make_fas [(q0,[x],q),(q,beta,q1)] fa'
+ where
+ make_fas xs fa = foldl' (\f' (s1,xs,s2) -> make_fa1 mr s1 xs s2 f') fa xs
+
+mutRecSets :: CFRules -> [Set Cat_] -> MutRecSets
+mutRecSets g = Map.fromList . concatMap mkMutRecSet
+ where
+ mkMutRecSet cs = [ (c,ms) | c <- csl ]
+ where csl = Set.toList cs
+ rs = catSetRules g cs
+ (nrs,rrs) = partition (ruleIsNonRecursive cs) rs
+ ms = MutRecSet {
+ mrCats = cs,
+ mrNonRecRules = nrs,
+ mrRecRules = rrs,
+ mrRec = rec
+ }
+ rec | null rrs = NotR
+ | all (isRightLinear cs) rrs = RightR
+ | otherwise = LeftR
+
+--
+-- * Utilities
+--
+
+-- | Add a state for the given NFA for each of the categories
+-- in the given set. Returns a map of categories to their
+-- corresponding states.
+addStatesForCats :: Set Cat_ -> NFA t -> (NFA t, Map Cat_ State)
+addStatesForCats cs fa = (fa', m)
+ where (fa', ns) = newStates (replicate (Set.size cs) ()) fa
+ m = Map.fromList (zip (Set.toList cs) (map fst ns))
diff --git a/src-2.9/GF/Speech/FiniteState.hs b/src-2.9/GF/Speech/FiniteState.hs
new file mode 100644
index 000000000..35274e3c4
--- /dev/null
+++ b/src-2.9/GF/Speech/FiniteState.hs
@@ -0,0 +1,329 @@
+----------------------------------------------------------------------
+-- |
+-- Module : FiniteState
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/10 16:43:44 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.16 $
+--
+-- A simple finite state network module.
+-----------------------------------------------------------------------------
+module GF.Speech.FiniteState (FA(..), State, NFA, DFA,
+ startState, finalStates,
+ states, transitions,
+ isInternal,
+ newFA, newFA_,
+ addFinalState,
+ newState, newStates,
+ newTransition, newTransitions,
+ insertTransitionWith, insertTransitionsWith,
+ mapStates, mapTransitions,
+ modifyTransitions,
+ nonLoopTransitionsTo, nonLoopTransitionsFrom,
+ loops,
+ removeState,
+ oneFinalState,
+ insertNFA,
+ onGraph,
+ moveLabelsToNodes, removeTrivialEmptyNodes,
+ minimize,
+ dfa2nfa,
+ unusedNames, renameStates,
+ prFAGraphviz, faToGraphviz) where
+
+import Data.List
+import Data.Maybe
+import Data.Map (Map)
+import qualified Data.Map as Map
+import Data.Set (Set)
+import qualified Data.Set as Set
+
+import GF.Data.Utilities
+import GF.Speech.Graph
+import qualified GF.Visualization.Graphviz as Dot
+
+type State = Int
+
+-- | Type parameters: node id type, state label type, edge label type
+-- Data constructor arguments: nodes and edges, start state, final states
+data FA n a b = FA !(Graph n a b) !n ![n]
+
+type NFA a = FA State () (Maybe a)
+
+type DFA a = FA State () a
+
+
+startState :: FA n a b -> n
+startState (FA _ s _) = s
+
+finalStates :: FA n a b -> [n]
+finalStates (FA _ _ ss) = ss
+
+states :: FA n a b -> [(n,a)]
+states (FA g _ _) = nodes g
+
+transitions :: FA n a b -> [(n,n,b)]
+transitions (FA g _ _) = edges g
+
+newFA :: Enum n => a -- ^ Start node label
+ -> FA n a b
+newFA l = FA g s []
+ where (g,s) = newNode l (newGraph [toEnum 0..])
+
+-- | Create a new finite automaton with an initial and a final state.
+newFA_ :: Enum n => (FA n () b, n, n)
+newFA_ = (fa'', s, f)
+ where fa = newFA ()
+ s = startState fa
+ (fa',f) = newState () fa
+ fa'' = addFinalState f fa'
+
+addFinalState :: n -> FA n a b -> FA n a b
+addFinalState f (FA g s ss) = FA g s (f:ss)
+
+newState :: a -> FA n a b -> (FA n a b, n)
+newState x (FA g s ss) = (FA g' s ss, n)
+ where (g',n) = newNode x g
+
+newStates :: [a] -> FA n a b -> (FA n a b, [(n,a)])
+newStates xs (FA g s ss) = (FA g' s ss, ns)
+ where (g',ns) = newNodes xs g
+
+newTransition :: n -> n -> b -> FA n a b -> FA n a b
+newTransition f t l = onGraph (newEdge (f,t,l))
+
+newTransitions :: [(n, n, b)] -> FA n a b -> FA n a b
+newTransitions es = onGraph (newEdges es)
+
+insertTransitionWith :: Eq n =>
+ (b -> b -> b) -> (n, n, b) -> FA n a b -> FA n a b
+insertTransitionWith f t = onGraph (insertEdgeWith f t)
+
+insertTransitionsWith :: Eq n =>
+ (b -> b -> b) -> [(n, n, b)] -> FA n a b -> FA n a b
+insertTransitionsWith f ts fa =
+ foldl' (flip (insertTransitionWith f)) fa ts
+
+mapStates :: (a -> c) -> FA n a b -> FA n c b
+mapStates f = onGraph (nmap f)
+
+mapTransitions :: (b -> c) -> FA n a b -> FA n a c
+mapTransitions f = onGraph (emap f)
+
+modifyTransitions :: ([(n,n,b)] -> [(n,n,b)]) -> FA n a b -> FA n a b
+modifyTransitions f = onGraph (\ (Graph r ns es) -> Graph r ns (f es))
+
+removeState :: Ord n => n -> FA n a b -> FA n a b
+removeState n = onGraph (removeNode n)
+
+minimize :: Ord a => NFA a -> DFA a
+minimize = determinize . reverseNFA . dfa2nfa . determinize . reverseNFA
+
+unusedNames :: FA n a b -> [n]
+unusedNames (FA (Graph names _ _) _ _) = names
+
+-- | Gets all incoming transitions to a given state, excluding
+-- transtions from the state itself.
+nonLoopTransitionsTo :: Eq n => n -> FA n a b -> [(n,b)]
+nonLoopTransitionsTo s fa =
+ [(f,l) | (f,t,l) <- transitions fa, t == s && f /= s]
+
+nonLoopTransitionsFrom :: Eq n => n -> FA n a b -> [(n,b)]
+nonLoopTransitionsFrom s fa =
+ [(t,l) | (f,t,l) <- transitions fa, f == s && t /= s]
+
+loops :: Eq n => n -> FA n a b -> [b]
+loops s fa = [l | (f,t,l) <- transitions fa, f == s && t == s]
+
+-- | Give new names to all nodes.
+renameStates :: Ord x => [y] -- ^ Infinite supply of new names
+ -> FA x a b
+ -> FA y a b
+renameStates supply (FA g s fs) = FA (renameNodes newName rest g) s' fs'
+ where (ns,rest) = splitAt (length (nodes g)) supply
+ newNodes = Map.fromList (zip (map fst (nodes g)) ns)
+ newName n = Map.findWithDefault (error "FiniteState.newName") n newNodes
+ s' = newName s
+ fs' = map newName fs
+
+-- | Insert an NFA into another
+insertNFA :: NFA a -- ^ NFA to insert into
+ -> (State, State) -- ^ States to insert between
+ -> NFA a -- ^ NFA to insert.
+ -> NFA a
+insertNFA (FA g1 s1 fs1) (f,t) (FA g2 s2 fs2)
+ = FA (newEdges es g') s1 fs1
+ where
+ es = (f,ren s2,Nothing):[(ren f2,t,Nothing) | f2 <- fs2]
+ (g',ren) = mergeGraphs g1 g2
+
+onGraph :: (Graph n a b -> Graph n c d) -> FA n a b -> FA n c d
+onGraph f (FA g s ss) = FA (f g) s ss
+
+
+-- | Make the finite automaton have a single final state
+-- by adding a new final state and adding an edge
+-- from the old final states to the new state.
+oneFinalState :: a -- ^ Label to give the new node
+ -> b -- ^ Label to give the new edges
+ -> FA n a b -- ^ The old network
+ -> FA n a b -- ^ The new network
+oneFinalState nl el fa =
+ let (FA g s fs,nf) = newState nl fa
+ es = [ (f,nf,el) | f <- fs ]
+ in FA (newEdges es g) s [nf]
+
+-- | Transform a standard finite automaton with labelled edges
+-- to one where the labels are on the nodes instead. This can add
+-- up to one extra node per edge.
+moveLabelsToNodes :: (Ord n,Eq a) => FA n () (Maybe a) -> FA n (Maybe a) ()
+moveLabelsToNodes = onGraph f
+ where f g@(Graph c _ _) = Graph c' ns (concat ess)
+ where is = [ ((n,l),inc) | (n, (l,inc,_)) <- Map.toList (nodeInfo g)]
+ (c',is') = mapAccumL fixIncoming c is
+ (ns,ess) = unzip (concat is')
+
+
+-- | Remove empty nodes which are not start or final, and have
+-- exactly one outgoing edge or exactly one incoming edge.
+removeTrivialEmptyNodes :: (Eq a, Ord n) => FA n (Maybe a) () -> FA n (Maybe a) ()
+removeTrivialEmptyNodes = pruneUnusable . skipSimpleEmptyNodes
+
+-- | Move edges to empty nodes to point to the next node(s).
+-- This is not done if the pointed-to node is a final node.
+skipSimpleEmptyNodes :: (Eq a, Ord n) => FA n (Maybe a) () -> FA n (Maybe a) ()
+skipSimpleEmptyNodes fa = onGraph og fa
+ where
+ og g@(Graph c ns es) = if es' == es then g else og (Graph c ns es')
+ where
+ es' = concatMap changeEdge es
+ info = nodeInfo g
+ changeEdge e@(f,t,())
+ | isNothing (getNodeLabel info t)
+ -- && (i * o <= i + o)
+ && not (isFinal fa t)
+ = [ (f,t',()) | (_,t',()) <- getOutgoing info t]
+ | otherwise = [e]
+-- where i = inDegree info t
+-- o = outDegree info t
+
+isInternal :: Eq n => FA n a b -> n -> Bool
+isInternal (FA _ start final) n = n /= start && n `notElem` final
+
+isFinal :: Eq n => FA n a b -> n -> Bool
+isFinal (FA _ _ final) n = n `elem` final
+
+-- | Remove all internal nodes with no incoming edges
+-- or no outgoing edges.
+pruneUnusable :: Ord n => FA n (Maybe a) () -> FA n (Maybe a) ()
+pruneUnusable fa = onGraph f fa
+ where
+ f g = if Set.null rns then g else f (removeNodes rns g)
+ where info = nodeInfo g
+ rns = Set.fromList [ n | (n,_) <- nodes g,
+ isInternal fa n,
+ inDegree info n == 0
+ || outDegree info n == 0]
+
+fixIncoming :: (Ord n, Eq a) => [n]
+ -> (Node n (),[Edge n (Maybe a)]) -- ^ A node and its incoming edges
+ -> ([n],[(Node n (Maybe a),[Edge n ()])]) -- ^ Replacement nodes with their
+ -- incoming edges.
+fixIncoming cs c@((n,()),es) = (cs'', ((n,Nothing),es'):newContexts)
+ where ls = nub $ map edgeLabel es
+ (cs',cs'') = splitAt (length ls) cs
+ newNodes = zip cs' ls
+ es' = [ (x,n,()) | x <- map fst newNodes ]
+ -- separate cyclic and non-cyclic edges
+ (cyc,ncyc) = partition (\ (f,_,_) -> f == n) es
+ -- keep all incoming non-cyclic edges with the right label
+ to (x,l) = [ (f,x,()) | (f,_,l') <- ncyc, l == l']
+ -- for each cyclic edge with the right label,
+ -- add an edge from each of the new nodes (including this one)
+ ++ [ (y,x,()) | (f,_,l') <- cyc, l == l', (y,_) <- newNodes]
+ newContexts = [ (v, to v) | v <- newNodes ]
+
+alphabet :: Eq b => Graph n a (Maybe b) -> [b]
+alphabet = nub . catMaybes . map edgeLabel . edges
+
+determinize :: Ord a => NFA a -> DFA a
+determinize (FA g s f) = let (ns,es) = h (Set.singleton start) Set.empty Set.empty
+ (ns',es') = (Set.toList ns, Set.toList es)
+ final = filter isDFAFinal ns'
+ fa = FA (Graph undefined [(n,()) | n <- ns'] es') start final
+ in renameStates [0..] fa
+ where info = nodeInfo g
+-- reach = nodesReachable out
+ start = closure info $ Set.singleton s
+ isDFAFinal n = not (Set.null (Set.fromList f `Set.intersection` n))
+ h currentStates oldStates es
+ | Set.null currentStates = (oldStates,es)
+ | otherwise = ((h $! uniqueNewStates) $! allOldStates) $! es'
+ where
+ allOldStates = oldStates `Set.union` currentStates
+ (newStates,es') = new (Set.toList currentStates) Set.empty es
+ uniqueNewStates = newStates Set.\\ allOldStates
+ -- Get the sets of states reachable from the given states
+ -- by consuming one symbol, and the associated edges.
+ new [] rs es = (rs,es)
+ new (n:ns) rs es = new ns rs' es'
+ where cs = reachable info n --reachable reach n
+ rs' = rs `Set.union` Set.fromList (map snd cs)
+ es' = es `Set.union` Set.fromList [(n,s,c) | (c,s) <- cs]
+
+
+-- | Get all the nodes reachable from a list of nodes by only empty edges.
+closure :: Ord n => NodeInfo n a (Maybe b) -> Set n -> Set n
+closure info x = closure_ x x
+ where closure_ acc check | Set.null check = acc
+ | otherwise = closure_ acc' check'
+ where
+ reach = Set.fromList [y | x <- Set.toList check,
+ (_,y,Nothing) <- getOutgoing info x]
+ acc' = acc `Set.union` reach
+ check' = reach Set.\\ acc
+
+-- | Get a map of labels to sets of all nodes reachable
+-- from a the set of nodes by one edge with the given
+-- label and then any number of empty edges.
+reachable :: (Ord n,Ord b) => NodeInfo n a (Maybe b) -> Set n -> [(b,Set n)]
+reachable info ns = Map.toList $ Map.map (closure info . Set.fromList) $ reachable1 info ns
+reachable1 info ns = Map.fromListWith (++) [(c, [y]) | n <- Set.toList ns, (_,y,Just c) <- getOutgoing info n]
+
+reverseNFA :: NFA a -> NFA a
+reverseNFA (FA g s fs) = FA g''' s' [s]
+ where g' = reverseGraph g
+ (g'',s') = newNode () g'
+ g''' = newEdges [(s',f,Nothing) | f <- fs] g''
+
+dfa2nfa :: DFA a -> NFA a
+dfa2nfa = mapTransitions Just
+
+--
+-- * Visualization
+--
+
+prFAGraphviz :: (Eq n,Show n) => FA n String String -> String
+prFAGraphviz = Dot.prGraphviz . faToGraphviz
+
+prFAGraphviz_ :: (Eq n,Show n,Show a, Show b) => FA n a b -> String
+prFAGraphviz_ = Dot.prGraphviz . faToGraphviz . mapStates show . mapTransitions show
+
+faToGraphviz :: (Eq n,Show n) => FA n String String -> Dot.Graph
+faToGraphviz (FA (Graph _ ns es) s f)
+ = Dot.Graph Dot.Directed Nothing [] (map mkNode ns) (map mkEdge es) []
+ where mkNode (n,l) = Dot.Node (show n) attrs
+ where attrs = [("label",l)]
+ ++ if n == s then [("shape","box")] else []
+ ++ if n `elem` f then [("style","bold")] else []
+ mkEdge (x,y,l) = Dot.Edge (show x) (show y) [("label",l)]
+
+--
+-- * Utilities
+--
+
+lookups :: Ord k => [k] -> Map k a -> [a]
+lookups xs m = mapMaybe (flip Map.lookup m) xs
diff --git a/src-2.9/GF/Speech/GrammarToVoiceXML.hs b/src-2.9/GF/Speech/GrammarToVoiceXML.hs
new file mode 100644
index 000000000..ad7f25d1c
--- /dev/null
+++ b/src-2.9/GF/Speech/GrammarToVoiceXML.hs
@@ -0,0 +1,285 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GrammarToVoiceXML
+-- Maintainer : Bjorn Bringert
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- Create VoiceXML dialogue system from a GF grammar.
+-----------------------------------------------------------------------------
+
+module GF.Speech.GrammarToVoiceXML (grammar2vxml) where
+
+import GF.Canon.CanonToGFCC (canon2gfcc)
+import qualified GF.GFCC.CId as C
+import GF.GFCC.DataGFCC (GFCC(..), Abstr(..))
+import GF.GFCC.Macros
+import qualified GF.Canon.GFC as GFC
+import GF.Canon.AbsGFC (Term)
+import GF.Canon.PrintGFC (printTree)
+import GF.Canon.CMacros (noMark, strsFromTerm)
+import GF.Canon.Unlex (formatAsText)
+import GF.Data.Utilities
+import GF.CF.CFIdent (cfCat2Ident)
+import GF.Compile.ShellState (StateGrammar,stateGrammarST,cncId,grammar,
+ startCatStateOpts,stateOptions)
+import GF.Data.Str (sstrV)
+import GF.Grammar.Macros hiding (assign,strsFromTerm)
+import GF.Grammar.Grammar (Fun)
+import GF.Grammar.Values (Tree)
+import GF.Infra.Option (Options, addOptions, getOptVal, speechLanguage)
+import GF.UseGrammar.GetTree (string2treeErr)
+import GF.UseGrammar.Linear (linTree2strings)
+
+import GF.Infra.Ident
+import GF.Infra.Option (noOptions)
+import GF.Infra.Modules
+import GF.Data.Operations
+
+import GF.Data.XML
+
+import Control.Monad (liftM)
+import Data.List (isPrefixOf, find, intersperse)
+import qualified Data.Map as Map
+import Data.Maybe (fromMaybe)
+
+import Debug.Trace
+
+-- | the main function
+grammar2vxml :: Options -> StateGrammar -> String
+grammar2vxml opt s = showsXMLDoc (skel2vxml name language startcat gr' qs) ""
+ where (_, gr') = vSkeleton (stateGrammarST s)
+ name = prIdent (cncId s)
+ qs = catQuestions s (map fst gr')
+ opts = addOptions opt (stateOptions s)
+ language = fmap (replace '_' '-') $ getOptVal opts speechLanguage
+ startcat = C.CId $ prIdent $ cfCat2Ident $ startCatStateOpts opts s
+
+--
+-- * VSkeleton: a simple description of the abstract syntax.
+--
+
+type VSkeleton = [(VIdent, [(VIdent, [VIdent])])]
+type VIdent = C.CId
+
+prid :: VIdent -> String
+prid (C.CId x) = x
+
+vSkeleton :: GFC.CanonGrammar -> (VIdent,VSkeleton)
+vSkeleton = gfccSkeleton . canon2gfcc noOptions
+
+gfccSkeleton :: GFCC -> (VIdent,VSkeleton)
+gfccSkeleton gfcc = (absname gfcc, ts)
+ where a = abstract gfcc
+ ts = [(c,[(f,ft f) | f <- fs]) | (c,fs) <- Map.toList (catfuns a)]
+ ft f = case lookMap (error $ prid f) f (funs a) of
+ (ty,_) -> fst $ GF.GFCC.Macros.catSkeleton ty
+
+--
+-- * Questions to ask
+--
+
+type CatQuestions = [(VIdent,String)]
+
+catQuestions :: StateGrammar -> [VIdent] -> CatQuestions
+catQuestions gr cats = [(c,catQuestion gr c) | c <- cats]
+
+catQuestion :: StateGrammar -> VIdent -> String
+catQuestion gr cat = err errHandler id (getPrintname gr cat >>= term2string)
+ where -- FIXME: use some better warning facility
+ errHandler e = trace ("GrammarToVoiceXML: " ++ e) ("quest_"++prid cat)
+ term2string = liftM sstrV . strsFromTerm
+
+getPrintname :: StateGrammar -> VIdent -> Err Term
+getPrintname gr cat =
+ do m <- lookupModMod (grammar gr) (cncId gr)
+ i <- lookupInfo m (IC (prid cat))
+ case i of
+ GFC.CncCat _ _ p -> return p
+ _ -> fail $ "getPrintname " ++ prid cat
+ ++ ": Expected CncCat, got " ++ show i
+
+
+{-
+lin :: StateGrammar -> String -> Err String
+lin gr fun = do
+ tree <- string2treeErr gr fun
+ let ls = map unt $ linTree2strings noMark g c tree
+ case ls of
+ [] -> fail $ "No linearization of " ++ fun
+ l:_ -> return l
+ where c = cncId gr
+ g = stateGrammarST gr
+ unt = formatAsText
+-}
+
+getCatQuestion :: VIdent -> CatQuestions -> String
+getCatQuestion c qs =
+ fromMaybe (error "No question for category " ++ prid c) (lookup c qs)
+
+--
+-- * Generate VoiceXML
+--
+
+skel2vxml :: String -> Maybe String -> VIdent -> VSkeleton -> CatQuestions -> XML
+skel2vxml name language start skel qs =
+ vxml language ([startForm] ++ concatMap (uncurry (catForms gr qs)) skel)
+ where
+ gr = grammarURI name
+ startForm = Tag "form" [] [subdialog "sub" [("src", "#"++catFormId start)]
+ [param "old" "{ name : '?' }"]]
+
+grammarURI :: String -> String
+grammarURI name = name ++ ".grxml"
+
+
+catForms :: String -> CatQuestions -> VIdent -> [(VIdent, [VIdent])] -> [XML]
+catForms gr qs cat fs =
+ comments [prid cat ++ " category."]
+ ++ [cat2form gr qs cat fs]
+
+cat2form :: String -> CatQuestions -> VIdent -> [(VIdent, [VIdent])] -> XML
+cat2form gr qs cat fs =
+ form (catFormId cat) $
+ [var "old" Nothing,
+ blockCond "old.name != '?'" [assign "term" "old"],
+ field "term" []
+ [promptString (getCatQuestion cat qs),
+ vxmlGrammar (gr++"#"++catFormId cat)
+ ]
+ ]
+ ++ concatMap (uncurry (fun2sub gr cat)) fs
+ ++ [block [return_ ["term"]{-]-}]]
+
+fun2sub :: String -> VIdent -> VIdent -> [VIdent] -> [XML]
+fun2sub gr cat fun args =
+ comments [prid fun ++ " : ("
+ ++ concat (intersperse ", " (map prid args))
+ ++ ") " ++ prid cat] ++ ss
+ where
+ ss = zipWith mkSub [0..] args
+ mkSub n t = subdialog s [("src","#"++catFormId t),
+ ("cond","term.name == "++string (prid fun))]
+ [param "old" v,
+ filled [] [assign v (s++".term")]]
+ where s = prid fun ++ "_" ++ show n
+ v = "term.args["++show n++"]"
+
+catFormId :: VIdent -> String
+catFormId c = prid c ++ "_cat"
+
+
+--
+-- * VoiceXML stuff
+--
+
+vxml :: Maybe String -> [XML] -> XML
+vxml ml = Tag "vxml" $ [("version","2.0"),
+ ("xmlns","http://www.w3.org/2001/vxml")]
+ ++ maybe [] (\l -> [("xml:lang", l)]) ml
+
+form :: String -> [XML] -> XML
+form id xs = Tag "form" [("id", id)] xs
+
+field :: String -> [(String,String)] -> [XML] -> XML
+field name attrs = Tag "field" ([("name",name)]++attrs)
+
+subdialog :: String -> [(String,String)] -> [XML] -> XML
+subdialog name attrs = Tag "subdialog" ([("name",name)]++attrs)
+
+filled :: [(String,String)] -> [XML] -> XML
+filled = Tag "filled"
+
+vxmlGrammar :: String -> XML
+vxmlGrammar uri = ETag "grammar" [("src",uri)]
+
+prompt :: [XML] -> XML
+prompt = Tag "prompt" []
+
+promptString :: String -> XML
+promptString p = prompt [Data p]
+
+reprompt :: XML
+reprompt = ETag "reprompt" []
+
+assign :: String -> String -> XML
+assign n e = ETag "assign" [("name",n),("expr",e)]
+
+value :: String -> XML
+value expr = ETag "value" [("expr",expr)]
+
+if_ :: String -> [XML] -> XML
+if_ c b = if_else c b []
+
+if_else :: String -> [XML] -> [XML] -> XML
+if_else c t f = cond [(c,t)] f
+
+cond :: [(String,[XML])] -> [XML] -> XML
+cond ((c,b):rest) els = Tag "if" [("cond",c)] (b ++ es)
+ where es = [Tag "elseif" [("cond",c')] b' | (c',b') <- rest]
+ ++ if null els then [] else (Tag "else" [] []:els)
+
+goto_item :: String -> XML
+goto_item nextitem = ETag "goto" [("nextitem",nextitem)]
+
+return_ :: [String] -> XML
+return_ names = ETag "return" [("namelist", unwords names)]
+
+block :: [XML] -> XML
+block = Tag "block" []
+
+blockCond :: String -> [XML] -> XML
+blockCond cond = Tag "block" [("cond", cond)]
+
+throw :: String -> String -> XML
+throw event msg = Tag "throw" [("event",event),("message",msg)] []
+
+nomatch :: [XML] -> XML
+nomatch = Tag "nomatch" []
+
+help :: [XML] -> XML
+help = Tag "help" []
+
+param :: String -> String -> XML
+param name expr = ETag "param" [("name",name),("expr",expr)]
+
+var :: String -> Maybe String -> XML
+var name expr = ETag "var" ([("name",name)]++e)
+ where e = maybe [] ((:[]) . (,) "expr") expr
+
+script :: String -> XML
+script s = Tag "script" [] [CData s]
+
+scriptURI :: String -> XML
+scriptURI uri = Tag "script" [("uri", uri)] []
+
+--
+-- * ECMAScript stuff
+--
+
+string :: String -> String
+string s = "'" ++ concatMap esc s ++ "'"
+ where esc '\'' = "\\'"
+ esc c = [c]
+
+{-
+--
+-- * List stuff
+--
+
+isListCat :: (VIdent, [(VIdent, [VIdent])]) -> Bool
+isListCat (cat,rules) = "List" `isPrefixOf` prIdent cat && length rules == 2
+ && ("Base"++c) `elem` fs && ("Cons"++c) `elem` fs
+ where c = drop 4 (prIdent cat)
+ fs = map (prIdent . fst) rules
+
+isBaseFun :: VIdent -> Bool
+isBaseFun f = "Base" `isPrefixOf` prIdent f
+
+isConsFun :: VIdent -> Bool
+isConsFun f = "Cons" `isPrefixOf` prIdent f
+
+baseSize :: (VIdent, [(VIdent, [VIdent])]) -> Int
+baseSize (_,rules) = length bs
+ where Just (_,bs) = find (isBaseFun . fst) rules
+-}
diff --git a/src-2.9/GF/Speech/Graph.hs b/src-2.9/GF/Speech/Graph.hs
new file mode 100644
index 000000000..1a0ebe0c0
--- /dev/null
+++ b/src-2.9/GF/Speech/Graph.hs
@@ -0,0 +1,178 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Graph
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/10 16:43:44 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.2 $
+--
+-- A simple graph module.
+-----------------------------------------------------------------------------
+module GF.Speech.Graph ( Graph(..), Node, Edge, NodeInfo
+ , newGraph, nodes, edges
+ , nmap, emap, newNode, newNodes, newEdge, newEdges
+ , insertEdgeWith
+ , removeNode, removeNodes
+ , nodeInfo
+ , getIncoming, getOutgoing, getNodeLabel
+ , inDegree, outDegree
+ , nodeLabel
+ , edgeFrom, edgeTo, edgeLabel
+ , reverseGraph, mergeGraphs, renameNodes
+ ) where
+
+import GF.Data.Utilities
+
+import Data.List
+import Data.Maybe
+import Data.Map (Map)
+import qualified Data.Map as Map
+import Data.Set (Set)
+import qualified Data.Set as Set
+
+data Graph n a b = Graph [n] ![Node n a] ![Edge n b]
+ deriving (Eq,Show)
+
+type Node n a = (n,a)
+type Edge n b = (n,n,b)
+
+type NodeInfo n a b = Map n (a, [Edge n b], [Edge n b])
+
+-- | Create a new empty graph.
+newGraph :: [n] -> Graph n a b
+newGraph ns = Graph ns [] []
+
+-- | Get all the nodes in the graph.
+nodes :: Graph n a b -> [Node n a]
+nodes (Graph _ ns _) = ns
+
+-- | Get all the edges in the graph.
+edges :: Graph n a b -> [Edge n b]
+edges (Graph _ _ es) = es
+
+-- | Map a function over the node labels.
+nmap :: (a -> c) -> Graph n a b -> Graph n c b
+nmap f (Graph c ns es) = Graph c [(n,f l) | (n,l) <- ns] es
+
+-- | Map a function over the edge labels.
+emap :: (b -> c) -> Graph n a b -> Graph n a c
+emap f (Graph c ns es) = Graph c ns [(x,y,f l) | (x,y,l) <- es]
+
+-- | Add a node to the graph.
+newNode :: a -- ^ Node label
+ -> Graph n a b
+ -> (Graph n a b,n) -- ^ Node graph and name of new node
+newNode l (Graph (c:cs) ns es) = (Graph cs ((c,l):ns) es, c)
+
+newNodes :: [a] -> Graph n a b -> (Graph n a b,[Node n a])
+newNodes ls g = (g', zip ns ls)
+ where (g',ns) = mapAccumL (flip newNode) g ls
+-- lazy version:
+--newNodes ls (Graph cs ns es) = (Graph cs' (ns'++ns) es, ns')
+-- where (xs,cs') = splitAt (length ls) cs
+-- ns' = zip xs ls
+
+newEdge :: Edge n b -> Graph n a b -> Graph n a b
+newEdge e (Graph c ns es) = Graph c ns (e:es)
+
+newEdges :: [Edge n b] -> Graph n a b -> Graph n a b
+newEdges es g = foldl' (flip newEdge) g es
+-- lazy version:
+-- newEdges es' (Graph c ns es) = Graph c ns (es'++es)
+
+insertEdgeWith :: Eq n =>
+ (b -> b -> b) -> Edge n b -> Graph n a b -> Graph n a b
+insertEdgeWith f e@(x,y,l) (Graph c ns es) = Graph c ns (h es)
+ where h [] = [e]
+ h (e'@(x',y',l'):es') | x' == x && y' == y = (x',y', f l l'):es'
+ | otherwise = e':h es'
+
+-- | Remove a node and all edges to and from that node.
+removeNode :: Ord n => n -> Graph n a b -> Graph n a b
+removeNode n = removeNodes (Set.singleton n)
+
+-- | Remove a set of nodes and all edges to and from those nodes.
+removeNodes :: Ord n => Set n -> Graph n a b -> Graph n a b
+removeNodes xs (Graph c ns es) = Graph c ns' es'
+ where
+ keepNode n = not (Set.member n xs)
+ ns' = [ x | x@(n,_) <- ns, keepNode n ]
+ es' = [ e | e@(f,t,_) <- es, keepNode f && keepNode t ]
+
+-- | Get a map of node names to info about each node.
+nodeInfo :: Ord n => Graph n a b -> NodeInfo n a b
+nodeInfo g = Map.fromList [ (n, (x, fn inc n, fn out n)) | (n,x) <- nodes g ]
+ where
+ inc = groupEdgesBy edgeTo g
+ out = groupEdgesBy edgeFrom g
+ fn m n = fromMaybe [] (Map.lookup n m)
+
+groupEdgesBy :: (Ord n) => (Edge n b -> n) -- ^ Gets the node to group by
+ -> Graph n a b -> Map n [Edge n b]
+groupEdgesBy f g = Map.fromListWith (++) [(f e, [e]) | e <- edges g]
+
+lookupNode :: Ord n => NodeInfo n a b -> n -> (a, [Edge n b], [Edge n b])
+lookupNode i n = fromJust $ Map.lookup n i
+
+getIncoming :: Ord n => NodeInfo n a b -> n -> [Edge n b]
+getIncoming i n = let (_,inc,_) = lookupNode i n in inc
+
+getOutgoing :: Ord n => NodeInfo n a b -> n -> [Edge n b]
+getOutgoing i n = let (_,_,out) = lookupNode i n in out
+
+inDegree :: Ord n => NodeInfo n a b -> n -> Int
+inDegree i n = length $ getIncoming i n
+
+outDegree :: Ord n => NodeInfo n a b -> n -> Int
+outDegree i n = length $ getOutgoing i n
+
+getNodeLabel :: Ord n => NodeInfo n a b -> n -> a
+getNodeLabel i n = let (l,_,_) = lookupNode i n in l
+
+nodeLabel :: Node n a -> a
+nodeLabel = snd
+
+edgeFrom :: Edge n b -> n
+edgeFrom (f,_,_) = f
+
+edgeTo :: Edge n b -> n
+edgeTo (_,t,_) = t
+
+edgeLabel :: Edge n b -> b
+edgeLabel (_,_,l) = l
+
+reverseGraph :: Graph n a b -> Graph n a b
+reverseGraph (Graph c ns es) = Graph c ns [ (t,f,l) | (f,t,l) <- es ]
+
+-- | Add the nodes from the second graph to the first graph.
+-- The nodes in the second graph will be renamed using the name
+-- supply in the first graph.
+-- This function is more efficient when the second graph
+-- is smaller than the first.
+mergeGraphs :: Ord m => Graph n a b -> Graph m a b
+ -> (Graph n a b, m -> n) -- ^ The new graph and a function translating
+ -- the old names of nodes in the second graph
+ -- to names in the new graph.
+mergeGraphs (Graph c ns1 es1) g2 = (Graph c' (ns2++ns1) (es2++es1), newName)
+ where
+ (xs,c') = splitAt (length (nodes g2)) c
+ newNames = Map.fromList (zip (map fst (nodes g2)) xs)
+ newName n = fromJust $ Map.lookup n newNames
+ Graph _ ns2 es2 = renameNodes newName undefined g2
+
+-- | Rename the nodes in the graph.
+renameNodes :: (n -> m) -- ^ renaming function
+ -> [m] -- ^ infinite supply of fresh node names, to
+ -- use when adding nodes in the future.
+ -> Graph n a b -> Graph m a b
+renameNodes newName c (Graph _ ns es) = Graph c ns' es'
+ where ns' = map' (\ (n,x) -> (newName n,x)) ns
+ es' = map' (\ (f,t,l) -> (newName f, newName t, l)) es
+
+-- | A strict 'map'
+map' :: (a -> b) -> [a] -> [b]
+map' _ [] = []
+map' f (x:xs) = ((:) $! f x) $! map' f xs
diff --git a/src-2.9/GF/Speech/PrFA.hs b/src-2.9/GF/Speech/PrFA.hs
new file mode 100644
index 000000000..2856039ec
--- /dev/null
+++ b/src-2.9/GF/Speech/PrFA.hs
@@ -0,0 +1,56 @@
+----------------------------------------------------------------------
+-- |
+-- Module : PrSLF
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/10 16:43:44 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.2 $
+--
+-- This module prints finite automata and regular grammars
+-- for a context-free grammar.
+--
+-- FIXME: remove \/ warn \/ fail if there are int \/ string literal
+-- categories in the grammar
+-----------------------------------------------------------------------------
+
+module GF.Speech.PrFA (faGraphvizPrinter,regularPrinter,faCPrinter) where
+
+import GF.Data.Utilities
+import GF.Conversion.Types
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..),symbol)
+import GF.Infra.Ident
+import GF.Infra.Option (Options)
+import GF.Infra.Print
+import GF.Speech.CFGToFiniteState
+import GF.Speech.FiniteState
+import GF.Speech.TransformCFG
+import GF.Compile.ShellState (StateGrammar)
+
+import Data.Char (toUpper,toLower)
+import Data.List
+import Data.Maybe (fromMaybe)
+
+
+
+faGraphvizPrinter :: Options -> StateGrammar -> String
+faGraphvizPrinter opts s =
+ prFAGraphviz $ mapStates (const "") $ cfgToFA opts s
+
+-- | Convert the grammar to a regular grammar and print it in BNF
+regularPrinter :: Options -> StateGrammar -> String
+regularPrinter opts s = prCFRules $ makeSimpleRegular opts s
+ where
+ prCFRules :: CFRules -> String
+ prCFRules g = unlines [ c ++ " ::= " ++ join " | " (map (showRhs . ruleRhs) rs) | (c,rs) <- allRulesGrouped g]
+ join g = concat . intersperse g
+ showRhs = unwords . map (symbol id show)
+
+faCPrinter :: Options -> StateGrammar -> String
+faCPrinter opts s = fa2c $ cfgToFA opts s
+
+fa2c :: DFA String -> String
+fa2c fa = undefined
diff --git a/src-2.9/GF/Speech/PrGSL.hs b/src-2.9/GF/Speech/PrGSL.hs
new file mode 100644
index 000000000..248991380
--- /dev/null
+++ b/src-2.9/GF/Speech/PrGSL.hs
@@ -0,0 +1,113 @@
+----------------------------------------------------------------------
+-- |
+-- Module : PrGSL
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/01 20:09:04 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.22 $
+--
+-- This module prints a CFG as a Nuance GSL 2.0 grammar.
+--
+-- FIXME: remove \/ warn \/ fail if there are int \/ string literal
+-- categories in the grammar
+-----------------------------------------------------------------------------
+
+module GF.Speech.PrGSL (gslPrinter) where
+
+import GF.Data.Utilities
+import GF.Speech.SRG
+import GF.Speech.RegExp
+import GF.Infra.Ident
+
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..))
+import GF.Conversion.Types
+import GF.Infra.Print
+import GF.Infra.Option
+import GF.Probabilistic.Probabilistic (Probs)
+import GF.Compile.ShellState (StateGrammar)
+
+import Data.Char (toUpper,toLower)
+import Data.List (partition)
+import Text.PrettyPrint.HughesPJ
+
+width :: Int
+width = 75
+
+gslPrinter :: Options -> StateGrammar -> String
+gslPrinter opts s = renderStyle st $ prGSL $ makeSimpleSRG opts s
+ where st = style { lineLength = width }
+
+prGSL :: SRG -> Doc
+prGSL (SRG{grammarName=name,startCat=start,origStartCat=origStart,rules=rs})
+ = header $++$ mainCat $++$ foldr ($++$) empty (map prRule rs)
+ where
+ header = text ";GSL2.0" $$
+ comment ("Nuance speech recognition grammar for " ++ name) $$
+ comment ("Generated by GF")
+ mainCat = comment ("Start category: " ++ origStart) $$
+ text ".MAIN" <+> prCat start
+ prRule (SRGRule cat origCat rhs) =
+ comment (prt origCat) $$
+ prCat cat <+> union (map prAlt rhs)
+ -- FIXME: use the probability
+ prAlt (SRGAlt mp _ rhs) = prItem rhs
+
+
+prItem :: SRGItem -> Doc
+prItem = f
+ where
+ f (REUnion xs) = (if null es then empty else text "?") <> union (map f nes)
+ where (es,nes) = partition isEpsilon xs
+ f (REConcat [x]) = f x
+ f (REConcat xs) = text "(" <> fsep (map f xs) <> text ")"
+ f (RERepeat x) = text "*" <> f x
+ f (RESymbol s) = prSymbol s
+
+union :: [Doc] -> Doc
+union [x] = x
+union xs = text "[" <> fsep xs <> text "]"
+
+prSymbol :: Symbol SRGNT Token -> Doc
+prSymbol (Cat (c,_)) = prCat c
+prSymbol (Tok t) = doubleQuotes (showToken t)
+
+-- GSL requires an upper case letter in category names
+prCat :: SRGCat -> Doc
+prCat c = text (firstToUpper c)
+
+
+firstToUpper :: String -> String
+firstToUpper [] = []
+firstToUpper (x:xs) = toUpper x : xs
+
+{-
+rmPunctCFG :: CGrammar -> CGrammar
+rmPunctCFG g = [CFRule c (filter keepSymbol ss) n | CFRule c ss n <- g]
+
+keepSymbol :: Symbol c Token -> Bool
+keepSymbol (Tok t) = not (all isPunct (prt t))
+keepSymbol _ = True
+-}
+
+-- Nuance does not like upper case characters in tokens
+showToken :: Token -> Doc
+showToken t = text (map toLower (prt t))
+
+isPunct :: Char -> Bool
+isPunct c = c `elem` "-_.:;.,?!()[]{}"
+
+comment :: String -> Doc
+comment s = text ";" <+> text s
+
+
+-- Pretty-printing utilities
+
+emptyLine :: Doc
+emptyLine = text ""
+
+($++$) :: Doc -> Doc -> Doc
+x $++$ y = x $$ emptyLine $$ y
diff --git a/src-2.9/GF/Speech/PrJSGF.hs b/src-2.9/GF/Speech/PrJSGF.hs
new file mode 100644
index 000000000..037a4f4e2
--- /dev/null
+++ b/src-2.9/GF/Speech/PrJSGF.hs
@@ -0,0 +1,145 @@
+----------------------------------------------------------------------
+-- |
+-- Module : PrJSGF
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/01 20:09:04 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.16 $
+--
+-- This module prints a CFG as a JSGF grammar.
+--
+-- FIXME: remove \/ warn \/ fail if there are int \/ string literal
+-- categories in the grammar
+--
+-- FIXME: convert to UTF-8
+-----------------------------------------------------------------------------
+
+module GF.Speech.PrJSGF (jsgfPrinter) where
+
+import GF.Conversion.Types
+import GF.Data.Utilities
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..), NameProfile(..), Profile(..), filterCats)
+import GF.Infra.Ident
+import GF.Infra.Print
+import GF.Infra.Option
+import GF.Probabilistic.Probabilistic (Probs)
+import GF.Speech.SISR
+import GF.Speech.SRG
+import GF.Speech.RegExp
+import GF.Compile.ShellState (StateGrammar)
+
+import Data.Char
+import Data.List
+import Data.Maybe
+import Text.PrettyPrint.HughesPJ
+import Debug.Trace
+
+width :: Int
+width = 75
+
+jsgfPrinter :: Maybe SISRFormat
+ -> Options
+ -> StateGrammar -> String
+jsgfPrinter sisr opts s = renderStyle st $ prJSGF sisr $ makeSimpleSRG opts s
+ where st = style { lineLength = width }
+
+prJSGF :: Maybe SISRFormat -> SRG -> Doc
+prJSGF sisr srg@(SRG{grammarName=name,grammarLanguage=ml,
+ startCat=start,origStartCat=origStart,rules=rs})
+ = header $++$ mainCat $++$ vcat topCatRules $++$ foldr ($++$) empty (map prRule rs)
+ where
+ header = text "#JSGF" <+> text "V1.0" <+> text "UTF-8" <+> lang <> char ';' $$
+ comment ("JSGF speech recognition grammar for " ++ name) $$
+ comment "Generated by GF" $$
+ text ("grammar " ++ name ++ ";")
+ lang = maybe empty text ml
+ mainCat = comment ("Start category: " ++ origStart) $$
+ case cfgCatToGFCat origStart of
+ Just c -> rule True "MAIN" [prCat (catFormId c)]
+ Nothing -> empty
+ prRule (SRGRule cat origCat rhs) =
+ comment origCat $$
+ rule False cat (map prAlt rhs)
+-- rule False cat (map prAlt rhs)
+ -- FIXME: use the probability
+ prAlt (SRGAlt mp n rhs) = sep [initTag, p (prItem sisr n rhs), finalTag]
+-- prAlt (SRGAlt mp n rhs) = initTag <+> prItem sisr n rhs <+> finalTag
+ where initTag | isEmpty t = empty
+ | otherwise = text "" <+> t
+ where t = tag sisr (profileInitSISR n)
+ finalTag = tag sisr (profileFinalSISR n)
+ p = if isEmpty initTag && isEmpty finalTag then id else parens
+
+ topCatRules = [rule True (catFormId tc) (map (it tc) cs) | (tc,cs) <- srgTopCats srg]
+ where it i c = prCat c <+> tag sisr (topCatSISR c)
+
+catFormId :: String -> String
+catFormId = (++ "_cat")
+
+prCat :: SRGCat -> Doc
+prCat c = char '<' <> text c <> char '>'
+
+prItem :: Maybe SISRFormat -> CFTerm -> SRGItem -> Doc
+prItem sisr t = f 0
+ where
+ f _ (REUnion []) = text ""
+ f p (REUnion xs)
+ | not (null es) = brackets (f 0 (REUnion nes))
+ | otherwise = (if p >= 1 then parens else id) (alts (map (f 1) xs))
+ where (es,nes) = partition isEpsilon xs
+ f _ (REConcat []) = text ""
+ f p (REConcat xs) = (if p >= 3 then parens else id) (fsep (map (f 2) xs))
+ f p (RERepeat x) = f 3 x <> char '*'
+ f _ (RESymbol s) = prSymbol sisr t s
+
+{-
+prItem :: Maybe SISRFormat -> CFTerm -> [Symbol SRGNT Token] -> Doc
+prItem _ _ [] = text ""
+prItem sisr cn ss = paren $ hsep $ map (prSymbol sisr cn) ss
+ where paren = if length ss == 1 then id else parens
+-}
+
+prSymbol :: Maybe SISRFormat -> CFTerm -> Symbol SRGNT Token -> Doc
+prSymbol sisr cn (Cat n@(c,_)) = prCat c <+> tag sisr (catSISR cn n)
+prSymbol _ cn (Tok t) | all isPunct (prt t) = empty -- removes punctuation
+ | otherwise = text (prt t) -- FIXME: quote if there is whitespace or odd chars
+
+tag :: Maybe SISRFormat -> (SISRFormat -> SISRTag) -> Doc
+tag Nothing _ = empty
+tag (Just fmt) t = case t fmt of
+ [] -> empty
+ ts -> char '{' <+> (text (e $ prSISR ts)) <+> char '}'
+ where e [] = []
+ e ('}':xs) = '\\':'}':e xs
+ e ('\n':xs) = ' ' : e (dropWhile isSpace xs)
+ e (x:xs) = x:e xs
+
+isPunct :: Char -> Bool
+isPunct c = c `elem` "-_.;.,?!"
+
+comment :: String -> Doc
+comment s = text "//" <+> text s
+
+alts :: [Doc] -> Doc
+alts = fsep . prepunctuate (text "| ")
+
+rule :: Bool -> SRGCat -> [Doc] -> Doc
+rule pub c xs = p <+> prCat c <+> char '=' <+> nest 2 (alts xs) <+> char ';'
+ where p = if pub then text "public" else empty
+
+-- Pretty-printing utilities
+
+emptyLine :: Doc
+emptyLine = text ""
+
+prepunctuate :: Doc -> [Doc] -> [Doc]
+prepunctuate _ [] = []
+prepunctuate p (x:xs) = x : map (p <>) xs
+
+($++$) :: Doc -> Doc -> Doc
+x $++$ y = x $$ emptyLine $$ y
+
diff --git a/src-2.9/GF/Speech/PrRegExp.hs b/src-2.9/GF/Speech/PrRegExp.hs
new file mode 100644
index 000000000..55a25d69b
--- /dev/null
+++ b/src-2.9/GF/Speech/PrRegExp.hs
@@ -0,0 +1,33 @@
+----------------------------------------------------------------------
+-- |
+-- Module : PrSLF
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- This module prints a grammar as a regular expression.
+-----------------------------------------------------------------------------
+
+module GF.Speech.PrRegExp (regexpPrinter,multiRegexpPrinter) where
+
+import GF.Conversion.Types
+import GF.Formalism.Utilities
+import GF.Infra.Ident
+import GF.Infra.Option (Options)
+import GF.Speech.CFGToFiniteState
+import GF.Speech.RegExp
+import GF.Compile.ShellState (StateGrammar)
+
+
+regexpPrinter :: Options -> StateGrammar -> String
+regexpPrinter opts s = (++"\n") $ prRE $ dfa2re $ cfgToFA opts s
+
+multiRegexpPrinter :: Options -> StateGrammar -> String
+multiRegexpPrinter opts s = prREs $ mfa2res $ cfgToMFA opts s
+
+prREs :: [(String,RE (MFALabel String))] -> String
+prREs res = unlines [l ++ " = " ++ prRE (mapRE showLabel re) | (l,re) <- res]
+ where showLabel = symbol (\l -> "<" ++ l ++ ">") id
+
+mfa2res :: MFA String -> [(String,RE (MFALabel String))]
+mfa2res (MFA _ dfas) = [(l, minimizeRE (dfa2re dfa)) | (l,dfa) <- dfas]
diff --git a/src-2.9/GF/Speech/PrSLF.hs b/src-2.9/GF/Speech/PrSLF.hs
new file mode 100644
index 000000000..9bc025558
--- /dev/null
+++ b/src-2.9/GF/Speech/PrSLF.hs
@@ -0,0 +1,190 @@
+----------------------------------------------------------------------
+-- |
+-- Module : PrSLF
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/10 16:43:44 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.12 $
+--
+-- This module converts a CFG to an SLF finite-state network
+-- for use with the ATK recognizer. The SLF format is described
+-- in the HTK manual, and an example for use in ATK is shown
+-- in the ATK manual.
+--
+-- FIXME: remove \/ warn \/ fail if there are int \/ string literal
+-- categories in the grammar
+-----------------------------------------------------------------------------
+
+module GF.Speech.PrSLF (slfPrinter,slfGraphvizPrinter,
+ slfSubPrinter,slfSubGraphvizPrinter) where
+
+import GF.Data.Utilities
+import GF.Conversion.Types
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..),symbol,mapSymbol)
+import GF.Infra.Ident
+import GF.Infra.Option (Options)
+import GF.Infra.Print
+import GF.Speech.CFGToFiniteState
+import GF.Speech.FiniteState
+import GF.Speech.TransformCFG
+import qualified GF.Visualization.Graphviz as Dot
+import GF.Compile.ShellState (StateGrammar)
+
+import Control.Monad
+import qualified Control.Monad.State as STM
+import Data.Char (toUpper)
+import Data.List
+import Data.Maybe
+
+data SLFs = SLFs [(String,SLF)] SLF
+
+data SLF = SLF { slfNodes :: [SLFNode], slfEdges :: [SLFEdge] }
+
+data SLFNode = SLFNode { nId :: Int, nWord :: SLFWord, nTag :: Maybe String }
+ | SLFSubLat { nId :: Int, nLat :: String }
+
+-- | An SLF word is a word, or the empty string.
+type SLFWord = Maybe String
+
+data SLFEdge = SLFEdge { eId :: Int, eStart :: Int, eEnd :: Int }
+
+type SLF_FA = FA State (Maybe (MFALabel String)) ()
+
+mkFAs :: Options -> StateGrammar -> (SLF_FA, [(String,SLF_FA)])
+mkFAs opts s = (slfStyleFA main, [(c,slfStyleFA n) | (c,n) <- subs])
+ where MFA start subs = {- renameSubs $ -} cfgToMFA opts s
+ main = let (fa,s,f) = newFA_ in newTransition s f (Cat start) fa
+
+slfStyleFA :: Eq a => DFA a -> FA State (Maybe a) ()
+slfStyleFA = renameStates [0..] . removeTrivialEmptyNodes . oneFinalState Nothing ()
+ . moveLabelsToNodes . dfa2nfa
+
+-- | Give sequential names to subnetworks.
+renameSubs :: MFA String -> MFA String
+renameSubs (MFA start subs) = MFA (newName start) subs'
+ where newNames = zip (map fst subs) ["sub"++show n | n <- [0..]]
+ newName s = lookup' s newNames
+ subs' = [(newName s,renameLabels n) | (s,n) <- subs]
+ renameLabels = mapTransitions (mapSymbol newName id)
+
+--
+-- * SLF graphviz printing (without sub-networks)
+--
+
+slfGraphvizPrinter :: Options -> StateGrammar -> String
+slfGraphvizPrinter opts s
+ = prFAGraphviz $ gvFA $ slfStyleFA $ cfgToFA' opts s
+ where
+ gvFA = mapStates (fromMaybe "") . mapTransitions (const "")
+
+--
+-- * SLF graphviz printing (with sub-networks)
+--
+
+slfSubGraphvizPrinter :: Options -> StateGrammar -> String
+slfSubGraphvizPrinter opts s = Dot.prGraphviz g
+ where (main, subs) = mkFAs opts s
+ g = STM.evalState (liftM2 Dot.addSubGraphs ss m) [0..]
+ ss = mapM (\ (c,f) -> gvSLFFA (Just c) f) subs
+ m = gvSLFFA Nothing main
+
+gvSLFFA :: Maybe String -> SLF_FA -> STM.State [State] Dot.Graph
+gvSLFFA n fa =
+ liftM (mkCluster n . faToGraphviz . mapStates (maybe "" mfaLabelToGv)
+ . mapTransitions (const "")) (rename fa)
+ where mfaLabelToGv = symbol ("#"++) id
+ mkCluster Nothing = id
+ mkCluster (Just x)
+ = Dot.setName ("cluster_"++x) . Dot.setAttr "label" x
+ rename fa = do
+ names <- STM.get
+ let fa' = renameStates names fa
+ names' = unusedNames fa'
+ STM.put names'
+ return fa'
+
+--
+-- * SLF printing (without sub-networks)
+--
+
+slfPrinter :: Options -> StateGrammar -> String
+slfPrinter opts s
+ = prSLF $ automatonToSLF mkSLFNode $ slfStyleFA $ cfgToFA' opts s
+
+--
+-- * SLF printing (with sub-networks)
+--
+
+-- | Make a network with subnetworks in SLF
+slfSubPrinter :: Options -> StateGrammar -> String
+slfSubPrinter opts s = prSLFs slfs
+ where
+ (main,subs) = mkFAs opts s
+ slfs = SLFs [(c, faToSLF fa) | (c,fa) <- subs] (faToSLF main)
+ faToSLF = automatonToSLF mfaNodeToSLFNode
+
+automatonToSLF :: (Int -> a -> SLFNode) -> FA State a () -> SLF
+automatonToSLF mkNode fa = SLF { slfNodes = ns, slfEdges = es }
+ where ns = map (uncurry mkNode) (states fa)
+ es = zipWith (\i (f,t,()) -> mkSLFEdge i (f,t)) [0..] (transitions fa)
+
+mfaNodeToSLFNode :: Int -> Maybe (MFALabel String) -> SLFNode
+mfaNodeToSLFNode i l = case l of
+ Nothing -> mkSLFNode i Nothing
+ Just (Tok x) -> mkSLFNode i (Just x)
+ Just (Cat s) -> mkSLFSubLat i s
+
+mkSLFNode :: Int -> Maybe String -> SLFNode
+mkSLFNode i Nothing = SLFNode { nId = i, nWord = Nothing, nTag = Nothing }
+mkSLFNode i (Just w)
+ | isNonWord w = SLFNode { nId = i,
+ nWord = Nothing,
+ nTag = Just w }
+ | otherwise = SLFNode { nId = i,
+ nWord = Just (map toUpper w),
+ nTag = Just w }
+
+mkSLFSubLat :: Int -> String -> SLFNode
+mkSLFSubLat i sub = SLFSubLat { nId = i, nLat = sub }
+
+mkSLFEdge :: Int -> (Int,Int) -> SLFEdge
+mkSLFEdge i (f,t) = SLFEdge { eId = i, eStart = f, eEnd = t }
+
+prSLFs :: SLFs -> String
+prSLFs (SLFs subs main) = unlinesS (map prSub subs ++ [prOneSLF main]) ""
+ where prSub (n,s) = showString "SUBLAT=" . shows n
+ . nl . prOneSLF s . showString "." . nl
+
+prSLF :: SLF -> String
+prSLF slf = prOneSLF slf ""
+
+prOneSLF :: SLF -> ShowS
+prOneSLF (SLF { slfNodes = ns, slfEdges = es})
+ = header . unlinesS (map prNode ns) . nl . unlinesS (map prEdge es) . nl
+ where
+ header = prFields [("N",show (length ns)),("L", show (length es))] . nl
+ prNode (SLFNode { nId = i, nWord = w, nTag = t })
+ = prFields $ [("I",show i),("W",showWord w)]
+ ++ maybe [] (\t -> [("s",t)]) t
+ prNode (SLFSubLat { nId = i, nLat = l })
+ = prFields [("I",show i),("L",show l)]
+ prEdge e = prFields [("J",show (eId e)),("S",show (eStart e)),("E",show (eEnd e))]
+
+-- | Check if a word should not correspond to a word in the SLF file.
+isNonWord :: String -> Bool
+isNonWord = any isPunct
+
+isPunct :: Char -> Bool
+isPunct c = c `elem` "-_.;.,?!()[]{}"
+
+showWord :: SLFWord -> String
+showWord Nothing = "!NULL"
+showWord (Just w) | null w = "!NULL"
+ | otherwise = w
+
+prFields :: [(String,String)] -> ShowS
+prFields fs = unwordsS [ showString l . showChar '=' . showString v | (l,v) <- fs ]
diff --git a/src-2.9/GF/Speech/PrSRGS.hs b/src-2.9/GF/Speech/PrSRGS.hs
new file mode 100644
index 000000000..d8ae07867
--- /dev/null
+++ b/src-2.9/GF/Speech/PrSRGS.hs
@@ -0,0 +1,153 @@
+----------------------------------------------------------------------
+-- |
+-- Module : PrSRGS
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- This module prints a CFG as an SRGS XML grammar.
+--
+-- FIXME: remove \/ warn \/ fail if there are int \/ string literal
+-- categories in the grammar
+-----------------------------------------------------------------------------
+
+module GF.Speech.PrSRGS (srgsXmlPrinter, srgsXmlNonRecursivePrinter) where
+
+import GF.Data.Utilities
+import GF.Data.XML
+import GF.Speech.RegExp
+import GF.Speech.SISR as SISR
+import GF.Speech.SRG
+import GF.Infra.Ident
+import GF.Today
+
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..), NameProfile(..), Profile(..), forestName, filterCats)
+import GF.Conversion.Types
+import GF.Infra.Print
+import GF.Infra.Option
+import GF.Probabilistic.Probabilistic (Probs)
+import GF.Compile.ShellState (StateGrammar)
+
+import Data.Char (toUpper,toLower)
+import Data.List
+import Data.Maybe
+import qualified Data.Map as Map
+import qualified Data.Set as Set
+
+srgsXmlPrinter :: Maybe SISRFormat
+ -> Bool -- ^ Include probabilities
+ -> Options
+ -> StateGrammar -> String
+srgsXmlPrinter sisr probs opts s = prSrgsXml sisr probs $ makeSimpleSRG opts s
+
+srgsXmlNonRecursivePrinter :: Options -> StateGrammar -> String
+srgsXmlNonRecursivePrinter opts s = prSrgsXml Nothing False $ makeNonRecursiveSRG opts s
+
+
+prSrgsXml :: Maybe SISRFormat -> Bool -> SRG -> String
+prSrgsXml sisr probs srg@(SRG{grammarName=name,startCat=start,
+ origStartCat=origStart,grammarLanguage=l,rules=rs})
+ = showXMLDoc (optimizeSRGS xmlGr)
+ where
+ Just root = cfgCatToGFCat origStart
+ xmlGr = grammar sisr (catFormId root) l $
+ [meta "description"
+ ("SRGS XML speech recognition grammar for " ++ name
+ ++ ". " ++ "Original start category: " ++ origStart),
+ meta "generator" ("Grammatical Framework " ++ version)]
+ ++ topCatRules
+ ++ concatMap ruleToXML rs
+ ruleToXML (SRGRule cat origCat alts) =
+ comments ["Category " ++ origCat] ++ [rule cat (prRhs alts)]
+ prRhs rhss = [oneOf (map (mkProd sisr probs) rhss)]
+ -- externally visible rules for each of the GF categories
+ topCatRules = [topRule tc [oneOf (map (it tc) cs)] | (tc,cs) <- srgTopCats srg]
+ where it i c = Tag "item" [] ([ETag "ruleref" [("uri","#" ++ c)]]
+ ++ tag sisr (topCatSISR c))
+ topRule i is = Tag "rule" [("id",catFormId i),("scope","public")] is
+
+rule :: String -> [XML] -> XML
+rule i = Tag "rule" [("id",i)]
+
+mkProd :: Maybe SISRFormat -> Bool -> SRGAlt -> XML
+mkProd sisr probs (SRGAlt mp n rhs) = Tag "item" w (ti ++ [x] ++ tf)
+ where x = mkItem sisr n rhs
+ w | probs = maybe [] (\p -> [("weight", show p)]) mp
+ | otherwise = []
+ ti = tag sisr (profileInitSISR n)
+ tf = tag sisr (profileFinalSISR n)
+
+mkItem :: Maybe SISRFormat -> CFTerm -> SRGItem -> XML
+mkItem sisr cn = f
+ where
+ f (REUnion []) = ETag "ruleref" [("special","VOID")]
+ f (REUnion xs)
+ | not (null es) = Tag "item" [("repeat","0-1")] [f (REUnion nes)]
+ | otherwise = oneOf (map f xs)
+ where (es,nes) = partition isEpsilon xs
+ f (REConcat []) = ETag "ruleref" [("special","NULL")]
+ f (REConcat xs) = Tag "item" [] (map f xs)
+ f (RERepeat x) = Tag "item" [("repeat","0-")] [f x]
+ f (RESymbol s) = symItem sisr cn s
+
+{-
+mkProd :: Maybe SISRFormat -> Bool -> SRGAlt -> XML
+mkProd sisr probs (SRGAlt mp n rhs) = Tag "item" w (ti ++ xs ++ tf)
+ where xs = mkItem sisr n rhs
+ w | probs = maybe [] (\p -> [("weight", show p)]) mp
+ | otherwise = []
+ ti = [tag sisr (profileInitSISR n)]
+ tf = [tag sisr (profileFinalSISR n)]
+
+
+mkItem :: Maybe SISRFormat -> CFTerm -> [Symbol SRGNT Token] -> [XML]
+mkItem sisr cn ss = map (symItem sisr cn) ss
+-}
+
+symItem :: Maybe SISRFormat -> CFTerm -> Symbol SRGNT Token -> XML
+symItem sisr cn (Cat n@(c,_)) =
+ Tag "item" [] $ [ETag "ruleref" [("uri","#" ++ c)]] ++ tag sisr (catSISR cn n)
+symItem _ _ (Tok t) = Tag "item" [] [Data (showToken t)]
+
+tag :: Maybe SISRFormat -> (SISRFormat -> SISRTag) -> [XML]
+tag Nothing _ = []
+tag (Just fmt) t = case t fmt of
+ [] -> []
+ ts -> [Tag "tag" [] [Data (prSISR ts)]]
+
+catFormId :: String -> String
+catFormId = (++ "_cat")
+
+
+showToken :: Token -> String
+showToken t = t
+
+oneOf :: [XML] -> XML
+oneOf = Tag "one-of" []
+
+grammar :: Maybe SISRFormat
+ -> String -- ^ root
+ -> Maybe String -- ^language
+ -> [XML] -> XML
+grammar sisr root ml =
+ Tag "grammar" $ [("xmlns","http://www.w3.org/2001/06/grammar"),
+ ("version","1.0"),
+ ("mode","voice"),
+ ("root",root)]
+ ++ (if isJust sisr then [("tag-format","semantics/1.0")] else [])
+ ++ maybe [] (\l -> [("xml:lang", l)]) ml
+
+meta :: String -> String -> XML
+meta n c = ETag "meta" [("name",n),("content",c)]
+
+optimizeSRGS :: XML -> XML
+optimizeSRGS = bottomUpXML f
+ where f (Tag "item" [] [x@(Tag "item" _ _)]) = x
+ f (Tag "item" [] [x@(Tag "one-of" _ _)]) = x
+ f (Tag "item" as [Tag "item" [] xs]) = Tag "item" as xs
+ f (Tag "item" as xs) = Tag "item" as (map g xs)
+ where g (Tag "item" [] [x@(ETag "ruleref" _)]) = x
+ g x = x
+ f (Tag "one-of" [] [x]) = x
+ f x = x
diff --git a/src-2.9/GF/Speech/PrSRGS_ABNF.hs b/src-2.9/GF/Speech/PrSRGS_ABNF.hs
new file mode 100644
index 000000000..abb84c5dc
--- /dev/null
+++ b/src-2.9/GF/Speech/PrSRGS_ABNF.hs
@@ -0,0 +1,147 @@
+----------------------------------------------------------------------
+-- |
+-- Module : PrJSRGS_ABNF
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/01 20:09:04 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.16 $
+--
+-- This module prints a CFG as a JSGF grammar.
+--
+-- FIXME: remove \/ warn \/ fail if there are int \/ string literal
+-- categories in the grammar
+--
+-- FIXME: convert to UTF-8
+-----------------------------------------------------------------------------
+
+module GF.Speech.PrSRGS_ABNF (srgsAbnfPrinter, srgsAbnfNonRecursivePrinter) where
+
+import GF.Conversion.Types
+import GF.Data.Utilities
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..), NameProfile(..), Profile(..), filterCats)
+import GF.Infra.Ident
+import GF.Infra.Print
+import GF.Infra.Option
+import GF.Probabilistic.Probabilistic (Probs)
+import GF.Speech.SISR
+import GF.Speech.SRG
+import GF.Speech.RegExp
+import GF.Compile.ShellState (StateGrammar)
+import GF.Today
+
+import Data.Char
+import Data.List
+import Data.Maybe
+import Text.PrettyPrint.HughesPJ
+import Debug.Trace
+
+width :: Int
+width = 75
+
+srgsAbnfPrinter :: Maybe SISRFormat
+ -> Bool -- ^ Include probabilities
+ -> Options
+ -> StateGrammar -> String
+srgsAbnfPrinter sisr probs opts s = showDoc $ prABNF sisr probs $ makeSimpleSRG opts s
+
+srgsAbnfNonRecursivePrinter :: Options -> StateGrammar -> String
+srgsAbnfNonRecursivePrinter opts s = showDoc $ prABNF Nothing False $ makeNonRecursiveSRG opts s
+
+showDoc = renderStyle (style { lineLength = width })
+
+prABNF :: Maybe SISRFormat -> Bool -> SRG -> Doc
+prABNF sisr probs srg@(SRG{grammarName=name,grammarLanguage=ml,
+ startCat=start,origStartCat=origStart,rules=rs})
+ = header $++$ vcat topCatRules $++$ foldr ($++$) empty (map prRule rs)
+ where
+ header = text "#ABNF 1.0 UTF-8;" $$
+ meta "description"
+ ("Speech recognition grammar for " ++ name
+ ++ ". " ++ "Original start category: " ++ origStart) $$
+ meta "generator" ("Grammatical Framework " ++ version) $$
+ language $$ tagFormat $$ mainCat
+ language = maybe empty (\l -> text "language" <+> text l <> char ';') ml
+ tagFormat | isJust sisr = text "tag-format" <+> text "" <> char ';'
+ | otherwise = empty
+ mainCat = case cfgCatToGFCat origStart of
+ Just c -> text "root" <+> prCat (catFormId c) <> char ';'
+ Nothing -> empty
+ prRule (SRGRule cat origCat rhs) =
+ comment origCat $$
+ rule False cat (map prAlt rhs)
+ -- FIXME: use the probability
+ prAlt (SRGAlt mp n rhs) = sep [initTag, p (prItem sisr n rhs), finalTag]
+ where initTag = tag sisr (profileInitSISR n)
+ finalTag = tag sisr (profileFinalSISR n)
+ p = if isEmpty initTag && isEmpty finalTag then id else parens
+
+ topCatRules = [rule True (catFormId tc) (map (it tc) cs) | (tc,cs) <- srgTopCats srg]
+ where it i c = prCat c <+> tag sisr (topCatSISR c)
+
+catFormId :: String -> String
+catFormId = (++ "_cat")
+
+prCat :: SRGCat -> Doc
+prCat c = char '$' <> text c
+
+prItem :: Maybe SISRFormat -> CFTerm -> SRGItem -> Doc
+prItem sisr t = f 0
+ where
+ f _ (REUnion []) = text "$VOID"
+ f p (REUnion xs)
+ | not (null es) = brackets (f 0 (REUnion nes))
+ | otherwise = (if p >= 1 then parens else id) (alts (map (f 1) xs))
+ where (es,nes) = partition isEpsilon xs
+ f _ (REConcat []) = text "$NULL"
+ f p (REConcat xs) = (if p >= 3 then parens else id) (fsep (map (f 2) xs))
+ f p (RERepeat x) = f 3 x <> text "<0->"
+ f _ (RESymbol s) = prSymbol sisr t s
+
+
+prSymbol :: Maybe SISRFormat -> CFTerm -> Symbol SRGNT Token -> Doc
+prSymbol sisr cn (Cat n@(c,_)) = prCat c <+> tag sisr (catSISR cn n)
+prSymbol _ cn (Tok t) | all isPunct (prt t) = empty -- removes punctuation
+ | otherwise = text (prt t) -- FIXME: quote if there is whitespace or odd chars
+
+tag :: Maybe SISRFormat -> (SISRFormat -> SISRTag) -> Doc
+tag Nothing _ = empty
+tag (Just fmt) t =
+ case t fmt of
+ [] -> empty
+ -- grr, silly SRGS ABNF does not have an escaping mechanism
+ ts | '{' `elem` x || '}' `elem` x -> text "{!{" <+> text x <+> text "}!}"
+ | otherwise -> text "{" <+> text x <+> text "}"
+ where x = prSISR ts
+
+isPunct :: Char -> Bool
+isPunct c = c `elem` "-_.;.,?!"
+
+comment :: String -> Doc
+comment s = text "//" <+> text s
+
+alts :: [Doc] -> Doc
+alts = fsep . prepunctuate (text "| ")
+
+rule :: Bool -> SRGCat -> [Doc] -> Doc
+rule pub c xs = p <+> prCat c <+> char '=' <+> nest 2 (alts xs) <+> char ';'
+ where p = if pub then text "public" else empty
+
+meta :: String -> String -> Doc
+meta n v = text "meta" <+> text (show n) <+> text "is" <+> text (show v) <> char ';'
+
+-- Pretty-printing utilities
+
+emptyLine :: Doc
+emptyLine = text ""
+
+prepunctuate :: Doc -> [Doc] -> [Doc]
+prepunctuate _ [] = []
+prepunctuate p (x:xs) = x : map (p <>) xs
+
+($++$) :: Doc -> Doc -> Doc
+x $++$ y = x $$ emptyLine $$ y
+
diff --git a/src-2.9/GF/Speech/RegExp.hs b/src-2.9/GF/Speech/RegExp.hs
new file mode 100644
index 000000000..5ee40828e
--- /dev/null
+++ b/src-2.9/GF/Speech/RegExp.hs
@@ -0,0 +1,143 @@
+module GF.Speech.RegExp (RE(..),
+ epsilonRE, nullRE,
+ isEpsilon, isNull,
+ unionRE, concatRE, seqRE,
+ repeatRE, minimizeRE,
+ mapRE, mapRE', joinRE,
+ symbolsRE,
+ dfa2re, prRE) where
+
+import Data.List
+
+import GF.Data.Utilities
+import GF.Speech.FiniteState
+
+data RE a =
+ REUnion [RE a] -- ^ REUnion [] is null
+ | REConcat [RE a] -- ^ REConcat [] is epsilon
+ | RERepeat (RE a)
+ | RESymbol a
+ deriving (Eq,Ord,Show)
+
+
+dfa2re :: (Ord a) => DFA a -> RE a
+dfa2re = finalRE . elimStates . modifyTransitions merge . addLoops
+ . oneFinalState () epsilonRE . mapTransitions RESymbol
+ where addLoops fa = newTransitions [(s,s,nullRE) | (s,_) <- states fa] fa
+ merge es = [(f,t,unionRE ls)
+ | ((f,t),ls) <- buildMultiMap [((f,t),l) | (f,t,l) <- es]]
+
+elimStates :: (Ord a) => DFA (RE a) -> DFA (RE a)
+elimStates fa =
+ case [s | (s,_) <- states fa, isInternal fa s] of
+ [] -> fa
+ sE:_ -> elimStates $ insertTransitionsWith (\x y -> unionRE [x,y]) ts $ removeState sE fa
+ where sAs = nonLoopTransitionsTo sE fa
+ sBs = nonLoopTransitionsFrom sE fa
+ r2 = unionRE $ loops sE fa
+ ts = [(sA, sB, r r1 r3) | (sA,r1) <- sAs, (sB,r3) <- sBs]
+ r r1 r3 = concatRE [r1, repeatRE r2, r3]
+
+epsilonRE :: RE a
+epsilonRE = REConcat []
+
+nullRE :: RE a
+nullRE = REUnion []
+
+isNull :: RE a -> Bool
+isNull (REUnion []) = True
+isNull _ = False
+
+isEpsilon :: RE a -> Bool
+isEpsilon (REConcat []) = True
+isEpsilon _ = False
+
+unionRE :: Ord a => [RE a] -> RE a
+unionRE = unionOrId . sortNub . concatMap toList
+ where
+ toList (REUnion xs) = xs
+ toList x = [x]
+ unionOrId [r] = r
+ unionOrId rs = REUnion rs
+
+concatRE :: [RE a] -> RE a
+concatRE xs | any isNull xs = nullRE
+ | otherwise = case concatMap toList xs of
+ [r] -> r
+ rs -> REConcat rs
+ where
+ toList (REConcat xs) = xs
+ toList x = [x]
+
+seqRE :: [a] -> RE a
+seqRE = concatRE . map RESymbol
+
+repeatRE :: RE a -> RE a
+repeatRE x | isNull x || isEpsilon x = epsilonRE
+ | otherwise = RERepeat x
+
+finalRE :: Ord a => DFA (RE a) -> RE a
+finalRE fa = concatRE [repeatRE r1, r2,
+ repeatRE (unionRE [r3, concatRE [r4, repeatRE r1, r2]])]
+ where
+ s0 = startState fa
+ [sF] = finalStates fa
+ r1 = unionRE $ loops s0 fa
+ r2 = unionRE $ map snd $ nonLoopTransitionsTo sF fa
+ r3 = unionRE $ loops sF fa
+ r4 = unionRE $ map snd $ nonLoopTransitionsFrom sF fa
+
+reverseRE :: RE a -> RE a
+reverseRE (REConcat xs) = REConcat $ map reverseRE $ reverse xs
+reverseRE (REUnion xs) = REUnion (map reverseRE xs)
+reverseRE (RERepeat x) = RERepeat (reverseRE x)
+reverseRE x = x
+
+minimizeRE :: Ord a => RE a -> RE a
+minimizeRE = reverseRE . mergeForward . reverseRE . mergeForward
+
+mergeForward :: Ord a => RE a -> RE a
+mergeForward (REUnion xs) =
+ unionRE [concatRE [mergeForward y,mergeForward (unionRE rs)] | (y,rs) <- buildMultiMap (map firstRE xs)]
+mergeForward (REConcat (x:xs)) = concatRE [mergeForward x,mergeForward (REConcat xs)]
+mergeForward (RERepeat r) = repeatRE (mergeForward r)
+mergeForward r = r
+
+firstRE :: RE a -> (RE a, RE a)
+firstRE (REConcat (x:xs)) = (x, REConcat xs)
+firstRE r = (r,epsilonRE)
+
+mapRE :: (a -> b) -> RE a -> RE b
+mapRE f = mapRE' (RESymbol . f)
+
+mapRE' :: (a -> RE b) -> RE a -> RE b
+mapRE' f (REConcat xs) = REConcat (map (mapRE' f) xs)
+mapRE' f (REUnion xs) = REUnion (map (mapRE' f) xs)
+mapRE' f (RERepeat x) = RERepeat (mapRE' f x)
+mapRE' f (RESymbol s) = f s
+
+joinRE :: RE (RE a) -> RE a
+joinRE (REConcat xs) = REConcat (map joinRE xs)
+joinRE (REUnion xs) = REUnion (map joinRE xs)
+joinRE (RERepeat xs) = RERepeat (joinRE xs)
+joinRE (RESymbol ss) = ss
+
+symbolsRE :: RE a -> [a]
+symbolsRE (REConcat xs) = concatMap symbolsRE xs
+symbolsRE (REUnion xs) = concatMap symbolsRE xs
+symbolsRE (RERepeat x) = symbolsRE x
+symbolsRE (RESymbol x) = [x]
+
+-- Debugging
+
+prRE :: RE String -> String
+prRE = prRE' 0
+
+prRE' _ (REUnion []) = ""
+prRE' n (REUnion xs) = p n 1 (concat (intersperse " | " (map (prRE' 1) xs)))
+prRE' n (REConcat xs) = p n 2 (unwords (map (prRE' 2) xs))
+prRE' n (RERepeat x) = p n 3 (prRE' 3 x) ++ "*"
+prRE' _ (RESymbol s) = s
+
+p n m s | n >= m = "(" ++ s ++ ")"
+ | True = s
diff --git a/src-2.9/GF/Speech/Relation.hs b/src-2.9/GF/Speech/Relation.hs
new file mode 100644
index 000000000..641d671a9
--- /dev/null
+++ b/src-2.9/GF/Speech/Relation.hs
@@ -0,0 +1,130 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Relation
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/10/26 17:13:13 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.1 $
+--
+-- A simple module for relations.
+-----------------------------------------------------------------------------
+
+module GF.Speech.Relation (Rel, mkRel, mkRel'
+ , allRelated , isRelatedTo
+ , transitiveClosure
+ , reflexiveClosure, reflexiveClosure_
+ , symmetricClosure
+ , symmetricSubrelation, reflexiveSubrelation
+ , reflexiveElements
+ , equivalenceClasses
+ , isTransitive, isReflexive, isSymmetric
+ , isEquivalence
+ , isSubRelationOf) where
+
+import Data.List
+import Data.Maybe
+import Data.Map (Map)
+import qualified Data.Map as Map
+import Data.Set (Set)
+import qualified Data.Set as Set
+
+import GF.Data.Utilities
+
+type Rel a = Map a (Set a)
+
+-- | Creates a relation from a list of related pairs.
+mkRel :: Ord a => [(a,a)] -> Rel a
+mkRel ps = relates ps Map.empty
+
+-- | Creates a relation from a list pairs of elements and the elements
+-- related to them.
+mkRel' :: Ord a => [(a,[a])] -> Rel a
+mkRel' xs = Map.fromListWith Set.union [(x,Set.fromList ys) | (x,ys) <- xs]
+
+relToList :: Rel a -> [(a,a)]
+relToList r = [ (x,y) | (x,ys) <- Map.toList r, y <- Set.toList ys ]
+
+-- | Add a pair to the relation.
+relate :: Ord a => a -> a -> Rel a -> Rel a
+relate x y r = Map.insertWith Set.union x (Set.singleton y) r
+
+-- | Add a list of pairs to the relation.
+relates :: Ord a => [(a,a)] -> Rel a -> Rel a
+relates ps r = foldl (\r' (x,y) -> relate x y r') r ps
+
+-- | Checks if an element is related to another.
+isRelatedTo :: Ord a => Rel a -> a -> a -> Bool
+isRelatedTo r x y = maybe False (y `Set.member`) (Map.lookup x r)
+
+-- | Get the set of elements to which a given element is related.
+allRelated :: Ord a => Rel a -> a -> Set a
+allRelated r x = fromMaybe Set.empty (Map.lookup x r)
+
+-- | Get all elements in the relation.
+domain :: Ord a => Rel a -> Set a
+domain r = foldl Set.union (Map.keysSet r) (Map.elems r)
+
+-- | Keep only pairs for which both elements are in the given set.
+intersectSetRel :: Ord a => Set a -> Rel a -> Rel a
+intersectSetRel s = filterRel (\x y -> x `Set.member` s && y `Set.member` s)
+
+transitiveClosure :: Ord a => Rel a -> Rel a
+transitiveClosure r = fix (Map.map growSet) r
+ where growSet ys = foldl Set.union ys (map (allRelated r) $ Set.toList ys)
+
+reflexiveClosure_ :: Ord a => [a] -- ^ The set over which the relation is defined.
+ -> Rel a -> Rel a
+reflexiveClosure_ u r = relates [(x,x) | x <- u] r
+
+-- | Uses 'domain'
+reflexiveClosure :: Ord a => Rel a -> Rel a
+reflexiveClosure r = reflexiveClosure_ (Set.toList $ domain r) r
+
+symmetricClosure :: Ord a => Rel a -> Rel a
+symmetricClosure r = relates [ (y,x) | (x,y) <- relToList r ] r
+
+symmetricSubrelation :: Ord a => Rel a -> Rel a
+symmetricSubrelation r = filterRel (flip $ isRelatedTo r) r
+
+reflexiveSubrelation :: Ord a => Rel a -> Rel a
+reflexiveSubrelation r = intersectSetRel (reflexiveElements r) r
+
+-- | Get the set of elements which are related to themselves.
+reflexiveElements :: Ord a => Rel a -> Set a
+reflexiveElements r = Set.fromList [ x | (x,ys) <- Map.toList r, x `Set.member` ys ]
+
+-- | Keep the related pairs for which the predicate is true.
+filterRel :: Ord a => (a -> a -> Bool) -> Rel a -> Rel a
+filterRel p = purgeEmpty . Map.mapWithKey (Set.filter . p)
+
+-- | Remove keys that map to no elements.
+purgeEmpty :: Ord a => Rel a -> Rel a
+purgeEmpty r = Map.filter (not . Set.null) r
+
+
+-- | Get the equivalence classes from an equivalence relation.
+equivalenceClasses :: Ord a => Rel a -> [Set a]
+equivalenceClasses r = equivalenceClasses_ (Map.keys r) r
+ where equivalenceClasses_ [] _ = []
+ equivalenceClasses_ (x:xs) r = ys:equivalenceClasses_ zs r
+ where ys = allRelated r x
+ zs = [x' | x' <- xs, not (x' `Set.member` ys)]
+
+isTransitive :: Ord a => Rel a -> Bool
+isTransitive r = and [z `Set.member` ys | (x,ys) <- Map.toList r,
+ y <- Set.toList ys, z <- Set.toList (allRelated r y)]
+
+isReflexive :: Ord a => Rel a -> Bool
+isReflexive r = all (\ (x,ys) -> x `Set.member` ys) (Map.toList r)
+
+isSymmetric :: Ord a => Rel a -> Bool
+isSymmetric r = and [isRelatedTo r y x | (x,y) <- relToList r]
+
+isEquivalence :: Ord a => Rel a -> Bool
+isEquivalence r = isReflexive r && isSymmetric r && isTransitive r
+
+isSubRelationOf :: Ord a => Rel a -> Rel a -> Bool
+isSubRelationOf r1 r2 = all (uncurry (isRelatedTo r2)) (relToList r1)
diff --git a/src-2.9/GF/Speech/RelationQC.hs b/src-2.9/GF/Speech/RelationQC.hs
new file mode 100644
index 000000000..47f783986
--- /dev/null
+++ b/src-2.9/GF/Speech/RelationQC.hs
@@ -0,0 +1,39 @@
+----------------------------------------------------------------------
+-- |
+-- Module : RelationQC
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/10/26 17:13:13 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.1 $
+--
+-- QuickCheck properties for GF.Speech.Relation
+-----------------------------------------------------------------------------
+
+module GF.Speech.RelationQC where
+
+import GF.Speech.Relation
+
+import Test.QuickCheck
+
+prop_transitiveClosure_trans :: [(Int,Int)] -> Bool
+prop_transitiveClosure_trans ps = isTransitive (transitiveClosure (mkRel ps))
+
+prop_symmetricSubrelation_symm :: [(Int,Int)] -> Bool
+prop_symmetricSubrelation_symm ps = isSymmetric (symmetricSubrelation (mkRel ps))
+
+prop_symmetricSubrelation_sub :: [(Int,Int)] -> Bool
+prop_symmetricSubrelation_sub ps = symmetricSubrelation r `isSubRelationOf` r
+ where r = mkRel ps
+
+prop_symmetricClosure_symm :: [(Int,Int)] -> Bool
+prop_symmetricClosure_symm ps = isSymmetric (symmetricClosure (mkRel ps))
+
+prop_reflexiveClosure_refl :: [(Int,Int)] -> Bool
+prop_reflexiveClosure_refl ps = isReflexive (reflexiveClosure (mkRel ps))
+
+prop_mkEquiv_equiv :: [(Int,Int)] -> Bool
+prop_mkEquiv_equiv ps = isEquivalence (mkEquiv ps)
+ where mkEquiv = transitiveClosure . symmetricClosure . reflexiveClosure . mkRel
diff --git a/src-2.9/GF/Speech/SISR.hs b/src-2.9/GF/Speech/SISR.hs
new file mode 100644
index 000000000..3e68a2e55
--- /dev/null
+++ b/src-2.9/GF/Speech/SISR.hs
@@ -0,0 +1,87 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GF.Speech.SISR
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- Abstract syntax and pretty printer for SISR,
+-- (Semantic Interpretation for Speech Recognition)
+--
+-----------------------------------------------------------------------------
+
+module GF.Speech.SISR (SISRFormat(..), SISRTag, prSISR,
+ topCatSISR, profileInitSISR, catSISR, profileFinalSISR) where
+
+import Data.List
+
+import GF.Conversion.Types
+import GF.Data.Utilities
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..), NameProfile(..), Profile(..), forestName)
+import GF.Infra.Ident
+import GF.Speech.TransformCFG
+import GF.Speech.SRG (SRGNT)
+
+import qualified GF.JavaScript.AbsJS as JS
+import qualified GF.JavaScript.PrintJS as JS
+
+data SISRFormat =
+ -- SISR Working draft 1 April 2003
+ -- http://www.w3.org/TR/2003/WD-semantic-interpretation-20030401/
+ SISROld
+ deriving Show
+
+type SISRTag = [JS.DeclOrExpr]
+
+
+prSISR :: SISRTag -> String
+prSISR = JS.printTree
+
+topCatSISR :: String -> SISRFormat -> SISRTag
+topCatSISR c fmt = map JS.DExpr [fmtOut fmt `ass` fmtRef fmt c]
+
+profileInitSISR :: CFTerm -> SISRFormat -> SISRTag
+profileInitSISR t fmt
+ | null (usedArgs t) = []
+ | otherwise = [JS.Decl [JS.DInit args (JS.EArray [])]]
+
+usedArgs :: CFTerm -> [Int]
+usedArgs (CFObj _ ts) = foldr union [] (map usedArgs ts)
+usedArgs (CFAbs _ x) = usedArgs x
+usedArgs (CFApp x y) = usedArgs x `union` usedArgs y
+usedArgs (CFRes i) = [i]
+usedArgs _ = []
+
+catSISR :: CFTerm -> SRGNT -> SISRFormat -> SISRTag
+catSISR t (c,i) fmt
+ | i `elem` usedArgs t = map JS.DExpr
+ [JS.EIndex (JS.EVar args) (JS.EInt (fromIntegral i)) `ass` fmtRef fmt c]
+ | otherwise = []
+
+profileFinalSISR :: CFTerm -> SISRFormat -> SISRTag
+profileFinalSISR term fmt = [JS.DExpr $ fmtOut fmt `ass` f term]
+ where
+ f (CFObj n ts) = tree (prIdent n) (map f ts)
+ f (CFAbs v x) = JS.EFun [var v] [JS.SReturn (f x)]
+ f (CFApp x y) = JS.ECall (f x) [f y]
+ f (CFRes i) = JS.EIndex (JS.EVar args) (JS.EInt (fromIntegral i))
+ f (CFVar v) = JS.EVar (var v)
+ f (CFMeta typ) = obj [("name",JS.EStr "?"), ("type",JS.EStr typ)]
+
+fmtOut SISROld = JS.EVar (JS.Ident "$")
+
+fmtRef SISROld c = JS.EVar (JS.Ident ("$" ++ c))
+
+args = JS.Ident "a"
+
+var v = JS.Ident ("x" ++ show v)
+
+field x y = JS.EMember x (JS.Ident y)
+
+ass = JS.EAssign
+
+tree n xs = obj [("name", JS.EStr n), ("args", JS.EArray xs)]
+
+obj ps = JS.EObj [JS.Prop (JS.StringPropName x) y | (x,y) <- ps]
+
diff --git a/src-2.9/GF/Speech/SRG.hs b/src-2.9/GF/Speech/SRG.hs
new file mode 100644
index 000000000..19b6c1c1b
--- /dev/null
+++ b/src-2.9/GF/Speech/SRG.hs
@@ -0,0 +1,235 @@
+----------------------------------------------------------------------
+-- |
+-- Module : SRG
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/01 20:09:04 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.20 $
+--
+-- Representation of, conversion to, and utilities for
+-- printing of a general Speech Recognition Grammar.
+--
+-- FIXME: remove \/ warn \/ fail if there are int \/ string literal
+-- categories in the grammar
+-----------------------------------------------------------------------------
+
+module GF.Speech.SRG (SRG(..), SRGRule(..), SRGAlt(..), SRGItem,
+ SRGCat, SRGNT, CFTerm
+ , makeSRG
+ , makeSimpleSRG
+ , makeNonRecursiveSRG
+ , lookupFM_, prtS
+ , cfgCatToGFCat, srgTopCats
+ ) where
+
+import GF.Data.Operations
+import GF.Data.Utilities
+import GF.Infra.Ident
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..), NameProfile(..)
+ , Profile(..), SyntaxForest
+ , filterCats, mapSymbol, symbol)
+import GF.Conversion.Types
+import GF.Infra.Print
+import GF.Speech.TransformCFG
+import GF.Speech.Relation
+import GF.Speech.FiniteState
+import GF.Speech.RegExp
+import GF.Speech.CFGToFiniteState
+import GF.Infra.Option
+import GF.Probabilistic.Probabilistic (Probs)
+import GF.Compile.ShellState (StateGrammar, stateProbs, stateOptions, cncId)
+
+import Data.List
+import Data.Maybe (fromMaybe, maybeToList)
+import Data.Map (Map)
+import qualified Data.Map as Map
+import Data.Set (Set)
+import qualified Data.Set as Set
+
+import Debug.Trace
+
+data SRG = SRG { grammarName :: String -- ^ grammar name
+ , startCat :: SRGCat -- ^ start category name
+ , origStartCat :: String -- ^ original start category name
+ , grammarLanguage :: Maybe String -- ^ The language for which the grammar
+ -- is intended, e.g. en-UK
+ , rules :: [SRGRule]
+ }
+ deriving (Eq,Show)
+
+data SRGRule = SRGRule SRGCat String [SRGAlt] -- ^ SRG category name, original category name
+ -- and productions
+ deriving (Eq,Show)
+
+-- | maybe a probability, a rule name and an EBNF right-hand side
+data SRGAlt = SRGAlt (Maybe Double) CFTerm SRGItem
+ deriving (Eq,Show)
+
+type SRGItem = RE (Symbol SRGNT Token)
+
+type SRGCat = String
+
+-- | An SRG non-terminal. Category name and its number in the profile.
+type SRGNT = (SRGCat, Int)
+
+-- | SRG category name and original name
+type CatName = (SRGCat,String)
+
+type CatNames = Map String String
+
+-- | Create a non-left-recursive SRG.
+-- FIXME: the probabilities in the returned
+-- grammar may be meaningless.
+makeSimpleSRG :: Options -- ^ Grammar options
+ -> StateGrammar
+ -> SRG
+makeSimpleSRG opt s = makeSRG preprocess opt s
+ where
+ preprocess origStart = traceStats "After mergeIdentical"
+ . mergeIdentical
+ . traceStats "After removeLeftRecursion"
+ . removeLeftRecursion origStart
+ . traceStats "After topDownFilter"
+ . topDownFilter origStart
+ . traceStats "After bottomUpFilter"
+ . bottomUpFilter
+ . traceStats "After removeCycles"
+ . removeCycles
+ . traceStats "Inital CFG"
+
+traceStats s g = trace ("---- " ++ s ++ ": " ++ stats g {- ++ "\n" ++ prCFRules g ++ "----" -}) g
+
+stats g = "Categories: " ++ show (countCats g)
+ ++ " Rules: " ++ show (countRules g)
+
+makeNonRecursiveSRG :: Options
+ -> StateGrammar
+ -> SRG
+makeNonRecursiveSRG opt s = renameSRG $
+ SRG { grammarName = prIdent (cncId s),
+ startCat = start,
+ origStartCat = origStart,
+ grammarLanguage = getSpeechLanguage opt s,
+ rules = rs }
+ where
+ origStart = getStartCatCF opt s
+ MFA start dfas = cfgToMFA opt s
+ rs = [SRGRule l l [SRGAlt Nothing dummyCFTerm (dfaToSRGItem dfa)] | (l,dfa) <- dfas]
+ where dfaToSRGItem = mapRE dummySRGNT . minimizeRE . dfa2re
+ dummyCFTerm = CFMeta "dummy"
+ dummySRGNT = mapSymbol (\c -> (c,0)) id
+
+makeSRG :: (Cat_ -> CFRules -> CFRules)
+ -> Options -- ^ Grammar options
+ -> StateGrammar
+ -> SRG
+makeSRG preprocess opt s = renameSRG $
+ SRG { grammarName = name,
+ startCat = origStart,
+ origStartCat = origStart,
+ grammarLanguage = getSpeechLanguage opt s,
+ rules = rs }
+ where
+ name = prIdent (cncId s)
+ origStart = getStartCatCF opt s
+ (_,cfgRules) = unzip $ allRulesGrouped $ preprocess origStart $ cfgToCFRules s
+ rs = map (cfgRulesToSRGRule (stateProbs s)) cfgRules
+
+-- | Give names on the form NameX to all categories.
+renameSRG :: SRG -> SRG
+renameSRG srg = srg { startCat = renameCat (startCat srg),
+ rules = map renameRule (rules srg) }
+ where
+ names = mkCatNames (grammarName srg) (allSRGCats srg)
+ renameRule (SRGRule _ origCat alts) = SRGRule (renameCat origCat) origCat (map renameAlt alts)
+ renameAlt (SRGAlt mp n rhs) = SRGAlt mp n (mapRE renameSymbol rhs)
+ renameSymbol = mapSymbol (\ (c,x) -> (renameCat c, x)) id
+ renameCat = lookupFM_ names
+
+getSpeechLanguage :: Options -> StateGrammar -> Maybe String
+getSpeechLanguage opt s =
+ fmap (replace '_' '-') $ getOptVal (addOptions opt (stateOptions s)) speechLanguage
+
+-- FIXME: merge alternatives with same rhs and profile but different probabilities
+cfgRulesToSRGRule :: Probs -> [CFRule_] -> SRGRule
+cfgRulesToSRGRule probs rs@(r:_) = SRGRule origCat origCat rhs
+ where
+ origCat = lhsCat r
+ alts = [((n,ruleProb probs r),mkSRGSymbols 0 ss) | CFRule c ss n <- rs]
+ rhs = [SRGAlt p n (srgItem sss) | ((n,p),sss) <- buildMultiMap alts ]
+
+ mkSRGSymbols _ [] = []
+ mkSRGSymbols i (Cat c:ss) = Cat (c,i) : mkSRGSymbols (i+1) ss
+ mkSRGSymbols i (Tok t:ss) = Tok t : mkSRGSymbols i ss
+
+ruleProb :: Probs -> CFRule_ -> Maybe Double
+ruleProb probs r = lookupProb probs (ruleFun r)
+
+-- FIXME: move to GF.Probabilistic.Probabilistic?
+lookupProb :: Probs -> Ident -> Maybe Double
+lookupProb probs i = lookupTree prIdent i probs
+
+mkCatNames :: String -- ^ Category name prefix
+ -> [String] -- ^ Original category names
+ -> Map String String -- ^ Maps original names to SRG names
+mkCatNames prefix origNames = Map.fromList (zip origNames names)
+ where names = [prefix ++ "_" ++ show x | x <- [0..]]
+
+
+allSRGCats :: SRG -> [String]
+allSRGCats SRG { rules = rs } = [c | SRGRule c _ _ <- rs]
+
+cfgCatToGFCat :: SRGCat -> Maybe String
+cfgCatToGFCat c
+ -- categories introduced by removeLeftRecursion contain dashes
+ | '-' `elem` c = Nothing
+ -- some categories introduced by -conversion=finite have the form
+ -- "{fun:cat}..."
+ | "{" `isPrefixOf` c = case dropWhile (/=':') $ takeWhile (/='}') $ tail c of
+ ':':c' -> Just c'
+ _ -> error $ "cfgCatToGFCat: Strange category " ++ show c
+ | otherwise = Just $ takeWhile (/='{') c
+
+srgTopCats :: SRG -> [(String,[SRGCat])]
+srgTopCats srg = buildMultiMap [(oc, cat) | SRGRule cat origCat _ <- rules srg,
+ oc <- maybeToList $ cfgCatToGFCat origCat]
+
+--
+-- * Size-optimized EBNF SRGs
+--
+
+srgItem :: [[Symbol SRGNT Token]] -> SRGItem
+srgItem = unionRE . map mergeItems . sortGroupBy (compareBy filterCats)
+-- non-optimizing version:
+--srgItem = unionRE . map seqRE
+
+-- | Merges a list of right-hand sides which all have the same
+-- sequence of non-terminals.
+mergeItems :: [[Symbol SRGNT Token]] -> SRGItem
+mergeItems = minimizeRE . ungroupTokens . minimizeRE . unionRE . map seqRE . map groupTokens
+
+groupTokens :: [Symbol SRGNT Token] -> [Symbol SRGNT [Token]]
+groupTokens [] = []
+groupTokens (Tok t:ss) = case groupTokens ss of
+ Tok ts:ss' -> Tok (t:ts):ss'
+ ss' -> Tok [t]:ss'
+groupTokens (Cat c:ss) = Cat c : groupTokens ss
+
+ungroupTokens :: RE (Symbol SRGNT [Token]) -> RE (Symbol SRGNT Token)
+ungroupTokens = joinRE . mapRE (symbol (RESymbol . Cat) (REConcat . map (RESymbol . Tok)))
+
+--
+-- * Utilities for building and printing SRGs
+--
+
+lookupFM_ :: (Ord key, Show key) => Map key elt -> key -> elt
+lookupFM_ fm k = Map.findWithDefault err k fm
+ where err = error $ "Key not found: " ++ show k
+ ++ "\namong " ++ show (Map.keys fm)
+
+prtS :: Print a => a -> ShowS
+prtS = showString . prt
diff --git a/src-2.9/GF/Speech/TransformCFG.hs b/src-2.9/GF/Speech/TransformCFG.hs
new file mode 100644
index 000000000..3d7ebd809
--- /dev/null
+++ b/src-2.9/GF/Speech/TransformCFG.hs
@@ -0,0 +1,378 @@
+----------------------------------------------------------------------
+-- |
+-- Module : TransformCFG
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/01 20:09:04 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.24 $
+--
+-- This module does some useful transformations on CFGs.
+--
+-- peb thinks: most of this module should be moved to GF.Conversion...
+-----------------------------------------------------------------------------
+
+module GF.Speech.TransformCFG where
+
+import GF.Canon.CanonToGFCC (canon2gfcc)
+import qualified GF.GFCC.CId as C
+import GF.GFCC.Macros (lookType,catSkeleton)
+import GF.GFCC.DataGFCC (GFCC)
+import GF.Conversion.Types
+import GF.CF.PPrCF (prCFCat)
+import GF.Data.Utilities
+import GF.Formalism.CFG
+import GF.Formalism.Utilities (Symbol(..), mapSymbol, filterCats, symbol,
+ NameProfile(..), Profile(..), name2fun, forestName)
+import GF.Infra.Ident
+import GF.Infra.Option
+import GF.Infra.Print
+import GF.Speech.Relation
+import GF.Compile.ShellState (StateGrammar, stateCFG, stateGrammarST, startCatStateOpts, stateOptions)
+
+import Control.Monad
+import Control.Monad.State (State, get, put, evalState)
+import Data.Map (Map)
+import qualified Data.Map as Map
+import Data.List
+import Data.Maybe (fromMaybe)
+import Data.Monoid (mconcat)
+import Data.Set (Set)
+import qualified Data.Set as Set
+
+-- not very nice to replace the structured CFCat type with a simple string
+type CFRule_ = CFRule Cat_ CFTerm Token
+
+data CFTerm
+ = CFObj Fun [CFTerm] -- ^ an abstract syntax function with arguments
+ | CFAbs Int CFTerm -- ^ A lambda abstraction. The Int is the variable id.
+ | CFApp CFTerm CFTerm -- ^ Application
+ | CFRes Int -- ^ The result of the n:th (0-based) non-terminal
+ | CFVar Int -- ^ A lambda-bound variable
+ | CFMeta String -- ^ A metavariable
+ deriving (Eq,Ord,Show)
+
+type Cat_ = String
+type CFSymbol_ = Symbol Cat_ Token
+
+type CFRules = Map Cat_ (Set CFRule_)
+
+
+cfgToCFRules :: StateGrammar -> CFRules
+cfgToCFRules s =
+ groupProds [CFRule (catToString c) (map symb r) (nameToTerm n)
+ | CFRule c r n <- cfg]
+ where cfg = stateCFG s
+ symb = mapSymbol catToString id
+ catToString = prt
+ gfcc = stateGFCC s
+ nameToTerm (Name IW [Unify [n]]) = CFRes n
+ nameToTerm (Name f@(IC c) prs) =
+ CFObj f (zipWith profileToTerm args prs)
+ where (args,_) = catSkeleton $ lookType gfcc (C.CId c)
+ nameToTerm n = error $ "cfgToCFRules.nameToTerm" ++ show n
+ profileToTerm (C.CId t) (Unify []) = CFMeta t
+ profileToTerm _ (Unify xs) = CFRes (last xs) -- FIXME: unify
+ profileToTerm (C.CId t) (Constant f) = maybe (CFMeta t) (\x -> CFObj x []) (forestName f)
+
+getStartCat :: Options -> StateGrammar -> String
+getStartCat opts sgr = prCFCat (startCatStateOpts opts' sgr)
+ where opts' = addOptions opts (stateOptions sgr)
+
+getStartCatCF :: Options -> StateGrammar -> String
+getStartCatCF opts sgr = getStartCat opts sgr ++ "{}.s"
+
+stateGFCC :: StateGrammar -> GFCC
+stateGFCC = canon2gfcc noOptions . stateGrammarST
+
+-- * Grammar filtering
+
+-- | Removes all directly and indirectly cyclic productions.
+-- FIXME: this may be too aggressive, only one production
+-- needs to be removed to break a given cycle. But which
+-- one should we pick?
+-- FIXME: Does not (yet) remove productions which are cyclic
+-- because of empty productions.
+removeCycles :: CFRules -> CFRules
+removeCycles = groupProds . f . allRules
+ where f rs = filter (not . isCycle) rs
+ where alias = transitiveClosure $ mkRel [(c,c') | CFRule c [Cat c'] _ <- rs]
+ isCycle (CFRule c [Cat c'] _) = isRelatedTo alias c' c
+ isCycle _ = False
+
+-- | Better bottom-up filter that also removes categories which contain no finite
+-- strings.
+bottomUpFilter :: CFRules -> CFRules
+bottomUpFilter gr = fix grow Map.empty
+ where grow g = g `unionCFRules` filterCFRules (all (okSym g) . ruleRhs) gr
+ okSym g = symbol (`elem` allCats g) (const True)
+
+-- | Removes categories which are not reachable from the start category.
+topDownFilter :: Cat_ -> CFRules -> CFRules
+topDownFilter start rules = filterCFRulesCats (isRelatedTo uses start) rules
+ where
+ rhsCats = [ (lhsCat r, c') | r <- allRules rules, c' <- filterCats (ruleRhs r) ]
+ uses = reflexiveClosure_ (allCats rules) $ transitiveClosure $ mkRel rhsCats
+
+-- | Merges categories with identical right-hand-sides.
+-- FIXME: handle probabilities
+mergeIdentical :: CFRules -> CFRules
+mergeIdentical g = groupProds $ map subst $ allRules g
+ where
+ -- maps categories to their replacement
+ m = Map.fromList [(y,concat (intersperse "+" xs))
+ | (_,xs) <- buildMultiMap [(rulesKey rs,c) | (c,rs) <- Map.toList g], y <- xs]
+ -- build data to compare for each category: a set of name,rhs pairs
+ rulesKey = Set.map (\ (CFRule _ r n) -> (n,r))
+ subst (CFRule c r n) = CFRule (substCat c) (map (mapSymbol substCat id) r) n
+ substCat c = Map.findWithDefault (error $ "mergeIdentical: " ++ c) c m
+
+-- * Removing left recursion
+
+-- The LC_LR algorithm from
+-- http://research.microsoft.com/users/bobmoore/naacl2k-proc-rev.pdf
+removeLeftRecursion :: Cat_ -> CFRules -> CFRules
+removeLeftRecursion start gr
+ = groupProds $ concat [scheme1, scheme2, scheme3, scheme4]
+ where
+ scheme1 = [CFRule a [x,Cat a_x] n' |
+ a <- retainedLeftRecursive,
+ x <- properLeftCornersOf a,
+ not (isLeftRecursive x),
+ let a_x = mkCat (Cat a) x,
+ -- this is an extension of LC_LR to avoid generating
+ -- A-X categories for which there are no productions:
+ a_x `Set.member` newCats,
+ let n' = symbol (\_ -> CFApp (CFRes 1) (CFRes 0))
+ (\_ -> CFRes 0) x]
+ scheme2 = [CFRule a_x (beta++[Cat a_b]) n' |
+ a <- retainedLeftRecursive,
+ b@(Cat b') <- properLeftCornersOf a,
+ isLeftRecursive b,
+ CFRule _ (x:beta) n <- catRules gr b',
+ let a_x = mkCat (Cat a) x,
+ let a_b = mkCat (Cat a) b,
+ let i = length $ filterCats beta,
+ let n' = symbol (\_ -> CFAbs 1 (CFApp (CFRes i) (shiftTerm n)))
+ (\_ -> CFApp (CFRes i) n) x]
+ scheme3 = [CFRule a_x beta n' |
+ a <- retainedLeftRecursive,
+ x <- properLeftCornersOf a,
+ CFRule _ (x':beta) n <- catRules gr a,
+ x == x',
+ let a_x = mkCat (Cat a) x,
+ let n' = symbol (\_ -> CFAbs 1 (shiftTerm n))
+ (\_ -> n) x]
+ scheme4 = catSetRules gr $ Set.fromList $ filter (not . isLeftRecursive . Cat) cats
+
+ newCats = Set.fromList (map lhsCat (scheme2 ++ scheme3))
+
+ shiftTerm :: CFTerm -> CFTerm
+ shiftTerm (CFObj f ts) = CFObj f (map shiftTerm ts)
+ shiftTerm (CFRes 0) = CFVar 1
+ shiftTerm (CFRes n) = CFRes (n-1)
+ shiftTerm t = t
+ -- note: the rest don't occur in the original grammar
+
+ cats = allCats gr
+ rules = allRules gr
+
+ directLeftCorner = mkRel [(Cat c,t) | CFRule c (t:_) _ <- allRules gr]
+ leftCorner = reflexiveClosure_ (map Cat cats) $ transitiveClosure directLeftCorner
+ properLeftCorner = transitiveClosure directLeftCorner
+ properLeftCornersOf = Set.toList . allRelated properLeftCorner . Cat
+ isProperLeftCornerOf = flip (isRelatedTo properLeftCorner)
+
+ leftRecursive = reflexiveElements properLeftCorner
+ isLeftRecursive = (`Set.member` leftRecursive)
+
+ retained = start `Set.insert`
+ Set.fromList [a | r <- allRules (filterCFRulesCats (not . isLeftRecursive . Cat) gr),
+ Cat a <- ruleRhs r]
+ isRetained = (`Set.member` retained)
+
+ retainedLeftRecursive = filter (isLeftRecursive . Cat) $ Set.toList retained
+
+mkCat :: CFSymbol_ -> CFSymbol_ -> Cat_
+mkCat x y = showSymbol x ++ "-" ++ showSymbol y
+ where showSymbol = symbol id show
+
+{-
+
+-- Paull's algorithm, see
+-- http://research.microsoft.com/users/bobmoore/naacl2k-proc-rev.pdf
+removeLeftRecursion :: Cat_ -> CFRules -> CFRules
+removeLeftRecursion start rs = removeDirectLeftRecursions $ map handleProds rs
+ where
+ handleProds (c, r) = (c, concatMap handleProd r)
+ handleProd (CFRule ai (Cat aj:alpha) n) | aj < ai =
+ -- FIXME: for non-recursive categories, this changes
+ -- the grammar unneccessarily, maybe we can use mutRecCats
+ -- to make this less invasive
+ -- FIXME: this will give multiple rules with the same name,
+ -- which may mess up the probabilities.
+ [CFRule ai (beta ++ alpha) n | CFRule _ beta _ <- lookup' aj rs]
+ handleProd r = [r]
+
+removeDirectLeftRecursions :: CFRules -> CFRules
+removeDirectLeftRecursions = concat . flip evalState 0 . mapM removeDirectLeftRecursion
+
+removeDirectLeftRecursion :: (Cat_,[CFRule_]) -- ^ All productions for a category
+ -> State Int CFRules
+removeDirectLeftRecursion (a,rs)
+ | null dr = return [(a,rs)]
+ | otherwise =
+ do
+ a' <- fresh a
+ let as = maybeEndWithA' nr
+ is = [CFRule a' (tail r) n | CFRule _ r n <- dr]
+ a's = maybeEndWithA' is
+ -- the not null constraint here avoids creating new
+ -- left recursive (cyclic) rules.
+ maybeEndWithA' xs = xs ++ [CFRule c (r++[Cat a']) n | CFRule c r n <- xs,
+ not (null r)]
+ return [(a, as), (a', a's)]
+ where
+ (dr,nr) = partition isDirectLeftRecursive rs
+ fresh x = do { n <- get; put (n+1); return $ x ++ "-" ++ show n }
+
+isDirectLeftRecursive :: CFRule_ -> Bool
+isDirectLeftRecursive (CFRule c (Cat c':_) _) = c == c'
+isDirectLeftRecursive _ = False
+
+-}
+
+-- | Get the sets of mutually recursive non-terminals for a grammar.
+mutRecCats :: Bool -- ^ If true, all categories will be in some set.
+ -- If false, only recursive categories will be included.
+ -> CFRules -> [Set Cat_]
+mutRecCats incAll g = equivalenceClasses $ refl $ symmetricSubrelation $ transitiveClosure r
+ where r = mkRel [(c,c') | CFRule c ss _ <- allRules g, Cat c' <- ss]
+ refl = if incAll then reflexiveClosure_ (allCats g) else reflexiveSubrelation
+
+--
+-- * Approximate context-free grammars with regular grammars.
+--
+
+-- Use the transformation algorithm from \"Regular Approximation of Context-free
+-- Grammars through Approximation\", Mohri and Nederhof, 2000
+-- to create an over-generating regular frammar for a context-free
+-- grammar
+makeRegular :: CFRules -> CFRules
+makeRegular g = groupProds $ concatMap trSet (mutRecCats True g)
+ where trSet cs | allXLinear cs rs = rs
+ | otherwise = concatMap handleCat csl
+ where csl = Set.toList cs
+ rs = catSetRules g cs
+ handleCat c = [CFRule c' [] (mkCFTerm (c++"-empty"))] -- introduce A' -> e
+ ++ concatMap (makeRightLinearRules c) (catRules g c)
+ where c' = newCat c
+ makeRightLinearRules b' (CFRule c ss n) =
+ case ys of
+ [] -> newRule b' (xs ++ [Cat (newCat c)]) n -- no non-terminals left
+ (Cat b:zs) -> newRule b' (xs ++ [Cat b]) n
+ ++ makeRightLinearRules (newCat b) (CFRule c zs n)
+ where (xs,ys) = break (`catElem` cs) ss
+ -- don't add rules on the form A -> A
+ newRule c rhs n | rhs == [Cat c] = []
+ | otherwise = [CFRule c rhs n]
+ newCat c = c ++ "$"
+
+--
+-- * CFG rule utilities
+--
+
+-- | Group productions by their lhs categories
+groupProds :: [CFRule_] -> CFRules
+groupProds = Map.fromListWith Set.union . map (\r -> (lhsCat r,Set.singleton r))
+
+allRules :: CFRules -> [CFRule_]
+allRules = concat . map Set.toList . Map.elems
+
+allRulesGrouped :: CFRules -> [(Cat_,[CFRule_])]
+allRulesGrouped = Map.toList . Map.map Set.toList
+
+allCats :: CFRules -> [Cat_]
+allCats = Map.keys
+
+catRules :: CFRules -> Cat_ -> [CFRule_]
+catRules rs c = Set.toList $ Map.findWithDefault Set.empty c rs
+
+catSetRules :: CFRules -> Set Cat_ -> [CFRule_]
+catSetRules g cs = allRules $ Map.filterWithKey (\c _ -> c `Set.member` cs) g
+
+cleanCFRules :: CFRules -> CFRules
+cleanCFRules = Map.filter (not . Set.null)
+
+unionCFRules :: CFRules -> CFRules -> CFRules
+unionCFRules = Map.unionWith Set.union
+
+filterCFRules :: (CFRule_ -> Bool) -> CFRules -> CFRules
+filterCFRules p = cleanCFRules . Map.map (Set.filter p)
+
+filterCFRulesCats :: (Cat_ -> Bool) -> CFRules -> CFRules
+filterCFRulesCats p = Map.filterWithKey (\c _ -> p c)
+
+countCats :: CFRules -> Int
+countCats = Map.size . cleanCFRules
+
+countRules :: CFRules -> Int
+countRules = length . allRules
+
+lhsCat :: CFRule c n t -> c
+lhsCat (CFRule c _ _) = c
+
+ruleRhs :: CFRule c n t -> [Symbol c t]
+ruleRhs (CFRule _ ss _) = ss
+
+ruleFun :: CFRule_ -> Fun
+ruleFun (CFRule _ _ t) = f t
+ where f (CFObj n _) = n
+ f (CFApp _ x) = f x
+ f (CFAbs _ x) = f x
+ f _ = IC ""
+
+-- | Checks if a symbol is a non-terminal of one of the given categories.
+catElem :: Ord c => Symbol c t -> Set c -> Bool
+catElem s cs = symbol (`Set.member` cs) (const False) s
+
+-- | Check if any of the categories used on the right-hand side
+-- are in the given list of categories.
+anyUsedBy :: Eq c => [c] -> CFRule c n t -> Bool
+anyUsedBy cs (CFRule _ ss _) = any (`elem` cs) (filterCats ss)
+
+mkCFTerm :: String -> CFTerm
+mkCFTerm n = CFObj (IC n) []
+
+ruleIsNonRecursive :: Ord c => Set c -> CFRule c n t -> Bool
+ruleIsNonRecursive cs = noCatsInSet cs . ruleRhs
+
+noCatsInSet :: Ord c => Set c -> [Symbol c t] -> Bool
+noCatsInSet cs = not . any (`catElem` cs)
+
+-- | Check if all the rules are right-linear, or all the rules are
+-- left-linear, with respect to given categories.
+allXLinear :: Ord c => Set c -> [CFRule c n t] -> Bool
+allXLinear cs rs = all (isRightLinear cs) rs || all (isLeftLinear cs) rs
+
+-- | Checks if a context-free rule is right-linear.
+isRightLinear :: Ord c =>
+ Set c -- ^ The categories to consider
+ -> CFRule c n t -- ^ The rule to check for right-linearity
+ -> Bool
+isRightLinear cs = noCatsInSet cs . safeInit . ruleRhs
+
+-- | Checks if a context-free rule is left-linear.
+isLeftLinear :: Ord c =>
+ Set c -- ^ The categories to consider
+ -> CFRule c n t -- ^ The rule to check for left-linearity
+ -> Bool
+isLeftLinear cs = noCatsInSet cs . drop 1 . ruleRhs
+
+prCFRules :: CFRules -> String
+prCFRules = unlines . map prRule . allRules
+ where
+ prRule r = lhsCat r ++ " --> " ++ unwords (map prSym (ruleRhs r))
+ prSym = symbol id (\t -> "\""++ t ++"\"")
diff --git a/src-2.9/GF/System/ATKSpeechInput.hs b/src-2.9/GF/System/ATKSpeechInput.hs
new file mode 100644
index 000000000..4b50293af
--- /dev/null
+++ b/src-2.9/GF/System/ATKSpeechInput.hs
@@ -0,0 +1,137 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GF.System.ATKSpeechInput
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (non-portable)
+--
+-- > CVS $Date: 2005/05/10 15:04:01 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.2 $
+--
+-- Use ATK and Speech.ATKRec for speech input.
+-----------------------------------------------------------------------------
+
+module GF.System.ATKSpeechInput (recognizeSpeech) where
+
+import GF.Infra.Ident (Ident, prIdent)
+import GF.Infra.Option
+import GF.Conversion.Types (CGrammar)
+import GF.Speech.PrSLF
+
+import Speech.ATKRec
+
+import Control.Monad
+import Data.Maybe
+import Data.IORef
+import System.Environment
+import System.IO
+import System.IO.Unsafe
+
+data ATKLang = ATKLang {
+ hmmlist :: FilePath,
+ mmf0 :: FilePath,
+ mmf1 :: FilePath,
+ dict :: FilePath,
+ opts :: [(String,String)]
+ }
+
+atk_home_error = "The environment variable ATK_HOME is not set. "
+ ++ "It should contain the path to your copy of ATK."
+
+gf_atk_cfg_error = "The environment variable GF_ATK_CFG is not set. "
+ ++ "It should contain the path to your GF ATK configuration"
+ ++ " file. A default version of this file can be found"
+ ++ " in GF/src/gf_atk.cfg"
+
+getLanguage :: String -> IO ATKLang
+getLanguage l =
+ case l of
+ "en_UK" -> do
+ atk_home <- getEnv_ "ATK_HOME" atk_home_error
+ let res = atk_home ++ "/Resources"
+ return $ ATKLang {
+ hmmlist = res ++ "/UK_SI_ZMFCC/hmmlistbg",
+ mmf0 = res ++ "/UK_SI_ZMFCC/WI4",
+ mmf1 = res ++ "/UK_SI_ZMFCC/BGHMM2",
+ dict = res ++ "/beep.dct",
+ opts = [("TARGETKIND", "MFCC_0_D_A_Z"),
+ ("HPARM:CMNDEFAULT", res ++ "/UK_SI_ZMFCC/cepmean")]
+ }
+ "sv_SE" -> do
+ let res = "/home/bjorn/projects/atkswe/numerals-swe/final"
+ return $ ATKLang {
+ hmmlist = res ++ "/hmm_tri/hmmlist",
+ mmf0 = res ++ "/hmm_tri/macros",
+ mmf1 = res ++ "/hmm_tri/hmmdefs",
+ dict = res ++ "/NumeralsSwe.dct",
+ opts = [("TARGETKIND", "MFCC_0_D_A")]
+ }
+ _ -> fail $ "ATKSpeechInput: language " ++ l ++ " not supported"
+
+-- | Current language for which we have loaded the HMM
+-- and dictionary.
+{-# NOINLINE currentLang #-}
+currentLang :: IORef (Maybe String)
+currentLang = unsafePerformIO $ newIORef Nothing
+
+-- | Initializes the ATK, loading the given language.
+-- ATK must not be initialized when calling this function.
+loadLang :: String -> IO ()
+loadLang lang =
+ do
+ l <- getLanguage lang
+ config <- getEnv_ "GF_ATK_CFG" gf_atk_cfg_error
+ hPutStrLn stderr $ "Initializing ATK..."
+ initialize (Just config) (opts l)
+ let hmmName = "hmm_" ++ lang
+ dictName = "dict_" ++ lang
+ hPutStrLn stderr $ "Initializing ATK (" ++ lang ++ ")..."
+ loadHMMSet hmmName (hmmlist l) (mmf0 l) (mmf1 l)
+ loadDict dictName (dict l)
+ writeIORef currentLang (Just lang)
+
+initATK :: String -> IO ()
+initATK lang =
+ do
+ ml <- readIORef currentLang
+ case ml of
+ Nothing -> loadLang lang
+ Just l | l == lang -> return ()
+ | otherwise -> do
+ deinitialize
+ loadLang lang
+
+recognizeSpeech :: Ident -- ^ Grammar name
+ -> String -- ^ Language, e.g. en_UK
+ -> CGrammar -- ^ Context-free grammar for input
+ -> String -- ^ Start category name
+ -> Int -- ^ Number of utterances
+ -> IO [String]
+recognizeSpeech name language cfg start number =
+ do
+ let slf = slfPrinter name start cfg
+ n = prIdent name
+ hmmName = "hmm_" ++ language
+ dictName = "dict_" ++ language
+ slfName = "gram_" ++ n
+ recName = "rec_" ++ language ++ "_" ++ n
+ writeFile "debug.net" slf
+ initATK language
+ hPutStrLn stderr $ "Loading grammar " ++ n ++ " ..."
+ loadGrammarString slfName slf
+ createRecognizer recName hmmName dictName slfName
+ hPutStrLn stderr $ "Listening in category " ++ start ++ "..."
+ s <- replicateM number (recognize recName)
+ return s
+
+
+getEnv_ :: String -- ^ Name of environment variable
+ -> String -- ^ Message to fail with if the variable is not set.
+ -> IO String
+getEnv_ e err =
+ do
+ env <- getEnvironment
+ case lookup e env of
+ Just v -> return v
+ Nothing -> fail err
diff --git a/src-2.9/GF/System/Arch.hs b/src-2.9/GF/System/Arch.hs
new file mode 100644
index 000000000..c0dac3644
--- /dev/null
+++ b/src-2.9/GF/System/Arch.hs
@@ -0,0 +1,90 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Arch
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/05/10 14:55:01 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.8 $
+--
+-- architecture\/compiler dependent definitions for unix\/hbc
+-----------------------------------------------------------------------------
+
+module GF.System.Arch (
+ myStdGen, prCPU, selectLater, modifiedFiles, ModTime, getModTime,getNowTime,
+ welcomeArch, fetchCommand, laterModTime) where
+
+import System.Time
+import System.Random
+import System.CPUTime
+import Control.Monad (filterM)
+import System.Directory
+
+import GF.System.Readline (fetchCommand)
+
+---- import qualified UnicodeF as U --(fudlogueWrite)
+
+-- architecture/compiler dependent definitions for unix/hbc
+
+myStdGen :: Int -> IO StdGen ---
+--- myStdGen _ = newStdGen --- gives always the same result
+myStdGen int0 = do
+ t0 <- getClockTime
+ cal <- toCalendarTime t0
+ let int = int0 + ctSec cal + fromInteger (div (ctPicosec cal) 10000000)
+ return $ mkStdGen int
+
+prCPU :: Integer -> IO Integer
+prCPU cpu = do
+ cpu' <- getCPUTime
+ putStrLn (show ((cpu' - cpu) `div` 1000000000) ++ " msec")
+ return cpu'
+
+welcomeArch :: String
+welcomeArch = "This is the system compiled with ghc."
+
+-- | selects the one with the later modification time of two
+selectLater :: FilePath -> FilePath -> IO FilePath
+selectLater x y = do
+ ex <- doesFileExist x
+ if not ex
+ then return y --- which may not exist
+ else do
+ ey <- doesFileExist y
+ if not ey
+ then return x
+ else do
+ tx <- getModificationTime x
+ ty <- getModificationTime y
+ return $ if tx < ty then y else x
+
+-- | a file is considered modified also if it has not been read yet
+--
+-- new 23\/2\/2004: the environment ofs has just module names
+modifiedFiles :: [(FilePath,ModTime)] -> [FilePath] -> IO [FilePath]
+modifiedFiles ofs fs = do
+ filterM isModified fs
+ where
+ isModified file = case lookup (justModName file) ofs of
+ Just to -> do
+ t <- getModificationTime file
+ return $ to < t
+ _ -> return True
+
+ justModName =
+ reverse . takeWhile (/='/') . tail . dropWhile (/='.') . reverse
+
+type ModTime = ClockTime
+
+laterModTime :: ModTime -> ModTime -> Bool
+laterModTime = (>)
+
+getModTime :: FilePath -> IO (Maybe ModTime)
+getModTime f = do
+ b <- doesFileExist f
+ if b then (getModificationTime f >>= return . Just) else return Nothing
+
+getNowTime :: IO ModTime
+getNowTime = getClockTime
diff --git a/src-2.9/GF/System/ArchEdit.hs b/src-2.9/GF/System/ArchEdit.hs
new file mode 100644
index 000000000..39b558cef
--- /dev/null
+++ b/src-2.9/GF/System/ArchEdit.hs
@@ -0,0 +1,30 @@
+----------------------------------------------------------------------
+-- |
+-- Module : ArchEdit
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:46:15 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.2 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.System.ArchEdit (
+ fudlogueEdit, fudlogueWrite, fudlogueWriteUni
+ ) where
+
+fudlogueEdit :: a -> b -> IO ()
+fudlogueEdit _ _ = do
+ putStrLn "sorry no fudgets available in Hugs"
+ return ()
+
+fudlogueWrite :: a -> b -> IO ()
+fudlogueWrite _ _ = do
+ putStrLn "sorry no fudgets available in Hugs"
+
+fudlogueWriteUni :: a -> b -> IO ()
+fudlogueWriteUni _ _ = do
+ putStrLn "sorry no fudgets available in Hugs"
diff --git a/src-2.9/GF/System/NoReadline.hs b/src-2.9/GF/System/NoReadline.hs
new file mode 100644
index 000000000..138ba4e28
--- /dev/null
+++ b/src-2.9/GF/System/NoReadline.hs
@@ -0,0 +1,27 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GF.System.NoReadline
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/05/10 15:04:01 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.1 $
+--
+-- Do not use readline.
+-----------------------------------------------------------------------------
+
+module GF.System.NoReadline (fetchCommand) where
+
+import System.IO.Error (try)
+import System.IO (stdout,hFlush)
+
+fetchCommand :: String -> IO (String)
+fetchCommand s = do
+ putStr s
+ hFlush stdout
+ res <- try getLine
+ case res of
+ Left e -> return "q"
+ Right l -> return l
diff --git a/src-2.9/GF/System/NoSignal.hs b/src-2.9/GF/System/NoSignal.hs
new file mode 100644
index 000000000..5d82a431e
--- /dev/null
+++ b/src-2.9/GF/System/NoSignal.hs
@@ -0,0 +1,29 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GF.System.NoSignal
+-- Maintainer : Bjorn Bringert
+-- Stability : (stability)
+-- Portability : (portability)
+--
+-- > CVS $Date: 2005/11/11 11:12:50 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.1 $
+--
+-- Dummy implementation of signal handling.
+-----------------------------------------------------------------------------
+
+module GF.System.NoSignal where
+
+import Control.Exception (Exception,catch)
+import Prelude hiding (catch)
+
+{-# NOINLINE runInterruptibly #-}
+runInterruptibly :: IO a -> IO (Either Exception a)
+--runInterruptibly = fmap Right
+runInterruptibly a =
+ p `catch` h
+ where p = a >>= \x -> return $! Right $! x
+ h e = return $ Left e
+
+blockInterrupt :: IO a -> IO a
+blockInterrupt = id
diff --git a/src-2.9/GF/System/NoSpeechInput.hs b/src-2.9/GF/System/NoSpeechInput.hs
new file mode 100644
index 000000000..04197ce92
--- /dev/null
+++ b/src-2.9/GF/System/NoSpeechInput.hs
@@ -0,0 +1,28 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GF.System.NoSpeechInput
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/05/10 15:04:01 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.2 $
+--
+-- Dummy speech input.
+-----------------------------------------------------------------------------
+
+module GF.System.NoSpeechInput (recognizeSpeech) where
+
+import GF.Infra.Ident (Ident)
+import GF.Infra.Option (Options)
+import GF.Conversion.Types (CGrammar)
+
+
+recognizeSpeech :: Ident -- ^ Grammar name
+ -> String -- ^ Language, e.g. en_UK
+ -> CGrammar -- ^ Context-free grammar for input
+ -> String -- ^ Start category name
+ -> Int -- ^ Number of utterances
+ -> IO [String]
+recognizeSpeech _ _ _ _ _ = fail "No speech input available"
diff --git a/src-2.9/GF/System/Readline.hs b/src-2.9/GF/System/Readline.hs
new file mode 100644
index 000000000..c12493f98
--- /dev/null
+++ b/src-2.9/GF/System/Readline.hs
@@ -0,0 +1,27 @@
+{-# OPTIONS -cpp #-}
+
+----------------------------------------------------------------------
+-- |
+-- Module : GF.System.Readline
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/05/10 15:04:01 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.2 $
+--
+-- Uses the right readline library to read user input.
+-----------------------------------------------------------------------------
+
+module GF.System.Readline (fetchCommand) where
+
+#ifdef USE_READLINE
+
+import GF.System.UseReadline (fetchCommand)
+
+#else
+
+import GF.System.NoReadline (fetchCommand)
+
+#endif
diff --git a/src-2.9/GF/System/Signal.hs b/src-2.9/GF/System/Signal.hs
new file mode 100644
index 000000000..fe8a12483
--- /dev/null
+++ b/src-2.9/GF/System/Signal.hs
@@ -0,0 +1,27 @@
+{-# OPTIONS -cpp #-}
+
+----------------------------------------------------------------------
+-- |
+-- Module : GF.System.Signal
+-- Maintainer : Bjorn Bringert
+-- Stability : (stability)
+-- Portability : (portability)
+--
+-- > CVS $Date: 2005/11/11 11:12:50 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.3 $
+--
+-- Import the right singal handling module.
+-----------------------------------------------------------------------------
+
+module GF.System.Signal (runInterruptibly,blockInterrupt) where
+
+#ifdef USE_INTERRUPT
+
+import GF.System.UseSignal (runInterruptibly,blockInterrupt)
+
+#else
+
+import GF.System.NoSignal (runInterruptibly,blockInterrupt)
+
+#endif
diff --git a/src-2.9/GF/System/SpeechInput.hs b/src-2.9/GF/System/SpeechInput.hs
new file mode 100644
index 000000000..6c2374473
--- /dev/null
+++ b/src-2.9/GF/System/SpeechInput.hs
@@ -0,0 +1,27 @@
+{-# OPTIONS -cpp #-}
+
+----------------------------------------------------------------------
+-- |
+-- Module : GF.System.SpeechInput
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/05/10 15:04:01 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.2 $
+--
+-- Uses the right speech recognition library for speech input.
+-----------------------------------------------------------------------------
+
+module GF.System.SpeechInput (recognizeSpeech) where
+
+#ifdef USE_ATK
+
+import GF.System.ATKSpeechInput (recognizeSpeech)
+
+#else
+
+import GF.System.NoSpeechInput (recognizeSpeech)
+
+#endif
diff --git a/src-2.9/GF/System/Tracing.hs b/src-2.9/GF/System/Tracing.hs
new file mode 100644
index 000000000..71bacfb75
--- /dev/null
+++ b/src-2.9/GF/System/Tracing.hs
@@ -0,0 +1,73 @@
+{-# OPTIONS -cpp #-}
+
+----------------------------------------------------------------------
+-- |
+-- Maintainer : PL
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/26 09:54:11 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.4 $
+--
+-- Tracing utilities for debugging purposes.
+-- If the CPP symbol TRACING is set, then the debugging output is shown.
+-----------------------------------------------------------------------------
+
+
+module GF.System.Tracing
+ (trace, trace2, traceM, traceCall, tracePrt, traceCalcFirst) where
+
+import qualified Debug.Trace as Trace
+
+-- | emit a string inside braces, before(?) calculating the value:
+-- @{str}@
+trace :: String -> a -> a
+
+-- | emit function name and debugging output:
+-- @{fun: out}@
+trace2 :: String -> String -> a -> a
+
+-- | monadic version of 'trace2'
+traceM :: Monad m => String -> String -> m ()
+
+-- | show when a value is starting to be calculated (with a '+'),
+-- and when it is finished (with a '-')
+traceCall :: String -> String -> (a -> String) -> a -> a
+
+-- | showing the resulting value (filtered through a printing function):
+-- @{fun: value}@
+tracePrt :: String -> (a -> String) -> a -> a
+
+-- | this is equivalent to 'seq' when tracing, but
+-- just skips the first argument otherwise
+traceCalcFirst :: a -> b -> b
+
+#if TRACING
+trace str a = Trace.trace (bold ++ "{" ++ normal ++ str ++ bold ++ "}" ++ normal) a
+trace2 fun str a = trace (bold ++ fgcol 1 ++ fun ++ ": " ++ normal ++ str) a
+traceM fun str = trace2 fun str (return ())
+traceCall fun start prt val
+ = trace2 ("+" ++ fun) start $
+ val `seq` trace2 ("-" ++ fun) (prt val) val
+tracePrt mod prt val = val `seq` trace2 mod (prt val) val
+traceCalcFirst = seq
+
+#else
+trace _ = id
+trace2 _ _ = id
+traceM _ _ = return ()
+traceCall _ _ _ = id
+tracePrt _ _ = id
+traceCalcFirst _ = id
+
+#endif
+
+
+escape = "\ESC"
+highlight = escape ++ "[7m"
+bold = escape ++ "[1m"
+underline = escape ++ "[4m"
+normal = escape ++ "[0m"
+fgcol col = escape ++ "[0" ++ show (30+col) ++ "m"
+bgcol col = escape ++ "[0" ++ show (40+col) ++ "m"
diff --git a/src-2.9/GF/System/UseReadline.hs b/src-2.9/GF/System/UseReadline.hs
new file mode 100644
index 000000000..c84b9d7f4
--- /dev/null
+++ b/src-2.9/GF/System/UseReadline.hs
@@ -0,0 +1,25 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GF.System.UseReadline
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/05/10 15:04:01 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.1 $
+--
+-- Use GNU readline
+-----------------------------------------------------------------------------
+
+module GF.System.UseReadline (fetchCommand) where
+
+import System.Console.Readline (readline, addHistory)
+
+fetchCommand :: String -> IO (String)
+fetchCommand s = do
+ res <- readline s
+ case res of
+ Nothing -> return "q"
+ Just s -> do addHistory s
+ return s
diff --git a/src-2.9/GF/System/UseSignal.hs b/src-2.9/GF/System/UseSignal.hs
new file mode 100644
index 000000000..5e6d81237
--- /dev/null
+++ b/src-2.9/GF/System/UseSignal.hs
@@ -0,0 +1,58 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GF.System.UseSignal
+-- Maintainer : Bjorn Bringert
+-- Stability : (stability)
+-- Portability : (portability)
+--
+-- > CVS $Date: 2005/11/11 11:12:50 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.1 $
+--
+-- Allows SIGINT (Ctrl-C) to interrupt computations.
+-----------------------------------------------------------------------------
+
+module GF.System.UseSignal where
+
+import Control.Concurrent (myThreadId, killThread)
+import Control.Exception (Exception,catch)
+import Prelude hiding (catch)
+import System.IO
+import System.Posix.Signals
+
+{-# NOINLINE runInterruptibly #-}
+
+-- | Run an IO action, and allow it to be interrupted
+-- by a SIGINT to the current process. Returns
+-- an exception if the process did not complete
+-- normally.
+-- NOTES:
+-- * This will replace any existing SIGINT
+-- handler during the action. After the computation
+-- has completed the existing handler will be restored.
+-- * If the IO action is lazy (e.g. using readFile,
+-- unsafeInterleaveIO etc.) the lazy computation will
+-- not be interruptible, as it will be performed
+-- after the signal handler has been removed.
+runInterruptibly :: IO a -> IO (Either Exception a)
+runInterruptibly a =
+ do t <- myThreadId
+ oldH <- installHandler sigINT (Catch (killThread t)) Nothing
+ x <- p `catch` h
+ installHandler sigINT oldH Nothing
+ return x
+ where p = a >>= \x -> return $! Right $! x
+ h e = return $ Left e
+
+-- | Like 'runInterruptibly', but always returns (), whether
+-- the computation fails or not.
+runInterruptibly_ :: IO () -> IO ()
+runInterruptibly_ = fmap (either (const ()) id) . runInterruptibly
+
+-- | Run an action with SIGINT blocked.
+blockInterrupt :: IO a -> IO a
+blockInterrupt a =
+ do oldH <- installHandler sigINT Ignore Nothing
+ x <- a
+ installHandler sigINT oldH Nothing
+ return x
diff --git a/src-2.9/GF/Text/Arabic.hs b/src-2.9/GF/Text/Arabic.hs
new file mode 100644
index 000000000..c482b1172
--- /dev/null
+++ b/src-2.9/GF/Text/Arabic.hs
@@ -0,0 +1,63 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Arabic
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:34 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.6 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.Arabic (mkArabic) where
+
+mkArabic :: String -> String
+mkArabic = unwords . (map mkArabicWord) . words
+----mkArabic = reverse . unwords . (map mkArabicWord) . words
+--- reverse : assumes everything's on same line
+
+type ArabicChar = Char
+
+mkArabicWord :: String -> [ArabicChar]
+mkArabicWord = map mkArabicChar . getLetterPos
+
+getLetterPos :: String -> [(Char,Int)]
+getLetterPos [] = []
+getLetterPos ('I':cs) = ('*',7) : getLetterPos cs -- 0xfe80
+getLetterPos ('O':cs) = ('*',8) : getIn cs -- 0xfe8b
+getLetterPos ('l':'a':cs) = ('*',5) : getLetterPos cs -- 0xfefb
+getLetterPos [c] = [(c,1)] -- 1=isolated
+getLetterPos (c:cs) | isReduced c = (c,1) : getLetterPos cs
+getLetterPos (c:cs) = (c,3) : getIn cs -- 3=initial
+
+
+getIn [] = []
+getIn ('I':cs) = ('*',7) : getLetterPos cs -- 0xfe80
+getIn ('O':cs) = ('*',9) : getIn cs -- 0xfe8c
+getIn ('l':'a':cs) = ('*',6) : getLetterPos cs -- 0xfefc
+getIn [c] = [(c,2)] -- 2=final
+getIn (c:cs) | isReduced c = (c,2) : getLetterPos cs
+getIn (c:cs) = (c,4) : getIn cs -- 4=medial
+
+isReduced :: Char -> Bool
+isReduced c = c `elem` "UuWiYOaAdVrzwj"
+
+mkArabicChar ('*',p) | p > 4 && p < 10 =
+ (map toEnum [0xfefb,0xfefc,0xfe80,0xfe8b,0xfe8c]) !! (p-5)
+mkArabicChar cp@(c,p) = case lookup c cc of Just c' -> (c' !! (p-1)) ; _ -> c
+ where
+ cc = mkArabicTab allArabicCodes allArabic
+
+mkArabicTab (c:cs) as = (c,as1) : mkArabicTab cs as2 where
+ (as1,as2) = if isReduced c then splitAt 2 as else splitAt 4 as
+mkArabicTab [] _ = []
+
+allArabicCodes = "UuWiYOabAtvgHCdVrzscSDTZoxfqklmnhwjy"
+
+allArabic :: String
+allArabic = (map toEnum [0xfe81 .. 0xfef4]) -- I=0xfe80
+
+
diff --git a/src-2.9/GF/Text/Devanagari.hs b/src-2.9/GF/Text/Devanagari.hs
new file mode 100644
index 000000000..bf4343cd0
--- /dev/null
+++ b/src-2.9/GF/Text/Devanagari.hs
@@ -0,0 +1,97 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Devanagari
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:34 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.5 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.Devanagari (mkDevanagari) where
+
+mkDevanagari :: String -> String
+mkDevanagari = digraphWordToUnicode . adHocToDigraphWord
+
+adHocToDigraphWord :: String -> [(Char, Char)]
+adHocToDigraphWord str = case str of
+ [] -> []
+ '<' : cs -> ('\\', '<') : spoolMarkup cs
+ ' ' : cs -> ('\\', ' ') : adHocToDigraphWord cs -- skip space
+
+-- if c1 is a vowel
+ -- Two of the same vowel => lengthening
+ c1 : c2 : cs | c1 == c2 && isVowel c1 -> (cap c1, ':') : adHocToDigraphWord cs
+ -- digraphed or long vowel
+ c1 : c2 : cs | isVowel c1 && isVowel c2 -> (cap c1, cap c2) : adHocToDigraphWord cs
+ c1 : cs | isVowel c1 -> (' ', cap c1) : adHocToDigraphWord cs
+
+-- c1 isn't a vowel
+ -- c1 : 'a' : [] -> [(' ', c1)] -- a inherent
+ -- c1 : c2 : [] | isVowel c2 -> (' ', c1) : [(' ', c2)]
+
+ -- c1 is aspirated
+ c1 : 'H' : c2 : c3 : cs | c2 == c3 && isVowel c2 ->
+ (c1, 'H') : (c2, ':') : adHocToDigraphWord cs
+ c1 : 'H' : c2 : c3 : cs | isVowel c2 && isVowel c3 ->
+ (c1, 'H') : (c2, c3) : adHocToDigraphWord cs
+ c1 : 'H' : 'a' : cs -> (c1, 'H') : adHocToDigraphWord cs -- a inherent
+ c1 : 'H' : c2 : cs | isVowel c2 -> (c1, 'H') : (' ', c2) : adHocToDigraphWord cs
+ -- not vowelless at EOW
+ c1 : 'H' : ' ' : cs -> (c1, 'H') : ('\\', ' ') : adHocToDigraphWord cs
+ c1 : 'H' : [] -> [(c1, 'H')]
+ c1 : 'H' : cs -> (c1, 'H') : (' ', '^') : adHocToDigraphWord cs -- vowelless
+
+ -- c1 unasp.
+ c1 : c2 : c3 : cs | c2 == c3 && isVowel c2 -> (' ', c1) : (c2, ':') : adHocToDigraphWord cs
+ c1 : c2 : c3 : cs | isVowel c2 && isVowel c3 -> (' ', c1) : (c2, c3) : adHocToDigraphWord cs
+ c1 : 'a' : cs -> (' ', c1) : adHocToDigraphWord cs -- a inherent
+ c1 : c2 : cs | isVowel c2 -> (' ', c1) : (' ', c2) : adHocToDigraphWord cs
+ -- not vowelless at EOW
+ c1 : ' ' : cs -> (' ', c1) : ('\\', ' '): adHocToDigraphWord cs
+ c1 : [] -> [(' ', c1)]
+ 'M' : cs -> (' ', 'M') : adHocToDigraphWord cs -- vowelless but no vowelless sign for anusvara
+ c1 : cs -> (' ', c1) : (' ', '^') : adHocToDigraphWord cs -- vowelless
+
+isVowel x = elem x "aeiou:"
+cap :: Char -> Char
+cap x = case x of
+ 'a' -> 'A'
+ 'e' -> 'E'
+ 'i' -> 'I'
+ 'o' -> 'O'
+ 'u' -> 'U'
+ c -> c
+
+spoolMarkup :: String -> [(Char, Char)]
+spoolMarkup s = case s of
+ -- [] -> [] -- Shouldn't happen
+ '>' : cs -> ('\\', '>') : adHocToDigraphWord cs
+ c1 : cs -> ('\\', c1) : spoolMarkup cs
+
+
+digraphWordToUnicode :: [(Char, Char)] -> String
+digraphWordToUnicode = map digraphToUnicode
+
+digraphToUnicode :: (Char, Char) -> Char
+digraphToUnicode (c1, c2) = case lookup (c1, c2) cc of Just c' -> c' ; _ -> c2
+ where
+ cc = zip allDevanagariCodes allDevanagari
+
+digraphedDevanagari = " ~ M ;__ AA: II: UU:RoLoEvE~ EE:AvA~ OAU kkH ggHNG ccH jjH \241 TTH DDH N ttH ddH nn. ppH bbH m y rr. l LL. v \231 S s h____ .-Sa: ii: uu:ror:eve~ eaiava~ oau ^____OM | -dddu______ Q X G zD.RH fy.R:L:mrmR#I#d#0#1#2#3#4#5#6#7#8#9#o"
+
+allDevanagariCodes :: [(Char, Char)]
+allDevanagariCodes = mkPairs digraphedDevanagari
+
+allDevanagari :: String
+allDevanagari = (map toEnum [0x0901 .. 0x0970])
+
+mkPairs :: String -> [(Char, Char)]
+mkPairs str = case str of
+ [] -> []
+ c1 : c2 : cs -> (c1, c2) : mkPairs cs
+
diff --git a/src-2.9/GF/Text/Ethiopic.hs b/src-2.9/GF/Text/Ethiopic.hs
new file mode 100644
index 000000000..81abbf719
--- /dev/null
+++ b/src-2.9/GF/Text/Ethiopic.hs
@@ -0,0 +1,72 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Ethiopic
+-- Maintainer : HH
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:35 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.6 $
+--
+-- Ascii-Unicode decoding for Ethiopian.
+-- Copyright (c) Harald Hammarström 2003 under Gnu General Public License
+-----------------------------------------------------------------------------
+
+module GF.Text.Ethiopic (mkEthiopic) where
+
+mkEthiopic :: String -> String
+mkEthiopic = digraphWordToUnicode . adHocToDigraphWord
+
+-- mkEthiopic :: String -> String
+-- mkEthiopic = reverse . unwords . (map (digraphWordToUnicode . adHocToDigraphWord)) . words
+--- reverse : assumes everything's on same line
+
+adHocToDigraphWord :: String -> [(Char, Int)]
+adHocToDigraphWord str = case str of
+ [] -> []
+ '<' : cs -> ('<', -1) : spoolMarkup cs
+ c1 : cs | isVowel c1 -> (')', vowelOrder c1) : adHocToDigraphWord cs
+ -- c1 isn't a vowel
+ c1 : cs | not (elem c1 allEthiopicCodes) -> (c1, -1) : adHocToDigraphWord cs
+ c1 : c2 : cs | isVowel c2 -> (c1, vowelOrder c2) : adHocToDigraphWord cs
+ c1 : cs -> (c1, 5) : adHocToDigraphWord cs
+
+spoolMarkup :: String -> [(Char, Int)]
+spoolMarkup s = case s of
+ -- [] -> [] -- Shouldn't happen
+ '>' : cs -> ('>', -1) : adHocToDigraphWord cs
+ c1 : cs -> (c1, -1) : spoolMarkup cs
+
+isVowel x = elem x "A\228ui\239aeoI"
+
+vowelOrder :: Char -> Int
+vowelOrder x = case x of
+ 'A' -> 0
+ '\228' -> 0 -- ä
+ 'u' -> 1
+ 'i' -> 2
+ 'a' -> 3
+ 'e' -> 4
+ 'I' -> 5
+ '\239' -> 5 -- ï
+ 'o' -> 6
+ c -> 5 -- vowelless
+
+digraphWordToUnicode = map digraphToUnicode
+
+digraphToUnicode :: (Char, Int) -> Char
+-- digraphToUnicode (c1, c2) = c1
+
+digraphToUnicode (c1, -1) = c1
+digraphToUnicode (c1, c2) = toEnum (0x1200 + c2 + 8*case lookup c1 cc of Just c' -> c')
+ where
+ cc = zip allEthiopicCodes allEthiopic
+
+allEthiopic :: [Int]
+allEthiopic = [0 .. 44] -- x 8
+
+allEthiopicCodes = "hlHmLrs$KQ__bBtcxXnN)kW__w(zZyd_jgG_TCPSLfp"
+
+-- Q = kW, X = xW, W = kW, G = gW
+
diff --git a/src-2.9/GF/Text/ExtendedArabic.hs b/src-2.9/GF/Text/ExtendedArabic.hs
new file mode 100644
index 000000000..d2c5faac5
--- /dev/null
+++ b/src-2.9/GF/Text/ExtendedArabic.hs
@@ -0,0 +1,99 @@
+----------------------------------------------------------------------
+-- |
+-- Module : ExtendedArabic
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:36 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.6 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.ExtendedArabic (mkArabic0600, mkExtendedArabic) where
+
+mkArabic0600 :: String -> String
+mkArabic0600 = digraphWordToUnicode . aarnesToDigraphWord
+
+aarnesToDigraphWord :: String -> [(Char, Char)]
+aarnesToDigraphWord str = case str of
+ [] -> []
+ '<' : cs -> ('\\', '<') : spoolMarkup2 cs
+
+ 'v' : cs -> ('T', 'H') : aarnesToDigraphWord cs
+ 'a' : cs -> (' ', 'A') : aarnesToDigraphWord cs
+ 'o' : cs -> (' ', '3') : aarnesToDigraphWord cs
+ 'O' : cs -> ('\'', 'i') : aarnesToDigraphWord cs
+
+ 'u' : cs -> ('\'', 'A') : aarnesToDigraphWord cs
+ 'C' : cs -> (' ', 'X') : aarnesToDigraphWord cs
+
+ 'U' : cs -> ('~', 'A') : aarnesToDigraphWord cs
+ 'A' : cs -> ('"', 't') : aarnesToDigraphWord cs
+ 'c' : cs -> ('s', 'h') : aarnesToDigraphWord cs
+ c : cs -> (' ', c) : aarnesToDigraphWord cs
+
+mkExtendedArabic :: String -> String
+mkExtendedArabic = digraphWordToUnicode . adHocToDigraphWord
+
+adHocToDigraphWord :: String -> [(Char, Char)]
+adHocToDigraphWord str = case str of
+ [] -> []
+ '<' : cs -> ('\\', '<') : spoolMarkup cs
+ -- Sorani
+ 'W' : cs -> (':', 'w') : adHocToDigraphWord cs -- ?? Will do
+ 'E' : cs -> (' ', 'i') : adHocToDigraphWord cs -- ?? Letter missing!
+ 'j' : cs -> ('d', 'j') : adHocToDigraphWord cs
+ 'O' : cs -> ('v', 'w') : adHocToDigraphWord cs
+ 'F' : cs -> (' ', 'v') : adHocToDigraphWord cs
+ 'Z' : cs -> ('z', 'h') : adHocToDigraphWord cs
+ 'I' : cs -> (' ', 'i') : adHocToDigraphWord cs -- ?? Letter missing!
+ 'C' : cs -> ('c', 'h') : adHocToDigraphWord cs
+ -- Pashto
+ 'e' : cs -> (':', 'y') : adHocToDigraphWord cs
+ '$' : cs -> ('3', 'H') : adHocToDigraphWord cs
+ 'X' : cs -> ('s', '.') : adHocToDigraphWord cs
+ 'G' : cs -> ('z', '.') : adHocToDigraphWord cs
+ 'a' : cs -> (' ', 'A') : adHocToDigraphWord cs
+ 'P' : cs -> ('\'', 'H') : adHocToDigraphWord cs
+ 'R' : cs -> ('o', 'r') : adHocToDigraphWord cs
+ -- Shared
+ 'A' : cs -> (' ', 'h') : adHocToDigraphWord cs -- ?? Maybe to "t or 0x06d5
+ 'c' : cs -> ('s', 'h') : adHocToDigraphWord cs
+ c : cs -> (' ', c) : adHocToDigraphWord cs
+
+
+-- Beginning 0x621 up and including 0x06d1
+digraphedExtendedArabic = " '~A'A'w,A'i A b\"t tTHdj H X dDH r z ssh S D T Z 3GH__________ - f q k l m n h w i y&a&w&i/a/w/i/W/o/~/'/,/|/6/v_____________#0#1#2#3#4#5#6#7#8#9#%#,#'#*>b>q$|> A2'2,3'A'w'w&y'Tb:b:BoT3b p4b4B'H:H2H\"H3Hch4HTdod.dTD:d:D3d3D4dTrvror.rvRz.:rzh4zs.+s*S:S3S3T33>ff.f: v4f.q3q-k~kok.k3k3K gog:g:G3Gvl.l3l3L:n>nTnon3n?h4H't>Y\"Yow-wvwww|w^w:w3w>y/yvy.w:y3y____ -ae"
+
+digraphWordToUnicode = map digraphToUnicode
+
+digraphToUnicode :: (Char, Char) -> Char
+digraphToUnicode (c1, c2) = case lookup (c1, c2) cc of Just c' -> c' ; _ -> c2
+ where
+ cc = zip allExtendedArabicCodes allExtendedArabic
+
+allExtendedArabicCodes :: [(Char, Char)]
+allExtendedArabicCodes = mkPairs digraphedExtendedArabic
+
+allExtendedArabic :: String
+allExtendedArabic = (map toEnum [0x0621 .. 0x06d1])
+
+mkPairs :: String -> [(Char, Char)]
+mkPairs str = case str of
+ [] -> []
+ c1 : c2 : cs -> (c1, c2) : mkPairs cs
+
+spoolMarkup :: String -> [(Char, Char)]
+spoolMarkup s = case s of
+ [] -> [] -- Shouldn't happen
+ '>' : cs -> ('\\', '>') : adHocToDigraphWord cs
+ c1 : cs -> ('\\', c1) : spoolMarkup cs
+
+spoolMarkup2 :: String -> [(Char, Char)]
+spoolMarkup2 s = case s of
+ [] -> [] -- Shouldn't happen
+ '>' : cs -> ('\\', '>') : aarnesToDigraphWord cs
+ c1 : cs -> ('\\', c1) : spoolMarkup2 cs
diff --git a/src-2.9/GF/Text/ExtraDiacritics.hs b/src-2.9/GF/Text/ExtraDiacritics.hs
new file mode 100644
index 000000000..f3d811c2c
--- /dev/null
+++ b/src-2.9/GF/Text/ExtraDiacritics.hs
@@ -0,0 +1,37 @@
+----------------------------------------------------------------------
+-- |
+-- Module : ExtraDiacritics
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:36 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.5 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.ExtraDiacritics (mkExtraDiacritics) where
+
+mkExtraDiacritics :: String -> String
+mkExtraDiacritics = mkExtraDiacriticsWord
+
+mkExtraDiacriticsWord :: String -> String
+mkExtraDiacriticsWord str = case str of
+ [] -> []
+ '<' : cs -> '<' : spoolMarkup cs
+ --
+ '/' : cs -> toEnum 0x0301 : mkExtraDiacriticsWord cs
+ '~' : cs -> toEnum 0x0306 : mkExtraDiacriticsWord cs
+ ':' : cs -> toEnum 0x0304 : mkExtraDiacriticsWord cs -- some of these could be put in LatinA
+ '.' : cs -> toEnum 0x0323 : mkExtraDiacriticsWord cs
+ 'i' : '-' : cs -> toEnum 0x0268 : mkExtraDiacriticsWord cs -- in IPA extensions
+ -- Default
+ c : cs -> c : mkExtraDiacriticsWord cs
+
+spoolMarkup :: String -> String
+spoolMarkup s = case s of
+ [] -> [] -- Shouldn't happen
+ '>' : cs -> '>' : mkExtraDiacriticsWord cs
+ c1 : cs -> c1 : spoolMarkup cs
diff --git a/src-2.9/GF/Text/Greek.hs b/src-2.9/GF/Text/Greek.hs
new file mode 100644
index 000000000..6b9361a29
--- /dev/null
+++ b/src-2.9/GF/Text/Greek.hs
@@ -0,0 +1,172 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Greek
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:37 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.5 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.Greek (mkGreek) where
+
+mkGreek :: String -> String
+mkGreek = unwords . (map mkGreekWord) . mkGravis . words
+
+--- TODO : optimize character formation by factorizing the case expressions
+
+type GreekChar = Char
+
+mkGreekWord :: String -> [GreekChar]
+mkGreekWord = map (toEnum . mkGreekChar) . mkGreekSpec
+
+mkGravis :: [String] -> [String]
+mkGravis [] = []
+mkGravis [w] = [w]
+mkGravis (w1:w2:ws)
+ | stressed w2 = mkG w1 : mkGravis (w2:ws)
+ | otherwise = w1 : w2 : mkGravis ws
+ where
+ stressed w = any (`elem` "'~`") w
+ mkG :: String -> String
+ mkG w = let (w1,w2) = span (/='\'') w in
+ case w2 of
+ '\'':v:cs | not (any isVowel cs) -> w1 ++ "`" ++ [v] ++ cs
+ '\'':'!':v:cs | not (any isVowel cs) -> w1 ++ "`!" ++ [v] ++ cs
+ _ -> w
+ isVowel c = elem c "aehiouw"
+
+mkGreekSpec :: String -> [(Char,Int)]
+mkGreekSpec str = case str of
+ [] -> []
+ '(' :'\'': '!' : c : cs -> (c,25) : mkGreekSpec cs
+ '(' :'~' : '!' : c : cs -> (c,27) : mkGreekSpec cs
+ '(' :'`' : '!' : c : cs -> (c,23) : mkGreekSpec cs
+ '(' : '!' : c : cs -> (c,21) : mkGreekSpec cs
+ ')' :'\'': '!' : c : cs -> (c,24) : mkGreekSpec cs
+ ')' :'~' : '!' : c : cs -> (c,26) : mkGreekSpec cs
+ ')' :'`' : '!' : c : cs -> (c,22) : mkGreekSpec cs
+ ')' : '!' : c : cs -> (c,20) : mkGreekSpec cs
+ '\'': '!' : c : cs -> (c,30) : mkGreekSpec cs
+ '~' : '!' : c : cs -> (c,31) : mkGreekSpec cs
+ '`' : '!' : c : cs -> (c,32) : mkGreekSpec cs
+ '!' : c : cs -> (c,33) : mkGreekSpec cs
+ '(' :'\'': c : cs -> (c,5) : mkGreekSpec cs
+ '(' :'~' : c : cs -> (c,7) : mkGreekSpec cs
+ '(' :'`' : c : cs -> (c,3) : mkGreekSpec cs
+ '(' : c : cs -> (c,1) : mkGreekSpec cs
+ ')' :'\'': c : cs -> (c,4) : mkGreekSpec cs
+ ')' :'~' : c : cs -> (c,6) : mkGreekSpec cs
+ ')' :'`' : c : cs -> (c,2) : mkGreekSpec cs
+ ')' : c : cs -> (c,0) : mkGreekSpec cs
+ '\'': c : cs -> (c,10) : mkGreekSpec cs
+ '~' : c : cs -> (c,11) : mkGreekSpec cs
+ '`' : c : cs -> (c,12) : mkGreekSpec cs
+ c : cs -> (c,-1) : mkGreekSpec cs
+
+mkGreekChar (c,-1) = case lookup c cc of Just c' -> c' ; _ -> fromEnum c
+ where
+ cc = zip "abgdezhqiklmnxoprjstyfcuw" allGreekMin
+mkGreekChar (c,n) = case (c,n) of
+ ('a',10) -> 0x03ac
+ ('a',11) -> 0x1fb6
+ ('a',12) -> 0x1f70
+ ('a',30) -> 0x1fb4
+ ('a',31) -> 0x1fb7
+ ('a',32) -> 0x1fb2
+ ('a',33) -> 0x1fb3
+ ('a',n) | n >19 -> 0x1f80 + n - 20
+ ('a',n) -> 0x1f00 + n
+ ('e',10) -> 0x03ad -- '
+-- ('e',11) -> 0x1fb6 -- ~ can't happen
+ ('e',12) -> 0x1f72 -- `
+ ('e',n) -> 0x1f10 + n
+ ('h',10) -> 0x03ae -- '
+ ('h',11) -> 0x1fc6 -- ~
+ ('h',12) -> 0x1f74 -- `
+
+ ('h',30) -> 0x1fc4
+ ('h',31) -> 0x1fc7
+ ('h',32) -> 0x1fc2
+ ('h',33) -> 0x1fc3
+ ('h',n) | n >19 -> 0x1f90 + n - 20
+
+ ('h',n) -> 0x1f20 + n
+ ('i',10) -> 0x03af -- '
+ ('i',11) -> 0x1fd6 -- ~
+ ('i',12) -> 0x1f76 -- `
+ ('i',n) -> 0x1f30 + n
+ ('o',10) -> 0x03cc -- '
+-- ('o',11) -> 0x1fb6 -- ~ can't happen
+ ('o',12) -> 0x1f78 -- `
+ ('o',n) -> 0x1f40 + n
+ ('y',10) -> 0x03cd -- '
+ ('y',11) -> 0x1fe6 -- ~
+ ('y',12) -> 0x1f7a -- `
+ ('y',n) -> 0x1f50 + n
+ ('w',10) -> 0x03ce -- '
+ ('w',11) -> 0x1ff6 -- ~
+ ('w',12) -> 0x1f7c -- `
+
+ ('w',30) -> 0x1ff4
+ ('w',31) -> 0x1ff7
+ ('w',32) -> 0x1ff2
+ ('w',33) -> 0x1ff3
+ ('w',n) | n >19 -> 0x1fa0 + n - 20
+
+ ('w',n) -> 0x1f60 + n
+ ('r',1) -> 0x1fe5
+ _ -> mkGreekChar (c,-1) --- should not happen
+
+allGreekMin :: [Int]
+allGreekMin = [0x03b1 .. 0x03c9]
+
+
+{-
+encoding of Greek writing. Those hard to guess are marked with ---
+
+ maj min
+A a Alpha 0391 03b1
+B b Beta 0392 03b2
+G g Gamma 0393 03b3
+D d Delta 0394 03b4
+E e Epsilon 0395 03b5
+Z z Zeta 0396 03b6
+H h Eta --- 0397 03b7
+Q q Theta --- 0398 03b8
+I i Iota 0399 03b9
+K k Kappa 039a 03ba
+L l Lambda 039b 03bb
+M m My 039c 03bc
+N n Ny 039d 03bd
+X x Xi 039e 03be
+O o Omikron 039f 03bf
+P p Pi 03a0 03c0
+R r Rho 03a1 03c1
+ j Sigma --- 03c2
+S s Sigma 03a3 03c3
+T t Tau 03a4 03c4
+Y y Ypsilon 03a5 03c5
+F f Phi 03a6 03c6
+C c Khi --- 03a7 03c7
+U u Psi 03a8 03c8
+W w Omega --- 03a9 03c9
+
+( spiritus asper
+) spiritus lenis
+! iota subscriptum
+
+' acutus
+~ circumflexus
+` gravis
+
+-}
+
+
+
+
+
diff --git a/src-2.9/GF/Text/Hebrew.hs b/src-2.9/GF/Text/Hebrew.hs
new file mode 100644
index 000000000..c7026d8da
--- /dev/null
+++ b/src-2.9/GF/Text/Hebrew.hs
@@ -0,0 +1,53 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Hebrew
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:37 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.8 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.Hebrew (mkHebrew) where
+
+mkHebrew :: String -> String
+mkHebrew = mkHebrewWord
+----mkHebrew = reverse . mkHebrewWord
+--- reverse : assumes everything's on same line
+
+type HebrewChar = Char
+
+-- HH 031103 added code for spooling the markup
+-- removed reverse, words, unwords
+-- (seemed obsolete and come out wrong on the screen)
+-- AR 26/1/2004 put reverse back - needed in Fudgets (but not in Java?)
+
+mkHebrewWord :: String -> [HebrewChar]
+-- mkHebrewWord = map mkHebrewChar
+
+mkHebrewWord s = case s of
+ [] -> []
+ '<' : cs -> '<' : spoolMarkup cs
+ ' ' : cs -> ' ' : mkHebrewWord cs
+ c1 : cs -> mkHebrewChar c1 : mkHebrewWord cs
+
+spoolMarkup :: String -> String
+spoolMarkup s = case s of
+ [] -> [] -- Shouldn't happen
+ '>' : cs -> '>' : mkHebrewWord cs
+ c1 : cs -> c1 : spoolMarkup cs
+
+mkHebrewChar c = case lookup c cc of Just c' -> c' ; _ -> c
+ where
+ cc = zip allHebrewCodes allHebrew
+
+allHebrewCodes = "-abgdhwzHTyKklMmNnSoPpCcqrst"
+
+allHebrew :: String
+allHebrew = (map toEnum (0x05be : [0x05d0 .. 0x05ea]))
+
+
diff --git a/src-2.9/GF/Text/Hiragana.hs b/src-2.9/GF/Text/Hiragana.hs
new file mode 100644
index 000000000..ba74fc83c
--- /dev/null
+++ b/src-2.9/GF/Text/Hiragana.hs
@@ -0,0 +1,95 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Hiragana
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:38 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.5 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.Hiragana (mkJapanese) where
+
+-- long vowel romaaji must be ei, ou not ee, oo
+
+mkJapanese :: String -> String
+mkJapanese = digraphWordToUnicode . romaajiToDigraphWord
+
+romaajiToDigraphWord :: String -> [(Char, Char)]
+romaajiToDigraphWord str = case str of
+ [] -> []
+ '<' : cs -> ('\\', '<') : spoolMarkup cs
+ ' ' : cs -> ('\\', ' ') : romaajiToDigraphWord cs
+
+ c1 : cs | isVowel c1 -> (' ', cap c1) : romaajiToDigraphWord cs
+
+ -- The combinations
+ c1 : 'y' : c2 : cs -> (c1, 'i') : ('y', cap c2) : romaajiToDigraphWord cs
+
+ 's' : 'h' : 'a' : cs -> ('S', 'i') : ('y', 'A') : romaajiToDigraphWord cs
+ 'c' : 'h' : 'a' : cs -> ('C', 'i') : ('y', 'A') : romaajiToDigraphWord cs
+ 'j' : 'a' : cs -> ('j', 'i') : ('y', 'A') : romaajiToDigraphWord cs
+
+ 's' : 'h' : 'u' : cs -> ('S', 'i') : ('y', 'U') : romaajiToDigraphWord cs
+ 'c' : 'h' : 'u' : cs -> ('C', 'i') : ('y', 'U') : romaajiToDigraphWord cs
+ 'j' : 'u' : cs -> ('j', 'i') : ('y', 'U') : romaajiToDigraphWord cs
+
+ 's' : 'h' : 'o' : cs -> ('S', 'i') : ('y', 'O') : romaajiToDigraphWord cs
+ 'c' : 'h' : 'o' : cs -> ('C', 'i') : ('y', 'O') : romaajiToDigraphWord cs
+ 'j' : 'o' : cs -> ('j', 'i') : ('y', 'O') : romaajiToDigraphWord cs
+
+ 'd' : 'z' : c3 : cs -> ('D', c3) : romaajiToDigraphWord cs
+ 't' : 's' : c3 : cs -> ('T', c3) : romaajiToDigraphWord cs
+ 'c' : 'h' : c3 : cs -> ('C', c3) : romaajiToDigraphWord cs
+ 's' : 'h' : c3 : cs -> ('S', c3) : romaajiToDigraphWord cs
+ 'z' : 'h' : c3 : cs -> ('Z', c3) : romaajiToDigraphWord cs
+
+ c1 : ' ' : cs -> (' ', c1) : ('\\', ' ') : romaajiToDigraphWord cs -- n
+ c1 : [] -> [(' ', c1)] -- n
+
+ c1 : c2 : cs | isVowel c2 -> (c1, c2) : romaajiToDigraphWord cs
+ c1 : c2 : cs | c1 == c2 -> ('T', 'U') : romaajiToDigraphWord (c2 : cs) -- double cons
+ c1 : cs -> (' ', c1) : romaajiToDigraphWord cs -- n
+
+isVowel x = elem x "aeiou"
+cap :: Char -> Char
+cap x = case x of
+ 'a' -> 'A'
+ 'e' -> 'E'
+ 'i' -> 'I'
+ 'o' -> 'O'
+ 'u' -> 'U'
+ c -> c
+
+spoolMarkup :: String -> [(Char, Char)]
+spoolMarkup s = case s of
+ -- [] -> [] -- Shouldn't happen
+ '>' : cs -> ('\\', '>') : romaajiToDigraphWord cs
+ c1 : cs -> ('\\', c1) : spoolMarkup cs
+
+digraphWordToUnicode :: [(Char, Char)] -> String
+digraphWordToUnicode = map digraphToUnicode
+
+digraphToUnicode :: (Char, Char) -> Char
+digraphToUnicode (c1, c2) = case lookup (c1, c2) cc of Just c' -> c' ; _ -> c2
+ where
+ cc = zip allHiraganaCodes allHiragana
+
+allHiraganaCodes :: [(Char, Char)]
+allHiraganaCodes = mkPairs digraphedHiragana
+
+allHiragana :: String
+allHiragana = (map toEnum [0x3041 .. 0x309f])
+
+mkPairs :: String -> [(Char, Char)]
+mkPairs str = case str of
+ [] -> []
+ c1 : c2 : cs -> (c1, c2) : mkPairs cs
+
+digraphedHiragana = " a A i I u U e E o OkagakigikugukegekogosazaSiZisuzusezesozotadaCijiTUTuDutedetodonaninunenohabapahibipihubupuhebepehobopomamimumemoyAyayUyuyOyorarirurerowaWawiwewo nvukAkE____<< o>>o >'> b"
+
+
diff --git a/src-2.9/GF/Text/LatinASupplement.hs b/src-2.9/GF/Text/LatinASupplement.hs
new file mode 100644
index 000000000..f42423c91
--- /dev/null
+++ b/src-2.9/GF/Text/LatinASupplement.hs
@@ -0,0 +1,69 @@
+----------------------------------------------------------------------
+-- |
+-- Module : LatinASupplement
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:39 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.5 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.LatinASupplement (mkLatinASupplement) where
+
+mkLatinASupplement :: String -> String
+mkLatinASupplement = mkLatinASupplementWord
+
+mkLatinASupplementWord :: String -> String
+mkLatinASupplementWord str = case str of
+ [] -> []
+ '<' : cs -> '<' : spoolMarkup cs
+ -- Romanian & partly Turkish
+ 's' : ',' : cs -> toEnum 0x015f : mkLatinASupplementWord cs
+ 'a' : '%' : cs -> toEnum 0x0103 : mkLatinASupplementWord cs
+ -- Slavic and more
+ 'c' : '^' : cs -> toEnum 0x010d : mkLatinASupplementWord cs
+ 's' : '^' : cs -> toEnum 0x0161 : mkLatinASupplementWord cs
+ 'c' : '\'' : cs -> toEnum 0x0107 : mkLatinASupplementWord cs
+ 'z' : '^' : cs -> toEnum 0x017e : mkLatinASupplementWord cs
+ -- Turkish
+ 'g' : '%' : cs -> toEnum 0x011f : mkLatinASupplementWord cs
+ 'I' : cs -> toEnum 0x0131 : mkLatinASupplementWord cs
+ 'c' : ',' : cs -> toEnum 0x00e7 : mkLatinASupplementWord cs
+ -- Polish
+ 'e' : ',' : cs -> toEnum 0x0119 : mkLatinASupplementWord cs
+ 'a' : ',' : cs -> toEnum 0x0105 : mkLatinASupplementWord cs
+ 'l' : '/' : cs -> toEnum 0x0142 : mkLatinASupplementWord cs
+ 'z' : '.' : cs -> toEnum 0x017c : mkLatinASupplementWord cs
+ 'n' : '\'' : cs -> toEnum 0x0144 : mkLatinASupplementWord cs
+ 's' : '\'' : cs -> toEnum 0x015b : mkLatinASupplementWord cs
+-- 'c' : '\'' : cs -> toEnum 0x0107 : mkLatinASupplementWord cs
+
+ -- Hungarian
+ 'o' : '%' : cs -> toEnum 0x0151 : mkLatinASupplementWord cs
+ 'u' : '%' : cs -> toEnum 0x0171 : mkLatinASupplementWord cs
+
+ -- Mongolian
+ 'j' : '^' : cs -> toEnum 0x0135 : mkLatinASupplementWord cs
+
+ -- Khowar (actually in Combining diacritical marks not Latin-A Suppl.)
+ 'o' : '.' : cs -> 'o' : (toEnum 0x0323 : mkLatinASupplementWord cs)
+
+ -- Length bars over vowels e.g korean
+ 'a' : ':' : cs -> toEnum 0x0101 : mkLatinASupplementWord cs
+ 'e' : ':' : cs -> toEnum 0x0113 : mkLatinASupplementWord cs
+ 'i' : ':' : cs -> toEnum 0x012b : mkLatinASupplementWord cs
+ 'o' : ':' : cs -> toEnum 0x014d : mkLatinASupplementWord cs
+ 'u' : ':' : cs -> toEnum 0x016b : mkLatinASupplementWord cs
+
+ -- Default
+ c : cs -> c : mkLatinASupplementWord cs
+
+spoolMarkup :: String -> String
+spoolMarkup s = case s of
+ [] -> [] -- Shouldn't happen
+ '>' : cs -> '>' : mkLatinASupplementWord cs
+ c1 : cs -> c1 : spoolMarkup cs
diff --git a/src-2.9/GF/Text/OCSCyrillic.hs b/src-2.9/GF/Text/OCSCyrillic.hs
new file mode 100644
index 000000000..0d4696944
--- /dev/null
+++ b/src-2.9/GF/Text/OCSCyrillic.hs
@@ -0,0 +1,47 @@
+----------------------------------------------------------------------
+-- |
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:39 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.6 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.OCSCyrillic (mkOCSCyrillic) where
+
+mkOCSCyrillic :: String -> String
+mkOCSCyrillic = mkOCSCyrillicWord
+
+mkOCSCyrillicWord :: String -> String
+mkOCSCyrillicWord str = case str of
+ [] -> []
+ ' ' : cs -> ' ' : mkOCSCyrillicWord cs
+ '<' : cs -> '<' : spoolMarkup cs
+ '\228' : cs -> toEnum 0x0463 : mkOCSCyrillicWord cs -- ä
+ 'j' : 'e' : '~' : cs -> toEnum 0x0469 : mkOCSCyrillicWord cs
+ 'j' : 'o' : '~' : cs -> toEnum 0x046d : mkOCSCyrillicWord cs
+ 'j' : 'e' : cs -> toEnum 0x0465 : mkOCSCyrillicWord cs
+ 'e' : '~' : cs -> toEnum 0x0467 : mkOCSCyrillicWord cs
+ 'o' : '~' : cs -> toEnum 0x046b : mkOCSCyrillicWord cs
+ 'j' : 'u' : cs -> toEnum 0x044e : mkOCSCyrillicWord cs
+ 'j' : 'a' : cs -> toEnum 0x044f : mkOCSCyrillicWord cs
+ 'u' : cs -> toEnum 0x0479 : mkOCSCyrillicWord cs
+ c : cs -> (mkOCSCyrillicChar c) : mkOCSCyrillicWord cs
+
+spoolMarkup :: String -> String
+spoolMarkup s = case s of
+ [] -> [] -- Shouldn't happen
+ '>' : cs -> '>' : mkOCSCyrillicWord cs
+ c1 : cs -> c1 : spoolMarkup cs
+
+mkOCSCyrillicChar :: Char -> Char
+mkOCSCyrillicChar c = case lookup c cc of Just c' -> c' ; _ -> c
+ where
+ cc = zip "abvgdeZziJklmnoprstYfxCqwWUyIE" allOCSCyrillic
+
+allOCSCyrillic :: String
+allOCSCyrillic = (map toEnum [0x0430 .. 0x044e])
diff --git a/src-2.9/GF/Text/Russian.hs b/src-2.9/GF/Text/Russian.hs
new file mode 100644
index 000000000..c4f1bfd89
--- /dev/null
+++ b/src-2.9/GF/Text/Russian.hs
@@ -0,0 +1,56 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Russian
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:40 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.5 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.Russian (mkRussian, mkRusKOI8) where
+
+-- | an ad hoc ASCII encoding. Delimiters: @\/_ _\/@
+mkRussian :: String -> String
+mkRussian = unwords . (map mkRussianWord) . words
+
+-- | the KOI8 encoding, incomplete. Delimiters: @\/* *\/@
+mkRusKOI8 :: String -> String
+mkRusKOI8 = unwords . (map mkRussianKOI8) . words
+
+type RussianChar = Char
+
+mkRussianWord :: String -> [RussianChar]
+mkRussianWord = map (mkRussianChar allRussianCodes)
+
+mkRussianKOI8 :: String -> [RussianChar]
+mkRussianKOI8 = map (mkRussianChar allRussianKOI8)
+
+mkRussianChar chars c = case lookup c cc of Just c' -> c' ; _ -> c
+ where
+ cc = zip chars allRussian
+
+allRussianCodes :: [Char]
+allRussianCodes =
+ -- changed to Ints to work with Haskell compilers e.g. GHC 6.5 CVS
+ -- which expect source files to be in UTF-8
+ -- /bringert 2006-05-19
+ -- "ÅåABVGDEXZIJKLMNOPRSTUFHCQW£}!*ÖYÄabvgdexzijklmnoprstufhcqw#01'öyä"
+ map toEnum [197,229,65,66,86,71,68,69,88,90,73,74,75,76,77,78,79,80,82,83,84,85,70,72,67,81,87,163,125,33,42,214,89,196,97,98,118,103,100,101,120,122,105,106,107,108,109,110,111,112,114,115,116,117,102,104,99,113,119,35,48,49,39,246,121,228]
+
+allRussianKOI8 :: [Char]
+allRussianKOI8 =
+ -- changed to Ints to work with Haskell compilers e.g. GHC 6.5 CVS
+ -- which expect source files to be in UTF-8
+ -- /bringert 2006-05-19
+ -- "^@áâ÷çäåöúéêëìíîïðòóôõæèãþûýøùÿüàñÁÂ×ÇÄÅÖÚÉÊËÌÍÎÏÐÒÓÔÕÆÈÃÞÛÝØÙßÜÀÑ"
+ map toEnum [94,64,225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,242,243,244,245,230,232,227,254,251,253,248,249,255,252,224,241,193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,210,211,212,213,198,200,195,222,219,221,216,217,223,220,192,209]
+
+allRussian :: String
+allRussian = (map toEnum (0x0401:0x0451:[0x0410 .. 0x044f])) -- Ëë in odd places
+
+
diff --git a/src-2.9/GF/Text/Tamil.hs b/src-2.9/GF/Text/Tamil.hs
new file mode 100644
index 000000000..8ee171acf
--- /dev/null
+++ b/src-2.9/GF/Text/Tamil.hs
@@ -0,0 +1,77 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Tamil
+-- Maintainer : (Maintainer)
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:40 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.5 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Text.Tamil (mkTamil) where
+
+mkTamil :: String -> String
+mkTamil = digraphWordToUnicode . adHocToDigraphWord
+
+adHocToDigraphWord :: String -> [(Char, Char)]
+adHocToDigraphWord str = case str of
+ [] -> []
+ '<' : cs -> ('\\', '<') : spoolMarkup cs
+ ' ' : cs -> ('\\', ' ') : adHocToDigraphWord cs -- skip space
+
+-- if c1 is a vowel
+ -- Two of the same vowel => lengthening
+ c1 : c2 : cs | c1 == c2 && isVowel c1 -> (cap c1, ':') : adHocToDigraphWord cs
+ -- digraphed or long vowel
+ c1 : c2 : cs | isVowel c1 && isVowel c2 -> (cap c1, cap c2) : adHocToDigraphWord cs
+ c1 : cs | isVowel c1 -> (' ', cap c1) : adHocToDigraphWord cs
+
+-- c1 isn't a vowel
+ c1 : c2 : c3 : cs | c2 == c3 && isVowel c2 -> (' ', c1) : (c2, ':') : adHocToDigraphWord cs
+ c1 : c2 : c3 : cs | isVowel c2 && isVowel c3 -> (' ', c1) : (c2, c3) : adHocToDigraphWord cs
+ c1 : 'a' : cs -> (' ', c1) : adHocToDigraphWord cs -- a inherent
+ c1 : c2 : cs | isVowel c2 -> (' ', c1) : (' ', c2) : adHocToDigraphWord cs
+
+ c1 : cs -> (' ', c1) : (' ', '.') : adHocToDigraphWord cs -- vowelless
+
+isVowel x = elem x "aeiou:"
+cap :: Char -> Char
+cap x = case x of
+ 'a' -> 'A'
+ 'e' -> 'E'
+ 'i' -> 'I'
+ 'o' -> 'O'
+ 'u' -> 'U'
+ c -> c
+
+spoolMarkup :: String -> [(Char, Char)]
+spoolMarkup s = case s of
+ -- [] -> [] -- Shouldn't happen
+ '>' : cs -> ('\\', '>') : adHocToDigraphWord cs
+ c1 : cs -> ('\\', c1) : spoolMarkup cs
+
+digraphWordToUnicode :: [(Char, Char)] -> String
+digraphWordToUnicode = map digraphToUnicode
+
+digraphToUnicode :: (Char, Char) -> Char
+digraphToUnicode (c1, c2) = case lookup (c1, c2) cc of Just c' -> c' ; _ -> c2
+ where
+ cc = zip allTamilCodes allTamil
+
+mkPairs :: String -> [(Char, Char)]
+mkPairs str = case str of
+ [] -> []
+ c1 : c2 : cs -> (c1, c2) : mkPairs cs
+
+allTamilCodes :: [(Char, Char)]
+allTamilCodes = mkPairs digraphedTamil
+
+allTamil :: String
+allTamil = (map toEnum [0x0b85 .. 0x0bfa])
+
+digraphedTamil = " AA: II: UU:______ EE:AI__ OO:AU k______ G c__ j__ \241 T______ N t______ V n p______ m y r l L M v__ s S h________a: ii: uu:______ ee:ai__ oo:au .__________________ :______________________________#1#2#3#4#5#6#7#8#9^1^2^3=d=m=y=d=c==ru##"
+
diff --git a/src-2.9/GF/Text/Text.hs b/src-2.9/GF/Text/Text.hs
new file mode 100644
index 000000000..b55355c20
--- /dev/null
+++ b/src-2.9/GF/Text/Text.hs
@@ -0,0 +1,149 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Text
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/06/23 14:32:44 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.10 $
+--
+-- elementary text postprocessing. AR 21\/11\/2001.
+--
+-- This is very primitive indeed. The functions should work on
+-- token lists and not on strings. AR 5\/12\/2002
+--
+-- XML hack 14\/8\/2004; not in use yet
+-----------------------------------------------------------------------------
+
+module GF.Text.Text (untokWithXML,
+ exceptXML,
+ formatAsTextLit,
+ formatAsCodeLit,
+ formatAsText,
+ formatAsHTML,
+ formatAsLatex,
+ formatAsCode,
+ performBinds,
+ performBindsFinnish,
+ unStringLit,
+ concatRemSpace
+ ) where
+
+import GF.Data.Operations
+import Data.Char
+
+-- | does not apply untokenizer within XML tags --- heuristic "< "
+-- this function is applied from top level...
+untokWithXML :: (String -> String) -> String -> String
+untokWithXML unt s = case s of
+ '<':cs@(c:_) | isAlpha c -> '<':beg ++ ">" ++ unto (drop 1 rest) where
+ (beg,rest) = span (/='>') cs
+ '<':cs -> '<':unto cs ---
+ [] -> []
+ _ -> unt beg ++ unto rest where
+ (beg,rest) = span (/='<') s
+ where
+ unto = untokWithXML unt
+
+-- | ... whereas this one is embedded on a branch
+exceptXML :: (String -> String) -> String -> String
+exceptXML unt s = '<':beg ++ ">" ++ unt (drop 1 rest) where
+ (beg,rest) = span (/='>') s
+
+formatAsTextLit :: String -> String
+formatAsTextLit = formatAsText . unwords . map unStringLit . words
+--- hope that there will be deforestation...
+
+formatAsCodeLit :: String -> String
+formatAsCodeLit = formatAsCode . unwords . map unStringLit . words
+
+formatAsText,formatAsHTML,formatAsLatex :: String -> String
+formatAsText = formatAsTextGen (const False) (=="&-")
+formatAsHTML = formatAsTextGen (\s -> take 1 s == "<" || last s == '>') (const False)
+formatAsLatex = formatAsTextGen ((=="\\") . take 1) (const False)
+
+formatAsTextGen :: (String -> Bool) -> (String -> Bool) -> String -> String
+formatAsTextGen tag para = unwords . format . cap . words where
+ format ws = case ws of
+ w : ww | capit w -> format $ (cap ww)
+ w : c : ww | major c -> format $ (w ++ c) :(cap ww)
+ w : c : ww | minor c -> format $ (w ++ c) : ww
+ p : c : ww | openp p -> format $ (p ++ c) :ww
+ p : c : ww | spanish p -> format $ (p ++ concat (cap [c])) :ww
+ c : ww | para c -> "\n\n" : format ww
+ w : ww -> w : format ww
+ [] -> []
+ cap (p:ww) | tag p = p : cap ww
+ cap ((c:cs):ww) = (toUpper c : cs) : ww
+ cap [] = []
+ capit = (=="&|")
+ major = flip elem (map singleton ".!?")
+ minor = flip elem (map singleton ",:;)")
+ openp = all (flip elem "(")
+ spanish = all (flip elem "\161\191")
+
+formatAsCode :: String -> String
+formatAsCode = rend 0 . words where
+ -- render from BNF Converter
+ rend i ss = case ss of
+ "[" :ts -> cons "[" $ rend i ts
+ "(" :ts -> cons "(" $ rend i ts
+ "{" :ts -> cons "{" $ new (i+1) $ rend (i+1) ts
+ "}" : ";":ts -> new (i-1) $ space "}" $ cons ";" $ new (i-1) $ rend (i-1) ts
+ "}" :ts -> new (i-1) $ cons "}" $ new (i-1) $ rend (i-1) ts
+ ";" :ts -> cons ";" $ new i $ rend i ts
+ t : "," :ts -> cons t $ space "," $ rend i ts
+ t : ")" :ts -> cons t $ cons ")" $ rend i ts
+ t : "]" :ts -> cons t $ cons "]" $ rend i ts
+ t :ts -> space t $ rend i ts
+ _ -> ""
+ cons s t = s ++ t
+ new i s = '\n' : replicate (2*i) ' ' ++ dropWhile isSpace s
+ space t s = if null s then t else t ++ " " ++ s
+
+performBinds :: String -> String
+performBinds = performBindsOpt (\x y -> y)
+
+
+-- The function defines an effect of the former on the latter part,
+-- such as in vowel harmony. It is triggered by the binder token "&*"
+
+performBindsOpt :: (String -> String -> String) -> String -> String
+performBindsOpt harm = unwords . format . words where
+ format ws = case ws of
+ w : "&+" : u : ws -> format ((w ++ u) : ws)
+ w : "&*" : u : ws -> format ((w ++ harm w u) : ws)
+ w : ws -> w : format ws
+ [] -> []
+
+-- unlexer for Finnish particles
+-- Notice: left associativity crucial for "tie &* ko &* han" --> "tieköhän"
+
+performBindsFinnish :: String -> String
+performBindsFinnish = performBindsOpt vowelHarmony where
+ vowelHarmony w p = if any (flip elem "aouAOU") w then p else map toFront p
+ toFront c = case c of
+ 'A' -> '\196'
+ 'O' -> '\214'
+ 'a' -> '\228'
+ 'o' -> '\246'
+ _ -> c
+
+unStringLit :: String -> String
+unStringLit s = case s of
+ c : cs | strlim c && strlim (last cs) -> init cs
+ _ -> s
+ where
+ strlim = (=='\'')
+
+concatRemSpace :: String -> String
+concatRemSpace = concat . words
+{-
+concatRemSpace s = case s of
+ '<':cs -> exceptXML concatRemSpace cs
+ c : cs | isSpace c -> concatRemSpace cs
+ c :cs -> c : concatRemSpace cs
+ _ -> s
+-}
diff --git a/src-2.9/GF/Text/Thai.hs b/src-2.9/GF/Text/Thai.hs
new file mode 100644
index 000000000..1b186cb3a
--- /dev/null
+++ b/src-2.9/GF/Text/Thai.hs
@@ -0,0 +1,368 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Thai
+-- Maintainer : (Maintainer)
+-- Stability : (experimental)
+-- Portability : (portable)
+--
+--
+-- Thai transliteration and other alphabet information.
+-----------------------------------------------------------------------------
+
+-- AR 27/12/2006. Execute test2 to see the transliteration table.
+
+module GF.Text.Thai (
+ mkThai,mkThaiWord,mkThaiPron,mkThaiFake,thaiFile,thaiPronFile,thaiFakeFile
+ ) where
+
+import qualified Data.Map as Map
+import Data.Char
+
+-- for testing
+import GF.Text.UTF8
+import Data.List
+
+import Debug.Trace
+
+
+mkThai :: String -> String
+mkThai = concat . map mkThaiWord . words
+mkThaiPron = unwords . map mkPronSyllable . words
+mkThaiFake = unwords . map (fakeEnglish . mkPronSyllable) . words
+
+
+type ThaiChar = Char
+
+mkThaiWord :: String -> [ThaiChar]
+mkThaiWord = map (toEnum . mkThaiChar) . unchar . snd . pronAndOrth
+
+mkThaiChar :: String -> Int
+mkThaiChar c = maybe 0 id $ Map.lookup c thaiMap
+
+thaiMap :: Map.Map String Int
+thaiMap = Map.fromList $ zip allThaiTrans allThaiCodes
+
+-- convert all string literals in a text
+
+thaiStrings :: String -> String
+thaiStrings = convStrings mkThai
+
+thaiPronStrings :: String -> String
+thaiPronStrings = convStrings mkThaiPron
+
+convStrings conv s = case s of
+ '"':cs -> let (t,_:r) = span (/='"') cs in
+ '"': conv t ++ "\"" ++ convStrings conv r
+ c:cs -> c : convStrings conv cs
+ _ -> s
+
+
+-- each character is either [letter] or [letter+nonletter]
+
+unchar :: String -> [String]
+unchar s = case s of
+ c:d:cs
+ | isAlpha d -> [c] : unchar (d:cs)
+ | d == '?' -> unchar cs -- use "o?" to represent implicit 'o'
+ | otherwise -> [c,d] : unchar cs
+ [_] -> [s]
+ _ -> []
+
+-- you can prefix transliteration by irregular phonology in []
+
+pronAndOrth :: String -> (Maybe String, String)
+pronAndOrth s = case s of
+ '[':cs -> case span (/=']') cs of
+ (p,_:o) -> (Just p,o)
+ _ -> (Nothing,s)
+ _ -> (Nothing,s)
+
+allThaiTrans :: [String]
+allThaiTrans = words $
+ "- k k1 - k2 - k3 g c c1 c2 s' c3 y' d' t' " ++
+ "t1 t2 t3 n' d t t4 t5 t6 n b p p1 f p2 f' " ++
+ "p3 m y r - l - w s- s. s h l' O h' - " ++
+ "a. a a: a+ i i: v v: u u: - - - - - - " ++
+ "e e' o: a% a& L R S T1 T2 T3 T4 K - - - " ++
+ "N0 N1 N2 N3 N4 N5 N6 N7 N8 N9 - - - - - - "
+
+allThaiCodes :: [Int]
+allThaiCodes = [0x0e00 .. 0x0e7f]
+
+
+---------------------
+-- heuristic pronunciation of codes
+---------------------
+
+-- fake English for TTS, a la Teach Yourself Thai
+
+fakeEnglish :: String -> String
+fakeEnglish s = case s of
+ 'a':'a':cs -> "ah" ++ fakeEnglish cs
+ 'a':'y':cs -> "ai" ++ fakeEnglish cs
+ 'a' :cs -> "ah" ++ fakeEnglish cs
+ 'c':'h':cs -> "ch" ++ fakeEnglish cs
+ 'c' :cs -> "j" ++ fakeEnglish cs
+ 'e':'e':cs -> "aih" ++ fakeEnglish cs
+ 'g' :cs -> "ng" ++ fakeEnglish cs
+ 'i':'i':cs -> "ee" ++ fakeEnglish cs
+ 'k':'h':cs -> "k" ++ fakeEnglish cs
+ 'k' :cs -> "g" ++ fakeEnglish cs
+ 'O':'O':cs -> "or" ++ fakeEnglish cs
+ 'O' :cs -> "or" ++ fakeEnglish cs
+ 'o':'o':cs -> "or" ++ fakeEnglish cs
+ 'p':'h':cs -> "p" ++ fakeEnglish cs
+ 'p' :cs -> "b" ++ fakeEnglish cs
+ 't':'h':cs -> "t" ++ fakeEnglish cs
+ 't' :cs -> "d" ++ fakeEnglish cs
+ 'u':'u':cs -> "oo" ++ fakeEnglish cs
+ 'u' :cs -> "oo" ++ fakeEnglish cs
+ 'v':'v':cs -> "eu" ++ fakeEnglish cs
+ 'v' :cs -> "eu" ++ fakeEnglish cs
+ '\228':'\228':cs -> "air" ++ fakeEnglish cs
+ '\228' :cs -> "a" ++ fakeEnglish cs
+ '\246':'\246':cs -> "er" ++ fakeEnglish cs
+ '\246' :cs -> "er" ++ fakeEnglish cs
+ c:cs | isTone c -> fakeEnglish cs
+ c:cs -> c : fakeEnglish cs
+ _ -> s
+ where
+ isTone = flip elem "'`^~"
+
+
+-- this works for one syllable
+
+mkPronSyllable s = case fst $ pronAndOrth s of
+ Just p -> p
+ _ -> pronSyllable $ getSyllable $ map mkThaiChar $ unchar s
+
+data Syllable = Syll {
+ initv :: [Int],
+ initc :: [Int],
+ midv :: [Int],
+ finalc :: [Int],
+ finalv :: [Int],
+ tone :: [Int],
+ shorten :: Bool,
+ kill :: Bool
+ }
+ deriving Show
+
+data Tone = TMid | TLow | THigh | TRise | TFall
+ deriving Show
+
+data CClass = CLow | CMid | CHigh
+ deriving Show
+
+pronSyllable :: Syllable -> String
+pronSyllable s =
+ initCons ++ tonem ++ vowel ++ finalCons
+ where
+
+ vowel = case (initv s, midv s, finalv s, finalc s, shorten s, tone s) of
+ ([0x0e40],[0x0e35],_,[0x0e22],_,_) -> "ia" -- e-i:y
+ ([0x0e40],[0x0e2d,0x0e35],_,_,_,_) -> "va" -- e-i:O
+ ([0x0e40],[0x0e30,0x0e35],_,[0x0e22],_,_) -> "ia" -- e-i:ya.
+ ([0x0e40],[0x0e30,0x0e2d],_,_,_,_) -> "\246" -- e-Oa.
+ ([0x0e40],[0x0e30,0x0e32],_,_,_,_) -> "O" -- e-a:a. -- open o
+ ([0x0e40],[0x0e2d],_,_,_,_) -> "\246\246" -- e-O
+ ([0x0e40],[0x0e34],_,_,_,_) -> "\246\246" -- e-i
+ ([0x0e40],[0x0e30],_,_,_,_) -> "e" -- e-a.
+ ([0x0e40],[0x0e32],_,_,_,_) -> "aw" -- e-a:
+ ([0x0e40],[],[],[0x0e22],_,_) -> "\246\246y" -- e-y
+ ([0x0e40],[],[],_,True,_) -> "e"
+
+ ([0x0e41],[0x0e30],_,_,_,_) -> "\228" -- ä-a.
+ ([0x0e41],[],[],_,True,_) -> "\228"
+
+ ([0x0e42],[0x0e30],_,_,_,_) -> "o" -- o:-a.
+
+ ([],[0x0e2d],_,[0x0e22],_,_) -> "OOy" -- Oy
+ ([],[0x0e2d],_,_,_,_) -> "OO" -- O
+
+ ([],[],[],_,_,_) -> "o"
+
+ (i,m,f,_,_,_) -> concatMap pronThaiChar (reverse $ f ++ m ++ i) ----
+
+ initCons = concatMap pronThaiChar $ case (reverse $ initc s) of
+ 0x0e2b:cs@(_:_) -> cs -- high h
+ 0x0e2d:cs@(_:_) -> cs -- O
+ cs -> cs
+
+ finalCons =
+ let (c,cs) = splitAt 1 $ finalc s
+ in
+ case c of
+ [] -> []
+ [0x0e22] -> [] --- y
+ [k] -> concatMap pronThaiChar (reverse cs) ++ finalThai k
+
+ iclass = case take 1 (reverse $ initc s) of
+ [c] -> classThai c
+ [] -> CMid -- O
+
+ isLong = not (shorten s) && case vowel of
+ _:_:_ -> True ----
+ _ -> False
+
+ isLive = case finalCons of
+ c | elem c ["n","m","g"] -> True
+ "" -> isLong
+ _ -> False
+
+ tonem = case (iclass,isLive,isLong,tone s) of
+ (_,_,_, [0x0e4a]) -> tHigh
+ (_,_,_, [0x0e4b]) -> tRise
+ (CLow,_,_,[0x0e49]) -> tRise
+ (_,_,_, [0x0e49]) -> tFall
+ (CLow,_,_,[0x0e48]) -> tFall
+ (_, _,_,[0x0e48]) -> tLow
+ (CHigh,True,_,_) -> tRise
+ (_, True,_,_) -> tMid
+ (CLow,False,False,_) -> tHigh
+ (CLow,False,_,_) -> tFall
+ _ -> tLow
+
+(tMid,tHigh,tLow,tRise,tFall) = ("-","'","`","~","^")
+
+isVowel c = 0x0e30 <= c && c <= 0x0e44 ----
+isCons c = 0x0e01 <= c && c <= 0x0e2f ----
+isTone c = 0x0e48 <= c && c <= 0x0e4b
+
+getSyllable :: [Int] -> Syllable
+getSyllable = foldl get (Syll [] [] [] [] [] [] False False) where
+ get syll c = case c of
+ 0x0e47 -> syll {shorten = True}
+ 0x0e4c -> syll {kill = True, finalc = tail (finalc syll)} --- always last
+ 0x0e2d
+ | null (initc syll) -> syll {initc = [c]} -- "O"
+ | otherwise -> syll {midv = c : midv syll}
+ _
+ | isVowel c -> if null (initc syll)
+ then syll {initv = c : initv syll}
+ else syll {midv = c : midv syll}
+ | isCons c -> if null (initc syll) ||
+ (null (midv syll) && isCluster (initc syll) c)
+ then syll {initc = c : initc syll}
+ else syll {finalc = c : finalc syll}
+ | isTone c -> syll {tone = [c]}
+ _ -> syll ---- check this
+
+ isCluster s c = length s == 1 && (c == 0x0e23 || s == [0x0e2b])
+
+-- to test
+
+test1 = testThai "k2wa:mrak"
+test2 = putStrLn $ thaiTable
+test3 = do
+ writeFile "thai.txt" "Thai Character Coding in GF\nAR 2007\n"
+ appendFile "thai.txt" thaiTable
+test4 = do
+ writeFile "alphthai.txt" "Thai Characters by Pronunciation\nAR 2007\n"
+ appendFile "alphthai.txt" thaiTableAlph
+
+
+testThai :: String -> IO ()
+testThai s = do
+ putStrLn $ encodeUTF8 $ mkThai s
+ putStrLn $ unwords $ map mkPronSyllable $ words s
+
+testSyllable s =
+ let y = getSyllable $ map mkThaiChar $ unchar s
+ in
+ putStrLn $ pronSyllable $ trace (show y) y
+
+thaiFile :: FilePath -> Maybe FilePath -> IO ()
+thaiFile f mo = do
+ s <- readFile f
+ let put = maybe putStr writeFile mo
+ put $ encodeUTF8 $ thaiStrings s
+
+thaiPronFile :: FilePath -> Maybe FilePath -> IO ()
+thaiPronFile f mo = do
+ s <- readFile f
+ let put = maybe putStr writeFile mo
+ put $ encodeUTF8 $ thaiPronStrings s
+
+thaiFakeFile :: FilePath -> Maybe FilePath -> IO ()
+thaiFakeFile f mo = do
+ s <- readFile f
+ let put = maybe putStr writeFile mo
+ put $ encodeUTF8 $ (convStrings mkThaiFake) s
+
+finalThai c = maybe "" return (Map.lookup c thaiFinalMap)
+thaiFinalMap = Map.fromList $ zip allThaiCodes finals
+
+classThai c = maybe CLow readClass (Map.lookup c thaiClassMap)
+thaiClassMap = Map.fromList $ zip allThaiCodes heights
+
+readClass s = case s of
+ 'L' -> CLow
+ 'M' -> CMid
+ 'H' -> CHigh
+
+
+thaiTable :: String
+thaiTable = unlines $ ("\n|| hex | thai | trans | pron | fin | class |" ) : [
+ "| " ++
+ hex c ++ " | " ++
+ encodeUTF8 (showThai s) ++ " | " ++
+ s ++ " | " ++
+ pronThai s ++ " | " ++
+ [f] ++ " | " ++
+ [q] ++ " | "
+ |
+ (c,q,f,s) <- zip4 allThaiCodes heights finals allThaiTrans
+ ]
+
+thaiTableAlph :: String
+thaiTableAlph = unlines $ ("\n|| pron | thai | trans |" ) : [
+ "| " ++ a ++
+ " | " ++ unwords (map (encodeUTF8 . showThai) ss) ++
+ " | " ++ unwords ss ++
+ " |"
+ |
+ (a,ss) <- allProns
+ ]
+ where
+ prons = sort $ nub
+ [p | s <- allThaiTrans, let p = pronThai s, not (null p),isAlpha (head p)]
+ allProns =
+ [(a,[s | s <- allThaiTrans, pronThai s == a]) | a <- prons]
+
+showThai s = case s of
+ "-" -> "-"
+--- v:_ | elem v "ivu" -> map (toEnum . mkThaiChar) ["O",s]
+ _ -> [toEnum $ mkThaiChar s]
+
+
+pronThaiChar = pronThai . recodeThai
+
+recodeThai c = allThaiTrans !! (c - 0x0e00)
+
+pronThai s = case s of
+ [c,p]
+ | c == 'N' && isDigit p -> [p]
+ | c == 'T' && isDigit p -> ['\'',p]
+ | isDigit p -> c:"h"
+ | p==':' -> c:[c]
+ | elem p "%&" -> c:"y"
+ | p=='+' -> c:"m"
+ | s == "e'" -> "\228\228"
+ | otherwise -> [c]
+ "O" -> "O"
+ "e" -> "ee"
+ [c] | isUpper c -> ""
+ _ -> s
+
+hex = map hx . reverse . digs where
+ digs 0 = [0]
+ digs n = n `mod` 16 : digs (n `div` 16)
+ hx d = "0123456789ABCDEF" !! d
+
+heights :: String
+finals :: String
+heights =
+ " MHHLLLLMHLLLLMMHLLLMMHLLLMMHHLLLLLL-L-LHHHHLML" ++ replicate 99 ' '
+finals =
+ " kkkkkkgt-tt-ntttttntttttnpp--pppmyn-n-wttt-n--" ++ replicate 99 ' '
diff --git a/src-2.9/GF/Text/UTF8.hs b/src-2.9/GF/Text/UTF8.hs
new file mode 100644
index 000000000..5e9687684
--- /dev/null
+++ b/src-2.9/GF/Text/UTF8.hs
@@ -0,0 +1,48 @@
+----------------------------------------------------------------------
+-- |
+-- Module : UTF8
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:42 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.5 $
+--
+-- From the Char module supplied with HBC.
+-- code by Thomas Hallgren (Jul 10 1999)
+-----------------------------------------------------------------------------
+
+module GF.Text.UTF8 (decodeUTF8, encodeUTF8) where
+
+-- | Take a Unicode string and encode it as a string
+-- with the UTF8 method.
+decodeUTF8 :: String -> String
+decodeUTF8 "" = ""
+decodeUTF8 (c:cs) | c < '\x80' = c : decodeUTF8 cs
+decodeUTF8 (c:c':cs) | '\xc0' <= c && c <= '\xdf' &&
+ '\x80' <= c' && c' <= '\xbf' =
+ toEnum ((fromEnum c `mod` 0x20) * 0x40 + fromEnum c' `mod` 0x40) : decodeUTF8 cs
+decodeUTF8 (c:c':c'':cs) | '\xe0' <= c && c <= '\xef' &&
+ '\x80' <= c' && c' <= '\xbf' &&
+ '\x80' <= c'' && c'' <= '\xbf' =
+ toEnum ((fromEnum c `mod` 0x10 * 0x1000) + (fromEnum c' `mod` 0x40) * 0x40 + fromEnum c'' `mod` 0x40) : decodeUTF8 cs
+decodeUTF8 s = s ---- AR workaround 22/6/2006
+----decodeUTF8 _ = error "UniChar.decodeUTF8: bad data"
+
+encodeUTF8 :: String -> String
+encodeUTF8 "" = ""
+encodeUTF8 (c:cs) =
+ if c > '\x0000' && c < '\x0080' then
+ c : encodeUTF8 cs
+ else if c < toEnum 0x0800 then
+ let i = fromEnum c
+ in toEnum (0xc0 + i `div` 0x40) :
+ toEnum (0x80 + i `mod` 0x40) :
+ encodeUTF8 cs
+ else
+ let i = fromEnum c
+ in toEnum (0xe0 + i `div` 0x1000) :
+ toEnum (0x80 + (i `mod` 0x1000) `div` 0x40) :
+ toEnum (0x80 + i `mod` 0x40) :
+ encodeUTF8 cs
diff --git a/src-2.9/GF/Text/Unicode.hs b/src-2.9/GF/Text/Unicode.hs
new file mode 100644
index 000000000..9d0b9d1a8
--- /dev/null
+++ b/src-2.9/GF/Text/Unicode.hs
@@ -0,0 +1,69 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Unicode
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:42 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.12 $
+--
+-- ad hoc Unicode conversions from different alphabets.
+-- AR 12\/4\/2000, 18\/9\/2001, 30\/5\/2002, 26\/1\/2004
+-----------------------------------------------------------------------------
+
+module GF.Text.Unicode (mkUnicode, treat) where
+
+import GF.Text.Greek (mkGreek)
+import GF.Text.Arabic (mkArabic)
+import GF.Text.Hebrew (mkHebrew)
+import GF.Text.Russian (mkRussian, mkRusKOI8)
+import GF.Text.Ethiopic (mkEthiopic)
+import GF.Text.Tamil (mkTamil)
+import GF.Text.OCSCyrillic (mkOCSCyrillic)
+import GF.Text.LatinASupplement (mkLatinASupplement)
+import GF.Text.Devanagari (mkDevanagari)
+import GF.Text.Hiragana (mkJapanese)
+import GF.Text.ExtendedArabic (mkArabic0600)
+import GF.Text.ExtendedArabic (mkExtendedArabic)
+import GF.Text.ExtraDiacritics (mkExtraDiacritics)
+
+import Data.Char
+
+mkUnicode :: String -> String
+mkUnicode s = case s of
+ '/':'/':cs -> treat [] mkGreek unic ++ mkUnicode rest
+ '/':'+':cs -> mkHebrew unic ++ mkUnicode rest
+ '/':'-':cs -> mkArabic unic ++ mkUnicode rest
+ '/':'_':cs -> treat [] mkRussian unic ++ mkUnicode rest
+ '/':'*':cs -> mkRusKOI8 unic ++ mkUnicode rest
+ '/':'E':cs -> mkEthiopic unic ++ mkUnicode rest
+ '/':'T':cs -> mkTamil unic ++ mkUnicode rest
+ '/':'C':cs -> mkOCSCyrillic unic ++ mkUnicode rest
+ '/':'&':cs -> mkDevanagari unic ++ mkUnicode rest
+ '/':'L':cs -> mkLatinASupplement unic ++ mkUnicode rest
+ '/':'J':cs -> mkJapanese unic ++ mkUnicode rest
+ '/':'6':cs -> mkArabic0600 unic ++ mkUnicode rest
+ '/':'A':cs -> mkExtendedArabic unic ++ mkUnicode rest
+ '/':'X':cs -> mkExtraDiacritics unic ++ mkUnicode rest
+ c:cs -> c:mkUnicode cs
+ _ -> s
+ where
+ (unic,rest) = remClosing [] $ dropWhile isSpace $ drop 2 s
+ remClosing u s = case s of
+ c:'/':s | elem c "/+-_*ETC&LJ6AX" -> (reverse u, s) --- end need not match
+ c:cs -> remClosing (c:u) cs
+ _ -> (reverse u,[]) -- forgiving missing end
+
+-- | don't convert XML tags --- assumes \<\> always means XML tags
+treat :: String -> (String -> String) -> String -> String
+treat old mk s = case s of
+ '<':cs -> mk (reverse old) ++ '<':noTreat cs
+ c:cs -> treat (c:old) mk cs
+ _ -> mk (reverse old)
+ where
+ noTreat s = case s of
+ '>':cs -> '>' : treat [] mk cs
+ c:cs -> c : noTreat cs
+ _ -> s
diff --git a/src-2.9/GF/Translate/GFT.hs b/src-2.9/GF/Translate/GFT.hs
new file mode 100644
index 000000000..e4a9d8193
--- /dev/null
+++ b/src-2.9/GF/Translate/GFT.hs
@@ -0,0 +1,56 @@
+----------------------------------------------------------------------
+-- |
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:43 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.7 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.Translate.GFT (main) where
+
+import GF.Compile.ShellState
+import GF.Canon.GetGFC
+import GF.API
+
+import GF.Text.Unicode
+import GF.Text.UTF8
+import GF.Infra.UseIO
+import GF.Infra.Option
+import GF.Infra.Modules (emptyMGrammar) ----
+import GF.Data.Operations
+
+import System
+import Data.List
+
+
+main :: IO ()
+main = do
+ file:_ <- getArgs
+ let opts = noOptions
+ can <- useIOE (error "no grammar file") $ getCanonGrammar file
+ st <- err error return $
+ grammar2shellState opts (can, emptyMGrammar)
+ let grs = allStateGrammars st
+ let cat = firstCatOpts opts (firstStateGrammar st)
+
+---- interact (doTranslate grs cat)
+ s <- getLine
+ putStrLnFlush $ doTranslate grs cat $ drop 2 s -- to remove "n="
+
+doTranslate grs cat s =
+ let ss = [l +++ ":" +++ s | (l,s) <- zip (map (prIdent . cncId) grs)
+ (translateBetweenAll grs cat s)]
+ in mkHTML ss
+
+mkHTML = unlines . htmlDoc . intersperse "" . map (encodeUTF8 . mkUnicode) . sort
+
+htmlDoc ss = "":metaHead:"
": ss ++ ["",""]
+
+metaHead =
+ ""
+
diff --git a/src-2.9/GF/UseGrammar/Custom.hs b/src-2.9/GF/UseGrammar/Custom.hs
new file mode 100644
index 000000000..983b7f683
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Custom.hs
@@ -0,0 +1,494 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Custom
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/16 10:21:21 $
+-- > CVS $Author: peb $
+-- > CVS $Revision: 1.85 $
+--
+-- A database for customizable GF shell commands.
+--
+-- databases for customizable commands. AR 21\/11\/2001.
+-- for: grammar parsers, grammar printers, term commands, string commands.
+-- idea: items added here are usable throughout GF; nothing else need be edited.
+-- they are often usable through the API: hence API cannot be imported here!
+--
+-- Major redesign 3\/4\/2002: the first entry in each database is DEFAULT.
+-- If no other value is given, the default is selected.
+-- Because of this, two invariants have to be preserved:
+--
+-- - no databases may be empty
+--
+-- - additions are made to the end of the database
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Custom where
+
+import GF.Data.Operations
+import GF.Text.Text
+import GF.UseGrammar.Tokenize
+import GF.Grammar.Values
+import qualified GF.Grammar.Grammar as G
+import qualified GF.Canon.AbsGFC as A
+import qualified GF.Canon.GFC as C
+
+import qualified GF.Devel.GFCCtoJS as JS
+import GF.Canon.CanonToGFCC
+import qualified GF.Devel.GFCCtoHaskell as CCH
+
+import qualified GF.Source.AbsGF as GF
+import qualified GF.Grammar.MMacros as MM
+import GF.Grammar.AbsCompute
+import GF.Grammar.TypeCheck
+import GF.UseGrammar.Generate
+import GF.UseGrammar.MatchTerm
+import GF.UseGrammar.Linear (unoptimizeCanon)
+------import Compile
+import GF.Compile.ShellState
+import GF.UseGrammar.Editing
+import GF.UseGrammar.Paraphrases
+import GF.Infra.Option
+import GF.CF.CF
+import GF.CF.CFIdent
+
+import GF.Canon.CanonToGrammar
+import GF.CF.PPrCF
+import GF.CF.PrLBNF
+import GF.Grammar.PrGrammar
+import GF.Compile.PrOld
+import GF.Canon.MkGFC
+import GF.Speech.PrGSL (gslPrinter)
+import GF.Speech.PrJSGF (jsgfPrinter)
+import GF.Speech.PrSRGS
+import GF.Speech.PrSRGS_ABNF
+import qualified GF.Speech.SISR as SISR
+import GF.Speech.PrSLF
+import GF.Speech.PrFA (faGraphvizPrinter,regularPrinter,faCPrinter)
+import GF.Speech.PrRegExp (regexpPrinter,multiRegexpPrinter)
+import GF.Speech.GrammarToVoiceXML (grammar2vxml)
+
+import GF.Data.Zipper
+
+import GF.UseGrammar.Statistics
+import GF.UseGrammar.Morphology
+import GF.UseGrammar.Information
+import GF.API.GrammarToHaskell
+import GF.API.GrammarToTransfer
+-----import GrammarToCanon (showCanon, showCanonOpt)
+-----import qualified GrammarToGFC as GFC
+import GF.Probabilistic.Probabilistic (prProbs)
+
+-- the cf parsing algorithms
+import GF.CF.ChartParser -- OBSOLETE
+import qualified GF.Parsing.CF as PCF
+import qualified GF.OldParsing.ParseCF as PCFOld -- OBSOLETE
+
+-- grammar conversions -- peb 19/4-04
+-- see also customGrammarPrinter
+import qualified GF.OldParsing.ConvertGrammar as CnvOld -- OBSOLETE
+import qualified GF.Printing.PrintParser as PrtOld -- OBSOLETE
+import qualified GF.Infra.Print as Prt
+import qualified GF.Conversion.GFC as Cnv
+import qualified GF.Conversion.Types as CnvTypes
+import qualified GF.Conversion.Haskell as CnvHaskell
+import qualified GF.Conversion.Prolog as CnvProlog
+import qualified GF.Conversion.TypeGraph as CnvTypeGraph
+import GF.Canon.Unparametrize
+import GF.Canon.Subexpressions
+import GF.Canon.AbsToBNF
+
+import GF.Canon.GFC
+import qualified GF.Canon.MkGFC as MC
+import GF.CFGM.PrintCFGrammar (prCanonAsCFGM)
+import GF.Visualization.VisualizeGrammar (visualizeCanonGrammar, visualizeSourceGrammar)
+
+import GF.API.MyParser
+
+import qualified GF.Infra.Modules as M
+import GF.Infra.UseIO
+
+import Control.Monad
+import Data.Char
+import Data.Maybe (fromMaybe)
+
+-- character codings
+import GF.Text.Unicode
+import GF.Text.UTF8 (decodeUTF8)
+import GF.Text.Greek (mkGreek)
+import GF.Text.Arabic (mkArabic)
+import GF.Text.Hebrew (mkHebrew)
+import GF.Text.Russian (mkRussian, mkRusKOI8)
+import GF.Text.Ethiopic (mkEthiopic)
+import GF.Text.Tamil (mkTamil)
+import GF.Text.OCSCyrillic (mkOCSCyrillic)
+import GF.Text.LatinASupplement (mkLatinASupplement)
+import GF.Text.Devanagari (mkDevanagari)
+import GF.Text.Hiragana (mkJapanese)
+import GF.Text.ExtendedArabic (mkArabic0600)
+import GF.Text.ExtendedArabic (mkExtendedArabic)
+import GF.Text.ExtraDiacritics (mkExtraDiacritics)
+
+-- minimal version also used in Hugs. AR 2/12/2002.
+
+-- databases for customizable commands. AR 21/11/2001
+-- for: grammar parsers, grammar printers, term commands, string commands
+-- idea: items added here are usable throughout GF; nothing else need be edited
+-- they are often usable through the API: hence API cannot be imported here!
+
+-- Major redesign 3/4/2002: the first entry in each database is DEFAULT.
+-- If no other value is given, the default is selected.
+-- Because of this, two invariants have to be preserved:
+-- - no databases may be empty
+-- - additions are made to the end of the database
+
+-- * these are the databases; the comment gives the name of the flag
+
+-- | grammarFormat, \"-format=x\" or file suffix
+customGrammarParser :: CustomData (FilePath -> IOE C.CanonGrammar)
+
+-- | grammarPrinter, \"-printer=x\"
+customGrammarPrinter :: CustomData (Options -> StateGrammar -> String)
+
+-- | multiGrammarPrinter, \"-printer=x\"
+customMultiGrammarPrinter :: CustomData (Options -> CanonGrammar -> String)
+
+-- | syntaxPrinter, \"-printer=x\"
+customSyntaxPrinter :: CustomData (GF.Grammar -> String)
+
+-- | termPrinter, \"-printer=x\"
+customTermPrinter :: CustomData (StateGrammar -> Tree -> String)
+
+-- | termCommand, \"-transform=x\"
+customTermCommand :: CustomData (StateGrammar -> Tree -> [Tree])
+
+-- | editCommand, \"-edit=x\"
+customEditCommand :: CustomData (StateGrammar -> Action)
+
+-- | filterString, \"-filter=x\"
+customStringCommand :: CustomData (StateGrammar -> String -> String)
+
+-- | useParser, \"-parser=x\"
+customParser :: CustomData (StateGrammar -> CFCat -> CFParser)
+
+-- | useTokenizer, \"-lexer=x\"
+customTokenizer :: CustomData (StateGrammar -> String -> [[CFTok]])
+
+-- | useUntokenizer, \"-unlexer=x\" --- should be from token list to string
+customUntokenizer :: CustomData (StateGrammar -> String -> String)
+
+-- | uniCoding, \"-coding=x\"
+--
+-- contains conversions from different codings to the internal
+-- unicode coding
+customUniCoding :: CustomData (String -> String)
+
+-- | this is the way of selecting an item
+customOrDefault :: Options -> OptFun -> CustomData a -> a
+customOrDefault opts optfun db = maybe (defaultCustomVal db) id $
+ customAsOptVal opts optfun db
+
+-- | to produce menus of custom operations
+customInfo :: CustomData a -> (String, [String])
+customInfo c = (titleCustomData c, map (ciStr . fst) (dbCustomData c))
+
+-------------------------------
+-- * types and stuff
+
+type CommandId = String
+
+strCI :: String -> CommandId
+strCI = id
+
+ciStr :: CommandId -> String
+ciStr = id
+
+ciOpt :: CommandId -> Option
+ciOpt = iOpt
+
+newtype CustomData a = CustomData (String, [(CommandId,a)])
+
+customData :: String -> [(CommandId, a)] -> CustomData a
+customData title db = CustomData (title,db)
+
+dbCustomData :: CustomData a -> [(CommandId, a)]
+dbCustomData (CustomData (_,db)) = db
+
+titleCustomData :: CustomData a -> String
+titleCustomData (CustomData (t,_)) = t
+
+lookupCustom :: CustomData a -> CommandId -> Maybe a
+lookupCustom = flip lookup . dbCustomData
+
+customAsOptVal :: Options -> OptFun -> CustomData a -> Maybe a
+customAsOptVal opts optfun db = do
+ arg <- getOptVal opts optfun
+ lookupCustom db (strCI arg)
+
+-- | take the first entry from the database
+defaultCustomVal :: CustomData a -> a
+defaultCustomVal (CustomData (s,db)) =
+ ifNull (error ("empty database:" +++ s)) (snd . head) db
+
+-------------------------------------------------------------------------
+-- * and here's the customizable part:
+
+-- grammar parsers: the ID is also used as file name suffix
+customGrammarParser =
+ customData "Grammar parsers, selected by file name suffix" $
+ [
+------ (strCI "gf", compileModule noOptions) -- DEFAULT
+-- add your own grammar parsers here
+ ]
+
+
+customGrammarPrinter =
+ customData "Grammar printers, selected by option -printer=x" $
+ [
+ (strCI "gfc", \_ -> prCanon . stateGrammarST) -- DEFAULT
+ ,(strCI "gf", \_ -> err id prGrammar . canon2sourceGrammar . stateGrammarST)
+ ,(strCI "cf", \_ -> prCF . stateCF)
+ ,(strCI "old", \_ -> printGrammarOld . stateGrammarST)
+ ,(strCI "gsl", gslPrinter)
+ ,(strCI "jsgf", jsgfPrinter Nothing)
+ ,(strCI "jsgf_sisr_old", jsgfPrinter (Just SISR.SISROld))
+ ,(strCI "srgs_xml", srgsXmlPrinter Nothing False)
+ ,(strCI "srgs_xml_non_rec", srgsXmlNonRecursivePrinter)
+ ,(strCI "srgs_xml_prob", srgsXmlPrinter Nothing True)
+ ,(strCI "srgs_xml_sisr_old", srgsXmlPrinter (Just SISR.SISROld) False)
+ ,(strCI "srgs_abnf", srgsAbnfPrinter Nothing False)
+ ,(strCI "srgs_abnf_non_rec", srgsAbnfNonRecursivePrinter)
+ ,(strCI "srgs_abnf_sisr_old", srgsAbnfPrinter (Just SISR.SISROld) False)
+ ,(strCI "vxml", grammar2vxml)
+ ,(strCI "slf", slfPrinter)
+ ,(strCI "slf_graphviz", slfGraphvizPrinter)
+ ,(strCI "slf_sub", slfSubPrinter)
+ ,(strCI "slf_sub_graphviz", slfSubGraphvizPrinter)
+ ,(strCI "fa_graphviz", faGraphvizPrinter)
+ ,(strCI "fa_c", faCPrinter)
+ ,(strCI "regexp", regexpPrinter)
+ ,(strCI "regexps", multiRegexpPrinter)
+ ,(strCI "regular", regularPrinter)
+ ,(strCI "plbnf", \_ -> prLBNF True)
+ ,(strCI "lbnf", \_ -> prLBNF False)
+ ,(strCI "bnf", \_ -> prBNF False)
+ ,(strCI "absbnf", \_ -> abstract2bnf . stateGrammarST)
+ ,(strCI "haskell", \_ -> grammar2haskell . stateGrammarST)
+ ,(strCI "gfcc_haskell", \opts -> CCH.grammar2haskell .
+ canon2gfcc opts . stateGrammarST)
+ ,(strCI "haskell_gadt", \_ -> grammar2haskellGADT . stateGrammarST)
+ ,(strCI "transfer", \_ -> grammar2transfer . stateGrammarST)
+ ,(strCI "morpho", \_ -> prMorpho . stateMorpho)
+ ,(strCI "fullform",\_ -> prFullForm . stateMorpho)
+ ,(strCI "opts", \_ -> prOpts . stateOptions)
+ ,(strCI "words", \_ -> unwords . stateGrammarWords)
+ ,(strCI "printnames", \_ -> C.prPrintnamesGrammar . stateGrammarST)
+ ,(strCI "stat", \_ -> prStatistics . stateGrammarST)
+ ,(strCI "probs", \_ -> prProbs . stateProbs)
+ ,(strCI "unpar", \_ -> prCanon . unparametrizeCanon . stateGrammarST)
+ ,(strCI "subs", \_ -> prSubtermStat . stateGrammarST)
+
+{- ----
+ (strCI "gf", prt . st2grammar . stateGrammarST) -- DEFAULT
+ ,(strCI "canon", showCanon "Lang" . stateGrammarST)
+ ,(strCI "gfc", GFC.showGFC . stateGrammarST)
+ ,(strCI "canonOpt",showCanonOpt "Lang" . stateGrammarST)
+-}
+
+-- add your own grammar printers here
+
+-- grammar conversions:
+ ,(strCI "mcfg", \_ -> Prt.prt . stateMCFG)
+ ,(strCI "fcfg", \_ -> Prt.prt . fst . stateFCFG)
+ ,(strCI "cfg", \_ -> Prt.prt . stateCFG)
+ ,(strCI "pinfo", \_ -> Prt.prt . statePInfo)
+ ,(strCI "abstract", \_ -> Prt.prtAfter "\n" . Cnv.gfc2abstract . stateGrammarLang)
+
+ ,(strCI "functiongraph",\_ -> CnvTypeGraph.prtFunctionGraph . Cnv.gfc2simple noOptions . stateGrammarLang)
+ ,(strCI "typegraph", \_ -> CnvTypeGraph.prtTypeGraph . Cnv.gfc2simple noOptions . stateGrammarLang)
+
+ ,(strCI "gfc-haskell", \_ -> CnvHaskell.prtSGrammar . uncurry Cnv.gfc2simple . stateGrammarLangOpts)
+ ,(strCI "mcfg-haskell", \_ -> CnvHaskell.prtMGrammar . stateMCFG)
+ ,(strCI "cfg-haskell", \_ -> CnvHaskell.prtCGrammar . stateCFG)
+ ,(strCI "gfc-prolog", \_ -> CnvProlog.prtSGrammar . uncurry Cnv.gfc2simple . stateGrammarLangOpts)
+ ,(strCI "mcfg-prolog", \_ -> CnvProlog.prtMGrammar . stateMCFG)
+ ,(strCI "cfg-prolog", \_ -> CnvProlog.prtCGrammar . stateCFG)
+
+-- obsolete, or only for testing:
+ ,(strCI "abs-skvatt", \_ -> Cnv.abstract2skvatt . Cnv.gfc2abstract . stateGrammarLang)
+ ,(strCI "cfg-skvatt", \_ -> Cnv.cfg2skvatt . stateCFG)
+ ,(strCI "simple", \_ -> Prt.prt . uncurry Cnv.gfc2simple . stateGrammarLangOpts)
+ ,(strCI "mcfg-erasing", \_ -> Prt.prt . fst . snd . uncurry Cnv.convertGFC . stateGrammarLangOpts)
+-- ,(strCI "mcfg-old", PrtOld.prt . CnvOld.mcfg . statePInfoOld)
+-- ,(strCI "cfg-old", PrtOld.prt . CnvOld.cfg . statePInfoOld)
+ ]
+ where stateGrammarLangOpts s = (stateOptions s, stateGrammarLang s)
+
+customMultiGrammarPrinter =
+ customData "Printers for multiple grammars, selected by option -printer=x" $
+ [
+ (strCI "gfcm", const MC.prCanon)
+ ,(strCI "gfcc", canon2gfccPr)
+ ,(strCI "js", \opts -> JS.gfcc2js . canon2gfcc opts)
+ ,(strCI "header", const (MC.prCanonMGr . unoptimizeCanon))
+ ,(strCI "cfgm", prCanonAsCFGM)
+ ,(strCI "graph", visualizeCanonGrammar)
+ ,(strCI "missing", const missingLinCanonGrammar)
+
+-- to prolog format:
+ ,(strCI "gfc-prolog", CnvProlog.prtSMulti)
+ ,(strCI "mcfg-prolog", CnvProlog.prtMMulti)
+ ,(strCI "cfg-prolog", CnvProlog.prtCMulti)
+ ]
+
+
+customSyntaxPrinter =
+ customData "Syntax printers, selected by option -printer=x" $
+ [
+-- add your own grammar printers here
+ ]
+
+
+customTermPrinter =
+ customData "Term printers, selected by option -printer=x" $
+ [
+ (strCI "gf", const prt) -- DEFAULT
+-- add your own term printers here
+ ]
+
+customTermCommand =
+ customData "Term transformers, selected by option -transform=x" $
+ [
+ (strCI "identity", \_ t -> [t]) -- DEFAULT
+ ,(strCI "compute", \g t -> let gr = grammar g in
+ err (const [t]) return
+ (exp2termCommand gr (computeAbsTerm gr) t))
+ ,(strCI "nodup", \_ t -> if (hasDupIdent $ tree2exp t) then [] else [t])
+ ,(strCI "nodupatom", \_ t -> if (hasDupAtom $ tree2exp t) then [] else [t])
+ ,(strCI "paraphrase", \g t -> let gr = grammar g in
+ exp2termlistCommand gr (mkParaphrases gr) t)
+
+ ,(strCI "generate", \g t -> let gr = grammar g
+ cat = actCat $ tree2loc t --- not needed
+ in
+ [tr | t <- generateTrees noOptions gr cat 2 Nothing (Just t),
+ Ok tr <- [annotate gr $ MM.qualifTerm (absId g) t]])
+ ,(strCI "typecheck", \g t -> err (const []) (return . loc2tree)
+ (reCheckStateReject (grammar g) (tree2loc t)))
+ ,(strCI "solve", \g t -> err (const []) (return . loc2tree)
+ (solveAll (grammar g) (tree2loc t)
+ >>= rejectUnsolvable))
+ ,(strCI "context", \g t -> err (const [t]) (return . loc2tree)
+ (contextRefinements (grammar g) (tree2loc t)))
+ ,(strCI "reindex", \g t -> let gr = grammar g in
+ err (const [t]) return
+ (exp2termCommand gr (return . MM.reindexTerm) t))
+--- ,(strCI "delete", \g t -> [MM.mExp0])
+-- add your own term commands here
+ ]
+
+customEditCommand =
+ customData "Editor state transformers, selected by option -edit=x" $
+ [
+ (strCI "identity", const return) -- DEFAULT
+ ,(strCI "typecheck", \g -> reCheckState (grammar g))
+ ,(strCI "solve", \g -> solveAll (grammar g))
+ ,(strCI "context", \g -> contextRefinements (grammar g))
+ ,(strCI "compute", \g -> computeSubTree (grammar g))
+ ,(strCI "paraphrase", const return) --- done ad hoc on top level
+ ,(strCI "generate", const return) --- done ad hoc on top level
+ ,(strCI "transfer", const return) --- done ad hoc on top level
+-- add your own edit commands here
+ ]
+
+customStringCommand =
+ customData "String filters, selected by option -filter=x" $
+ [
+ (strCI "identity", const $ id) -- DEFAULT
+ ,(strCI "erase", const $ const "")
+ ,(strCI "take100", const $ take 100)
+ ,(strCI "text", const $ formatAsText)
+ ,(strCI "code", const $ formatAsCode)
+---- ,(strCI "latexfile", const $ mkLatexFile)
+ ,(strCI "length", const $ show . length)
+-- add your own string commands here
+ ]
+
+customParser =
+ customData "Parsers, selected by option -parser=x" $
+ [
+ (strCI "chart", PCFOld.parse "ibn" . stateCF) -- DEPRECATED
+ ,(strCI "bottomup", PCF.parse "gb" . stateCF)
+ ,(strCI "topdown", PCF.parse "gt" . stateCF)
+-- commented for now, since there's a bug in the incremental algorithm:
+-- ,(strCI "incremental", PCF.parse "ib" . stateCF)
+-- ,(strCI "incremental-bottomup", PCF.parse "ib" . stateCF)
+-- ,(strCI "incremental-topdown", PCF.parse "it" . stateCF)
+ ,(strCI "old", chartParser . stateCF) -- DEPRECATED
+ ,(strCI "myparser", myParser)
+-- add your own parsers here
+ ]
+
+customTokenizer =
+ let sg = singleton in
+ customData "Tokenizers, selected by option -lexer=x" $
+ [
+ (strCI "words", const $ sg . tokWords)
+ ,(strCI "literals", const $ sg . tokLits)
+ ,(strCI "vars", const $ sg . tokVars)
+ ,(strCI "chars", const $ sg . map (tS . singleton))
+ ,(strCI "code", const $ sg . lexHaskell)
+ ,(strCI "codevars", \gr -> sg . (lexHaskellVar $ stateIsWord gr))
+ ,(strCI "textvars", \gr -> sg . (lexTextVar $ stateIsWord gr))
+ ,(strCI "text", const $ sg . lexText)
+ ,(strCI "unglue", \gr -> sg . map tS . decomposeWords (stateMorpho gr))
+ ,(strCI "codelit", \gr -> sg . (lexHaskellLiteral $ stateIsWord gr))
+ ,(strCI "textlit", \gr -> sg . (lexTextLiteral $ stateIsWord gr))
+ ,(strCI "codeC", const $ sg . lexC2M)
+ ,(strCI "ignore", \gr -> sg . lexIgnore (stateIsWord gr) . tokLits)
+ ,(strCI "subseqs", \gr -> subSequences . lexIgnore (stateIsWord gr) . tokLits)
+ ,(strCI "codeCHigh", const $ sg . lexC2M' True)
+-- add your own tokenizers here
+ ]
+
+customUntokenizer =
+ customData "Untokenizers, selected by option -unlexer=x" $
+ [
+ (strCI "unwords", const $ id) -- DEFAULT
+ ,(strCI "text", const $ formatAsText)
+ ,(strCI "html", const $ formatAsHTML)
+ ,(strCI "latex", const $ formatAsLatex)
+ ,(strCI "code", const $ formatAsCode)
+ ,(strCI "concat", const $ filter (not . isSpace))
+ ,(strCI "textlit", const $ formatAsTextLit)
+ ,(strCI "codelit", const $ formatAsCodeLit)
+ ,(strCI "concat", const $ concatRemSpace)
+ ,(strCI "glue", const $ performBinds)
+ ,(strCI "finnish", const $ performBindsFinnish)
+ ,(strCI "reverse", const $ reverse)
+ ,(strCI "bind", const $ performBinds) -- backward compat
+-- add your own untokenizers here
+ ]
+
+customUniCoding =
+ customData "Alphabet codings, selected by option -coding=x" $
+ [
+ (strCI "latin1", id) -- DEFAULT
+ ,(strCI "utf8", decodeUTF8)
+ ,(strCI "greek", treat [] mkGreek)
+ ,(strCI "hebrew", mkHebrew)
+ ,(strCI "arabic", mkArabic)
+ ,(strCI "russian", treat [] mkRussian)
+ ,(strCI "russianKOI8", mkRusKOI8)
+ ,(strCI "ethiopic", mkEthiopic)
+ ,(strCI "tamil", mkTamil)
+ ,(strCI "OCScyrillic", mkOCSCyrillic)
+ ,(strCI "devanagari", mkDevanagari)
+ ,(strCI "latinasupplement", mkLatinASupplement)
+ ,(strCI "japanese", mkJapanese)
+ ,(strCI "arabic0600", mkArabic0600)
+ ,(strCI "extendedarabic", mkExtendedArabic)
+ ,(strCI "extradiacritics", mkExtraDiacritics)
+ ]
diff --git a/src-2.9/GF/UseGrammar/Editing.hs b/src-2.9/GF/UseGrammar/Editing.hs
new file mode 100644
index 000000000..762562eb0
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Editing.hs
@@ -0,0 +1,435 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Editing
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:45 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.14 $
+--
+-- generic tree editing, with some grammar notions assumed. AR 18\/8\/2001.
+-- 19\/6\/2003 for GFC
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Editing where
+
+import GF.Grammar.Abstract
+import qualified GF.Canon.GFC as GFC
+import GF.Grammar.TypeCheck
+import GF.Grammar.LookAbs
+import GF.Grammar.AbsCompute
+import GF.Grammar.Macros (errorCat)
+
+import GF.Data.Operations
+import GF.Data.Zipper
+
+-- generic tree editing, with some grammar notions assumed. AR 18/8/2001
+-- 19/6/2003 for GFC
+
+type CGrammar = GFC.CanonGrammar
+
+type State = Loc TrNode
+
+-- | the "empty" state
+initState :: State
+initState = tree2loc uTree
+
+isRootState :: State -> Bool
+isRootState s = case actPath s of
+ Top -> True
+ _ -> False
+
+actTree :: State -> Tree
+actTree (Loc (t,_)) = t
+
+actPath :: State -> Path TrNode
+actPath (Loc (_,p)) = p
+
+actVal :: State -> Val
+actVal = valNode . nodeTree . actTree
+
+actCat :: State -> Cat
+actCat = errVal errorCat . val2cat . actVal ---- undef
+
+actAtom :: State -> Atom
+actAtom = atomTree . actTree
+
+actFun :: State -> Err Fun
+actFun s = case actAtom s of
+ AtC f -> return f
+ t -> prtBad "active atom: expected function, found" t
+
+actExp :: State -> Exp
+actExp = tree2exp . actTree
+
+-- | current local bindings
+actBinds :: State -> Binds
+actBinds = bindsNode . nodeTree . actTree
+
+-- | constraints in current subtree
+actConstrs :: State -> Constraints
+actConstrs = allConstrsTree . actTree
+
+-- | constraints in the whole tree
+allConstrs :: State -> Constraints
+allConstrs = allConstrsTree . loc2tree
+
+-- | metas in current subtree
+actMetas :: State -> [Meta]
+actMetas = metasTree . actTree
+
+-- | metas in the whole tree
+allMetas :: State -> [Meta]
+allMetas = metasTree . loc2tree
+
+actTreeBody :: State -> Tree
+actTreeBody = bodyTree . actTree
+
+allPrevBinds :: State -> Binds
+allPrevBinds = concatMap bindsNode . traverseCollect . actPath
+
+allBinds :: State -> Binds
+allBinds s = actBinds s ++ allPrevBinds s
+
+actGen :: State -> Int
+actGen = length . allBinds -- symbol generator for VGen
+
+allPrevVars :: State -> [Var]
+allPrevVars = map fst . allPrevBinds
+
+allVars :: State -> [Var]
+allVars = map fst . allBinds
+
+vGenIndex :: State -> Int
+vGenIndex = length . allBinds
+
+actIsMeta :: State -> Bool
+actIsMeta = atomIsMeta . actAtom
+
+actMeta :: State -> Err Meta
+actMeta = getMetaAtom . actAtom
+
+-- | meta substs are not only on the actual path...
+entireMetaSubst :: State -> MetaSubst
+entireMetaSubst = concatMap metaSubstsNode . scanTree . loc2tree
+
+isCompleteTree :: Tree -> Bool
+isCompleteTree = null . filter atomIsMeta . map atomNode . scanTree
+
+isCompleteState :: State -> Bool
+isCompleteState = isCompleteTree . loc2tree
+
+initStateCat :: Context -> Cat -> Err State
+initStateCat cont cat = do
+ return $ tree2loc (Tr (mkNode [] mAtom (cat2val cont cat) ([],[]), []))
+
+-- | this function only concerns the body of an expression...
+annotateInState :: CGrammar -> Exp -> State -> Err Tree
+annotateInState gr exp state = do
+ let binds = allBinds state
+ val = actVal state
+ annotateIn gr binds exp (Just val)
+
+-- | ...whereas this one works with lambda abstractions
+annotateExpInState :: CGrammar -> Exp -> State -> Err Tree
+annotateExpInState gr exp state = do
+ let cont = allPrevBinds state
+ binds = actBinds state
+ val = actVal state
+ typ <- mkProdVal binds val
+ annotateIn gr binds exp (Just typ)
+
+treeByExp :: (Exp -> Err Exp) -> CGrammar -> Exp -> State -> Err Tree
+treeByExp trans gr exp0 state = do
+ exp <- trans exp0
+ annotateExpInState gr exp state
+
+-- * actions
+
+type Action = State -> Err State
+
+newCat :: CGrammar -> Cat -> Action
+newCat gr cat@(m,c) _ = do
+ cont <- lookupCatContext gr m c
+ testErr (null cont) "start cat must have null context" -- for easier meta refresh
+ initStateCat cont cat
+
+newFun :: CGrammar -> Fun -> Action
+newFun gr fun@(m,c) _ = do
+ typ <- lookupFunType gr m c
+ cat <- valCat typ
+ st1 <- newCat gr cat initState
+ refineWithAtom True gr (qq fun) st1
+
+newTree :: Tree -> Action
+newTree t _ = return $ tree2loc t
+
+newExpTC :: CGrammar -> Exp -> Action
+newExpTC gr t s = annotate gr (refreshMetas [] t) >>= flip newTree s
+
+goNextMeta, goPrevMeta, goNextNewMeta, goPrevNewMeta, goNextMetaIfCan :: Action
+
+goNextMeta = repeatUntilErr actIsMeta goAhead -- can be the location itself
+goPrevMeta = repeatUntilErr actIsMeta goBack
+
+goNextNewMeta s = goAhead s >>= goNextMeta -- always goes away from location
+goPrevNewMeta s = goBack s >>= goPrevMeta
+
+goNextMetaIfCan = actionIfPossible goNextMeta
+
+actionIfPossible :: Action -> Action
+actionIfPossible a s = return $ errVal s (a s)
+
+goFirstMeta, goLastMeta :: Action
+goFirstMeta s = goNextMeta $ goRoot s
+goLastMeta s = goLast s >>= goPrevMeta
+
+noMoreMetas :: State -> Bool
+noMoreMetas = err (const True) (const False) . goNextMeta
+
+replaceSubTree :: Tree -> Action
+replaceSubTree tree state = changeLoc state tree
+
+refineOrReplaceWithTree :: Bool -> CGrammar -> Tree -> Action
+refineOrReplaceWithTree der gr tree state = case actMeta state of
+ Ok m -> refineWithTreeReal der gr tree m state
+ _ -> do
+ let tree1 = addBinds (actBinds state) $ tree
+ state' <- replaceSubTree tree1 state
+ reCheckState gr state'
+
+refineWithTree :: Bool -> CGrammar -> Tree -> Action
+refineWithTree der gr tree state = do
+ m <- errIn "move pointer to meta" $ actMeta state
+ refineWithTreeReal der gr tree m state
+
+refineWithTreeReal :: Bool -> CGrammar -> Tree -> Meta -> Action
+refineWithTreeReal der gr tree m state = do
+ state' <- replaceSubTree tree state
+ let cs0 = allConstrs state'
+ (cs,ms) = splitConstraints gr cs0
+ v = vClos $ tree2exp (bodyTree tree)
+ msubst = (m,v) : ms
+ metaSubstRefinements gr msubst $
+ mapLoc (reduceConstraintsNode gr . performMetaSubstNode msubst) state'
+
+ -- without dep. types, no constraints, no grammar needed - simply: do
+ -- testErr (actIsMeta state) "move pointer to meta"
+ -- replaceSubTree tree state
+
+refineAllNodes :: Action -> Action
+refineAllNodes act state = do
+ let estate0 = goFirstMeta state
+ case estate0 of
+ Bad _ -> return state
+ Ok state0 -> do
+ (state',n) <- tryRefine 0 state0
+ if n==0
+ then return state
+ else actionIfPossible goFirstMeta state'
+ where
+ tryRefine n state = err (const $ return (state,n)) return $ do
+ state' <- goNextMeta state
+ meta <- actMeta state'
+ case act state' of
+ Ok state2 -> tryRefine (n+1) state2
+ _ -> err (const $ return (state',n)) return $ do
+ state2 <- goNextNewMeta state'
+ tryRefine n state2
+
+uniqueRefinements :: CGrammar -> Action
+uniqueRefinements = refineAllNodes . uniqueRefine
+
+metaSubstRefinements :: CGrammar -> MetaSubst -> Action
+metaSubstRefinements gr = refineAllNodes . metaSubstRefine gr
+
+contextRefinements :: CGrammar -> Action
+contextRefinements gr = refineAllNodes contextRefine where
+ contextRefine state = case varRefinementsState state of
+ [(e,_)] -> refineWithAtom False gr e state
+ _ -> Bad "no unique refinement in context"
+ varRefinementsState state =
+ [r | r@(e,_) <- refinementsState gr state, isVariable e]
+
+uniqueRefine :: CGrammar -> Action
+uniqueRefine gr state = case refinementsState gr state of
+ [(e,(_,True))] -> Bad "only circular refinement"
+ [(e,_)] -> refineWithAtom False gr e state
+ _ -> Bad "no unique refinement"
+
+metaSubstRefine :: CGrammar -> MetaSubst -> Action
+metaSubstRefine gr msubst state = do
+ m <- errIn "move pointer to meta" $ actMeta state
+ case lookup m msubst of
+ Just v -> do
+ e <- val2expSafe v
+ refineWithExpTC False gr e state
+ _ -> Bad "no metavariable substitution available"
+
+refineWithExpTC :: Bool -> CGrammar -> Exp -> Action
+refineWithExpTC der gr exp0 state = do
+ let oldmetas = allMetas state
+ exp = refreshMetas oldmetas exp0
+ tree0 <- annotateInState gr exp state
+ let tree = addBinds (actBinds state) $ tree0
+ refineWithTree der gr tree state
+
+refineWithAtom :: Bool -> CGrammar -> Ref -> Action -- function or variable
+refineWithAtom der gr at state = do
+ val <- lookupRef gr (allBinds state) at
+ typ <- val2exp val
+ let oldvars = allVars state
+ exp <- ref2exp oldvars typ at
+ refineWithExpTC der gr exp state
+
+-- | in this command, we know that the result is well-typed, since computation
+-- rules have been type checked and the result is equal
+computeSubTree :: CGrammar -> Action
+computeSubTree gr state = do
+ let exp = tree2exp (actTree state)
+ tree <- treeByExp (compute gr) gr exp state
+ replaceSubTree tree state
+
+-- | but here we don't, since the transfer flag isn't type checked,
+-- and computing the transfer function is not checked to preserve equality
+transferSubTree :: Maybe Fun -> CGrammar -> Action
+transferSubTree Nothing _ s = return s
+transferSubTree (Just fun) gr state = do
+ let exp = mkApp (qq fun) [tree2exp $ actTree state]
+ tree <- treeByExp (compute gr) gr exp state
+ state' <- replaceSubTree tree state
+ reCheckState gr state'
+
+deleteSubTree :: CGrammar -> Action
+deleteSubTree gr state =
+ if isRootState state
+ then do
+ let cat = actCat state
+ newCat gr cat state
+ else do
+ let metas = allMetas state
+ binds = actBinds state
+ exp = refreshMetas metas mExp0
+ tree <- annotateInState gr exp state
+ state' <- replaceSubTree (addBinds binds tree) state
+ reCheckState gr state' --- must be unfortunately done. 20/11/2001
+
+wrapWithFun :: CGrammar -> (Fun,Int) -> Action
+wrapWithFun gr (f@(m,c),i) state = do
+ typ <- lookupFunType gr m c
+ let olds = allPrevVars state
+ oldmetas = allMetas state
+ exp0 <- fun2wrap olds ((f,i),typ) (tree2exp (actTreeBody state))
+ let exp = refreshMetas oldmetas exp0
+ tree0 <- annotateInState gr exp state
+ let tree = addBinds (actBinds state) $ tree0
+ state' <- replaceSubTree tree state
+ reCheckState gr state' --- must be unfortunately done. 20/11/2001
+
+alphaConvert :: CGrammar -> (Var,Var) -> Action
+alphaConvert gr (x,x') state = do
+ let oldvars = allPrevVars state
+ testErr (notElem x' oldvars) ("clash with previous bindings" +++ show x')
+ let binds0 = actBinds state
+ vars0 = map fst binds0
+ testErr (notElem x' vars0) ("clash with other bindings" +++ show x')
+ let binds = [(if z==x then x' else z, t) | (z,t) <- binds0]
+ vars = map fst binds
+ exp' <- alphaConv (vars ++ oldvars) (x,x') (tree2exp (actTreeBody state))
+ let exp = mkAbs vars exp'
+ tree <- annotateExpInState gr exp state
+ replaceSubTree tree state
+
+changeFunHead :: CGrammar -> Fun -> Action
+changeFunHead gr f state = do
+ let state' = changeNode (changeAtom (const (atomC f))) state
+ reCheckState gr state' --- must be done because of constraints elsewhere
+
+peelFunHead :: CGrammar -> (Fun,Int) -> Action
+peelFunHead gr (f@(m,c),i) state = do
+ tree0 <- nthSubtree i $ actTree state
+ let tree = addBinds (actBinds state) $ tree0
+ state' <- replaceSubTree tree state
+ reCheckState gr state' --- must be unfortunately done. 20/11/2001
+
+-- | an expensive operation
+reCheckState :: CGrammar -> State -> Err State
+reCheckState gr st = annotate gr (tree2exp (loc2tree st)) >>= return . tree2loc
+
+-- | a variant that returns Bad instead of a tree with unsolvable constraints
+reCheckStateReject :: CGrammar -> State -> Err State
+reCheckStateReject gr st = do
+ st' <- reCheckState gr st
+ rejectUnsolvable st'
+
+rejectUnsolvable :: State -> Err State
+rejectUnsolvable st = case (constrsNode $ nodeTree $ actTree st) of
+ [] -> return st
+ cs -> Bad $ "Unsolvable constraints:" +++ prConstraints cs
+
+-- | extract metasubstitutions from constraints and solve them
+solveAll :: CGrammar -> State -> Err State
+solveAll gr st = solve st >>= solve where
+ solve st0 = do ---- why need twice?
+ st <- reCheckState gr st0
+ let cs0 = allConstrs st
+ (cs,ms) = splitConstraints gr cs0
+ metaSubstRefinements gr ms $
+ mapLoc (reduceConstraintsNode gr . performMetaSubstNode ms) st
+
+-- * active refinements
+
+refinementsState :: CGrammar -> State -> [(Term,(Val,Bool))]
+refinementsState gr state =
+ let filt = possibleRefVal gr state in
+ if actIsMeta state
+ then refsForType filt gr (allBinds state) (actVal state)
+ else []
+
+wrappingsState :: CGrammar -> State -> [((Fun,Int),Type)]
+wrappingsState gr state
+ | actIsMeta state = []
+ | isRootState state = funs
+ | otherwise = [rule | rule@(_,typ) <- funs, possibleRefVal gr state aval typ]
+ where
+ funs = funsOnType (possibleRefVal gr state) gr aval
+ aval = actVal state
+
+peelingsState :: CGrammar -> State -> [(Fun,Int)]
+peelingsState gr state
+ | actIsMeta state = []
+ | isRootState state =
+ err (const []) (\f -> [(f,i) | i <- [0 .. arityTree tree - 1]]) $ actFun state
+ | otherwise =
+ err (const [])
+ (\f -> [fi | (fi@(g,_),typ) <- funs,
+ possibleRefVal gr state aval typ,g==f]) $ actFun state
+ where
+ funs = funsOnType (possibleRefVal gr state) gr aval
+ aval = actVal state
+ tree = actTree state
+
+headChangesState :: CGrammar -> State -> [Fun]
+headChangesState gr state = errVal [] $ do
+ f@(m,c) <- funAtom (actAtom state)
+ typ0 <- lookupFunType gr m c
+ return [fun | (fun,typ) <- funRulesOf gr, fun /= f, typ == typ0]
+ --- alpha-conv !
+
+possibleRefVal :: CGrammar -> State -> Val -> Type -> Bool
+possibleRefVal gr state val typ = errVal True $ do --- was False
+ vtyp <- valType typ
+ let gen = actGen state
+ cs <- return [(val, vClos vtyp)] --- eqVal gen val (vClos vtyp) --- only poss cs
+ return $ possibleConstraints gr cs --- a simple heuristic
+
+possibleTreeVal :: CGrammar -> State -> Tree -> Bool
+possibleTreeVal gr state tree = errVal True $ do --- was False
+ let aval = actVal state
+ let gval = valTree tree
+ let gen = actGen state
+ cs <- return [(aval, gval)] --- eqVal gen val (vClos vtyp) --- only poss cs
+ return $ possibleConstraints gr cs --- a simple heuristic
+
diff --git a/src-2.9/GF/UseGrammar/Generate.hs b/src-2.9/GF/UseGrammar/Generate.hs
new file mode 100644
index 000000000..5f07e0b85
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Generate.hs
@@ -0,0 +1,116 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Generate
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/10/12 12:38:30 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.16 $
+--
+-- Generate all trees of given category and depth. AR 30\/4\/2004
+--
+-- (c) Aarne Ranta 2004 under GNU GPL
+--
+-- Purpose: to generate corpora. We use simple types and don't
+-- guarantee the correctness of bindings\/dependences.
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Generate (generateTrees,generateAll) where
+
+import GF.Canon.GFC
+import GF.Grammar.LookAbs
+import GF.Grammar.PrGrammar
+import GF.Grammar.Macros
+import GF.Grammar.Values
+import GF.Grammar.Grammar (Cat)
+import GF.Grammar.SGrammar
+import GF.Data.Operations
+import GF.Data.Zipper
+import GF.Infra.Option
+import Data.List
+
+-- Generate all trees of given category and depth. AR 30/4/2004
+-- (c) Aarne Ranta 2004 under GNU GPL
+--
+-- Purpose: to generate corpora. We use simple types and don't
+-- guarantee the correctness of bindings/dependences.
+
+
+-- | the main function takes an abstract syntax and returns a list of trees
+generateTrees ::
+ Options -> GFCGrammar -> Cat -> Int -> Maybe Int -> Maybe Tree -> [Exp]
+generateTrees opts gr cat n mn mt = map str2tr $ generate gr' opts cat' n mn mt'
+ where
+ gr' = gr2sgr opts emptyProbs gr
+ cat' = prt $ snd cat
+ mt' = maybe Nothing (return . tr2str) mt
+--- ifm = oElem withMetas opts
+ ifm = oElem showOld opts
+
+generateAll :: Options -> (Exp -> IO ()) -> GFCGrammar -> Cat -> IO ()
+generateAll opts io gr cat = mapM_ (io . str2tr) $ num $ gen cat'
+ where
+ num = optIntOrAll opts flagNumber
+ gr' = gr2sgr opts emptyProbs gr
+ cat' = prt $ snd cat
+ gen c = generate gr' opts c 10 Nothing Nothing
+
+
+
+------------------------------------------
+-- do the main thing with a simpler data structure
+-- the first Int gives tree depth, the second constrains subtrees
+-- chosen for each branch. A small number, such as 2, is a good choice
+-- if the depth is large (more than 3)
+-- If a tree is given as argument, generation concerns its metavariables.
+
+generate :: SGrammar -> Options -> SCat -> Int -> Maybe Int -> Maybe STree -> [STree]
+generate gr opts cat i mn mt = case mt of
+ Nothing -> gen opts cat
+ Just t -> genM t
+ where
+--- now use ifm to choose between two algorithms
+ gen opts cat
+ | oElem (iOpt "mem") opts = concat $ errVal [] $ lookupTree id cat $ allTrees -- -old
+ | oElem (iOpt "nonub") opts = concatMap (\i -> gener i cat) [0..i-1] -- some duplicates
+ | otherwise = nub $ concatMap (\i -> gener i cat) [0..i-1] -- new
+
+ gener 0 c = [SApp (f, []) | (f,([],_)) <- funs c]
+ gener i c = [
+ tr |
+ (f,(cs,_)) <- funs c,
+ let alts = map (gener (i-1)) cs,
+ ts <- combinations alts,
+ let tr = SApp (f, ts)
+-- depth tr >= i -- NO!
+ ]
+
+ allTrees = genAll i
+
+ -- dynamic generation
+ genAll :: Int -> BinTree SCat [[STree]]
+ genAll i = iter i genNext (mapTree (\ (c,_) -> (c,[[]])) gr)
+
+ iter 0 f tr = tr
+ iter n f tr = iter (n-1) f (f tr)
+
+ genNext tr = mapTree (genNew tr) tr
+
+ genNew tr (cat,ts) = let size = length ts in
+ (cat, [SApp (f, xs) |
+ (f,(cs,_)) <- funs cat,
+ xs <- combinations (map look cs),
+ let fxs = SApp (f, xs),
+ depth fxs == size]
+ : ts)
+ where
+ look c = concat $ errVal [] $ lookupTree id c tr
+
+ funs cat = maybe id take mn $ errVal [] $ lookupTree id cat gr
+
+ genM t = case t of
+ SApp (f,ts) -> [SApp (f,ts') | ts' <- combinations (map genM ts)]
+ SMeta k -> gen opts k
+ _ -> [t]
diff --git a/src-2.9/GF/UseGrammar/GetTree.hs b/src-2.9/GF/UseGrammar/GetTree.hs
new file mode 100644
index 000000000..e980a3d95
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/GetTree.hs
@@ -0,0 +1,74 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GetTree
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/09/15 16:22:02 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.9 $
+--
+-- how to form linearizable trees from strings and from terms of different levels
+--
+-- 'String' --> raw 'Term' --> annot, qualif 'Term' --> 'Tree'
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.GetTree where
+
+import GF.Canon.GFC
+import GF.Grammar.Values
+import qualified GF.Grammar.Grammar as G
+import GF.Infra.Ident
+import GF.Grammar.MMacros
+import GF.Grammar.Macros
+import GF.Compile.Rename
+import GF.Grammar.TypeCheck
+import GF.Grammar.AbsCompute (beta)
+import GF.Compile.PGrammar
+import GF.Compile.ShellState
+
+import GF.Data.Operations
+
+import Data.Char
+
+-- how to form linearizable trees from strings and from terms of different levels
+--
+-- String --> raw Term --> annot, qualif Term --> Tree
+
+string2tree :: StateGrammar -> String -> Tree
+string2tree gr = errVal uTree . string2treeErr gr
+
+string2treeErr :: StateGrammar -> String -> Err Tree
+string2treeErr _ "" = Bad "empty string"
+string2treeErr gr s = do
+ t <- pTerm s
+ let t0 = beta [] t
+ let t1 = refreshMetas [] t0
+ let t2 = qualifTerm abstr t1
+ annotate grc t2
+ where
+ abstr = absId gr
+ grc = grammar gr
+
+string2Cat, string2Fun :: StateGrammar -> String -> (Ident,Ident)
+string2Cat gr c = (absId gr,identC c)
+string2Fun = string2Cat
+
+strings2Cat, strings2Fun :: String -> (Ident,Ident)
+strings2Cat s = (identC m, identC (drop 1 c)) where (m,c) = span (/= '.') s
+strings2Fun = strings2Cat
+
+string2ref :: StateGrammar -> String -> Err G.Term
+string2ref gr s = case s of
+ 'x':'_':ds -> return $ freshAsTerm ds --- hack for generated vars
+ '"':_:_ -> return $ G.K $ init $ tail s
+ _:_ | all isDigit s -> return $ G.EInt $ read s
+ _ | elem '.' s -> return $ uncurry G.Q $ strings2Fun s
+ _ -> return $ G.Vr $ identC s
+
+string2cat :: StateGrammar -> String -> Err G.Cat
+string2cat gr s =
+ if elem '.' s
+ then return $ strings2Fun s
+ else return $ curry id (absId gr) (identC s)
diff --git a/src-2.9/GF/UseGrammar/Information.hs b/src-2.9/GF/UseGrammar/Information.hs
new file mode 100644
index 000000000..4526980d6
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Information.hs
@@ -0,0 +1,162 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Information
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/10/05 20:02:20 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.7 $
+--
+-- information on module, category, function, operation, parameter,...
+-- AR 16\/9\/2003.
+-- uses source grammar
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Information (
+ showInformation,
+ missingLinCanonGrammar
+ ) where
+
+import GF.Grammar.Grammar
+import GF.Infra.Ident
+import GF.Infra.Modules
+import GF.Infra.Option
+import GF.CF.CF
+import GF.CF.PPrCF
+import GF.Compile.ShellState
+import GF.Grammar.PrGrammar
+import GF.Grammar.Lookup
+import GF.Grammar.Macros (zIdent)
+import qualified GF.Canon.GFC as GFC
+import qualified GF.Canon.AbsGFC as AbsGFC
+
+import GF.Data.Operations
+import GF.Infra.UseIO
+
+-- information on module, category, function, operation, parameter,... AR 16/9/2003
+-- uses source grammar
+
+-- | the top level function
+showInformation :: Options -> ShellState -> Ident -> IOE ()
+showInformation opts st c = do
+ is <- ioeErr $ getInformation opts st c
+ if null is
+ then putStrLnE "Identifier not in scope"
+ else mapM_ (putStrLnE . prInformationM c) is
+ where
+ prInformationM c (i,m) = prInformation opts c i ++ "file:" +++ m ++ "\n"
+
+-- | the data type of different kinds of information
+data Information =
+ IModAbs SourceAbs
+ | IModRes SourceRes
+ | IModCnc SourceCnc
+ | IModule SourceAbs -- ^ to be deprecated
+ | ICatAbs Ident Context [Ident]
+ | ICatCnc Ident Type [CFRule] Term
+ | IFunAbs Ident Type (Maybe Term)
+ | IFunCnc Ident Type [CFRule] Term
+ | IOper Ident Type Term
+ | IParam Ident [Param] [Term]
+ | IValue Ident Type
+
+type CatId = AbsGFC.CIdent
+type FunId = AbsGFC.CIdent
+
+prInformation :: Options -> Ident -> Information -> String
+prInformation opts c i = unlines $ prt c : case i of
+ IModule m -> [
+ "module of type" +++ show (mtype m),
+ "extends" +++ show (extends m),
+ "opens" +++ show (opens m),
+ "defines" +++ unwords (map prt (ownConstants (jments m)))
+ ]
+ ICatAbs m co _ -> [
+ "category in abstract module" +++ prt m,
+ if null co then "not a dependent type"
+ else "dependent type with context" +++ prContext co
+ ]
+ ICatCnc m ty cfs tr -> [
+ "category in concrete module" +++ prt m,
+ "linearization type" +++ prt ty
+ ]
+ IFunAbs m ty _ -> [
+ "function in abstract module" +++ prt m,
+ "type" +++ prt ty
+ ]
+ IFunCnc m ty cfs tr -> [
+ "function in concrete module" +++ prt m,
+ "linearization" +++ prt tr
+ --- "linearization type" +++ prt ty
+ ]
+ IOper m ty tr -> [
+ "operation in resource module" +++ prt m,
+ "type" +++ prt ty,
+ "definition" +++ prt tr
+ ]
+ IParam m ty ts -> [
+ "parameter type in resource module" +++ prt m,
+ "constructors" +++ unwords (map prParam ty),
+ "values" +++ unwords (map prt ts)
+ ]
+ IValue m ty -> [
+ "parameter constructor in resource module" +++ prt m,
+ "type" +++ show ty
+ ]
+
+-- | also finds out if an identifier is defined in many places
+getInformation :: Options -> ShellState -> Ident -> Err [(Information,FilePath)]
+getInformation opts st c = allChecks $ [
+ do
+ m <- lookupModule src c
+ case m of
+ ModMod mo -> returnm c $ IModule mo
+ _ -> prtBad "not a source module" c
+ ] ++ map lookInSrc ss ++ map lookInCan cs
+ where
+ lookInSrc (i,m) = do
+ j <- lookupInfo m c
+ case j of
+ AbsCat (Yes co) _ -> returnm i $ ICatAbs i co [] ---
+ AbsFun (Yes ty) _ -> returnm i $ IFunAbs i ty Nothing ---
+ CncCat (Yes ty) _ _ -> do
+ ---- let cat = ident2CFCat i c
+ ---- rs <- concat [rs | (c,rs) <- cf, ]
+ returnm i $ ICatCnc i ty [] ty ---
+ CncFun _ (Yes tr) _ -> do
+ rs <- return []
+ returnm i $ IFunCnc i tr rs tr ---
+ ResOper (Yes ty) (Yes tr) -> returnm i $ IOper i ty tr
+ ResParam (Yes (ps,_)) -> do
+ ts <- allParamValues src (QC i c)
+ returnm i $ IParam i ps ts
+ ResValue (Yes (ty,_)) -> returnm i $ IValue i ty ---
+
+ _ -> prtBad "nothing available for" i
+ lookInCan (i,m) = do
+ Bad "nothing available yet in canonical"
+
+ returnm m i = return (i, pathOfModule st m)
+
+ src = srcModules st
+ can = canModules st
+ ss = [(i,m) | (i,ModMod m) <- modules src]
+ cs = [(i,m) | (i,ModMod m) <- modules can]
+ cf = concatMap ruleGroupsOfCF $ map snd $ cfs st
+
+ownConstants :: BinTree Ident Info -> [Ident]
+ownConstants = map fst . filter isOwn . tree2list where
+ isOwn (c,i) = case i of
+ AnyInd _ _ -> False
+ _ -> True
+
+missingLinCanonGrammar :: GFC.CanonGrammar -> String
+missingLinCanonGrammar cgr =
+ unlines $ concat [prt_ c : missing js | (c,js) <- concretes] where
+ missing js = map ((" " ++) . prt_) $ filter (not . flip isInBinTree js) abstract
+ abstract = err (const []) (map fst . tree2list . jments) $ lookupModMod cgr absId
+ absId = maybe (zIdent "") id $ greatestAbstract cgr
+ concretes = [(cnc,jments mo) |
+ cnc <- allConcretes cgr absId, Ok mo <- [lookupModMod cgr cnc]]
diff --git a/src-2.9/GF/UseGrammar/Linear.hs b/src-2.9/GF/UseGrammar/Linear.hs
new file mode 100644
index 000000000..c9b94ccb0
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Linear.hs
@@ -0,0 +1,292 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Linear
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/14 16:03:41 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.19 $
+--
+-- Linearization for canonical GF. AR 7\/6\/2003
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Linear where
+
+import GF.Canon.GFC
+import GF.Canon.AbsGFC
+import qualified GF.Grammar.Abstract as A
+import GF.Canon.MkGFC (rtQIdent) ----
+import GF.Infra.Ident
+import GF.Grammar.PrGrammar
+import GF.Canon.CMacros
+import GF.Canon.Look
+import GF.Grammar.LookAbs
+import GF.Grammar.MMacros
+import GF.Grammar.TypeCheck (annotate) ----
+import GF.Data.Str
+import GF.Text.Text
+----import TypeCheck -- to annotate
+
+import GF.Data.Operations
+import GF.Data.Zipper
+import qualified GF.Infra.Modules as M
+
+import Control.Monad
+import Data.List (intersperse)
+
+-- Linearization for canonical GF. AR 7/6/2003
+
+-- | The worker function: linearize a Tree, return
+-- a record. Possibly mark subtrees.
+--
+-- NB. Constants in trees are annotated by the name of the abstract module.
+-- A concrete module name must be given to find (and choose) linearization rules.
+--
+-- - If no marking is wanted, 'noMark' :: 'Marker'.
+--
+-- - For xml marking, use 'markXML' :: 'Marker'
+linearizeToRecord :: CanonGrammar -> Marker -> Ident -> A.Tree -> Err Term
+linearizeToRecord gr mk m = lin [] where
+
+ lin ts t@(Tr (n,xs)) = errIn ("linearization of" +++ prt t) $ do
+
+ let binds = A.bindsNode n
+ at = A.atomNode n
+ fmk = markSubtree mk n ts (A.isFocusNode n)
+ c <- A.val2cat $ A.valNode n
+ xs' <- mapM (\ (i,x) -> lin (i:ts) x) $ zip [0..] xs
+
+ r <- case at of
+ A.AtC f -> lookf c t f >>= comp xs'
+ A.AtI i -> return $ recInt i
+ A.AtL s -> return $ recS $ tK $ prt at
+ A.AtF i -> return $ recS $ tK $ prt at
+ A.AtV x -> lookCat c >>= comp [tK (prt_ at)]
+ A.AtM m -> lookCat c >>= comp [tK (prt_ at)]
+
+ r' <- case r of -- to see stg in case the result is variants {}
+ FV [] -> lookCat c >>= comp [tK (prt_ t)]
+ _ -> return r
+
+ return $ fmk $ mkBinds binds r'
+
+ look = lookupLin gr . redirectIdent m . rtQIdent
+ comp = ccompute gr
+ mkBinds bs bdy = case bdy of
+ R fs -> R $ [Ass (LV i) (tK (prt t)) | (i,(t,_)) <- zip [0..] bs] ++ fs
+ FV rs -> FV $ map (mkBinds bs) rs
+
+ recS t = R [Ass (L (identC "s")) t] ----
+
+ recInt i = R [
+ Ass (L (identC "last")) (EInt (rem i 10)),
+ Ass (L (identC "s")) (tK $ show i),
+ Ass (L (identC "size")) (EInt (if i > 9 then 1 else 0))
+ ]
+
+ lookCat = return . errVal defLindef . look
+ ---- should always be given in the module
+
+ -- to show missing linearization as term
+ lookf c t f = case look f of
+ Ok h -> return h
+ _ -> lookCat c >>= comp [tK (prt_ t)]
+
+
+-- | thus the special case:
+linearizeNoMark :: CanonGrammar -> Ident -> A.Tree -> Err Term
+linearizeNoMark gr = linearizeToRecord gr noMark
+
+-- | expand tables in linearized term to full, normal-order tables
+--
+-- NB expand from inside-out so that values are not looked up in copies of branches
+
+expandLinTables :: CanonGrammar -> Term -> Err Term
+expandLinTables gr t = case t of
+ R rs -> liftM (R . map (uncurry Ass)) $ mapPairsM exp [(l,r) | Ass l r <- rs]
+ T ty rs -> do
+ rs' <- mapPairsM exp [(l,r) | Cas l r <- rs] -- expand from inside-out
+ let t' = T ty $ map (uncurry Cas) rs'
+ vs <- alls ty
+ ps <- mapM term2patt vs
+ ts' <- mapM (comp . S t') $ vs
+ return $ T ty [Cas [p] t | (p,t) <- zip ps ts']
+ V ty ts0 -> do
+ ts <- mapM exp ts0 -- expand from inside-out
+ vs <- alls ty
+ ps <- mapM term2patt vs
+ return $ T ty [Cas [p] t | (p,t) <- zip ps ts]
+ FV ts -> liftM FV $ mapM exp ts
+ _ -> composOp exp t
+ where
+ alls = allParamValues gr
+ exp = expandLinTables gr
+ comp = ccompute gr []
+
+-- Do this for an entire grammar:
+
+unoptimizeCanon :: CanonGrammar -> CanonGrammar
+unoptimizeCanon g@(M.MGrammar ms) = M.MGrammar $ map (unoptimizeCanonMod g) ms
+
+unoptimizeCanonMod :: CanonGrammar -> CanonModule -> CanonModule
+unoptimizeCanonMod g = convMod where
+ convMod (m, M.ModMod (M.Module (M.MTConcrete a) x flags me os defs)) =
+ (m, M.ModMod (M.Module (M.MTConcrete a) x flags me os (mapTree convDef defs)))
+ convMod mm = mm
+ convDef (c,CncCat ty df pr) = (c,CncCat ty (convT df) (convT pr))
+ convDef (f,CncFun c xs li pr) = (f,CncFun c xs (convT li) (convT pr))
+ convDef cd = cd
+ convT = err error id . exp
+ -- a version of expandLinTables that does not destroy share optimization
+ exp t = case t of
+ R rs -> liftM (R . map (uncurry Ass)) $ mapPairsM exp [(l,r) | Ass l r <- rs]
+ T ty rs@[Cas [_] _] -> do
+ rs' <- mapPairsM exp [(l,r) | Cas l r <- rs] -- expand from inside-out
+ let t' = T ty $ map (uncurry Cas) rs'
+ vs <- alls ty
+ ps <- mapM term2patt vs
+ ts' <- mapM (comp . S t') $ vs
+ return $ T ty [Cas [p] t | (p,t) <- zip ps ts']
+ V ty ts0 -> do
+ ts <- mapM exp ts0 -- expand from inside-out
+ vs <- alls ty
+ ps <- mapM term2patt vs
+ return $ T ty [Cas [p] t | (p,t) <- zip ps ts]
+ FV ts -> liftM FV $ mapM exp ts
+ I _ -> comp t
+ _ -> composOp exp t
+ where
+ alls = allParamValues g
+ comp = ccompute g []
+
+
+-- | from records, one can get to records of tables of strings
+rec2strTables :: Term -> Err [[(Label,[([Patt],[Str])])]]
+rec2strTables r = do
+ vs <- allLinValues r
+ mapM (mapPairsM (mapPairsM strsFromTerm)) vs
+
+-- | from these tables, one may want to extract the ones for the "s" label
+strTables2sTables :: [[(Label,[([Patt],[Str])])]] -> [[([Patt],[Str])]]
+strTables2sTables ts = [t | r <- ts, (l,t) <- r, l == linLab0]
+
+linLab0 :: Label
+linLab0 = L (identC "s")
+
+-- | to get lists of token lists is easy
+sTables2strs :: [[([Patt],[Str])]] -> [[Str]]
+sTables2strs = map snd . concat
+
+-- | from this, to get a list of strings
+strs2strings :: [[Str]] -> [String]
+strs2strings = map unlex
+
+-- | this is just unwords; use an unlexer from Text to postprocess
+unlex :: [Str] -> String
+unlex = concat . map sstr . take 1 ----
+
+-- | finally, a top-level function to get a string from an expression
+linTree2string :: Marker -> CanonGrammar -> Ident -> A.Tree -> String
+linTree2string mk gr m e = head $ linTree2strings mk gr m e -- never empty
+
+-- | you can also get many strings
+linTree2strings :: Marker -> CanonGrammar -> Ident -> A.Tree -> [String]
+linTree2strings mk gr m e = err return id $ do
+ t <- linearizeToRecord gr mk m e
+ r <- expandLinTables gr t
+ ts <- rec2strTables r
+ let ss = strs2strings $ sTables2strs $ strTables2sTables ts
+ ifNull (prtBad "empty linearization of" e) return ss -- thus never empty
+
+-- | argument is a Tree, value is a list of strs; needed in Parsing
+allLinsOfTree :: CanonGrammar -> Ident -> A.Tree -> [Str]
+allLinsOfTree gr a e = err (singleton . str) id $ do
+ e' <- return e ---- annotateExp gr e
+ r <- linearizeNoMark gr a e'
+ r' <- expandLinTables gr r
+ ts <- rec2strTables r'
+ return $ concat $ sTables2strs $ strTables2sTables ts
+
+-- | the value is a list of structures arranged as records of tables of terms
+allLinsAsRec :: CanonGrammar -> Ident -> A.Tree -> Err [[(Label,[([Patt],Term)])]]
+allLinsAsRec gr c t = linearizeNoMark gr c t >>= expandLinTables gr >>= allLinValues
+
+-- | the value is a list of structures arranged as records of tables of strings
+-- only taking into account string fields
+-- True: sep. by /, False: sep by \n
+allLinTables ::
+ Bool -> CanonGrammar ->Ident ->A.Tree ->Err [[(Label,[([Patt],[String])])]]
+allLinTables slash gr c t = do
+ r' <- allLinsAsRec gr c t
+ mapM (mapM getS) r'
+ where
+ getS (lab,pss) = liftM (curry id lab) $ mapM gets pss
+ gets (ps,t) = liftM (curry id ps . cc . map str2strings) $ strsFromTerm t
+ cc = concat . intersperse [if slash then "/" else "\n"]
+
+-- | the value is a list of strings gathered from all fields
+
+allLinBranchFields :: CanonGrammar -> Ident -> A.Tree -> Err [String]
+allLinBranchFields gr c trm = do
+ r <- linearizeNoMark gr c trm >>= expandLinTables gr
+ return [s | (_,t) <- allLinBranches r, s <- gets t]
+ where
+ gets t = concat [cc (map str2strings s) | Ok s <- [strsFromTerm t]]
+ cc = concat . intersperse ["/"]
+
+prLinTable :: Bool -> [[(Label,[([Patt],[String])])]] -> [String]
+prLinTable pars = concatMap prOne . concat where
+ prOne (lab,pss) = (if pars then ((prt lab) :) else id) (map pr pss) ----
+ pr (ps,ss) = (if pars then ((unwords (map prt_ ps) +++ ":") +++)
+ else id) (unwords ss)
+
+{-
+-- the value is a list of strs
+allLinStrings :: CanonGrammar -> Tree -> [Str]
+allLinStrings gr ft = case allLinsAsStrs gr ft of
+ Ok ts -> map snd $ concat $ map snd $ concat ts
+ Bad s -> [str s]
+
+-- the value is a list of strs, not forgetting their arguments
+allLinsAsStrs :: CanonGrammar -> Tree -> Err [[(Label,[([Patt],Str)])]]
+allLinsAsStrs gr ft = do
+ lpts <- allLinearizations gr ft
+ return $ concat $ mapM (mapPairsM (mapPairsM strsFromTerm)) lpts
+
+
+-- to a list of strings
+linearizeToStrings :: CanonGrammar -> ([Int] ->Term -> Term) -> Tree -> Err [String]
+linearizeToStrings gr mk = liftM (map unlex) . linearizeToStrss gr mk
+
+-- to a list of token lists
+linearizeToStrss :: CanonGrammar -> ([Int] -> Term -> Term) -> Tree -> Err [[Str]]
+linearizeToStrss gr mk e = do
+ R rs <- linearizeToRecord gr mk e ----
+ t <- lookupErr linLab0 [(r,s) | Ass r s <- rs]
+ return $ map strsFromTerm $ allInTable t
+-}
+
+-- | the value is a list of strings, not forgetting their arguments
+allLinsOfFun :: CanonGrammar -> CIdent -> Err [[(Label,[([Patt],Term)])]]
+allLinsOfFun gr f = do
+ t <- lookupLin gr f
+ allAllLinValues t --- all fields, not only s. 11/12/2005
+
+
+-- | returns printname if one exists; otherwise linearizes with metas
+printOrLinearize :: CanonGrammar -> Ident -> A.Fun -> String
+printOrLinearize gr c f@(m, d) = errVal (prt fq) $
+ case lookupPrintname gr (CIQ c d) of
+ Ok t -> do
+ ss <- strsFromTerm t
+ let s = strs2strings [ss]
+ return $ ifNull (prt fq) head s
+ _ -> do
+ ty <- lookupFunType gr m d
+ f' <- ref2exp [] ty (A.QC m d)
+ tr <- annotate gr f'
+ return $ linTree2string noMark gr c tr
+ where
+ fq = CIQ m d
diff --git a/src-2.9/GF/UseGrammar/MatchTerm.hs b/src-2.9/GF/UseGrammar/MatchTerm.hs
new file mode 100644
index 000000000..9acffd44c
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/MatchTerm.hs
@@ -0,0 +1,50 @@
+----------------------------------------------------------------------
+-- |
+-- Module : MatchTerm
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+--
+-- functions for matching with terms. AR 16/3/2006
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.MatchTerm where
+
+import GF.Data.Operations
+import GF.Data.Zipper
+
+import GF.Grammar.Grammar
+import GF.Grammar.PrGrammar
+import GF.Infra.Ident
+import GF.Grammar.Values
+import GF.Grammar.Macros
+import GF.Grammar.MMacros
+
+import Control.Monad
+import Data.List
+
+-- test if a term has duplicated idents, either any or just atoms
+
+hasDupIdent, hasDupAtom :: Exp -> Bool
+hasDupIdent = (>1) . maximum . map length . group . sort . allConstants True
+hasDupAtom = (>1) . maximum . map length . group . sort . allConstants False
+
+-- test if a certain ident occurs in term
+
+grepIdent :: Ident -> Exp -> Bool
+grepIdent c = elem c . allConstants True
+
+-- form the list of all constants, optionally ignoring all but atoms
+
+allConstants :: Bool -> Exp -> [Ident]
+allConstants alsoApp = err (const []) snd . flip appSTM [] . collect where
+ collect e = case e of
+ Q _ c -> add c e
+ QC _ c -> add c e
+ Cn c -> add c e
+ App f a | not alsoApp -> case f of
+ App g b -> collect b >> collect a
+ _ -> collect a
+ _ -> composOp collect e
+ add c e = updateSTM (c:) >> return e
diff --git a/src-2.9/GF/UseGrammar/Morphology.hs b/src-2.9/GF/UseGrammar/Morphology.hs
new file mode 100644
index 000000000..3aeb08dc7
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Morphology.hs
@@ -0,0 +1,140 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Morphology
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:49 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.8 $
+--
+-- Morphological analyser constructed from a GF grammar.
+--
+-- we first found the binary search tree sorted by word forms more efficient
+-- than a trie, at least for grammars with 7000 word forms
+-- (18\/11\/2003) but this may change since we have to use a trie
+-- for decompositions and also want to use it in the parser
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Morphology where
+
+import GF.Canon.AbsGFC
+import GF.Canon.GFC
+import GF.Grammar.PrGrammar
+import GF.Canon.CMacros
+import GF.Canon.Look
+import GF.Grammar.LookAbs
+import GF.Infra.Ident
+import qualified GF.Grammar.Macros as M
+import GF.UseGrammar.Linear
+
+import GF.Data.Operations
+import GF.Data.Glue
+
+import Data.Char
+import Data.List (sortBy, intersperse)
+import Control.Monad (liftM)
+import GF.Data.Trie2
+
+-- construct a morphological analyser from a GF grammar. AR 11/4/2001
+
+-- we first found the binary search tree sorted by word forms more efficient
+-- than a trie, at least for grammars with 7000 word forms
+-- (18\/11\/2003) but this may change since we have to use a trie
+-- for decompositions and also want to use it in the parser
+
+type Morpho = Trie Char String
+
+emptyMorpho :: Morpho
+emptyMorpho = emptyTrie
+
+appMorpho :: Morpho -> String -> (String,[String])
+appMorpho = appMorphoOnly
+---- add lookup for literals
+
+-- without literals
+appMorphoOnly :: Morpho -> String -> (String,[String])
+appMorphoOnly m s = trieLookup m s
+
+-- recognize word, exluding literals
+isKnownWord :: Morpho -> String -> Bool
+isKnownWord mo = not . null . snd . appMorphoOnly mo
+
+mkMorpho :: CanonGrammar -> Ident -> Morpho
+mkMorpho gr a = tcompile $ concatMap mkOne $ allItems where
+
+ comp = ccompute gr [] -- to undo 'values' optimization
+
+ mkOne (Left (fun,c)) = map (prOne fun c) $ allLins fun
+ mkOne (Right (fun,_)) = map (prSyn fun) $ allSyns fun
+
+ -- gather forms of lexical items
+ allLins fun@(m,f) = errVal [] $ do
+ ts <- lookupLin gr (CIQ a f) >>= comp >>= allAllLinValues
+ ss <- mapM (mapPairsM (mapPairsM (liftM wordsInTerm . comp))) ts
+ return [(p,s) | (p,fs) <- concat $ map snd $ concat ss, s <- fs]
+ prOne (_,f) c (ps,s) = (s, [prt f +++ tagPrt c +++ unwords (map prt_ ps)])
+
+ -- gather syncategorematic words
+ allSyns fun@(m,f) = errVal [] $ do
+ tss <- allLinsOfFun gr (CIQ a f)
+ let ss = [s | ts <- tss, (_,fs) <- ts, (_,s) <- fs]
+ return $ concat $ map wordsInTerm ss
+ prSyn f s = (s, ["+" ++ tagPrt f])
+
+ -- all words, Left from lexical rules and Right syncategorematic
+ allItems = [lexRole t (f,c) | (f,c,t) <- allFuns] where
+ allFuns = [(f,c,t) | (f,t) <- funRulesOf gr, Ok c <- [M.valCat t]]
+ lexRole t = case M.typeForm t of
+ Ok ([],_,_) -> Left
+ _ -> Right
+
+-- printing full-form lexicon and results
+
+prMorpho :: Morpho -> String
+prMorpho = unlines . map prMorphoAnalysis . collapse
+
+prMorphoAnalysis :: (String,[String]) -> String
+prMorphoAnalysis (w,fs0) =
+ let fs = filter (not . null) fs0 in
+ if null fs then w ++++ "*" else unlines (w:fs)
+
+prMorphoAnalysisShort :: (String,[String]) -> String
+prMorphoAnalysisShort (w,fs) = prBracket (w' ++ prTList "/" fs) where
+ w' = if null fs then w +++ "*" else ""
+
+tagPrt :: Print a => (a,a) -> String
+tagPrt (m,c) = "+" ++ prt c --- module name
+
+-- | print all words recognized
+allMorphoWords :: Morpho -> [String]
+allMorphoWords = map fst . collapse
+
+-- analyse running text and show results either in short form or on separate lines
+
+-- | analyse running text and show just the word, with "*" if not found
+morphoTextStatus :: Morpho -> String -> String
+morphoTextStatus mo = unlines . map (prMark . appMorpho mo) . words where
+ prMark (w,fs) = if null fs then "*" +++ w else w
+
+-- | analyse running text and show results in short form, one word per line
+morphoTextShort :: Morpho -> String -> String
+morphoTextShort mo = unlines . map (prMorphoAnalysisShort . appMorpho mo) . words
+
+-- | analyse running text and show results on separate lines
+morphoText :: Morpho -> String -> String
+morphoText mo = unlines . map (('\n':) . prMorphoAnalysis . appMorpho mo) . words
+
+-- format used in the Italian Verb Engine
+prFullForm :: Morpho -> String
+prFullForm = unlines . map prOne . collapse where
+ prOne (s,ps) = s ++ " : " ++ unwords (intersperse "/" ps)
+
+-- using Huet's unglueing method to find word boundaries
+---- it would be much better to use a trie also for morphological analysis,
+---- so this is for the sake of experiment
+---- Moreover, we should specify the cases in which this happens - not all words
+
+decomposeWords :: Morpho -> String -> [String]
+decomposeWords mo s = errVal (words s) $ decomposeSimple mo s
diff --git a/src-2.9/GF/UseGrammar/Paraphrases.hs b/src-2.9/GF/UseGrammar/Paraphrases.hs
new file mode 100644
index 000000000..d04f22aa6
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Paraphrases.hs
@@ -0,0 +1,70 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Paraphrases
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:49 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.6 $
+--
+-- paraphrases of GF terms. AR 6\/10\/1998 -- 24\/9\/1999 -- 5\/7\/2000 -- 5\/6\/2002
+--
+-- Copyright (c) Aarne Ranta 1998--99, under GNU General Public License (see GPL)
+--
+-- thus inherited from the old GF. Incomplete and inefficient...
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Paraphrases (mkParaphrases) where
+
+import GF.Grammar.Abstract
+import GF.Grammar.PrGrammar
+import GF.Grammar.LookAbs
+import GF.Grammar.AbsCompute
+
+import GF.Data.Operations
+
+import Data.List (nub)
+
+-- paraphrases of GF terms. AR 6/10/1998 -- 24/9/1999 -- 5/7/2000 -- 5/6/2002
+-- Copyright (c) Aarne Ranta 1998--99, under GNU General Public License (see GPL)
+-- thus inherited from the old GF. Incomplete and inefficient...
+
+mkParaphrases :: GFCGrammar -> Term -> [Term]
+mkParaphrases st = nub . map (beta []) . paraphrases (allDefs st)
+
+type Definition = (Fun,Term)
+
+paraphrases :: [Definition] -> Term -> [Term]
+paraphrases th t =
+ paraImmed th t ++
+--- paraMatch th t ++
+ case t of
+ App c a -> [App d b | d <- paraphrases th c, b <- paraphrases th a]
+ Abs x b -> [Abs x d | d <- paraphrases th b]
+ c -> []
+ ++ [t]
+
+paraImmed :: [Definition] -> Term -> [Term]
+paraImmed defs t =
+ [Q m f | ((m,f), u) <- defs, t == u] ++ --- eqTerm
+ case t of
+ ---- Cn c -> [u | (f, u) <- defs, eqStrIdent f c]
+ _ -> []
+
+{- ---
+paraMatch :: [Definition] -> Trm -> [Trm]
+paraMatch th@defs t =
+ [mkApp (Cn f) xx | (PC f zz, u) <- defs,
+ let (fs,sn) = fullApp u, fs == h, length sn == length zz] ++
+ case findAMatch defs t of
+ Ok (g,b) -> [substTerm [] g b]
+ _ -> []
+ where
+ (h,xx) = fullApp t
+ fullApp c = case c of
+ App f a -> (f', a' ++ [a]) where (f',a') = fullApp f
+ c -> (c,[])
+
+-}
diff --git a/src-2.9/GF/UseGrammar/Parsing.hs b/src-2.9/GF/UseGrammar/Parsing.hs
new file mode 100644
index 000000000..2ca057410
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Parsing.hs
@@ -0,0 +1,177 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Parsing
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/06/02 10:23:52 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.25 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Parsing where
+
+import GF.Infra.CheckM
+import qualified GF.Canon.AbsGFC as C
+import GF.Canon.GFC
+import GF.Canon.MkGFC (trExp) ----
+import GF.Canon.CMacros
+import GF.Grammar.MMacros (refreshMetas)
+import GF.UseGrammar.Linear
+import GF.Data.Str
+import GF.CF.CF
+import GF.CF.CFIdent
+import GF.Infra.Ident
+import GF.Grammar.TypeCheck
+import GF.Grammar.Values
+--import CFMethod
+import GF.UseGrammar.Tokenize
+import GF.UseGrammar.Morphology (isKnownWord)
+import GF.CF.Profile
+import GF.Infra.Option
+import GF.UseGrammar.Custom
+import GF.Compile.ShellState
+
+import GF.CF.PPrCF (prCFTree)
+-- import qualified GF.OldParsing.ParseGFC as NewOld -- OBSOLETE
+import qualified GF.Parsing.GFC as New
+
+import GF.Data.Operations
+
+import Data.List (nub,sortBy)
+import Data.Char (toLower)
+import Control.Monad (liftM)
+
+-- AR 26/1/2000 -- 8/4 -- 28/1/2001 -- 9/12/2002
+
+parseString :: Options -> StateGrammar -> CFCat -> String -> Err [Tree]
+parseString os sg cat = liftM fst . parseStringMsg os sg cat
+
+parseStringMsg :: Options -> StateGrammar -> CFCat -> String -> Err ([Tree],String)
+parseStringMsg os sg cat s = do
+ case checkStart $ parseStringC os sg cat s of
+ Ok (ts,(_,ss)) -> return (ts, unlines $ reverse ss)
+ Bad s -> return ([],s)
+
+parseStringC :: Options -> StateGrammar -> CFCat -> String -> Check [Tree]
+parseStringC opts0 sg cat s
+ | oElem (iOpt "old") opts0 ||
+ (not (oElem (iOpt "fcfg") opts0) && stateHasHOAS sg) = do
+ let opts = unionOptions opts0 $ stateOptions sg
+ cf = stateCF sg
+ gr = stateGrammarST sg
+ cn = cncId sg
+ toks = customOrDefault opts useTokenizer customTokenizer sg s
+ parser = customOrDefault opts useParser customParser sg cat
+ if oElem (iOpt "cut") opts
+ then doUntil (not . null) $ map (tokens2trms opts sg cn parser) toks
+ else mapM (tokens2trms opts sg cn parser) toks >>= return . concat
+
+---- | or [oElem p opts0 |
+---- p <- [newCParser,newMParser,newFParser,newParser,newerParser] = do
+
+ | otherwise = do
+ let opts = unionOptions opts0 $ stateOptions sg
+ algorithm | oElem newCParser opts0 = "c"
+ | oElem newMParser opts0 = "m"
+ | oElem newFParser opts0 = "f"
+ | otherwise = "f" -- default algorithm: FCFG
+ strategy = maybe "bottomup" id $ getOptVal opts useParser
+ -- -parser=bottomup/topdown
+ tokenizer = customOrDefault opts useTokenizer customTokenizer sg
+ toks = case tokenizer s of
+ t:_ -> t
+ _ -> [] ---- no support for undet. tok.
+ unknowns =
+ [w | TC w <- toks, unk w && unk (uncap w)] ++ [w | TS w <- toks, unk w]
+ where
+ unk w = not $ isKnownWord (morpho sg) w
+ uncap (c:cs) = toLower c : cs
+ uncap s = s
+
+ case unknowns of
+ _:_ | oElem (iOpt "trynextlang") opts -> return []
+ _:_ -> fail $ "Unknown words:" +++ unwords unknowns
+ _ -> do
+
+ ts <- checkErr $ New.parse algorithm strategy (pInfo sg) (absId sg) cat toks
+ ts' <- checkErr $
+ allChecks $ map (annotate (stateGrammarST sg) . refreshMetas []) ts
+ return $ optIntOrAll opts flagNumber ts'
+
+
+tokens2trms :: Options ->StateGrammar ->Ident -> CFParser -> [CFTok] -> Check [Tree]
+tokens2trms opts sg cn parser toks = trees2trms opts sg cn toks trees info
+ where result = parser toks
+ info = snd result
+ trees = {- nub $ -} cfParseResults result -- peb 25/5-04: removed nub (O(n^2))
+
+trees2trms ::
+ Options -> StateGrammar -> Ident -> [CFTok] -> [CFTree] -> String -> Check [Tree]
+trees2trms opts sg cn as ts0 info = do
+ let s = unwords $ map prCFTok as
+ ts <- case () of
+ _ | null ts0 -> checkWarn ("No success in cf parsing" +++ s) >> return []
+ _ | raw -> do
+ ts1 <- return (map cf2trm0 ts0) ----- should not need annot
+ checks [
+ mapM (checkErr . (annotate gr) . trExp) ts1 ---- complicated, often fails
+ ,checkWarn (unlines ("Raw CF trees:":(map prCFTree ts0))) >> return []
+ ]
+ _ -> do
+ let num = optIntOrN opts flagRawtrees 999999
+ let (ts01,rest) = splitAt num ts0
+ if null rest then return ()
+ else raise ("Warning: only" +++ show num +++ "raw parses out of" +++
+ show (length ts0) +++
+ "considered; use -rawtrees= to see more"
+ )
+ (ts1,ss) <- checkErr $ mapErrN 1 postParse ts01
+ if null ts1 then raise ss else return ()
+ ts2 <- checkErr $
+ allChecks $ map (annotate gr . refreshMetas [] . trExp) ts1 ----
+ if forgive then return ts2 else do
+ let tsss = [(t, allLinsOfTree gr cn t) | t <- ts2]
+ ps = [t | (t,ss) <- tsss,
+ any (compatToks as) (map str2cftoks ss)]
+ if null ps
+ then raise $ "Failure in morphology." ++
+ if verb
+ then "\nPossible corrections: " +++++
+ unlines (nub (map sstr (concatMap snd tsss)))
+ else ""
+ else return ps
+ if verb
+ then checkWarn $ " the token list" +++ show as ++++ unknownWords sg as +++++ info
+ else return ()
+
+ return $ optIntOrAll opts flagNumber $ nub ts
+ where
+ gr = stateGrammarST sg
+
+ raw = oElem rawParse opts
+ verb = oElem beVerbose opts
+ forgive = oElem forgiveParse opts
+
+---- Operatins.allChecks :: ErrorMonad m => [m a] -> m [a]
+
+unknownWords sg ts = case filter noMatch [t | t@(TS _) <- ts] of
+ [] -> "where all words are known"
+ us -> "with the unknown tokens" +++ show us --- needs to be fixed for literals
+ where
+ terminals = map TS $ stateGrammarWords sg
+ noMatch t = all (not . compatTok t) terminals
+
+
+--- too much type checking in building term info? return FullTerm to save work?
+
+-- | raw parsing: so simple it is for a context-free CF grammar
+cf2trm0 :: CFTree -> C.Exp
+cf2trm0 (CFTree (fun, (_, trees))) = mkAppAtom (cffun2trm fun) (map cf2trm0 trees)
+ where
+ cffun2trm (CFFun (fun,_)) = fun
+ mkApp = foldl C.EApp
+ mkAppAtom a = mkApp (C.EAtom a)
diff --git a/src-2.9/GF/UseGrammar/Randomized.hs b/src-2.9/GF/UseGrammar/Randomized.hs
new file mode 100644
index 000000000..c1c77edb2
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Randomized.hs
@@ -0,0 +1,66 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Randomized
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:51 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.8 $
+--
+-- random generation and refinement. AR 22\/8\/2001.
+-- implemented as sequence of refinement menu selecsions, encoded as integers
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Randomized where
+
+import GF.Grammar.Abstract
+import GF.UseGrammar.Editing
+
+import GF.Data.Operations
+import GF.Data.Zipper
+
+--- import Arch (myStdGen) --- circular for hbc
+import System.Random --- (mkStdGen, StdGen, randoms) --- bad import for hbc
+
+-- random generation and refinement. AR 22/8/2001
+-- implemented as sequence of refinement menu selecsions, encoded as integers
+
+myStdGen :: Int -> StdGen
+myStdGen = mkStdGen ---
+
+-- | build one random tree; use mx to prevent infinite search
+mkRandomTree :: StdGen -> Int -> CGrammar -> Either Cat Fun -> Err Tree
+mkRandomTree gen mx gr cat = mkTreeFromInts (take mx (randoms gen)) gr cat
+
+refineRandom :: StdGen -> Int -> CGrammar -> Action
+refineRandom gen mx = mkStateFromInts $ take mx $ map abs (randoms gen)
+
+-- | build a tree from a list of integers
+mkTreeFromInts :: [Int] -> CGrammar -> Either Cat Fun -> Err Tree
+mkTreeFromInts ints gr catfun = do
+ st0 <- either (\cat -> newCat gr cat initState)
+ (\fun -> newFun gr fun initState)
+ catfun
+ state <- mkStateFromInts ints gr st0
+ return $ loc2tree state
+
+mkStateFromInts :: [Int] -> CGrammar -> Action
+mkStateFromInts ints gr z = mkRandomState ints z >>= reCheckState gr where
+ mkRandomState [] state = do
+ testErr (isCompleteState state) "not completed"
+ return state
+ mkRandomState (n:ns) state = do
+ let refs = refinementsState gr state
+ refs0 = map (not . snd . snd) refs
+ testErr (not (null refs0)) $ "no nonrecursive refinements available for" +++
+ prt (actVal state)
+ (ref,_) <- (refs !? (n `mod` (length refs)))
+ state1 <- refineWithAtom False gr ref state
+ if isCompleteState state1
+ then return state1
+ else do
+ state2 <- goNextMeta state1
+ mkRandomState ns state2
+
diff --git a/src-2.9/GF/UseGrammar/Session.hs b/src-2.9/GF/UseGrammar/Session.hs
new file mode 100644
index 000000000..e54d0e3fb
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Session.hs
@@ -0,0 +1,181 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Session
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/08/17 15:13:55 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.12 $
+--
+-- (Description of the module)
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Session where
+
+import GF.Grammar.Abstract
+import GF.Infra.Option
+import GF.UseGrammar.Custom
+import GF.UseGrammar.Editing
+import GF.Compile.ShellState ---- grammar
+
+import GF.Data.Operations
+import GF.Data.Zipper (keepPosition) ---
+
+-- First version 8/2001. Adapted to GFC with modules 19/6/2003.
+-- Nothing had to be changed, which is a sign of good modularity.
+
+-- keep these abstract
+
+-- | 'Exp'-list: candidate refinements,clipboard
+type SState = [(State,([Exp],[Clip]),SInfo)]
+
+-- | 'String' is message, 'Int' is the view
+type SInfo = ([String],(Int,Options))
+
+initSState :: SState
+initSState = [(initState, ([],[]), (["Select 'New' category to start"],(0,noOptions)))]
+ -- instead of empty
+
+type Clip = Tree ---- (Exp,Type)
+
+-- | (peb): Something wrong with this definition??
+-- Shouldn't the result type be 'SInfo'?
+--
+-- > okInfo :: Int -> SInfo == ([String], (Int, Options))
+okInfo :: n -> ([s], (n, Bool))
+okInfo n = ([],(n,True))
+
+stateSState :: SState -> State
+candsSState :: SState -> [Exp]
+clipSState :: SState -> [Clip]
+infoSState :: SState -> SInfo
+msgSState :: SState -> [String]
+viewSState :: SState -> Int
+optsSState :: SState -> Options
+
+stateSState ((s,_,_):_) = s
+candsSState ((_,(ts,_),_):_)= ts
+clipSState ((_,(_,ts),_):_)= ts
+infoSState ((_,_,i):_) = i
+msgSState ((_,_,(m,_)):_) = m
+viewSState ((_,_,(_,(v,_))):_) = v
+optsSState ((_,_,(_,(_,o))):_) = o
+
+treeSState :: SState -> Tree
+treeSState = actTree . stateSState
+
+
+-- | from state to state
+type ECommand = SState -> SState
+
+-- * elementary commands
+
+-- ** change state, drop cands, drop message, preserve options
+
+changeState :: State -> ECommand
+changeState s ss = changeMsg [] $ (s,([],clipSState ss),infoSState ss) : ss
+
+changeCands :: [Exp] -> ECommand
+changeCands ts ss@((s,(_,cb),(_,b)):_) = (s,(ts,cb),(candInfo ts,b)) : ss
+
+addtoClip :: Clip -> ECommand
+addtoClip t ss@((s,(ts,cb),(i,b)):_) = (s,(ts,t:cb),(i,b)) : ss
+
+removeClip :: Int -> ECommand
+removeClip n ss@((s,(ts,cb),(i,b)):_) = (s,(ts, drop n cb),(i,b)) : ss
+
+changeMsg :: [String] -> ECommand
+changeMsg m ((s,ts,(_,b)):ss) = (s,ts,(m,b)) : ss -- just change message
+changeMsg m _ = (s,ts,(m,b)) : [] where [(s,ts,(_,b))] = initSState
+
+changeView :: ECommand
+changeView ((s,ts,(m,(v,b))):ss) = (s,ts,(m,(v+1,b))) : ss -- toggle view
+
+withMsg :: [String] -> ECommand -> ECommand
+withMsg m c = changeMsg m . c
+
+changeStOptions :: (Options -> Options) -> ECommand
+changeStOptions f ((s,ts,(m,(v,o))):ss) = (s,ts,(m,(v, f o))) : ss
+
+noNeedForMsg :: ECommand
+noNeedForMsg = changeMsg [] -- everything's all right: no message
+
+candInfo :: [Exp] -> [String]
+candInfo ts = case length ts of
+ 0 -> ["no acceptable alternative"]
+ 1 -> ["just one acceptable alternative"]
+ n -> [show n +++ "alternatives to select"]
+
+-- * keep SState abstract from this on
+
+-- ** editing commands
+
+action2command :: Action -> ECommand
+action2command act state = case act (stateSState state) of
+ Ok s -> changeState s state
+ Bad m -> changeMsg [m] state
+
+action2commandNext :: Action -> ECommand -- move to next meta after execution
+action2commandNext act = action2command (\s -> act s >>= goNextMetaIfCan)
+
+action2commandKeep :: Action -> ECommand -- keep old position after execution
+action2commandKeep act = action2command (\s -> keepPosition act s)
+
+undoCommand :: Int -> ECommand
+undoCommand n ss =
+ let k = length ss in
+ if k < n
+ then changeMsg ["cannot go all the way back"] [last ss]
+ else changeMsg ["successful undo"] (drop n ss)
+
+selectCand :: CGrammar -> Int -> ECommand
+selectCand gr i state = err (\m -> changeMsg [m] state) id $ do
+ exp <- candsSState state !? i
+ let s = stateSState state
+ tree <- annotateInState gr exp s
+ return $ case replaceSubTree tree s of
+ Ok st' -> changeState st' state
+ Bad s -> changeMsg [s] state
+
+refineByExps :: Bool -> CGrammar -> [Exp] -> ECommand
+refineByExps der gr trees = case trees of
+ [t] -> action2commandNext (refineWithExpTC der gr t)
+ _ -> changeCands trees
+
+refineByTrees :: Bool -> CGrammar -> [Tree] -> ECommand
+refineByTrees der gr trees = case trees of
+ [t] -> action2commandNext (refineOrReplaceWithTree der gr t)
+ _ -> changeCands $ map tree2exp trees
+
+replaceByTrees :: CGrammar -> [Exp] -> ECommand
+replaceByTrees gr trees = case trees of
+ [t] -> action2commandNext (\s ->
+ annotateExpInState gr t s >>= flip replaceSubTree s)
+ _ -> changeCands trees
+
+replaceByEditCommand :: StateGrammar -> String -> ECommand
+replaceByEditCommand gr co =
+ action2commandKeep $
+ maybe return ($ gr) $
+ lookupCustom customEditCommand (strCI co)
+
+replaceByTermCommand :: Bool -> StateGrammar -> String -> Tree -> ECommand ----
+replaceByTermCommand der gr co exp =
+ let g = grammar gr in
+ refineByTrees der g $ maybe [exp] (\f -> f gr exp) $
+ lookupCustom customTermCommand (strCI co)
+
+possClipsSState :: StateGrammar -> SState -> [(Int,Clip)]
+possClipsSState gr s = filter poss $ zip [0..] (clipSState s)
+ where
+ poss = possibleTreeVal cgr st . snd
+ st = stateSState s
+ cgr = grammar gr
+
+getNumberedClip :: Int -> SState -> Err Clip
+getNumberedClip i s = if length cs > i then return (cs !! i)
+ else Bad "not enough clips"
+ where
+ cs = clipSState s
diff --git a/src-2.9/GF/UseGrammar/Statistics.hs b/src-2.9/GF/UseGrammar/Statistics.hs
new file mode 100644
index 000000000..46e4fcc3b
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Statistics.hs
@@ -0,0 +1,44 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Statistics
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/09/04 11:45:38 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.1 $
+--
+-- statistics on canonical grammar: amounts of generated code
+-- AR 4\/9\/2005.
+-- uses canonical grammar
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Statistics (prStatistics) where
+
+import GF.Infra.Modules
+import GF.Infra.Option
+import GF.Grammar.PrGrammar
+import GF.Canon.GFC
+import GF.Canon.MkGFC
+
+import GF.Data.Operations
+
+import Data.List (sortBy)
+
+-- | the top level function
+prStatistics :: CanonGrammar -> String
+prStatistics can = unlines $ [
+ show (length mods) ++ "\t\t modules",
+ show chars ++ "\t\t gfc size",
+ "",
+ "Top 40 definitions"
+ ] ++
+ [show d ++ "\t\t " ++ f | (d,f) <- tops]
+ where
+ tops = take 40 $ reverse $ sortBy (\ (i,_) (j,_) -> compare i j) defs
+ defs = [(length (prt (info2def j)), name m j) | (m,j) <- infos]
+ infos = [(m,j) | (m,ModMod mo) <- mods, j <- tree2list (jments mo)]
+ name m (f,_) = prt m ++ "." ++ prt f
+ mods = modules can
+ chars = length $ prCanon can
diff --git a/src-2.9/GF/UseGrammar/Tokenize.hs b/src-2.9/GF/UseGrammar/Tokenize.hs
new file mode 100644
index 000000000..9f1ab5449
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Tokenize.hs
@@ -0,0 +1,222 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Tokenize
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/09/29 13:20:08 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.14 $
+--
+-- lexers = tokenizers, to prepare input for GF grammars. AR 4\/1\/2002.
+-- an entry for each is included in 'Custom.customTokenizer'
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Tokenize ( tokWords,
+ tokLits,
+ tokVars,
+ lexHaskell,
+ lexHaskellLiteral,
+ lexHaskellVar,
+ lexText,
+ lexTextVar,
+ lexC2M, lexC2M',
+ lexTextLiteral,
+ lexIgnore,
+ wordsLits
+ ) where
+
+import GF.Data.Operations
+---- import UseGrammar (isLiteral,identC)
+import GF.CF.CFIdent
+
+import Data.Char
+
+-- lexers = tokenizers, to prepare input for GF grammars. AR 4/1/2002
+-- an entry for each is included in Custom.customTokenizer
+
+-- | just words
+tokWords :: String -> [CFTok]
+tokWords = map tS . words
+
+tokLits :: String -> [CFTok]
+tokLits = map mkCFTok . mergeStr . wordsLits where
+ mergeStr ss = case ss of
+ w@(c:cs):rest | elem c "\'\"" && c /= last w -> getStr [w] rest
+ w :rest -> w : mergeStr rest
+ [] -> []
+ getStr v ss = case ss of
+ w@(_:_):rest | elem (last w) "\'\"" -> (unwords (reverse (w:v))) : mergeStr rest
+ w :rest -> getStr (w:v) rest
+ [] -> reverse v
+
+tokVars :: String -> [CFTok]
+tokVars = map mkCFTokVar . wordsLits
+
+isFloat s = case s of
+ c:cs | isDigit c -> isFloat cs
+ '.':cs@(_:_) -> all isDigit cs
+ _ -> False
+
+isString s = case s of
+ c:cs@(_:_) -> (c == '\'' && d == '\'') || (c == '"' && d == '"') where d = last cs
+ _ -> False
+
+
+mkCFTok :: String -> CFTok
+mkCFTok s = case s of
+ '"' :cs@(_:_) | last cs == '"' -> tL $ init cs
+ '\'':cs@(_:_) | last cs == '\'' -> tL $ init cs --- 's Gravenhage
+ _:_ | isFloat s -> tF s
+ _:_ | all isDigit s -> tI s
+ _ -> tS s
+
+mkCFTokVar :: String -> CFTok
+mkCFTokVar s = case s of
+ '?':_:_ -> tM s --- "?" --- compat with prCF
+ 'x':'_':_ -> tV s
+ 'x':[] -> tV s
+ '$':xs@(_:_) -> if last s == '$' then tV (init xs) else tS s
+ _ -> tS s
+
+mkTokVars :: (String -> [CFTok]) -> String -> [CFTok]
+mkTokVars tok = map tv . tok where
+ tv (TS s) = mkCFTokVar s
+ tv t = t
+
+mkLit :: String -> CFTok
+mkLit s
+ | isFloat s = tF s
+ | all isDigit s = tI s
+ | otherwise = tL s
+
+-- obsolete
+mkTL :: String -> CFTok
+mkTL s
+ | isFloat s = tF s
+ | all isDigit s = tI s
+ | otherwise = tL ("'" ++ s ++ "'")
+
+
+-- | Haskell lexer, usable for much code
+lexHaskell :: String -> [CFTok]
+lexHaskell ss = case lex ss of
+ [(w@(_:_),ws)] -> tS w : lexHaskell ws
+ _ -> []
+
+-- | somewhat shaky text lexer
+lexText :: String -> [CFTok]
+lexText = uncap . lx where
+
+ lx s = case s of
+ '?':'?':cs -> tS "??" : lx cs
+ p : cs | isMPunct p -> tS [p] : uncap (lx cs)
+ p : cs | isPunct p -> tS [p] : lx cs
+ s : cs | isSpace s -> lx cs
+ _ : _ -> getWord s
+ _ -> []
+
+ getWord s = tS w : lx ws where (w,ws) = span isNotSpec s
+ isMPunct c = elem c ".!?"
+ isPunct c = elem c ",:;()\""
+ isNotSpec c = not (isMPunct c || isPunct c || isSpace c)
+ uncap (TS (c:cs) : ws) = tC (c:cs) : ws
+ uncap s = s
+
+-- | lexer for C--, a mini variant of C
+lexC2M :: String -> [CFTok]
+lexC2M = lexC2M' False
+
+lexC2M' :: Bool -> String -> [CFTok]
+lexC2M' isHigherOrder s = case s of
+ '#':cs -> lexC $ dropWhile (/='\n') cs
+ '/':'*':cs -> lexC $ dropComment cs
+ c:cs | isSpace c -> lexC cs
+ c:cs | isAlpha c -> getId s
+ c:cs | isDigit c -> getLit s
+ c:d:cs | isSymb [c,d] -> tS [c,d] : lexC cs
+ c:cs | isSymb [c] -> tS [c] : lexC cs
+ _ -> [] --- covers end of file and unknown characters
+ where
+ lexC = lexC2M' isHigherOrder
+ getId s = mkT i : lexC cs where (i,cs) = span isIdChar s
+ getLit s = tI i : lexC cs where (i,cs) = span isDigit s ---- Float!
+ isIdChar c = isAlpha c || isDigit c || elem c "'_"
+ isSymb = reservedAnsiCSymbol
+ dropComment s = case s of
+ '*':'/':cs -> cs
+ _:cs -> dropComment cs
+ _ -> []
+ mkT i = if (isRes i) then (tS i) else
+ if isHigherOrder then (tV i) else (tL ("'" ++ i ++ "'"))
+ isRes = reservedAnsiC
+
+
+reservedAnsiCSymbol s = case lookupTree show s ansiCtree of
+ Ok True -> True
+ _ -> False
+
+reservedAnsiC s = case lookupTree show s ansiCtree of
+ Ok False -> True
+ _ -> False
+
+-- | for an efficient lexer: precompile this!
+ansiCtree = buildTree $ [(s,True) | s <- reservedAnsiCSymbols] ++
+ [(s,False) | s <- reservedAnsiCWords]
+
+reservedAnsiCSymbols = words $
+ "<<= >>= << >> ++ -- == <= >= *= += -= %= /= &= ^= |= " ++
+ "^ { } = , ; + * - ( ) < > & % ! ~"
+
+reservedAnsiCWords = words $
+ "auto break case char const continue default " ++
+ "do double else enum extern float for goto if int " ++
+ "long register return short signed sizeof static struct switch typedef " ++
+ "union unsigned void volatile while " ++
+ "main printin putchar" --- these are not ansi-C
+
+-- | turn unknown tokens into string literals; not recursively for literals 123, 'foo'
+unknown2string :: (String -> Bool) -> [CFTok] -> [CFTok]
+unknown2string isKnown = map mkOne where
+ mkOne t@(TS s)
+ | isKnown s = t
+ | isFloat s = tF s
+ | all isDigit s = tI s
+ | otherwise = tL s
+ mkOne t@(TC s) = if isKnown s then t else mkLit s
+ mkOne t = t
+
+unknown2var :: (String -> Bool) -> [CFTok] -> [CFTok]
+unknown2var isKnown = map mkOne where
+ mkOne t@(TS "??") = if isKnown "??" then t else tM "??"
+ mkOne t@(TS s)
+ | isKnown s = t
+ | isFloat s = tF s
+ | isString s = tL (init (tail s))
+ | all isDigit s = tI s
+ | otherwise = tV s
+ mkOne t@(TC s) = if isKnown s then t else tV s
+ mkOne t = t
+
+lexTextLiteral, lexHaskellLiteral, lexHaskellVar :: (String -> Bool) -> String -> [CFTok]
+
+lexTextLiteral isKnown = unknown2string (eitherUpper isKnown) . lexText
+lexHaskellLiteral isKnown = unknown2string isKnown . lexHaskell
+
+lexHaskellVar isKnown = unknown2var isKnown . lexHaskell
+lexTextVar isKnown = unknown2var (eitherUpper isKnown) . lexText
+
+
+eitherUpper isKnown w@(c:cs) = isKnown (toLower c : cs) || isKnown (toUpper c : cs)
+eitherUpper isKnown w = isKnown w
+
+-- ignore unknown tokens (e.g. keyword spotting)
+
+lexIgnore :: (String -> Bool) -> [CFTok] -> [CFTok]
+lexIgnore isKnown = concatMap mkOne where
+ mkOne t@(TS s)
+ | isKnown s = [t]
+ | otherwise = []
+ mkOne t = [t]
+
diff --git a/src-2.9/GF/UseGrammar/Transfer.hs b/src-2.9/GF/UseGrammar/Transfer.hs
new file mode 100644
index 000000000..5d62f4385
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Transfer.hs
@@ -0,0 +1,79 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Transfer
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:23:53 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.5 $
+--
+-- linearize, parse, etc, by transfer. AR 9\/10\/2003
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Transfer where
+
+import GF.Grammar.Grammar
+import GF.Grammar.Values
+import GF.Grammar.AbsCompute
+import qualified GF.Canon.GFC as GFC
+import GF.Grammar.LookAbs
+import GF.Grammar.MMacros
+import GF.Grammar.Macros
+import GF.Grammar.PrGrammar
+import GF.Grammar.TypeCheck
+
+import GF.Infra.Ident
+import GF.Data.Operations
+
+import qualified Transfer.Core.Abs as T
+
+import Control.Monad
+
+
+-- transfer is done in T.Exp - we only need these conversions.
+
+exp2core :: Ident -> Exp -> T.Exp
+exp2core f = T.EApp (T.EVar (var f)) . exp2c where
+ exp2c e = case e of
+ App f a -> T.EApp (exp2c f) (exp2c a)
+ Abs x b -> T.EAbs (T.PVVar (var x)) (exp2c b) ---- should be syntactic abstr
+ Q _ c -> T.EVar (var c)
+ QC _ c -> T.EVar (var c)
+ K s -> T.EStr s
+ EInt i -> T.EInteger $ toInteger i
+ Meta m -> T.EMeta (T.TMeta (prt m)) ---- which meta symbol?
+ Vr x -> T.EVar (var x) ---- should be syntactic var
+
+ var x = T.CIdent $ prt x
+
+core2exp :: T.Exp -> Exp
+core2exp e = case e of
+ T.EApp f a -> App (core2exp f) (core2exp a)
+ T.EAbs (T.PVVar x) b -> Abs (var x) (core2exp b) ---- only from syntactic abstr
+ T.EVar c -> Vr (var c) -- GF annotates to Q or QC
+ T.EStr s -> K s
+ T.EInteger i -> EInt $ fromInteger i
+ T.EMeta _ -> uExp -- meta symbol 0, refreshed by GF
+ where
+ var :: T.CIdent -> Ident
+ var (T.CIdent x) = zIdent x
+
+
+
+-- The following are now obsolete (30/11/2005)
+-- linearize, parse, etc, by transfer. AR 9/10/2003
+
+doTransfer :: GFC.CanonGrammar -> Ident -> Tree -> Err Tree
+doTransfer gr tra t = do
+ cat <- liftM snd $ val2cat $ valTree t
+ f <- lookupTransfer gr tra cat
+ e <- compute gr $ App f $ tree2exp t
+ annotate gr e
+
+useByTransfer :: (Tree -> Err a) -> GFC.CanonGrammar -> Ident -> (Tree -> Err a)
+useByTransfer lin gr tra t = doTransfer gr tra t >>= lin
+
+mkByTransfer :: (a -> Err [Tree]) -> GFC.CanonGrammar -> Ident -> (a -> Err [Tree])
+mkByTransfer parse gr tra s = parse s >>= mapM (doTransfer gr tra)
diff --git a/src-2.9/GF/UseGrammar/TreeSelections.hs b/src-2.9/GF/UseGrammar/TreeSelections.hs
new file mode 100644
index 000000000..9bf2711be
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/TreeSelections.hs
@@ -0,0 +1,77 @@
+----------------------------------------------------------------------
+-- |
+-- Module : TreeSelections
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- choose shallowest trees, and remove an overload resolution prefix
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.TreeSelections (
+
+ getOverloadResults, smallestTrs, sizeTr, depthTr
+
+ ) where
+
+import GF.Grammar.Abstract
+import GF.Grammar.Macros
+
+import GF.Data.Operations
+import GF.Data.Zipper
+import Data.List
+
+-- AR 2/7/2007
+-- The top-level function takes a set of trees (typically parses)
+-- and returns the list of those trees that have the minimum size.
+-- In addition, the overload prefix "ovrld123_", is removed
+-- from each constructor in which it appears. This is used for
+-- showing the library API constructors in a parsable grammar.
+-- TODO: access the generic functions smallestTrs, sizeTr, depthTr from shell
+
+getOverloadResults :: [Tree] -> [Tree]
+getOverloadResults = smallestTrs sizeTr . map (mkOverload "ovrld")
+
+-- NB: this does not always give the desired result, since
+-- some genuine alternatives may be deeper: now we will exclude the
+-- latter of
+--
+-- mkCl this_NP love_V2 (mkNP that_NP here_Adv)
+-- mkCl this_NP (mkVP (mkVP love_V2 that_NP) here_Adv)
+--
+-- A perfect method would know the definitional equivalences of constructors.
+--
+-- Notice also that size is a better measure than depth, because:
+-- 1. Global depth does not exclude the latter of
+--
+-- mkCl (mkNP he_Pron) love_V2 that_NP
+-- mkCl (mkNP he_Pron) (mkVP love_V2 that_NP)
+--
+-- 2. Length is needed to exclude the latter of
+--
+-- mkS (mkCl (mkNP he_Pron) love_V2 that_NP)
+-- mkS presentTense (mkCl (mkNP he_Pron) love_V2 that_NP)
+--
+
+smallestTrs :: (Tr a -> Int) -> [Tr a] -> [Tr a]
+smallestTrs size ts = map fst $ filter ((==mx) . snd) tds where
+ tds = [(t, size t) | t <- ts]
+ mx = minimum $ map snd tds
+
+depthTr :: Tr a -> Int
+depthTr (Tr (_, ts)) = case ts of
+ [] -> 1
+ _ -> 1 + (maximum $ map depthTr ts)
+
+sizeTr :: Tr a -> Int
+sizeTr (Tr (_, ts)) = 1 + sum (map sizeTr ts)
+
+-- remove from each constant a prefix starting with "pref", up to first "_"
+-- example format: ovrld123_mkNP
+
+mkOverload :: String -> Tree -> Tree
+mkOverload pref = mapTr (changeAtom overAtom) where
+ overAtom a = case a of
+ AtC (m, IC f) | isPrefixOf pref f ->
+ AtC (m, IC (tail (dropWhile (/='_') f)))
+ _ -> a
diff --git a/src-2.9/GF/UseGrammar/Treebank.hs b/src-2.9/GF/UseGrammar/Treebank.hs
new file mode 100644
index 000000000..841a9c6dc
--- /dev/null
+++ b/src-2.9/GF/UseGrammar/Treebank.hs
@@ -0,0 +1,251 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Treebank
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- Generate multilingual treebanks. AR 8\/2\/2006
+--
+-- (c) Aarne Ranta 2006 under GNU GPL
+--
+-- Purpose: to generate treebanks.
+-----------------------------------------------------------------------------
+
+module GF.UseGrammar.Treebank (
+ mkMultiTreebank,
+ mkUniTreebank,
+ multi2uniTreebank,
+ uni2multiTreebank,
+ testMultiTreebank,
+ treesTreebank,
+ getTreebank,
+ getUniTreebank,
+ readUniTreebanks,
+ readMultiTreebank,
+ lookupTreebank,
+ assocsTreebank,
+ isWordInTreebank,
+ printAssoc,
+ mkCompactTreebank
+ ) where
+
+import GF.Compile.ShellState
+import GF.UseGrammar.Linear -- (linTree2string)
+import GF.UseGrammar.Custom
+import GF.UseGrammar.GetTree (string2tree)
+import GF.Grammar.TypeCheck (annotate)
+import GF.Canon.CMacros (noMark)
+import GF.Grammar.Grammar (Trm)
+import GF.Grammar.MMacros (exp2tree)
+import GF.Grammar.Macros (zIdent)
+import GF.Grammar.PrGrammar (prt_,prt)
+import GF.Grammar.Values (tree2exp)
+import GF.Data.Operations
+import GF.Infra.Option
+import GF.Infra.Ident (Ident)
+import GF.Infra.UseIO
+import qualified GF.Grammar.Abstract as A
+import qualified Data.Map as M
+import qualified Data.Set as S
+import qualified Data.List as L
+import Control.Monad (liftM)
+import System.FilePath
+
+-- Generate a treebank with a multilingual grammar. AR 8/2/2006
+-- (c) Aarne Ranta 2006 under GNU GPL
+
+-- keys are trees; format: XML file
+type MultiTreebank = [(String,[(String,String)])] -- tree,lang,lin
+
+-- keys are strings; format: string TAB tree TAB ... TAB tree
+type UniTreebank = Treebank -- M.Map String [String] -- string,tree
+
+-- both formats can be read from both kinds of files
+readUniTreebanks :: FilePath -> IO [(Ident,UniTreebank)]
+readUniTreebanks file = do
+ s <- readFileIf file
+ return $ if isMultiTreebank s
+ then multi2uniTreebank $ getTreebank $ lines s
+ else
+ let tb = getUniTreebank $ lines s
+ in [(zIdent (dropExtension file),tb)]
+
+readMultiTreebank :: FilePath -> IO MultiTreebank
+readMultiTreebank file = do
+ s <- readFileIf file
+ return $ if isMultiTreebank s
+ then getTreebank $ lines s
+ else uni2multiTreebank (zIdent (dropExtension file)) $ getUniTreebank $ lines s
+
+isMultiTreebank :: String -> Bool
+isMultiTreebank s = take 10 s == ""
+
+multi2uniTreebank :: MultiTreebank -> [(Ident,UniTreebank)]
+multi2uniTreebank mt@((_,lls):_) = [(zIdent la, mkTb la) | (la,_) <- lls] where
+ mkTb la = M.fromListWith (++) [(s,[t]) | (t,lls) <- mt, (l,s) <- lls, l==la]
+multi2uniTreebank [] = []
+
+uni2multiTreebank :: Ident -> UniTreebank -> MultiTreebank
+uni2multiTreebank la tb =
+ [(t,[(prt_ la, s)]) | (s,ts) <- assocsTreebank tb, t <- ts]
+
+-- | the main functions
+
+-- builds a treebank where trees are the keys, and writes a file (opt. XML)
+mkMultiTreebank :: Options -> ShellState -> String -> [A.Tree] -> Res
+mkMultiTreebank opts sh com trees
+ | oElem (iOpt "compact") opts = mkCompactTreebank opts sh trees
+mkMultiTreebank opts sh com trees =
+ putInXML opts "treebank" comm (concatMap mkItem tris) where
+ mkItem(t,i)= putInXML opts "item" (cat i) (mkTree t ++ concatMap (mkLin t) langs)
+-- mkItem(t,i)= putInXML opts "item" (cat i) (mkTree t >>mapM_ (mkLin t) langs)
+ mkTree t = putInXML opts "tree" [] (puts $ showTree t)
+ mkLin t lg = putInXML opts "lin" (lang lg) (puts $ linearize opts sh lg t)
+
+ langs = [prt_ l | l <- allLanguages sh]
+ comm = "" --- " command=" ++ show com +++ "abstract=" ++ show abstr
+ abstr = "" --- "Abs" ----
+ cat i = " number=" ++ show (show i) --- " cat=" ++ show "S" ----
+ lang lg = " lang=" ++ show (prt_ (zIdent lg))
+ tris = zip trees [1..]
+
+-- builds a unilingual treebank where strings are the keys into an internal treebank
+
+mkUniTreebank :: Options -> ShellState -> Language -> [A.Tree] -> Treebank
+mkUniTreebank opts sh lg trees = M.fromListWith (++) [(lin t, [prt_ t]) | t <- trees]
+ where
+ lang = prt_ lg
+ lin t = linearize opts sh lang t
+
+-- reads a treebank and linearizes its trees again, printing all differences
+testMultiTreebank :: Options -> ShellState -> String -> Res
+testMultiTreebank opts sh = putInXML opts "testtreebank" [] .
+ concatMap testOne .
+ getTreebanks . lines
+ where
+ testOne (e,lang,str0) = do
+ let tr = annot gr e
+ let str = linearize opts sh lang tr
+ if str == str0 then ret else putInXML opts "diff" [] $ concat [
+ putInXML opts "tree" [] (puts $ showTree tr),
+ putInXML opts "old" (" lang=" ++ show (prt_ (zIdent lang))) $ puts str0,
+ putInXML opts "new" (" lang=" ++ show (prt_ (zIdent lang))) $ puts str
+ ]
+ gr = firstStateGrammar sh
+
+-- writes all the trees of the treebank
+treesTreebank :: Options -> String -> [String]
+treesTreebank _ = terms . getTreebank . lines where
+ terms ts = [t | (t,_) <- ts]
+
+-- string vs. IO
+type Res = [String] -- IO ()
+puts :: String -> Res
+puts = return -- putStrLn
+ret = [] -- return ()
+--
+
+-- here strings are keys
+assocsTreebank :: UniTreebank -> [(String,[String])]
+assocsTreebank = M.assocs
+
+isWordInTreebank :: UniTreebank -> String -> Bool
+isWordInTreebank tb w = S.member w (S.fromList (concatMap words (M.keys tb)))
+
+printAssoc (s, ts) = s ++ concat ["\t" ++ t | t <- ts]
+
+getTreebanks :: [String] -> [(String,String,String)]
+getTreebanks = concatMap grps . getTreebank where
+ grps (t,lls) = [(t,x,y) | (x,y) <- lls]
+
+getTreebank :: [String] -> MultiTreebank
+getTreebank ll = case ll of
+ l:ls@(_:_:_) ->
+ let (l1,l2) = getItem ls
+ (tr,lins) = getTree l1
+ lglins = getLins lins
+ in (tr,lglins) : getTreebank l2
+ _ -> []
+ where
+ getItem = span ((/=" UniTreebank
+getUniTreebank ls = M.fromListWith (++) [(s, ts) | s:ts <- map chop ls] where
+ chop = chunks '\t'
+
+lookupTreebank :: Treebank -> String -> [String]
+lookupTreebank tb s = maybe [] id $ M.lookup s tb
+
+annot :: StateGrammar -> String -> A.Tree
+annot gr s = errVal (error "illegal tree") $ do
+ let t = tree2exp $ string2tree gr s
+ annotate (grammar gr) t
+
+putInXML :: Options -> String -> String -> Res -> Res
+putInXML opts tag attrs io =
+ (ifXML $ puts $ tagXML $ tag ++ attrs) ++
+ io ++
+ (ifXML $ puts $ tagXML $ '/':tag)
+ where
+ ifXML c = if oElem showXML opts then c else []
+
+
+tagXML :: String -> String
+tagXML s = "<" ++ s ++ ">"
+
+-- print the treebank in a compact format:
+-- first a sorted list of all words, referrable by index
+-- then the linearization of each tree, as sequences of word indices
+-- this format is usable in embedded translation systems.
+
+mkCompactTreebank :: Options -> ShellState -> [A.Tree] -> [String]
+mkCompactTreebank opts sh = printCompactTreebank . mkJustMultiTreebank opts sh
+
+printCompactTreebank :: (MultiTreebank,[String]) -> [String]
+printCompactTreebank (tb,lgs) = (stat:langs:unwords ws : "\n" : linss) where
+ ws = L.sort $ L.nub $ concat $ map (concatMap (words . snd) . snd) tb
+
+ linss = map (unwords . pad) linss0
+ linss0 = map (map (show . encode) . words) allExs
+ allExs = concat [[snd (ls !! i) | (_,ls) <- tb] | i <- [0..length lgs - 1]]
+ encode w = maybe undefined id $ M.lookup w wmap
+ wmap = M.fromAscList $ zip ws [1..]
+ stat = unwords $ map show [length ws, length lgs, length tb, smax]
+ langs = unwords lgs
+ smax = maximum $ map length linss0
+ pad ws = ws ++ replicate (smax - length ws) "0"
+
+-- [(String,[(String,String)])] -- tree,lang,lin
+mkJustMultiTreebank :: Options -> ShellState -> [A.Tree] -> (MultiTreebank,[String])
+mkJustMultiTreebank opts sh ts =
+ ([(prt_ t, [(la, lin la t) | la <- langs]) | t <- ts],langs) where
+ langs = map prt_ $ allLanguages sh
+ lin = linearize opts sh
+
+
+--- these handy functions are borrowed from EmbedAPI
+
+linearize opts mgr lang = lin where
+ sgr = stateGrammarOfLangOpt False mgr zlang
+ cgr = canModules mgr
+ zlang = zIdent lang
+ untok = customOrDefault (addOptions opts (stateOptions sgr)) useUntokenizer customUntokenizer sgr
+ lin
+ | oElem showRecord opts = err id id . liftM prt . linearizeNoMark cgr zlang
+ | oElem tableLin opts =
+ err id id . liftM (unlines . map untok . prLinTable True) . allLinTables True cgr zlang
+ | oElem showAll opts =
+ err id id . liftM (unlines . map untok . prLinTable False) . allLinTables False cgr zlang
+
+ | otherwise = untok . linTree2string noMark cgr zlang
+
+showTree t = prt_ $ tree2exp t
diff --git a/src-2.9/GF/Visualization/Graphviz.hs b/src-2.9/GF/Visualization/Graphviz.hs
new file mode 100644
index 000000000..b59e3ecd2
--- /dev/null
+++ b/src-2.9/GF/Visualization/Graphviz.hs
@@ -0,0 +1,116 @@
+----------------------------------------------------------------------
+-- |
+-- Module : Graphviz
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/09/15 18:10:44 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.2 $
+--
+-- Graphviz DOT format representation and printing.
+-----------------------------------------------------------------------------
+
+module GF.Visualization.Graphviz (
+ Graph(..), GraphType(..),
+ Node(..), Edge(..),
+ Attr,
+ addSubGraphs,
+ setName,
+ setAttr,
+ prGraphviz
+ ) where
+
+import Data.Char
+
+import GF.Data.Utilities
+
+-- | Graph type, graph ID, graph attirbutes, graph nodes, graph edges, subgraphs
+data Graph = Graph {
+ gType :: GraphType,
+ gId :: Maybe String,
+ gAttrs :: [Attr],
+ gNodes :: [Node],
+ gEdges :: [Edge],
+ gSubgraphs :: [Graph]
+ }
+ deriving (Show)
+
+data GraphType = Directed | Undirected
+ deriving (Show)
+
+data Node = Node String [Attr]
+ deriving Show
+
+data Edge = Edge String String [Attr]
+ deriving Show
+
+type Attr = (String,String)
+
+--
+-- * Graph construction
+--
+
+addSubGraphs :: [Graph] -> Graph -> Graph
+addSubGraphs gs g = g { gSubgraphs = gs ++ gSubgraphs g }
+
+setName :: String -> Graph -> Graph
+setName n g = g { gId = Just n }
+
+setAttr :: String -> String -> Graph -> Graph
+setAttr n v g = g { gAttrs = tableSet n v (gAttrs g) }
+
+--
+-- * Pretty-printing
+--
+
+prGraphviz :: Graph -> String
+prGraphviz g@(Graph t i _ _ _ _) =
+ graphtype t ++ " " ++ maybe "" esc i ++ " {\n" ++ prGraph g ++ "}\n"
+
+prSubGraph :: Graph -> String
+prSubGraph g@(Graph _ i _ _ _ _) =
+ "subgraph" ++ " " ++ maybe "" esc i ++ " {\n" ++ prGraph g ++ "}"
+
+prGraph :: Graph -> String
+prGraph (Graph t id at ns es ss) =
+ unlines $ map (++";") (map prAttr at
+ ++ map prNode ns
+ ++ map (prEdge t) es
+ ++ map prSubGraph ss)
+
+graphtype :: GraphType -> String
+graphtype Directed = "digraph"
+graphtype Undirected = "graph"
+
+prNode :: Node -> String
+prNode (Node n at) = esc n ++ " " ++ prAttrList at
+
+prEdge :: GraphType -> Edge -> String
+prEdge t (Edge x y at) = esc x ++ " " ++ edgeop t ++ " " ++ esc y ++ " " ++ prAttrList at
+
+edgeop :: GraphType -> String
+edgeop Directed = "->"
+edgeop Undirected = "--"
+
+prAttrList :: [Attr] -> String
+prAttrList [] = ""
+prAttrList at = "[" ++ join "," (map prAttr at) ++ "]"
+
+prAttr :: Attr -> String
+prAttr (n,v) = esc n ++ " = " ++ esc v
+
+esc :: String -> String
+esc s | needEsc s = "\"" ++ concat [ if shouldEsc c then ['\\',c] else [c] | c <- s ] ++ "\""
+ | otherwise = s
+ where shouldEsc = (`elem` ['"', '\\'])
+
+needEsc :: String -> Bool
+needEsc [] = True
+needEsc xs | all isDigit xs = False
+needEsc (x:xs) = not (isIDFirst x && all isIDChar xs)
+
+isIDFirst, isIDChar :: Char -> Bool
+isIDFirst c = c `elem` (['_']++['a'..'z']++['A'..'Z'])
+isIDChar c = isIDFirst c || isDigit c
diff --git a/src-2.9/GF/Visualization/VisualizeGrammar.hs b/src-2.9/GF/Visualization/VisualizeGrammar.hs
new file mode 100644
index 000000000..b5446aec8
--- /dev/null
+++ b/src-2.9/GF/Visualization/VisualizeGrammar.hs
@@ -0,0 +1,125 @@
+----------------------------------------------------------------------
+-- |
+-- Module : VisualizeGrammar
+-- Maintainer : BB
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/09/14 15:17:30 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.10 $
+--
+-- Print a graph of module dependencies in Graphviz DOT format
+-- FIXME: change this to use GF.Visualization.Graphviz,
+-- instead of rolling its own.
+-----------------------------------------------------------------------------
+
+module GF.Visualization.VisualizeGrammar ( visualizeCanonGrammar,
+ visualizeSourceGrammar
+ ) where
+
+import qualified GF.Infra.Modules as M
+import GF.Canon.GFC
+import GF.Infra.Ident
+import GF.Infra.Option
+import GF.Grammar.Grammar (SourceGrammar)
+
+import Data.List (intersperse, nub)
+import Data.Maybe (maybeToList)
+
+data GrType = GrAbstract
+ | GrConcrete
+ | GrResource
+ | GrInterface
+ | GrInstance
+ deriving Show
+
+data Node = Node {
+ label :: String,
+ url :: String,
+ grtype :: GrType,
+ extends :: [String],
+ opens :: [String],
+ implements :: Maybe String
+ }
+ deriving Show
+
+
+visualizeCanonGrammar :: Options -> CanonGrammar -> String
+visualizeCanonGrammar opts = prGraph . canon2graph
+
+visualizeSourceGrammar :: SourceGrammar -> String
+visualizeSourceGrammar = prGraph . source2graph
+
+canon2graph :: CanonGrammar -> [Node]
+canon2graph gr = [ toNode i m | (i,M.ModMod m) <- M.modules gr ]
+
+source2graph :: SourceGrammar -> [Node]
+source2graph gr = [ toNode i m | (i,M.ModMod m) <- M.modules gr ] -- FIXME: handle ModWith?
+
+toNode :: Ident -> M.Module Ident f i -> Node
+toNode i m = Node {
+ label = l,
+ url = l ++ ".gf", -- FIXME: might be in a different directory
+ grtype = t,
+ extends = map prIdent (M.extends m),
+ opens = nub $ map openName (M.opens m), -- FIXME: nub is needed because of triple open with
+ -- instance modules
+ implements = is
+ }
+ where
+ l = prIdent i
+ (t,is) = fromModType (M.mtype m)
+
+fromModType :: M.ModuleType Ident -> (GrType, Maybe String)
+fromModType t = case t of
+ M.MTAbstract -> (GrAbstract, Nothing)
+ M.MTTransfer _ _ -> error "Can't visualize transfer modules yet" -- FIXME
+ M.MTConcrete i -> (GrConcrete, Just (prIdent i))
+ M.MTResource -> (GrResource, Nothing)
+ M.MTInterface -> (GrInterface, Nothing)
+ M.MTInstance i -> (GrInstance, Just (prIdent i))
+ M.MTReuse rt -> error "Can't visualize reuse modules yet" -- FIXME
+ M.MTUnion _ _ -> error "Can't visualize union modules yet" -- FIXME
+
+-- | FIXME: there is something odd about OQualif with 'with' modules,
+-- both names seem to be the same.
+openName :: M.OpenSpec Ident -> String
+openName (M.OSimple q i) = prIdent i
+openName (M.OQualif q i _) = prIdent i
+
+prGraph :: [Node] -> String
+prGraph ns = concat $ map (++"\n") $ ["digraph {\n"] ++ map prNode ns ++ ["}"]
+
+prNode :: Node -> String
+prNode n = concat (map (++";\n") stmts)
+ where
+ l = label n
+ t = grtype n
+ stmts = [l ++ " [" ++ prAttributes attrs ++ "]"]
+ ++ map (prExtend t l) (extends n)
+ ++ map (prOpen l) (opens n)
+ ++ map (prImplement t l) (maybeToList (implements n))
+ (shape,style) = case t of
+ GrAbstract -> ("ellipse","solid")
+ GrConcrete -> ("box","dashed")
+ GrResource -> ("ellipse","dashed")
+ GrInterface -> ("ellipse","dotted")
+ GrInstance -> ("diamond","dotted")
+ attrs = [("style", style),("shape", shape),("URL", url n)]
+
+
+prExtend :: GrType -> String -> String -> String
+prExtend g f t = prEdge f t [("style","solid")]
+
+prOpen :: String -> String -> String
+prOpen f t = prEdge f t [("style","dotted")]
+
+prImplement :: GrType -> String -> String -> String
+prImplement g f t = prEdge f t [("arrowhead","empty"),("style","dashed")]
+
+prEdge :: String -> String -> [(String,String)] -> String
+prEdge f t as = f ++ " -> " ++ t ++ " [" ++ prAttributes as ++ "]"
+
+prAttributes :: [(String,String)] -> String
+prAttributes = concat . intersperse ", " . map (\ (n,v) -> n ++ " = " ++ show v)
diff --git a/src-2.9/GF/Visualization/VisualizeTree.hs b/src-2.9/GF/Visualization/VisualizeTree.hs
new file mode 100644
index 000000000..5fe740c12
--- /dev/null
+++ b/src-2.9/GF/Visualization/VisualizeTree.hs
@@ -0,0 +1,58 @@
+----------------------------------------------------------------------
+-- |
+-- Module : VisualizeTree
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date:
+-- > CVS $Author:
+-- > CVS $Revision:
+--
+-- Print a graph of an abstract syntax tree in Graphviz DOT format
+-- Based on BB's VisualizeGrammar
+-- FIXME: change this to use GF.Visualization.Graphviz,
+-- instead of rolling its own.
+-----------------------------------------------------------------------------
+
+module GF.Visualization.VisualizeTree ( visualizeTrees
+ ) where
+
+import GF.Infra.Ident
+import GF.Infra.Option
+import GF.Grammar.Abstract
+import GF.Data.Zipper
+import GF.Grammar.PrGrammar
+
+import Data.List (intersperse, nub)
+import Data.Maybe (maybeToList)
+
+visualizeTrees :: Options -> [Tree] -> String
+visualizeTrees opts = unlines . map (prGraph opts . tree2graph opts)
+
+tree2graph :: Options -> Tree -> [String]
+tree2graph opts = prf [] where
+ prf ps t@(Tr (node, trees)) =
+ let (nod,lab) = prn ps node in
+ (nod ++ " [label = " ++ lab ++ ", style = \"solid\", shape = \"plaintext\"] ;") :
+ [ pra (j:ps) nod t | (j,t) <- zip [0..] trees] ++
+ concat [prf (j:ps) t | (j,t) <- zip [0..] trees]
+ prn ps (N (bi,at,val,_,_)) =
+ let
+ lab =
+ "\"" ++
+ prb bi ++
+ prc at val ++
+ "\""
+ in if oElem (iOpt "g") opts then (lab,lab) else (show(show (ps :: [Int])),lab)
+ prb [] = ""
+ prb bi = "\\" ++ concat (intersperse "," (map (prt_ . fst) bi)) ++ " -> "
+ pra i nod t@(Tr (node,_)) = nod ++ arr ++ fst (prn i node) ++ " [style = \"solid\"];"
+ prc a v
+ | oElem (iOpt "c") opts = prt_ v
+ | oElem (iOpt "f") opts = prt_ a
+ | otherwise = prt_ a ++ " : " ++ prt_ v
+ arr = if oElem (iOpt "g") opts then " -> " else " -- "
+
+prGraph opts ns = concat $ map (++"\n") $ [graph ++ "{\n"] ++ ns ++ ["}"] where
+ graph = if oElem (iOpt "g") opts then "digraph" else "graph"
diff --git a/src-2.9/HelpFile b/src-2.9/HelpFile
new file mode 100644
index 000000000..c6b38b313
--- /dev/null
+++ b/src-2.9/HelpFile
@@ -0,0 +1,693 @@
+-- GF help file updated for GF 2.6, 17/6/2006.
+-- *: Commands and options marked with * are currently not implemented.
+--
+-- Each command has a long and a short name, options, and zero or more
+-- arguments. Commands are sorted by functionality. The short name is
+-- given first.
+
+-- Type "h -all" for full help file, "h " for full help on a command.
+
+-- commands that change the state
+
+i, import: i File
+ Reads a grammar from File and compiles it into a GF runtime grammar.
+ Files "include"d in File are read recursively, nubbing repetitions.
+ If a grammar with the same language name is already in the state,
+ it is overwritten - but only if compilation succeeds.
+ The grammar parser depends on the file name suffix:
+ .gf normal GF source
+ .gfc canonical GF
+ .gfr precompiled GF resource
+ .gfcm multilingual canonical GF
+ .gfe example-based grammar files (only with the -ex option)
+ .gfwl multilingual word list (preprocessed to abs + cncs)
+ .ebnf Extended BNF format
+ .cf Context-free (BNF) format
+ .trc TransferCore format
+ options:
+ -old old: parse in GF<2.0 format (not necessary)
+ -v verbose: give lots of messages
+ -s silent: don't give error messages
+ -src from source: ignore precompiled gfc and gfr files
+ -gfc from gfc: use compiled modules whenever they exist
+ -retain retain operations: read resource modules (needed in comm cc)
+ -nocf don't build old-style context-free grammar (default without HOAS)
+ -docf do build old-style context-free grammar (default with HOAS)
+ -nocheckcirc don't eliminate circular rules from CF
+ -cflexer build an optimized parser with separate lexer trie
+ -noemit do not emit code (default with old grammar format)
+ -o do emit code (default with new grammar format)
+ -ex preprocess .gfe files if needed
+ -prob read probabilities from top grammar file (format --# prob Fun Double)
+ -treebank read a treebank file to memory (xml format)
+ flags:
+ -abs set the name used for abstract syntax (with -old option)
+ -cnc set the name used for concrete syntax (with -old option)
+ -res set the name used for resource (with -old option)
+ -path use the (colon-separated) search path to find modules
+ -optimize select an optimization to override file-defined flags
+ -conversion select parsing method (values strict|nondet)
+ -probs read probabilities from file (format (--# prob) Fun Double)
+ -preproc use a preprocessor on each source file
+ -noparse read nonparsable functions from file (format --# noparse Funs)
+ examples:
+ i English.gf -- ordinary import of Concrete
+ i -retain german/ParadigmsGer.gf -- import of Resource to test
+
+r, reload: r
+ Executes the previous import (i) command.
+
+rl, remove_language: rl Language
+ Takes away the language from the state.
+
+e, empty: e
+ Takes away all languages and resets all global flags.
+
+sf, set_flags: sf Flag*
+ The values of the Flags are set for Language. If no language
+ is specified, the flags are set globally.
+ examples:
+ sf -nocpu -- stop showing CPU time
+ sf -lang=Swe -- make Swe the default concrete
+
+s, strip: s
+ Prune the state by removing source and resource modules.
+
+dc, define_command Name Anything
+ Add a new defined command. The Name must star with '%'. Later,
+ if 'Name X' is used, it is replaced by Anything where #1 is replaced
+ by X.
+ Restrictions: Currently at most one argument is possible, and a defined
+ command cannot appear in a pipe.
+ To see what definitions are in scope, use help -defs.
+ examples:
+ dc %tnp p -cat=NP -lang=Eng #1 | l -lang=Swe -- translate NPs
+ %tnp "this man" -- translate and parse
+
+dt, define_term Name Tree
+ Add a constant for a tree. The constant can later be called by
+ prefixing it with '$'.
+ Restriction: These terms are not yet usable as a subterm.
+ To see what definitions are in scope, use help -defs.
+ examples:
+ p -cat=NP "this man" | dt tm -- define tm as parse result
+ l -all $tm -- linearize tm in all forms
+
+-- commands that give information about the state
+
+pg, print_grammar: pg
+ Prints the actual grammar (overridden by the -lang=X flag).
+ The -printer=X flag sets the format in which the grammar is
+ written.
+ N.B. since grammars are compiled when imported, this command
+ generally does not show the grammar in the same format as the
+ source. In particular, the -printer=latex is not supported.
+ Use the command tg -printer=latex File to print the source
+ grammar in LaTeX.
+ options:
+ -utf8 apply UTF8-encoding to the grammar
+ flags:
+ -printer
+ -lang
+ -startcat -- The start category of the generated grammar.
+ Only supported by some grammar printers.
+ examples:
+ pg -printer=cf -- show the context-free skeleton
+
+pm, print_multigrammar: pm
+ Prints the current multilingual grammar in .gfcm form.
+ (Automatically executes the strip command (s) before doing this.)
+ options:
+ -utf8 apply UTF8 encoding to the tokens in the grammar
+ -utf8id apply UTF8 encoding to the identifiers in the grammar
+ examples:
+ pm | wf Letter.gfcm -- print the grammar into the file Letter.gfcm
+ pm -printer=graph | wf D.dot -- then do 'dot -Tps D.dot > D.ps'
+
+vg, visualize_graph: vg
+ Show the dependency graph of multilingual grammar via dot and gv.
+
+po, print_options: po
+ Print what modules there are in the state. Also
+ prints those flag values in the current state that differ from defaults.
+
+pl, print_languages: pl
+ Prints the names of currently available languages.
+
+pi, print_info: pi Ident
+ Prints information on the identifier.
+
+-- commands that execute and show the session history
+
+eh, execute_history: eh File
+ Executes commands in the file.
+
+ph, print_history; ph
+ Prints the commands issued during the GF session.
+ The result is readable by the eh command.
+ examples:
+ ph | wf foo.hist" -- save the history into a file
+
+-- linearization, parsing, translation, and computation
+
+l, linearize: l PattList? Tree
+ Shows all linearization forms of Tree by the actual grammar
+ (which is overridden by the -lang flag).
+ The pattern list has the form [P, ... ,Q] where P,...,Q follow GF
+ syntax for patterns. All those forms are generated that match with the
+ pattern list. Too short lists are filled with variables in the end.
+ Only the -table flag is available if a pattern list is specified.
+ HINT: see GF language specification for the syntax of Pattern and Term.
+ You can also copy and past parsing results.
+ options:
+ -struct bracketed form
+ -table show parameters (not compatible with -record, -all)
+ -record record, i.e. explicit GF concrete syntax term (not compatible with -table, -all)
+ -all show all forms and variants (not compatible with -record, -table)
+ -multi linearize to all languages (can be combined with the other options)
+ flags:
+ -lang linearize in this grammar
+ -number give this number of forms at most
+ -unlexer filter output through unlexer
+ examples:
+ l -lang=Swe -table -- show full inflection table in Swe
+
+p, parse: p String
+ Shows all Trees returned for String by the actual
+ grammar (overridden by the -lang flag), in the category S (overridden
+ by the -cat flag).
+ options for batch input:
+ -lines parse each line of input separately, ignoring empty lines
+ -all as -lines, but also parse empty lines
+ -prob rank results by probability
+ -cut stop after first lexing result leading to parser success
+ -fail show strings whose parse fails prefixed by #FAIL
+ -ambiguous show strings that have more than one parse prefixed by #AMBIGUOUS
+ options for selecting parsing method:
+ -fcfg parse using a fast variant of MCFG (default is no HOAS in grammar)
+ -old parse using an overgenerating CFG (default if HOAS in grammar)
+ -cfg parse using a much less overgenerating CFG
+ -mcfg parse using an even less overgenerating MCFG
+ Note: the first time parsing with -cfg, -mcfg, and -fcfg may take a long time
+ options that only work for the -old default parsing method:
+ -n non-strict: tolerates morphological errors
+ -ign ignore unknown words when parsing
+ -raw return context-free terms in raw form
+ -v verbose: give more information if parsing fails
+ flags:
+ -cat parse in this category
+ -lang parse in this grammar
+ -lexer filter input through this lexer
+ -parser use this parsing strategy
+ -number return this many results at most
+ examples:
+ p -cat=S -mcfg "jag är gammal" -- parse an S with the MCFG
+ rf examples.txt | p -lines -- parse each non-empty line of the file
+
+at, apply_transfer: at (Module.Fun | Fun)
+ Transfer a term using Fun from Module, or the topmost transfer
+ module. Transfer modules are given in the .trc format. They are
+ shown by the 'po' command.
+ flags:
+ -lang typecheck the result in this lang instead of default lang
+ examples:
+ p -lang=Cncdecimal "123" | at num2bin | l -- convert dec to bin
+
+tb, tree_bank: tb
+ Generate a multilingual treebank from a list of trees (default) or compare
+ to an existing treebank.
+ options:
+ -c compare to existing xml-formatted treebank
+ -trees return the trees of the treebank
+ -all show all linearization alternatives (branches and variants)
+ -table show tables of linearizations with parameters
+ -record show linearization records
+ -xml wrap the treebank (or comparison results) with XML tags
+ -mem write the treebank in memory instead of a file TODO
+ examples:
+ gr -cat=S -number=100 | tb -xml | wf tb.xml -- random treebank into file
+ rf tb.xml | tb -c -- compare-test treebank from file
+ rf old.xml | tb -trees | tb -xml -- create new treebank from old
+
+ut, use_treebank: ut String
+ Lookup a string in a treebank and return the resulting trees.
+ Use 'tb' to create a treebank and 'i -treebank' to read one from
+ a file.
+ options:
+ -assocs show all string-trees associations in the treebank
+ -strings show all strings in the treebank
+ -trees show all trees in the treebank
+ -raw return the lookup result as string, without typechecking it
+ flags:
+ -treebank use this treebank (instead of the latest introduced one)
+ examples:
+ ut "He adds this to that" | l -multi -- use treebank lookup as parser in translation
+ ut -assocs | grep "ComplV2" -- show all associations with ComplV2
+
+tt, test_tokenizer: tt String
+ Show the token list sent to the parser when String is parsed.
+ HINT: can be useful when debugging the parser.
+ flags:
+ -lexer use this lexer
+ examples:
+ tt -lexer=codelit "2*(x + 3)" -- a favourite lexer for program code
+
+g, grep: g String1 String2
+ Grep the String1 in the String2. String2 is read line by line,
+ and only those lines that contain String1 are returned.
+ flags:
+ -v return those lines that do not contain String1.
+ examples:
+ pg -printer=cf | grep "mother" -- show cf rules with word mother
+
+cc, compute_concrete: cc Term
+ Compute a term by concrete syntax definitions. Uses the topmost
+ resource module (the last in listing by command po) to resolve
+ constant names.
+ N.B. You need the flag -retain when importing the grammar, if you want
+ the oper definitions to be retained after compilation; otherwise this
+ command does not expand oper constants.
+ N.B.' The resulting Term is not a term in the sense of abstract syntax,
+ and hence not a valid input to a Tree-demanding command.
+ flags:
+ -table show output in a similar readable format as 'l -table'
+ -res use another module than the topmost one
+ examples:
+ cc -res=ParadigmsFin (nLukko "hyppy") -- inflect "hyppy" with nLukko
+
+so, show_operations: so Type
+ Show oper operations with the given value type. Uses the topmost
+ resource module to resolve constant names.
+ N.B. You need the flag -retain when importing the grammar, if you want
+ the oper definitions to be retained after compilation; otherwise this
+ command does not find any oper constants.
+ N.B.' The value type may not be defined in a supermodule of the
+ topmost resource. In that case, use appropriate qualified name.
+ flags:
+ -res use another module than the topmost one
+ examples:
+ so -res=ParadigmsFin ResourceFin.N -- show N-paradigms in ParadigmsFin
+
+t, translate: t Lang Lang String
+ Parses String in Lang1 and linearizes the resulting Trees in Lang2.
+ flags:
+ -cat
+ -lexer
+ -parser
+ examples:
+ t Eng Swe -cat=S "every number is even or odd"
+
+gr, generate_random: gr Tree?
+ Generates a random Tree of a given category. If a Tree
+ argument is given, the command completes the Tree with values to
+ the metavariables in the tree.
+ options:
+ -prob use probabilities (works for nondep types only)
+ -cf use a very fast method (works for nondep types only)
+ flags:
+ -cat generate in this category
+ -lang use the abstract syntax of this grammar
+ -number generate this number of trees (not impl. with Tree argument)
+ -depth use this number of search steps at most
+ examples:
+ gr -cat=Query -- generate in category Query
+ gr (PredVP ? (NegVG ?)) -- generate a random tree of this form
+ gr -cat=S -tr | l -- gererate and linearize
+
+gt, generate_trees: gt Tree?
+ Generates all trees up to a given depth. If the depth is large,
+ a small -alts is recommended. If a Tree argument is given, the
+ command completes the Tree with values to the metavariables in
+ the tree.
+ options:
+ -metas also return trees that include metavariables
+ -all generate all (can be infinitely many, lazily)
+ -lin linearize result of -all (otherwise, use pipe to linearize)
+ flags:
+ -depth generate to this depth (default 3)
+ -atoms take this number of atomic rules of each category (default unlimited)
+ -alts take this number of alternatives at each branch (default unlimited)
+ -cat generate in this category
+ -nonub don't remove duplicates (faster, not effective with -mem)
+ -mem use a memorizing algorithm (often faster, usually more memory-consuming)
+ -lang use the abstract syntax of this grammar
+ -number generate (at most) this number of trees (also works with -all)
+ -noexpand don't expand these categories (comma-separated, e.g. -noexpand=V,CN)
+ -doexpand only expand these categories (comma-separated, e.g. -doexpand=V,CN)
+ examples:
+ gt -depth=10 -cat=NP -- generate all NP's to depth 10
+ gt (PredVP ? (NegVG ?)) -- generate all trees of this form
+ gt -cat=S -tr | l -- generate and linearize
+ gt -noexpand=NP | l -mark=metacat -- the only NP is meta, linearized "?0 +NP"
+ gt | l | p -lines -ambiguous | grep "#AMBIGUOUS" -- show ambiguous strings
+
+ma, morphologically_analyse: ma String
+ Runs morphological analysis on each word in String and displays
+ the results line by line.
+ options:
+ -short show analyses in bracketed words, instead of separate lines
+ -status show just the work at success, prefixed with "*" at failure
+ flags:
+ -lang
+ examples:
+ wf Bible.txt | ma -short | wf Bible.tagged -- analyse the Bible
+
+
+-- elementary generation of Strings and Trees
+
+ps, put_string: ps String
+ Returns its argument String, like Unix echo.
+ HINT. The strength of ps comes from the possibility to receive the
+ argument from a pipeline, and altering it by the -filter flag.
+ flags:
+ -filter filter the result through this string processor
+ -length cut the string after this number of characters
+ examples:
+ gr -cat=Letter | l | ps -filter=text -- random letter as text
+
+pt, put_tree: pt Tree
+ Returns its argument Tree, like a specialized Unix echo.
+ HINT. The strength of pt comes from the possibility to receive
+ the argument from a pipeline, and altering it by the -transform flag.
+ flags:
+ -transform transform the result by this term processor
+ -number generate this number of terms at most
+ examples:
+ p "zero is even" | pt -transform=solve -- solve ?'s in parse result
+
+* st, show_tree: st Tree
+ Prints the tree as a string. Unlike pt, this command cannot be
+ used in a pipe to produce a tree, since its output is a string.
+ flags:
+ -printer show the tree in a special format (-printer=xml supported)
+
+wt, wrap_tree: wt Fun
+ Wraps the tree as the sole argument of Fun.
+ flags:
+ -c compute the resulting new tree to normal form
+
+vt, visualize_tree: vt Tree
+ Shows the abstract syntax tree via dot and gv (via temporary files
+ grphtmp.dot, grphtmp.ps).
+ flags:
+ -c show categories only (no functions)
+ -f show functions only (no categories)
+ -g show as graph (sharing uses of the same function)
+ -o just generate the .dot file
+ examples:
+ p "hello world" | vt -o | wf my.dot ;; ! open -a GraphViz my.dot
+ -- This writes the parse tree into my.dot and opens the .dot file
+ -- with another application without generating .ps.
+
+-- subshells
+
+es, editing_session: es
+ Opens an interactive editing session.
+ N.B. Exit from a Fudget session is to the Unix shell, not to GF.
+ options:
+ -f Fudget GUI (necessary for Unicode; only available in X Window System)
+
+ts, translation_session: ts
+ Translates input lines from any of the actual languages to all other ones.
+ To exit, type a full stop (.) alone on a line.
+ N.B. Exit from a Fudget session is to the Unix shell, not to GF.
+ HINT: Set -parser and -lexer locally in each grammar.
+ options:
+ -f Fudget GUI (necessary for Unicode; only available in X Windows)
+ -lang prepend translation results with language names
+ flags:
+ -cat the parser category
+ examples:
+ ts -cat=Numeral -lang -- translate numerals, show language names
+
+tq, translation_quiz: tq Lang Lang
+ Random-generates translation exercises from Lang1 to Lang2,
+ keeping score of success.
+ To interrupt, type a full stop (.) alone on a line.
+ HINT: Set -parser and -lexer locally in each grammar.
+ flags:
+ -cat
+ examples:
+ tq -cat=NP TestResourceEng TestResourceSwe -- quiz for NPs
+
+tl, translation_list: tl Lang Lang
+ Random-generates a list of ten translation exercises from Lang1
+ to Lang2. The number can be changed by a flag.
+ HINT: use wf to save the exercises in a file.
+ flags:
+ -cat
+ -number
+ examples:
+ tl -cat=NP TestResourceEng TestResourceSwe -- quiz list for NPs
+
+mq, morphology_quiz: mq
+ Random-generates morphological exercises,
+ keeping score of success.
+ To interrupt, type a full stop (.) alone on a line.
+ HINT: use printname judgements in your grammar to
+ produce nice expressions for desired forms.
+ flags:
+ -cat
+ -lang
+ examples:
+ mq -cat=N -lang=TestResourceSwe -- quiz for Swedish nouns
+
+ml, morphology_list: ml
+ Random-generates a list of ten morphological exercises,
+ keeping score of success. The number can be changed with a flag.
+ HINT: use wf to save the exercises in a file.
+ flags:
+ -cat
+ -lang
+ -number
+ examples:
+ ml -cat=N -lang=TestResourceSwe -- quiz list for Swedish nouns
+
+
+-- IO related commands
+
+rf, read_file: rf File
+ Returns the contents of File as a String; error if File does not exist.
+
+wf, write_file: wf File String
+ Writes String into File; File is created if it does not exist.
+ N.B. the command overwrites File without a warning.
+
+af, append_file: af File
+ Writes String into the end of File; File is created if it does not exist.
+
+* tg, transform_grammar: tg File
+ Reads File, parses as a grammar,
+ but instead of compiling further, prints it.
+ The environment is not changed. When parsing the grammar, the same file
+ name suffixes are supported as in the i command.
+ HINT: use this command to print the grammar in
+ another format (the -printer flag); pipe it to wf to save this format.
+ flags:
+ -printer (only -printer=latex supported currently)
+
+* cl, convert_latex: cl File
+ Reads File, which is expected to be in LaTeX form.
+ Three environments are treated in special ways:
+ \begGF - \end{verbatim}, which contains GF judgements,
+ \begTGF - \end{verbatim}, which contains a GF expression (displayed)
+ \begInTGF - \end{verbatim}, which contains a GF expressions (inlined).
+ Moreover, certain macros should be included in the file; you can
+ get those macros by applying 'tg -printer=latex foo.gf' to any grammar
+ foo.gf. Notice that the same File can be imported as a GF grammar,
+ consisting of all the judgements in \begGF environments.
+ HINT: pipe with 'wf Foo.tex' to generate a new Latex file.
+
+sa, speak_aloud: sa String
+ Uses the Flite speech generator to produce speech for String.
+ Works for American English spelling.
+ examples:
+ h | sa -- listen to the list of commands
+ gr -cat=S | l | sa -- generate a random sentence and speak it aloud
+
+si, speech_input: si
+ Uses an ATK speech recognizer to get speech input.
+ flags:
+ -lang: The grammar to use with the speech recognizer.
+ -cat: The grammar category to get input in.
+ -language: Use acoustic model and dictionary for this language.
+ -number: The number of utterances to recognize.
+
+h, help: h Command?
+ Displays the paragraph concerning the command from this help file.
+ Without the argument, shows the first lines of all paragraphs.
+ options
+ -all show the whole help file
+ -defs show user-defined commands and terms
+ -FLAG show the values of FLAG (works for grammar-independent flags)
+ examples:
+ h print_grammar -- show all information on the pg command
+
+q, quit: q
+ Exits GF.
+ HINT: you can use 'ph | wf history' to save your session.
+
+!, system_command: ! String
+ Issues a system command. No value is returned to GF.
+ example:
+ ! ls
+
+?, system_command: ? String
+ Issues a system command that receives its arguments from GF pipe
+ and returns a value to GF.
+ example:
+ h | ? 'wc -l' | p -cat=Num
+
+
+-- Flags. The availability of flags is defined separately for each command.
+
+-cat, category in which parsing is performed.
+ The default is S.
+
+-depth, the search depth in e.g. random generation.
+ The default depends on application.
+
+-filter, operation performed on a string. The default is identity.
+ -filter=identity no change
+ -filter=erase erase the text
+ -filter=take100 show the first 100 characters
+ -filter=length show the length of the string
+ -filter=text format as text (punctuation, capitalization)
+ -filter=code format as code (spacing, indentation)
+
+-lang, grammar used when executing a grammar-dependent command.
+ The default is the last-imported grammar.
+
+-language, voice used by Festival as its --language flag in the sa command.
+ The default is system-dependent.
+
+-length, the maximum number of characters shown of a string.
+ The default is unlimited.
+
+-lexer, tokenization transforming a string into lexical units for a parser.
+ The default is words.
+ -lexer=words tokens are separated by spaces or newlines
+ -lexer=literals like words, but GF integer and string literals recognized
+ -lexer=vars like words, but "x","x_...","$...$" as vars, "?..." as meta
+ -lexer=chars each character is a token
+ -lexer=code use Haskell's lex
+ -lexer=codevars like code, but treat unknown words as variables, ?? as meta
+ -lexer=textvars like text, but treat unknown words as variables, ?? as meta
+ -lexer=text with conventions on punctuation and capital letters
+ -lexer=codelit like code, but treat unknown words as string literals
+ -lexer=textlit like text, but treat unknown words as string literals
+ -lexer=codeC use a C-like lexer
+ -lexer=ignore like literals, but ignore unknown words
+ -lexer=subseqs like ignore, but then try all subsequences from longest
+
+-number, the maximum number of generated items in a list.
+ The default is unlimited.
+
+-optimize, optimization on generated code.
+ The default is share for concrete, none for resource modules.
+ Each of the flags can have the suffix _subs, which performs
+ common subexpression elimination after the main optimization.
+ Thus, -optimize=all_subs is the most aggressive one. The _subs
+ strategy only works in GFC, and applies therefore in concrete but
+ not in resource modules.
+ -optimize=share share common branches in tables
+ -optimize=parametrize first try parametrize then do share with the rest
+ -optimize=values represent tables as courses-of-values
+ -optimize=all first try parametrize then do values with the rest
+ -optimize=none no optimization
+
+-parser, parsing strategy. The default is chart. If -cfg or -mcfg are
+ selected, only bottomup and topdown are recognized.
+ -parser=chart bottom-up chart parsing
+ -parser=bottomup a more up to date bottom-up strategy
+ -parser=topdown top-down strategy
+ -parser=old an old bottom-up chart parser
+
+-printer, format in which the grammar is printed. The default is
+ gfc. Those marked with M are (only) available for pm, the rest
+ for pg.
+ -printer=gfc GFC grammar
+ -printer=gf GF grammar
+ -printer=old old GF grammar
+ -printer=cf context-free grammar, with profiles
+ -printer=bnf context-free grammar, without profiles
+ -printer=lbnf labelled context-free grammar for BNF Converter
+ -printer=plbnf grammar for BNF Converter, with precedence levels
+ *-printer=happy source file for Happy parser generator (use lbnf!)
+ -printer=haskell abstract syntax in Haskell, with transl to/from GF
+ -printer=haskell_gadt abstract syntax GADT in Haskell, with transl to/from GF
+ -printer=morpho full-form lexicon, long format
+ *-printer=latex LaTeX file (for the tg command)
+ -printer=fullform full-form lexicon, short format
+ *-printer=xml XML: DTD for the pg command, object for st
+ -printer=old old GF: file readable by GF 1.2
+ -printer=stat show some statistics of generated GFC
+ -printer=probs show probabilities of all functions
+ -printer=gsl Nuance GSL speech recognition grammar
+ -printer=jsgf Java Speech Grammar Format
+ -printer=jsgf_sisr_old Java Speech Grammar Format with semantic tags in
+ SISR WD 20030401 format
+ -printer=srgs_abnf SRGS ABNF format
+ -printer=srgs_abnf_non_rec SRGS ABNF format, without any recursion.
+ -printer=srgs_abnf_sisr_old SRGS ABNF format, with semantic tags in
+ SISR WD 20030401 format
+ -printer=srgs_xml SRGS XML format
+ -printer=srgs_xml_non_rec SRGS XML format, without any recursion.
+ -printer=srgs_xml_prob SRGS XML format, with weights
+ -printer=srgs_xml_sisr_old SRGS XML format, with semantic tags in
+ SISR WD 20030401 format
+ -printer=vxml Generate a dialogue system in VoiceXML.
+ -printer=slf a finite automaton in the HTK SLF format
+ -printer=slf_graphviz the same automaton as slf, but in Graphviz format
+ -printer=slf_sub a finite automaton with sub-automata in the
+ HTK SLF format
+ -printer=slf_sub_graphviz the same automaton as slf_sub, but in
+ Graphviz format
+ -printer=fa_graphviz a finite automaton with labelled edges
+ -printer=regular a regular grammar in a simple BNF
+ -printer=unpar a gfc grammar with parameters eliminated
+ -printer=functiongraph abstract syntax functions in 'dot' format
+ -printer=typegraph abstract syntax categories in 'dot' format
+ -printer=transfer Transfer language datatype (.tr file format)
+ -printer=cfg-prolog M cfg in prolog format (also pg)
+ -printer=gfc-prolog M gfc in prolog format (also pg)
+ -printer=gfcm M gfcm file (default for pm)
+ -printer=graph M module dependency graph in 'dot' (graphviz) format
+ -printer=header M gfcm file with header (for GF embedded in Java)
+ -printer=js M JavaScript type annotator and linearizer
+ -printer=mcfg-prolog M mcfg in prolog format (also pg)
+ -printer=missing M the missing linearizations of each concrete
+
+-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)
+
+-transform, transformation performed on a syntax tree. The default is identity.
+ -transform=identity no change
+ -transform=compute compute by using definitions in the grammar
+ -transform=nodup return the term only if it has no constants duplicated
+ -transform=nodupatom return the term only if it has no atomic constants duplicated
+ -transform=typecheck return the term only if it is type-correct
+ -transform=solve solve metavariables as derived refinements
+ -transform=context solve metavariables by unique refinements as variables
+ -transform=delete replace the term by metavariable
+
+-unlexer, untokenization transforming linearization output into a string.
+ The default is unwords.
+ -unlexer=unwords space-separated token list (like unwords)
+ -unlexer=text format as text: punctuation, capitals, paragraph
+ -unlexer=code format as code (spacing, indentation)
+ -unlexer=textlit like text, but remove string literal quotes
+ -unlexer=codelit like code, but remove string literal quotes
+ -unlexer=concat remove all spaces
+ -unlexer=bind like identity, but bind at "&+"
+
+-mark, marking of parts of tree in linearization. The default is none.
+ -mark=metacat append "+CAT" to every metavariable, showing its category
+ -mark=struct show tree structure with brackets
+ -mark=java show tree structure with XML tags (used in gfeditor)
+
+-coding, Some grammars are in UTF-8, some in isolatin-1.
+ If the letters ä (a-umlaut) and ö (o-umlaut) look strange, either
+ change your terminal to isolatin-1, or rewrite the grammar with
+ 'pg -utf8'.
+
+-- *: Commands and options marked with * are not currently implemented.
diff --git a/src-2.9/INSTALL b/src-2.9/INSTALL
new file mode 100644
index 000000000..ef7949b07
--- /dev/null
+++ b/src-2.9/INSTALL
@@ -0,0 +1,93 @@
+To make and install GF (Updated for version 2.4).
+
+1. Unpack GF and go to the source directory (the place where this
+ INSTALL file is - so you have probably done this already!)
+
+ tar xvfz GF-2.4.tgz
+ cd GF-2.4/src
+
+3. Make sure you have GHC (Glasgow Haskell Compiler), version 6.4 or later.
+ In Windows, you also need Cygwin.
+
+ ghc --version
+
+4. If you are building the darcs version, run autoconf (in src/):
+
+ autoconf
+
+5. Run configure
+
+ ./configure
+
+ If you want to install the GF somewhere other than /usr/local, use
+ the --prefix flag. E.g.
+
+ ./configure --prefix=/usr
+
+ To compile on Chalmers Solaris systems using VCS, use this configuration:
+
+ ./configure CPPFLAGS="`lib__readline -I` `lib__ncurses -I`" LDFLAGS="`lib__readline -l` `lib__ncurses -l`"
+
+ If you experience problems with readline, try:
+
+ ./configure --with-readline=no
+
+ You may need to run "make clean" after ./configure when you change the
+ readline setting.
+
+6. Compile with GNU make:
+
+ make
+
+ or
+
+ gmake
+
+ (if your system has a proprietary make)
+
+ The binary is sent to the file GF/bin/gf .
+
+7. Move files to their right places:
+
+ make install
+
+8. To run GF, the following environment variables must be set:
+
+ GFHOME the GF directory, e.g., "$HOME/project/GF-2.4"
+ GF_LIB_PATH the GF library directory, e.g,, "$HOME/project/GF-2.4/lib"
+
+ (Usually, you do this in ~/.login, if your shell is any *csh,
+ or in ~/.profile, if your shell is either of sh, ksh, zsh or bash.
+ Afterwards, you have to start a login shell to have the settings available.)
+
+9. For a quick test:
+ Start gf, load a grammar and parse a string:
+
+ cd $GFHOME/examples/tutorial/food
+ gf FoodIta.gf FoodEng.gf
+
+ -- when gf has started and shows the prompt >:
+
+ > parse "this cheese is very very Italian" | tree_bank
+
+ -- this is the response from GF:
+ Is (This Cheese) (Very (Very Italian))
+ this cheese is very very Italian
+ questo formaggio è molto molto italiano
+
+10. If you want to run the Java GUI, go back to $GFHOME/src directory
+ and also do
+
+ make install-java
+
+ Test the GUI with some grammars:
+
+ cd ../examples/letter
+ gf j) GFEditor.send("> "+String.valueOf(i-j));
+ else GFEditor.send("< "+String.valueOf(j-i));
+ }
+ }
+ });
+
+ tree.setCellRenderer(new MyRenderer());
+ tree.setShowsRootHandles(true);
+ setPreferredSize(new Dimension(200, 100));
+ JScrollPane scrollPane = new JScrollPane(tree);
+ setLayout(new GridLayout(1,0));
+ add(scrollPane);
+ }
+
+ /** Remove all nodes except the root node. */
+ public void clear() {
+ rootNode.removeAllChildren();
+ treeModel.reload();
+ }
+
+ /** Remove the currently selected node. */
+ public void removeCurrentNode() {
+ TreePath currentSelection = tree.getSelectionPath();
+ if (currentSelection != null) {
+ DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode)
+ (currentSelection.getLastPathComponent());
+ MutableTreeNode parent = (MutableTreeNode)(currentNode.getParent());
+ if (parent != null) {
+ treeModel.removeNodeFromParent(currentNode);
+ return;
+ }
+ }
+
+ // Either there was no selection, or the root was selected.
+ toolkit.beep();
+ }
+
+ /** Add child to the currently selected node. */
+ public DefaultMutableTreeNode addObject(Object child) {
+ DefaultMutableTreeNode parentNode = null;
+ TreePath parentPath = tree.getSelectionPath();
+
+ if (parentPath == null) {
+ parentNode = rootNode;
+ } else {
+ parentNode = (DefaultMutableTreeNode)
+ (parentPath.getLastPathComponent());
+ }
+
+ return addObject(parentNode, child, true);
+ }
+
+ public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
+ Object child) {
+ return addObject(parent, child, false);
+ }
+
+ public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
+ Object child,
+ boolean shouldBeVisible) {
+ DefaultMutableTreeNode childNode =
+ new DefaultMutableTreeNode(child);
+
+ if (parent == null) {
+ parent = rootNode;
+ }
+
+ treeModel.insertNodeInto(childNode, parent,
+ parent.getChildCount());
+
+ // Make sure the user can see the lovely new node.
+ if (shouldBeVisible) {
+ tree.scrollPathToVisible(new TreePath(childNode.getPath()));
+ }
+ return childNode;
+ }
+
+ class MyTreeModelListener implements TreeModelListener {
+ public void treeNodesChanged(TreeModelEvent e) {
+ DefaultMutableTreeNode node;
+ node = (DefaultMutableTreeNode)
+ (e.getTreePath().getLastPathComponent());
+
+ /*
+ * If the event lists children, then the changed
+ * node is the child of the node we've already
+ * gotten. Otherwise, the changed node and the
+ * specified node are the same.
+ */
+ try {
+ int index = e.getChildIndices()[0];
+ node = (DefaultMutableTreeNode)
+ (node.getChildAt(index));
+ } catch (NullPointerException exc) {}
+
+ if (GFEditor.debug) System.out.println
+ ("The user has finished editing the node.");
+ if (GFEditor.debug) System.out.println(
+ "New value: " + node.getUserObject());
+ }
+ public void treeNodesInserted(TreeModelEvent e) {
+ }
+ public void treeNodesRemoved(TreeModelEvent e) {
+ }
+ public void treeStructureChanged(TreeModelEvent e) {
+ }
+ }
+
+ private class MyRenderer extends DefaultTreeCellRenderer {
+ ImageIcon tutorialIcon;
+
+ public MyRenderer() {
+ tutorialIcon = new ImageIcon("images/middle.gif");
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus) {
+
+ super.getTreeCellRendererComponent(
+ tree, value, sel,
+ expanded, leaf, row,
+ hasFocus);
+ if (leaf && isTutorialBook(value))
+ setIcon(tutorialIcon);
+
+ return this;
+ }
+ protected boolean isTutorialBook(Object value) {
+ DefaultMutableTreeNode node =
+ (DefaultMutableTreeNode)value;
+ String nodeInfo =
+ (String)(node.getUserObject());
+
+ if (nodeInfo.indexOf("?") >= 0) {
+ return true;
+ }
+
+ return false;
+ }
+
+ }//class
+
+ class PopupListener extends MouseAdapter {
+ public void mousePressed(MouseEvent e) {
+ int selRow = tree.getRowForLocation(e.getX(), e.getY());
+ tree.setSelectionRow(selRow);
+ if (GFEditor.debug) System.out.println("selection changed!");
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ if (GFEditor.debug) System.out.println("mouse released!");
+ maybeShowPopup(e);
+ }
+ }
+ void maybeShowPopup(MouseEvent e) {
+ if (GFEditor.debug) System.out.println("may be!");
+ if (e.isPopupTrigger()) {
+ m=e;
+ timer.start();
+ }
+ }
+ void addMenuItem(String name){
+ menuItem = new JMenuItem(name);
+ menuItem.addActionListener(this);
+ popup.add(menuItem);
+
+ }
+
+ public void actionPerformed(ActionEvent ae)
+ {
+ if (ae.getSource()==timer){
+ if (GFEditor.debug) System.out.println("changing menu!");
+ popup.removeAll();
+ for (int i = 0; ij) GFEditor2.send("> "+String.valueOf(i-j));
+ else GFEditor2.send("< "+String.valueOf(j-i));
+ }
+ }
+ });
+
+ tree.setCellRenderer(new MyRenderer());
+ tree.setShowsRootHandles(true);
+ setPreferredSize(new Dimension(200, 100));
+ JScrollPane scrollPane = new JScrollPane(tree);
+ setLayout(new GridLayout(1,0));
+ add(scrollPane);
+ }
+
+ /** Remove all nodes except the root node. */
+ public void clear() {
+ rootNode.removeAllChildren();
+ treeModel.reload();
+ }
+
+ /** Remove the currently selected node. */
+ public void removeCurrentNode() {
+ TreePath currentSelection = tree.getSelectionPath();
+ if (currentSelection != null) {
+ DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode)
+ (currentSelection.getLastPathComponent());
+ MutableTreeNode parent = (MutableTreeNode)(currentNode.getParent());
+ if (parent != null) {
+ treeModel.removeNodeFromParent(currentNode);
+ return;
+ }
+ }
+
+ // Either there was no selection, or the root was selected.
+ toolkit.beep();
+ }
+
+ /** Add child to the currently selected node. */
+ public DefaultMutableTreeNode addObject(Object child) {
+ DefaultMutableTreeNode parentNode = null;
+ TreePath parentPath = tree.getSelectionPath();
+
+ if (parentPath == null) {
+ parentNode = rootNode;
+ } else {
+ parentNode = (DefaultMutableTreeNode)
+ (parentPath.getLastPathComponent());
+ }
+
+ return addObject(parentNode, child, true);
+ }
+
+ public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
+ Object child) {
+ return addObject(parent, child, false);
+ }
+
+ public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
+ Object child,
+ boolean shouldBeVisible) {
+ DefaultMutableTreeNode childNode =
+ new DefaultMutableTreeNode(child);
+
+ if (parent == null) {
+ parent = rootNode;
+ }
+
+ treeModel.insertNodeInto(childNode, parent,
+ parent.getChildCount());
+
+ // Make sure the user can see the lovely new node.
+ if (shouldBeVisible) {
+ tree.scrollPathToVisible(new TreePath(childNode.getPath()));
+ }
+ return childNode;
+ }
+
+ class MyTreeModelListener implements TreeModelListener {
+ public void treeNodesChanged(TreeModelEvent e) {
+ DefaultMutableTreeNode node;
+ node = (DefaultMutableTreeNode)
+ (e.getTreePath().getLastPathComponent());
+
+ /*
+ * If the event lists children, then the changed
+ * node is the child of the node we've already
+ * gotten. Otherwise, the changed node and the
+ * specified node are the same.
+ */
+ try {
+ int index = e.getChildIndices()[0];
+ node = (DefaultMutableTreeNode)
+ (node.getChildAt(index));
+ } catch (NullPointerException exc) {}
+
+ if (GFEditor2.debug) System.out.println
+ ("The user has finished editing the node.");
+ if (GFEditor2.debug) System.out.println(
+ "New value: " + node.getUserObject());
+ }
+ public void treeNodesInserted(TreeModelEvent e) {
+ }
+ public void treeNodesRemoved(TreeModelEvent e) {
+ }
+ public void treeStructureChanged(TreeModelEvent e) {
+ }
+ }
+
+ private class MyRenderer extends DefaultTreeCellRenderer {
+ ImageIcon tutorialIcon;
+
+ public MyRenderer() {
+ tutorialIcon = new ImageIcon("images/middle.gif");
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus) {
+
+ super.getTreeCellRendererComponent(
+ tree, value, sel,
+ expanded, leaf, row,
+ hasFocus);
+ if (leaf && isTutorialBook(value))
+ setIcon(tutorialIcon);
+
+ return this;
+ }
+ protected boolean isTutorialBook(Object value) {
+ DefaultMutableTreeNode node =
+ (DefaultMutableTreeNode)value;
+ String nodeInfo =
+ (String)(node.getUserObject());
+
+ if (nodeInfo.indexOf("?") >= 0) {
+ return true;
+ }
+
+ return false;
+ }
+
+ }//class
+
+ class PopupListener extends MouseAdapter {
+ public void mousePressed(MouseEvent e) {
+ int selRow = tree.getRowForLocation(e.getX(), e.getY());
+ tree.setSelectionRow(selRow);
+ if (GFEditor2.debug) System.out.println("selection changed!");
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ if (GFEditor2.debug) System.out.println("mouse released!");
+ maybeShowPopup(e);
+ }
+ }
+ void maybeShowPopup(MouseEvent e) {
+ if (GFEditor2.debug) System.out.println("may be!");
+ if (e.isPopupTrigger()) {
+ m = e;
+ timer.start();
+ }
+ }
+ void addMenuItem(String name){
+ menuItem = new JMenuItem(name);
+ menuItem.addActionListener(this);
+ popup.add(menuItem);
+
+ }
+
+ public void actionPerformed(ActionEvent ae)
+ {
+ if (ae.getSource()==timer){
+ if (GFEditor2.debug) System.out.println("changing menu!");
+ popup.removeAll();
+ for (int i = 0; i");
+ private JButton rightMeta = new JButton(">?");
+ private JButton read = new JButton("Read");
+ // private JButton parse = new JButton("Parse");
+ // private JButton term = new JButton("Term");
+ private JButton alpha = new JButton("Alpha");
+ private JButton random = new JButton("Random");
+ private JButton undo = new JButton("Undo");
+
+ private JPanel inputPanel = new JPanel();
+ private JPanel inputPanel2 = new JPanel();
+ private JPanel inputPanel3 = new JPanel();
+ private JButton ok = new JButton("OK");
+ private JButton cancel = new JButton("Cancel");
+ private JTextField inputField = new JTextField();
+ private JLabel inputLabel = new JLabel("Read: ");
+ private JButton browse = new JButton("Browse...");
+ private ButtonGroup readGroup = new ButtonGroup();
+ private JRadioButton termReadButton = new JRadioButton("Term");
+ private JRadioButton stringReadButton = new JRadioButton("String");
+
+ private JDialog dialog;
+
+ private static JComboBox menu = new JComboBox(newMenu);
+ private JComboBox filter = new JComboBox(filterMenu);
+ private JComboBox modify = new JComboBox(modifyMenu);
+ // private JComboBox mode = new JComboBox(modeMenu);
+
+ private JPanel downPanel = new JPanel();
+ private JSplitPane treePanel;
+ private JPanel upPanel = new JPanel();
+ private JPanel middlePanel = new JPanel();
+ private JPanel middlePanelUp = new JPanel();
+ private JPanel middlePanelDown = new JPanel();
+ private JSplitPane centerPanel;
+ private static JFrame gui2 = new JFrame();
+ private JPanel centerPanel2= new JPanel();
+ private JPanel centerPanelDown = new JPanel();
+ private JScrollPane outputPanelDown = new JScrollPane(list);
+ private JScrollPane outputPanelCenter = new JScrollPane(output);
+ private JPanel outputPanelUp = new JPanel();
+ private JPanel statusPanel = new JPanel();
+ private static JLabel statusLabel = new JLabel(status);
+ private Container cp;
+
+ private static JMenuBar menuBar= new JMenuBar();;
+ private static ButtonGroup menuGroup = new ButtonGroup();
+ private JMenu viewMenu= new JMenu("View");
+ private JMenu submenu= new JMenu("language");
+ private JMenu modeMenu= new JMenu("Menus");
+ private static JMenu langMenu= new JMenu("Languages");
+ private static JMenu fileMenu= new JMenu("File");
+ private JRadioButtonMenuItem rbMenuItem;
+ private JRadioButtonMenuItem rbMenuItemLong;
+ // private JRadioButtonMenuItem rbMenuItemAbs;
+ private JRadioButtonMenuItem rbMenuItemUnTyped;
+ private static JMenuItem fileMenuItem;
+ private static JCheckBoxMenuItem cbMenuItem;
+ private static RadioListener myListener ;
+ private static ButtonGroup group = new ButtonGroup();
+ private static ButtonGroup languageGroup = new ButtonGroup();
+
+ public GFEditor()
+ {
+ this.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ endProgram();
+ }
+ });
+ setJMenuBar(menuBar);
+ setTitle("GF Syntax Editor");
+ viewMenu.setToolTipText("View settings");
+ fileMenu.setToolTipText("Main operations");
+ langMenu.setToolTipText("Language settings");
+ menuBar.add(fileMenu);
+ menuBar.add(langMenu);
+ menuBar.add(viewMenu);
+ menuBar.add(modeMenu);
+
+ cbMenuItem = new JCheckBoxMenuItem("Tree");
+ cbMenuItem.setActionCommand("showTree");
+ myListener = new RadioListener();
+ cbMenuItem.addActionListener(myListener);
+ cbMenuItem.setSelected(true);
+ viewMenu.add(cbMenuItem);
+ viewMenu.addSeparator();
+
+ fileMenuItem = new JMenuItem("Open...");
+ fileMenuItem.setActionCommand("open");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenuItem = new JMenuItem("New Topic...");
+ fileMenuItem.setActionCommand("newTopic");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenuItem = new JMenuItem("Reset");
+ fileMenuItem.setActionCommand("reset");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenuItem = new JMenuItem("Save As...");
+ fileMenuItem.setActionCommand("save");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenu.addSeparator();
+ fileMenuItem = new JMenuItem("Exit");
+ fileMenuItem.setActionCommand("quit");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+
+ rbMenuItem = new JRadioButtonMenuItem("One window");
+ rbMenuItem.setActionCommand("combine");
+ rbMenuItem.addActionListener(myListener);
+ rbMenuItem.setSelected(true);
+/* rbMenuItem.setMnemonic(KeyEvent.VK_R);
+ rbMenuItem.setAccelerator(KeyStroke.getKeyStroke(
+ KeyEvent.VK_1, ActionEvent.ALT_MASK));
+ rbMenuItem.getAccessibleContext().setAccessibleDescription(
+ "This doesn't really do anything");
+*/
+ menuGroup.add(rbMenuItem);
+ viewMenu.add(rbMenuItem);
+
+ rbMenuItem = new JRadioButtonMenuItem("Split windows");
+ rbMenuItem.setMnemonic(KeyEvent.VK_O);
+ rbMenuItem.setActionCommand("split");
+ rbMenuItem.addActionListener(myListener);
+ menuGroup.add(rbMenuItem);
+ viewMenu.add(rbMenuItem);
+
+ modeMenu.add(submenu);
+
+ /* rbMenuItemAbs = new JRadioButtonMenuItem("Abstract");
+ rbMenuItemAbs.setActionCommand("Abstract");
+ rbMenuItemAbs.addActionListener(myListener);
+ languageGroup.add(rbMenuItemAbs);
+ */
+
+ modeMenu.addSeparator();
+ menuGroup = new ButtonGroup();
+ rbMenuItemLong = new JRadioButtonMenuItem("long");
+ rbMenuItemLong.setActionCommand("long");
+ rbMenuItemLong.setSelected(true);
+ rbMenuItemLong.addActionListener(myListener);
+ menuGroup.add(rbMenuItemLong);
+ modeMenu.add(rbMenuItemLong);
+ rbMenuItem = new JRadioButtonMenuItem("short");
+ rbMenuItem.setActionCommand("short");
+ rbMenuItem.addActionListener(myListener);
+ menuGroup.add(rbMenuItem);
+ modeMenu.add(rbMenuItem);
+ modeMenu.addSeparator();
+
+ menuGroup = new ButtonGroup();
+ rbMenuItem = new JRadioButtonMenuItem("typed");
+ rbMenuItem.setActionCommand("typed");
+ rbMenuItem.addActionListener(myListener);
+ rbMenuItem.setSelected(false);
+ menuGroup.add(rbMenuItem);
+ modeMenu.add(rbMenuItem);
+ rbMenuItemUnTyped = new JRadioButtonMenuItem("untyped");
+ rbMenuItemUnTyped.setSelected(true);
+ rbMenuItemUnTyped.setActionCommand("untyped");
+ rbMenuItemUnTyped.addActionListener(myListener);
+ menuGroup.add(rbMenuItemUnTyped);
+ modeMenu.add(rbMenuItemUnTyped);
+
+ cp = getContentPane();
+ cp.setLayout(new BorderLayout());
+ output.setToolTipText("Linearizations' display area");
+ output.setEditable(false);
+ output.setLineWrap(true);
+ output.setWrapStyleWord(true);
+// output.setSelectionColor(Color.green);
+ output.setSelectionColor(Color.white);
+// output.setFont(new Font("Arial Unicode MS", Font.PLAIN, 17));
+ output.setFont(new Font(null, Font.PLAIN, 17));
+// System.out.println(output.getFont().getFontName());
+ gfCommand.setToolTipText("Sending a command to GF");
+ read.setToolTipText("Refining with term or linearization from typed string or file");
+ modify.setToolTipText("Choosing a linearization method");
+ alpha.setToolTipText("Performing alpha-conversion");
+ random.setToolTipText("Generating random refinement");
+ undo.setToolTipText("Going back to the previous state");
+ downPanel.add(gfCommand);
+ //downPanel.add(parse);
+ //downPanel.add(term);
+ downPanel.add(read);
+ downPanel.add(modify);
+ downPanel.add(alpha);
+ downPanel.add(random);
+ downPanel.add(undo);
+
+ leftMeta.setToolTipText("Moving the focus to the previous metavariable");
+ rightMeta.setToolTipText("Moving the focus to the next metavariable");
+ left.setToolTipText("Moving the focus to the previous term");
+ right.setToolTipText("Moving the focus to the next term");
+ top.setToolTipText("Moving the focus to the top term");
+ middlePanelUp.add(leftMeta);
+ middlePanelUp.add(left);
+ middlePanelUp.add(top);
+ middlePanelUp.add(right);
+ middlePanelUp.add(rightMeta);
+ middlePanelDown.add(new JLabel("Select Action on Subterm"));
+ middlePanel.setLayout(new BorderLayout());
+ middlePanel.add(middlePanelUp, BorderLayout.NORTH);
+ middlePanel.add(middlePanelDown, BorderLayout.CENTER);
+
+ menu.setToolTipText("The list of available categories to start editing");
+ open.setToolTipText("Reading both a new environment and an editing object from file. Current editing will be discarded");
+ save.setToolTipText("Writing the current editing object to file in the term or text format");
+ grammar.setToolTipText("Current Topic");
+ newTopic.setToolTipText("Reading a new environment from file. Current editing will be discarded.");
+ upPanel.add(grammar);
+ upPanel.add(menu);
+ upPanel.add(open);
+ upPanel.add(save);
+ upPanel.add(newTopic);
+
+ filter.setToolTipText("Choosing the linearization representation format");
+ modeMenu.setToolTipText("Choosing the refinement options' representation");
+ statusLabel.setToolTipText("The current focus type");
+ list.setToolTipText("The list of current refinment options");
+ tree.setToolTipText("The abstract syntax tree representation of the current editing object");
+ upPanel.add(filter);
+ //upPanel.add(mode);
+ populateTree(tree);
+ outputPanelUp.setLayout(new BorderLayout());
+ outputPanelUp.add(outputPanelCenter, BorderLayout.CENTER);
+ outputPanelUp.add(statusPanel, BorderLayout.SOUTH);
+ statusPanel.setLayout(new GridLayout(1,1));
+ statusPanel.add(statusLabel);
+ treePanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
+ tree, outputPanelUp);
+ treePanel.setDividerSize(5);
+ treePanel.setDividerLocation(100);
+ centerPanel2.setLayout(new BorderLayout());
+ gui2.setSize(350,150);
+ gui2.setTitle("Select Action on Subterm");
+ gui2.setLocationRelativeTo(treePanel);
+ centerPanelDown.setLayout(new BorderLayout());
+ centerPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
+ treePanel, centerPanelDown);
+ centerPanel.addKeyListener(tree);
+ centerPanel.setOneTouchExpandable(true);
+ centerPanelDown.add(middlePanel, BorderLayout.NORTH);
+ centerPanelDown.add(outputPanelDown, BorderLayout.CENTER);
+ cp.add(centerPanel, BorderLayout.CENTER);
+ cp.add(upPanel, BorderLayout.NORTH);
+ cp.add(downPanel, BorderLayout.SOUTH);
+
+ list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+
+ MouseListener mouseListener = new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ listAction(list.locationToIndex(e.getPoint()));
+ }
+ }
+ };
+ list.addMouseListener(mouseListener);
+ list.addKeyListener(this);
+ menu.addActionListener(this);
+ save.addActionListener(this);
+ open.addActionListener(this);
+ newTopic.addActionListener(this);
+ gfCommand.addActionListener(this);
+
+ filter.addActionListener(this);
+ filter.setMaximumRowCount(9);
+ leftMeta.addActionListener(this);
+ left.addActionListener(this);
+
+ menu.setFocusable(false);
+ save.setFocusable(false);
+ save.setActionCommand("save");
+ open.setFocusable(false);
+ open.setActionCommand("open");
+ newTopic.setFocusable(false);
+ newTopic.setActionCommand("newTopic");
+ gfCommand.setFocusable(false);
+
+ filter.setFocusable(false);
+ leftMeta.setFocusable(false);
+ left.setFocusable(false);
+
+ top.addActionListener(this);
+ right.addActionListener(this);
+ rightMeta.addActionListener(this);
+ //parse.addActionListener(this);
+ //term.addActionListener(this);
+ read.addActionListener(this);
+ modify.addActionListener(this);
+ //mode.addActionListener(this);
+ alpha.addActionListener(this);
+ random.addActionListener(this);
+ undo.addActionListener(this);
+
+ top.setFocusable(false);
+ right.setFocusable(false);
+ rightMeta.setFocusable(false);
+ //parse.setFocusable(false);
+ //term.setFocusable(false);
+ read.setFocusable(false);
+ modify.setFocusable(false);
+ //mode.setFocusable(false);
+ alpha.setFocusable(false);
+ random.setFocusable(false);
+ undo.setFocusable(false);
+
+ output.addKeyListener(tree);
+ setSize(800,730);
+ outputPanelUp.setPreferredSize(new Dimension(500,300));
+ treePanel.setDividerLocation(0.3);
+ nodeTable.put(new TreePath(DynamicTree.rootNode.getPath()), new Integer(0));
+ setVisible(true);
+
+ JRadioButton termButton = new JRadioButton("Term");
+ termButton.setActionCommand("term");
+ termButton.setSelected(true);
+ JRadioButton linButton = new JRadioButton("Text");
+ linButton.setActionCommand("lin");
+ // Group the radio buttons.
+ group.add(linButton);
+ group.add(termButton);
+ JPanel buttonPanel = new JPanel();
+ buttonPanel.setPreferredSize(new Dimension(70, 70));
+ buttonPanel.add(new JLabel("Format:"));
+ buttonPanel.add(linButton);
+ buttonPanel.add(termButton);
+ fc1.setAccessory(buttonPanel);
+
+ termReadButton.setActionCommand("term");
+ stringReadButton.setSelected(true);
+ stringReadButton.setActionCommand("lin");
+ // Group the radio buttons.
+ readGroup.add(stringReadButton);
+ readGroup.add(termReadButton);
+ JPanel readButtonPanel = new JPanel();
+ readButtonPanel.setLayout(new GridLayout(3,1));
+ readButtonPanel.setPreferredSize(new Dimension(70, 70));
+ readButtonPanel.add(new JLabel("Format:"));
+ readButtonPanel.add(stringReadButton);
+ readButtonPanel.add(termReadButton);
+ dialog= new JDialog(this, "Input");
+ dialog.setLocationRelativeTo(this);
+ dialog.getContentPane().add(inputPanel);
+ inputPanel.setLayout(new BorderLayout(10,10));
+ inputPanel3.setLayout(new GridLayout(2,1,5,5));
+ inputPanel3.add(inputLabel);
+ inputPanel3.add(inputField);
+ ok.addActionListener(this);
+ browse.addActionListener(this);
+ cancel.addActionListener(this);
+ inputField.setPreferredSize(new Dimension(300,23));
+ inputPanel.add(inputPanel3, BorderLayout.CENTER);
+ inputPanel.add(new JLabel(" "), BorderLayout.WEST);
+ inputPanel.add(readButtonPanel, BorderLayout.EAST);
+ inputPanel.add(inputPanel2, BorderLayout.SOUTH);
+ inputPanel2.add(ok);
+ inputPanel2.add(cancel);
+ inputPanel2.add(browse);
+ dialog.setSize(350,135);
+
+ try {
+ result = fromProc.readLine();
+ while(result != null) {
+ finished = false;
+ if (debug) System.out.println("1 "+result);
+ while (result.indexOf("gf")==-1){
+ outputString +=result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("1 "+result);
+ }
+ output.append(outputString);
+ while ((result.indexOf("newcat")==-1)&&(result.indexOf("8)
+ s+=result.trim();
+ else
+ s+=result;
+ }
+ }
+// if (s.charAt(0)!='d')
+// listModel.addElement("Refine " + s);
+// else
+ listModel.addElement(s);
+ s="";
+ //read /show
+ //read send
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ saveCommand();
+ // read /item
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ }
+ } catch(IOException e){ }
+ }
+
+ public static void saveCommand(){
+ if (newObject) commands.add(result);
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("9 "+result);
+ } catch(IOException e){ }
+ }
+
+ public void readLin(){
+ try {
+ linearization="";
+ linearization += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ while (result.indexOf("/linearization")==-1){
+ linearization += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ }
+ if (newObject) formLin();
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ } catch(IOException e){ }
+ }
+
+ public static void readTree(){
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ while (result.indexOf("/tree")==-1){
+ treeString += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ }
+ if (treeChanged && (newObject)) {
+ formTree(tree);
+ treeChanged = false;
+ }
+ treeString="";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ } catch(IOException e){ }
+ }
+
+ public static void readMessage(){
+ String s ="";
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("7 "+result);
+ while (result.indexOf("/message")==-1){
+ s += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("7 "+result);
+ }
+ if (s.length()>1)
+ output.append("-------------"+'\n'+s);
+ result = fromProc.readLine();
+ if (debug) System.out.println("7 "+result);
+ } catch(IOException e){ }
+ }
+
+ public void formNewMenu () {
+ boolean more = true;
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+
+ while (more){
+ if (result.indexOf("language")==-1) {
+ menu.addItem(result.substring(6));
+ }
+ else
+ more = false;
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("3 "+result);
+ if (result.indexOf("language")!=-1)
+ more = false;
+ result = fromProc.readLine();
+ if (debug) System.out.println("4 "+result);
+ }
+
+ more = true;
+ while (more){
+ if ((result.indexOf("/gf")==-1)&&(result.indexOf("lin")==-1)) {
+ //form lang and Menu menu:
+ cbMenuItem = new JCheckBoxMenuItem(result.substring(4));
+ if (debug) System.out.println ("menu item: "+result.substring(4));
+ cbMenuItem.setSelected(true);
+ cbMenuItem.setActionCommand("lang");
+ cbMenuItem.addActionListener(myListener);
+ langMenu.add(cbMenuItem);
+/* if ((result.substring(4)).equals("Abstract"))
+ {
+ submenu.add(rbMenuItemAbs);
+ if (selectedMenuLanguage.equals("Abstract"))
+ rbMenuItemAbs.setSelected(true);
+ languageGroup.add(rbMenuItemAbs);
+ }
+ else
+ {
+*/
+ rbMenuItem = new JRadioButtonMenuItem(result.substring(4));
+ rbMenuItem.setActionCommand(result.substring(4));
+ rbMenuItem.addActionListener(myListener);
+ languageGroup.add(rbMenuItem);
+ if ((result.substring(4)).equals(selectedMenuLanguage))
+ {
+ System.out.println("Selecting "+selectedMenuLanguage);
+ rbMenuItem.setSelected(true);
+ }
+
+ submenu.add(rbMenuItem);
+// }
+ }
+ else
+ more = false;
+ // read
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+ // read or
+ result = fromProc.readLine();
+ if (debug) System.out.println("3 "+result);
+ if ((result.indexOf("/gf")!=-1)||(result.indexOf("lin")!=-1))
+ more = false;
+ if (result.indexOf("/gf")!=-1)
+ finished = true;
+ // registering the file name:
+ if (result.indexOf("language")!=-1) {
+ String path = result.substring(result.indexOf('=')+1,
+ result.indexOf('>'));
+ path =path.substring(path.lastIndexOf('/')+1);
+ if (debug) System.out.println("name: "+path);
+ fileString +="--" + path +"\n";
+ if (path.lastIndexOf('.')!=path.indexOf('.'))
+ grammar.setText(path.substring(0,
+ path.indexOf('.')).toUpperCase()+" ");
+ }
+ result = fromProc.readLine();
+ if (debug) System.out.println("4 "+result);
+ }
+ System.out.println("languageGroupElement formed"+
+ languageGroup.getButtonCount());
+ langMenu.addSeparator();
+ fileMenuItem = new JMenuItem("Add...");
+ fileMenuItem.setActionCommand("import");
+ fileMenuItem.addActionListener(this);
+ langMenu.add(fileMenuItem);
+ // in order to get back in main in the beggining of while:
+ result = fromProc.readLine();
+ } catch(IOException e){ }
+ }
+
+ public void outputAppend(){
+ int i, j, k, l, l2, m;
+ l = result.indexOf("',i);
+ l2 = result.indexOf("focus");
+ if (l2!=-1){
+
+ // in case focus tag is cut into two lines:
+ if (l==-1) l=l2-7;
+
+ if (debug) System.out.println("form Lin1: "+result);
+ statusLabel.setText(" "+result.substring(i+5,j));
+ //cutting
+ result= result.substring(0,l)+result.substring(j+1);
+ i=result.indexOf("/focus",l);
+ if (debug) System.out.println("/ is at the position"+i);
+ j=result.indexOf('>',i);
+ k=result.length()-j;
+ if (debug) System.out.println("form Lin2: "+result);
+ m = output.getText().length();
+
+ //cutting
+ // in case focus tag is cut into two lines:
+ if (debug)
+ System.out.println("char at the previous position"+result.charAt(i-1));
+ if (result.charAt(i-1)!='<')
+ result= result.substring(0,i-8)+result.substring(j+1);
+ else
+ result= result.substring(0,i-1)+result.substring(j+1);
+ j= result.indexOf("');
+ String s = result.substring(ind+1,ind2);
+ result = lin.substring(0,lin.indexOf(""));
+ lin = lin.substring(lin.indexOf(""));
+ while (lin.length()>1) {
+ //check if the language is on
+ if (!visible) visible = true;
+ // in the list?
+ for (int i=0; i
+ lin = lin.substring(lin.indexOf('\n')+1);
+ // read lin or 'end'
+ if (lin.length()<1) break;
+
+ result = lin.substring(0,lin.indexOf('\n'));
+ lin = lin.substring(lin.indexOf('\n')+1);
+ if (result.indexOf("');
+ s = result.substring(ind+1,ind2);
+ result = lin.substring(0,lin.indexOf(""));
+ lin = lin.substring(lin.indexOf(""));
+ }
+ }
+ }
+
+ public void actionPerformed(ActionEvent ae)
+ {
+ boolean abs = true;
+ Object obj = ae.getSource();
+ if ( obj == menu ) {
+ if (!menu.getSelectedItem().equals("New"))
+ {
+ treeChanged = true;
+ send("n " + menu.getSelectedItem());
+ newObject = true;
+ menu.setSelectedIndex(0);
+ }
+ }
+ if ( obj == filter ) {
+ if (!filter.getSelectedItem().equals("Filter"))
+ {
+ send("f " + filter.getSelectedItem());
+ filter.setSelectedIndex(0);
+ }
+ }
+ if ( obj == modify ) {
+ if (!modify.getSelectedItem().equals("Modify"))
+ {
+ treeChanged = true;
+ send("c " + modify.getSelectedItem());
+ modify.setSelectedIndex(0);
+ }
+ }
+/* if ( obj == mode ) {
+ if (!mode.getSelectedItem().equals("Menus"))
+ {
+ send("o " + mode.getSelectedItem());
+ mode.setSelectedIndex(0);
+ }
+ }
+*/
+ // buttons and menu items:
+ try {
+ if (Class.forName("javax.swing.AbstractButton").isInstance(obj)) {
+ String name =((AbstractButton)obj).getActionCommand();
+
+ if ( name.equals("quit")) {
+ endProgram();
+ }
+
+ if ( name.equals("save") ) {
+
+ if (fc1.getChoosableFileFilters().length<2)
+ fc1.addChoosableFileFilter(new GrammarFilter());
+ int returnVal = fc1.showSaveDialog(GFEditor.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc1.getSelectedFile();
+ if (debug) System.out.println("saving ... ");
+
+ // checking if the abstract syntax is on:
+ for (int i=0; i0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+ submenu.removeAll();
+
+ File file = fc1.getSelectedFile();
+ // opening the file for editing :
+ if (debug) System.out.println("opening: "+ file.getPath().replace('\\','/'));
+ if (group.getSelection().getActionCommand().equals("term")) {
+ if (debug) System.out.println(" opening as a term ");
+ send("open "+ file.getPath().replace('\\','/'));
+ }
+ else {
+ if (debug) System.out.println(" opening as a linearization ");
+ send("openstring "+ file.getPath().replace('\\','/'));
+ }
+
+ fileString ="";
+ grammar.setText("No Topic ");
+ }
+ }
+
+ if ( name.equals("import") ) {
+ if (fc.getChoosableFileFilters().length<2)
+ fc.addChoosableFileFilter(new GrammarFilter());
+ int returnVal = fc.showOpenDialog(GFEditor.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc.getSelectedFile();
+ // importing a new language :
+ if (debug) System.out.println("importing: "+ file.getPath());
+
+ langMenu.removeAll();
+
+ AbstractButton ab = null;
+
+ while (languageGroup.getButtonCount()>0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+
+ submenu.removeAll();
+
+ menu.removeAllItems();
+ menu.addItem("New");
+ fileString ="";
+ send("i "+ file.getPath().replace('\\','/'));
+
+ }
+ }
+ if ( name.equals("newTopic") ) {
+ if (fc.getChoosableFileFilters().length<2)
+ fc.addChoosableFileFilter(new GrammarFilter());
+ int returnVal = fc.showOpenDialog(GFEditor.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ int n = JOptionPane.showConfirmDialog(this,
+ "This will dismiss the previous editing. Would you like to continue?",
+ "Starting a new topic", JOptionPane.YES_NO_OPTION);
+ if (n == JOptionPane.YES_OPTION){
+ File file = fc.getSelectedFile();
+ // importing a new grammar :
+ newObject = false;
+ statusLabel.setText(status);
+ listModel.clear();
+ tree.clear();
+ populateTree(tree);
+ menu.removeAllItems();
+ menu.addItem("New");
+ langMenu.removeAll();
+
+ AbstractButton ab = null;
+
+ while (languageGroup.getButtonCount()>0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+
+ selectedMenuLanguage = "Abstract";
+ rbMenuItemLong.setSelected(true);
+ rbMenuItemUnTyped.setSelected(true);
+ submenu.removeAll();
+
+ fileString="";
+ grammar.setText("No Topic ");
+ send("e "+ file.getPath().replace('\\','/'));
+ }
+ }
+ }
+
+ if ( obj == gfCommand ){
+ String s = JOptionPane.showInputDialog("Command:", parseInput);
+ if (s!=null) {
+ parseInput = s;
+ s = "gf "+s;
+ //treeChanged = true;
+ send(s);
+ }
+ }
+
+ if ( name.equals("reset") ) {
+ newObject = false;
+ statusLabel.setText(status);
+ listModel.clear();
+ tree.clear();
+ populateTree(tree);
+ menu.removeAllItems();
+ menu.addItem("New");
+ langMenu.removeAll();
+
+ AbstractButton ab = null;
+
+ while (languageGroup.getButtonCount()>0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+
+ selectedMenuLanguage = "Abstract";
+
+ submenu.removeAll();
+ rbMenuItemLong.setSelected(true);
+ rbMenuItemUnTyped.setSelected(true);
+
+ fileString="";
+ grammar.setText("No Topic ");
+ send("e");
+ }
+
+ if ( obj == leftMeta ) {
+ treeChanged = true;
+ send("<<");
+ }
+ if ( obj == left ) {
+ treeChanged = true;
+ send("<");
+ }
+ if ( obj == top ) {
+ treeChanged = true;
+ send("'");
+ }
+ if ( obj == right ) {
+ treeChanged = true;
+ send(">");
+ }
+ if ( obj == rightMeta ) {
+ treeChanged = true;
+ send(">>");
+ }
+
+ if ( obj == cancel ) {
+ dialog.hide();
+ }
+
+ if ( obj == browse ) {
+ if (fc.getChoosableFileFilters().length<2)
+ fc.addChoosableFileFilter(new GrammarFilter());
+ int returnVal = fc.showOpenDialog(GFEditor.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc.getSelectedFile();
+ inputField.setText(file.getPath().replace('\\','/'));
+ }
+ }
+
+ if ( obj == ok ) {
+ treeChanged = true;
+ if (termReadButton.isSelected()) {
+ termInput = inputField.getText();
+ if (termInput.indexOf('/')==-1){
+ send("g "+termInput);
+ System.out.println("sending term string");
+ }
+ else {
+ send("tfile "+termInput);
+ System.out.println("sending file term: "+termInput);
+ }
+ }
+ else {
+ parseInput = inputField.getText();
+ if (parseInput.indexOf('/')==-1){
+ send("p "+parseInput);
+ System.out.println("sending parse string"+parseInput);
+ }
+ else {
+ send("pfile "+parseInput);
+ System.out.println("sending file parse string: "+parseInput);
+ }
+ }
+ dialog.hide();
+ }
+
+ if ( obj == read ) {
+ if (stringReadButton.isSelected())
+ inputField.setText(parseInput);
+ else
+ inputField.setText(termInput);
+ dialog.show();
+ }
+
+/* if ( obj == term ) {
+ inputLabel.setText("Term:");
+ inputField.setText(termInput);
+ dialog.show();
+ }
+ if ( obj == parse ) {
+ inputLabel.setText("Parse:");
+ inputField.setText(parseInput);
+ dialog.show();
+ }
+*/
+ if ( obj == alpha){
+ String s = JOptionPane.showInputDialog("Type string:", alphaInput);
+ if (s!=null) {
+ alphaInput = s;
+ treeChanged = true;
+ send("x "+s);
+ }
+ }
+ if ( obj == random){
+ treeChanged = true;
+ send("a");
+ }
+ if ( obj == undo){
+ treeChanged = true;
+ send("u");
+ }
+ }
+ } catch (Exception e){}
+ }
+ static void writeOutput(String str, String fileName) {
+
+ try {
+ FileOutputStream fos = new FileOutputStream(fileName);
+ Writer out = new OutputStreamWriter(fos, "UTF8");
+ out.write(str);
+ out.close();
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(null,
+ "Document is empty!","Error", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ public static void populateTree(DynamicTree treePanel) {
+ String p1Name = new String("Root");
+ DefaultMutableTreeNode p1;
+ p1 = treePanel.addObject(null, p1Name);
+ }
+
+ public static void formTree(DynamicTree treePanel) {
+ Hashtable table = new Hashtable();
+ TreePath path=null;
+ boolean treeStarted = false, selected = false;
+ String s = treeString;
+ String name ="";
+ treePanel.clear();
+ int j, shift=0, star=0, index = 0;
+ DefaultMutableTreeNode p2=null, p1=null;
+ if (debug) System.out.print("treeString: "+ s);
+ if (s.indexOf('*')!=-1) star = 1;
+ while (s.length()>0) {
+ while ((s.length()>0) && ((s.charAt(0)=='*')||(s.charAt(0)==' '))){
+ if (s.charAt(0) == '*') selected = true;
+ s = s.substring(1);
+ shift++;
+ }
+ if (s.length()>0) {
+ j = s.indexOf("\n");
+ name = s.substring(0, j);
+ index++;
+ s = s.substring(j+1);
+ shift = (shift - star)/2;
+
+ p1 = (DefaultMutableTreeNode)table.get(new Integer(shift));
+ p2 = treePanel.addObject(p1, name);
+ table.put(new Integer(shift+1), p2);
+ path = new TreePath(p2.getPath());
+ nodeTable.put(path, new Integer(index));
+ if (selected) {
+ treePanel.tree.setSelectionPath(path);
+ treePanel.oldSelection = index;
+ if (debug) System.out.println("new selected index "+ index);
+ selected = false;
+ }
+ treeStarted=true;
+ }
+ shift = 0;
+ }
+ if ((p2!=null)) {
+ treePanel.tree.makeVisible(path);
+ gui2.toFront();
+ index = 0;
+ }
+ }
+
+ /** Listens to the radio buttons. */
+ class RadioListener implements ActionListener {
+ public void actionPerformed(ActionEvent e) {
+ String action = e.getActionCommand();
+ if (action.equals("split") ) {
+ cp.remove(centerPanel);
+ centerPanel2.add(middlePanelUp, BorderLayout.SOUTH);
+ if (((JCheckBoxMenuItem)viewMenu.getItem(0)).isSelected()) {
+ centerPanel2.add(treePanel, BorderLayout.CENTER);
+ }
+ else {
+ centerPanel2.add(outputPanelUp, BorderLayout.CENTER);
+ }
+ cp.add(centerPanel2, BorderLayout.CENTER);
+ gui2.getContentPane().add(outputPanelDown);
+ gui2.setVisible(true);
+ pack();
+ repaint();
+ }
+ if (action.equals("combine") ) {
+ cp.remove(centerPanel2);
+ middlePanel.add(middlePanelUp, BorderLayout.NORTH);
+ if (((JCheckBoxMenuItem)viewMenu.getItem(0)).isSelected()) { gui2.setVisible(false);
+ centerPanel.setLeftComponent(treePanel);
+ }
+ else {
+ centerPanel.setLeftComponent(outputPanelUp);
+ gui2.setVisible(false);
+ }
+ cp.add(centerPanel, BorderLayout.CENTER);
+ centerPanelDown.add(outputPanelDown, BorderLayout.CENTER);
+ pack();
+ repaint();
+ }
+ if (action.equals("showTree") ) {
+ if (!((JCheckBoxMenuItem)e.getSource()).isSelected()){
+ if (debug) System.out.println("was selected");
+ cbMenuItem.setSelected(false);
+ if (((JRadioButtonMenuItem)viewMenu.getItem(2)).isSelected()) {
+ centerPanel.remove(treePanel);
+ centerPanel.setLeftComponent(outputPanelUp);
+ }
+ else {
+ centerPanel2.remove(treePanel);
+ centerPanel2.add(outputPanelUp, BorderLayout.CENTER);
+ }
+ }
+ else {
+ if (debug) System.out.println("was not selected");
+ cbMenuItem.setSelected(true);
+ if (((JRadioButtonMenuItem)viewMenu.getItem(2)).isSelected()) {
+ centerPanel.remove(outputPanelUp);
+ treePanel.setRightComponent(outputPanelUp);
+ centerPanel.setLeftComponent(treePanel);
+ }
+ else {
+ centerPanel2.remove(outputPanelUp);
+ treePanel.setRightComponent(outputPanelUp);
+ centerPanel2.add(treePanel, BorderLayout.CENTER);
+ }
+ }
+ pack();
+ repaint();
+ }
+ if (action.equals("lang")) {
+ if (newObject) {
+ output.setText("");
+ formLin();
+ }
+ if (debug)
+ System.out.println("language option has changed "+((JCheckBoxMenuItem)e.getSource()).getText());
+ if (((JCheckBoxMenuItem)e.getSource()).isSelected()){
+ System.out.println("turning on");
+ send("on "+((JCheckBoxMenuItem)e.getSource()).getText());
+ }
+ else{
+ System.out.println("turning off");
+ send("off "+((JCheckBoxMenuItem)e.getSource()).getText());
+ }
+ }
+ //modeMenus actions:
+ else {
+ if ((action.equals("long")) || (action.equals("short")))
+ {
+ send("ms " + action);
+ }
+ else
+ if ((action.equals("typed")) || (action.equals("untyped")))
+ {
+ send("mt " + action);
+ }
+ else
+ {
+ selectedMenuLanguage = action;
+ if (action.equals("Abstract"))
+ {
+ send("ml Abs");
+ }
+ else
+ {
+ System.out.println("sending "+action);
+ send("ml " + action);
+ }
+ }
+ }
+ }
+ }
+
+ /** Handle the key pressed event. */
+ public void keyPressed(KeyEvent e) {
+ int keyCode = e.getKeyCode();
+ if (keyCode == 10) {
+ listAction(list.getSelectedIndex());
+ }
+ }
+ /** Handle the key typed event. */
+ public void keyTyped(KeyEvent e) {
+ }
+ /** Handle the key released event. */
+ public void keyReleased(KeyEvent e) {
+ }
+
+ public void listAction(int index) {
+ if (index == -1)
+ {if (debug) System.out.println("no selection");}
+ else {
+ treeChanged = true;
+ send((String)commands.elementAt(list.getSelectedIndex()));
+ }
+ }
+}
diff --git a/src-2.9/JavaGUI/GFEditor2.java b/src-2.9/JavaGUI/GFEditor2.java
new file mode 100644
index 000000000..f71210d7c
--- /dev/null
+++ b/src-2.9/JavaGUI/GFEditor2.java
@@ -0,0 +1,2357 @@
+//package javaGUI;
+
+import java.awt.*;
+import java.beans.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.text.*;
+import javax.swing.event.*;
+import javax.swing.tree.*;
+import java.io.*;
+import java.util.*;
+//import gfWindow.GrammarFilter;
+
+public class GFEditor2 extends JFrame implements ActionListener, CaretListener,
+ KeyListener, FocusListener {
+
+ private static Color color = Color.green;
+ private int[] sizes = {14,18,22,26,30};
+ private String[] envfonts;
+ private Font font;
+ Font[] fontObjs;
+ private static int DEFAULT_FONT_SIZE = 14;
+ private JComboBox fontList;
+ private JLabel fontLabel = new JLabel(" Font: ");
+ private JComboBox sizeList;
+ private JLabel sizeLabel = new JLabel(" Size: ");
+
+ public JPopupMenu popup2 = new JPopupMenu();
+ public JMenuItem menuItem2;
+ public static JTextField field = new JTextField("textField!");
+ public javax.swing.Timer timer2 = new javax.swing.Timer(500, this);
+ public MouseEvent m2;
+ public static String selectedText="";
+
+ // XML parsing:
+ public static boolean debug = false;
+ // pop-up/mouse handling:
+ public static boolean debug3 = false;
+ // red mark-up && html:
+ public static boolean debug4 = false;
+ // linearization marking:
+ public static boolean debug2 = false;
+
+ public static boolean selectionCheck = false;
+ public static LinPosition focusPosition ;
+ public static String stringToAppend = "";
+
+ //stack for storing the current position:
+ public static Vector currentPosition = new Vector();
+ public static int selStart = -1;
+ public static int selEnd = -1;
+ //public static int oldSelStart = 0;
+ public static String restString = "";
+ public static int currentLength = 0;
+ public static int newLength = 0;
+ public static int oldLength = 0;
+ public static int addedLength = 0;
+
+ public static boolean newObject = false;
+ public static boolean finished = false;
+ private String parseInput = "";
+ private String alphaInput = "";
+ private static String status = "status";
+ private static String selectedMenuLanguage = "Abstract";
+ private static String linearization = "";
+ private String termInput = "";
+ private static String outputString = "";
+ private static String treeString = "";
+ private static String fileString = "";
+ public static Vector commands = new Vector();
+ public static Vector outputVector = new Vector();
+ public static Hashtable nodeTable = new Hashtable();
+ JFileChooser fc1 = new JFileChooser("./");
+ JFileChooser fc = new JFileChooser("./");
+ private String [] filterMenu = {"Filter", "identity",
+ "erase", "take100", "text", "code", "latexfile",
+ "structured", "unstructured" };
+ private String [] modifyMenu = {"Modify", "identity","transfer",
+ "compute", "paraphrase", "generate","typecheck", "solve", "context" };
+// private String [] modeMenu = {"Menus", "printname",
+// "plain", "short", "long", "typed", "untyped" };
+ private static String [] newMenu = {"New"};
+
+ private static boolean firstLin = true;
+ private static boolean waiting = false;
+ public static boolean treeChanged = true;
+ private static String result;
+ private static BufferedReader fromProc;
+ private static BufferedWriter toProc;
+ private static String commandPath = new String("GF");
+ private static JTextArea output = new JTextArea();
+ public static DefaultListModel listModel= new DefaultListModel();
+ private JList list = new JList(listModel);
+ private static DynamicTree2 tree = new DynamicTree2();
+
+ private JLabel grammar = new JLabel("No topic ");
+ private JButton save = new JButton("Save");
+ private JButton open = new JButton("Open");
+ private JButton newTopic = new JButton("New Topic");
+ private JButton gfCommand = new JButton("GF command");
+
+ private JButton leftMeta = new JButton("?<");
+ private JButton left = new JButton("<");
+ private JButton top = new JButton("Top");
+ private JButton right = new JButton(">");
+ private JButton rightMeta = new JButton(">?");
+ private JButton read = new JButton("Read");
+ // private JButton parse = new JButton("Parse");
+ // private JButton term = new JButton("Term");
+ private JButton alpha = new JButton("Alpha");
+ private JButton random = new JButton("Random");
+ private JButton undo = new JButton("Undo");
+ private JPanel coverPanel = new JPanel();
+ private JPanel inputPanel = new JPanel();
+
+ private JPanel inputPanel2 = new JPanel();
+ private JPanel inputPanel3 = new JPanel();
+ private JButton ok = new JButton("OK");
+ private JButton cancel = new JButton("Cancel");
+ private JTextField inputField = new JTextField();
+ private JLabel inputLabel = new JLabel("Read: ");
+ private JButton browse = new JButton("Browse...");
+ private ButtonGroup readGroup = new ButtonGroup();
+ private JRadioButton termReadButton = new JRadioButton("Term");
+ private JRadioButton stringReadButton = new JRadioButton("String");
+
+ private JDialog dialog;
+
+ private static JComboBox menu = new JComboBox(newMenu);
+ private JComboBox filter = new JComboBox(filterMenu);
+ private JComboBox modify = new JComboBox(modifyMenu);
+ // private JComboBox mode = new JComboBox(modeMenu);
+
+ private JPanel downPanel = new JPanel();
+ private JSplitPane treePanel;
+ private JPanel upPanel = new JPanel();
+ private JPanel middlePanel = new JPanel();
+ private JPanel middlePanelUp = new JPanel();
+ private JPanel middlePanelDown = new JPanel();
+ private JSplitPane centerPanel;
+ private static JFrame gui2 = new JFrame();
+ private JPanel centerPanel2= new JPanel();
+ private JPanel centerPanelDown = new JPanel();
+ private JScrollPane outputPanelDown = new JScrollPane(list);
+ private JScrollPane outputPanelCenter = new JScrollPane(output);
+ private JPanel outputPanelUp = new JPanel();
+ private JPanel statusPanel = new JPanel();
+ private static JLabel statusLabel = new JLabel(status);
+ private Container cp;
+
+ private static JMenuBar menuBar= new JMenuBar();;
+ private static ButtonGroup menuGroup = new ButtonGroup();
+ private JMenu viewMenu= new JMenu("View");
+ private JMenu submenu= new JMenu("language");
+ private JMenu modeMenu= new JMenu("Menus");
+ private static JMenu langMenu= new JMenu("Languages");
+ private static JMenu fileMenu= new JMenu("File");
+ private JRadioButtonMenuItem rbMenuItem;
+ private JRadioButtonMenuItem rbMenuItemLong;
+ // private JRadioButtonMenuItem rbMenuItemAbs;
+ private JRadioButtonMenuItem rbMenuItemUnTyped;
+ private static JMenuItem fileMenuItem;
+ private static JCheckBoxMenuItem cbMenuItem;
+ private static JCheckBoxMenuItem treeCbMenuItem;
+ private static RadioListener myListener ;
+ private static ButtonGroup group = new ButtonGroup();
+ private static ButtonGroup languageGroup = new ButtonGroup();
+
+ public GFEditor2()
+ {
+ this.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ endProgram();
+ }
+ });
+
+
+ //Add listener to components that can bring up popup menus.
+ MouseListener popupListener2 = new PopupListener();
+ output.addMouseListener(popupListener2);
+ timer2.setRepeats(false);
+
+ setJMenuBar(menuBar);
+ setTitle("GF Syntax Editor");
+ viewMenu.setToolTipText("View settings");
+ fileMenu.setToolTipText("Main operations");
+ langMenu.setToolTipText("Language settings");
+ menuBar.add(fileMenu);
+ menuBar.add(langMenu);
+ menuBar.add(viewMenu);
+ menuBar.add(modeMenu);
+
+ treeCbMenuItem = new JCheckBoxMenuItem("Tree");
+ treeCbMenuItem.setActionCommand("showTree");
+ myListener = new RadioListener();
+ treeCbMenuItem.addActionListener(myListener);
+ treeCbMenuItem.setSelected(true);
+ viewMenu.add(treeCbMenuItem);
+ viewMenu.addSeparator();
+
+ fileMenuItem = new JMenuItem("Open...");
+ fileMenuItem.setActionCommand("open");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenuItem = new JMenuItem("New Topic...");
+ fileMenuItem.setActionCommand("newTopic");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenuItem = new JMenuItem("Reset");
+ fileMenuItem.setActionCommand("reset");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenuItem = new JMenuItem("Save As...");
+ fileMenuItem.setActionCommand("save");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenu.addSeparator();
+ fileMenuItem = new JMenuItem("Exit");
+ fileMenuItem.setActionCommand("quit");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+
+ rbMenuItem = new JRadioButtonMenuItem("One window");
+ rbMenuItem.setActionCommand("combine");
+ rbMenuItem.addActionListener(myListener);
+ rbMenuItem.setSelected(true);
+/* rbMenuItem.setMnemonic(KeyEvent.VK_R);
+ rbMenuItem.setAccelerator(KeyStroke.getKeyStroke(
+ KeyEvent.VK_1, ActionEvent.ALT_MASK));
+ rbMenuItem.getAccessibleContext().setAccessibleDescription(
+ "This doesn't really do anything");
+*/
+ menuGroup.add(rbMenuItem);
+ viewMenu.add(rbMenuItem);
+
+ rbMenuItem = new JRadioButtonMenuItem("Split windows");
+ rbMenuItem.setMnemonic(KeyEvent.VK_O);
+ rbMenuItem.setActionCommand("split");
+ rbMenuItem.addActionListener(myListener);
+ menuGroup.add(rbMenuItem);
+ viewMenu.add(rbMenuItem);
+
+ modeMenu.add(submenu);
+
+ /* rbMenuItemAbs = new JRadioButtonMenuItem("Abstract");
+ rbMenuItemAbs.setActionCommand("Abstract");
+ rbMenuItemAbs.addActionListener(myListener);
+ languageGroup.add(rbMenuItemAbs);
+ */
+
+ modeMenu.addSeparator();
+ menuGroup = new ButtonGroup();
+ rbMenuItemLong = new JRadioButtonMenuItem("long");
+ rbMenuItemLong.setActionCommand("long");
+ rbMenuItemLong.setSelected(true);
+ rbMenuItemLong.addActionListener(myListener);
+ menuGroup.add(rbMenuItemLong);
+ modeMenu.add(rbMenuItemLong);
+ rbMenuItem = new JRadioButtonMenuItem("short");
+ rbMenuItem.setActionCommand("short");
+ rbMenuItem.addActionListener(myListener);
+ menuGroup.add(rbMenuItem);
+ modeMenu.add(rbMenuItem);
+ modeMenu.addSeparator();
+
+ menuGroup = new ButtonGroup();
+ rbMenuItem = new JRadioButtonMenuItem("typed");
+ rbMenuItem.setActionCommand("typed");
+ rbMenuItem.addActionListener(myListener);
+ rbMenuItem.setSelected(false);
+ menuGroup.add(rbMenuItem);
+ modeMenu.add(rbMenuItem);
+ rbMenuItemUnTyped = new JRadioButtonMenuItem("untyped");
+ rbMenuItemUnTyped.setSelected(true);
+ rbMenuItemUnTyped.setActionCommand("untyped");
+ rbMenuItemUnTyped.addActionListener(myListener);
+ menuGroup.add(rbMenuItemUnTyped);
+ modeMenu.add(rbMenuItemUnTyped);
+
+ cp = getContentPane();
+ JScrollPane cpPanelScroll = new JScrollPane(coverPanel);
+ cp.add(cpPanelScroll);
+ coverPanel.setLayout(new BorderLayout());
+ output.setToolTipText("Linearizations' display area");
+ output.addCaretListener(this);
+ output.setEditable(false);
+ output.setLineWrap(true);
+ output.setWrapStyleWord(true);
+ output.setSelectionColor(Color.green);
+// output.setSelectionColor(Color.white);
+// output.setFont(new Font("Arial Unicode MS", Font.PLAIN, 17));
+ font = new Font(null, Font.PLAIN, DEFAULT_FONT_SIZE);
+ output.setFont(font);
+ field.setFont(font);
+ field.setFocusable(true);
+ field.addKeyListener(this);
+ field.addFocusListener(this);
+// System.out.println(output.getFont().getFontName());
+ gfCommand.setToolTipText("Sending a command to GF");
+ read.setToolTipText("Refining with term or linearization from typed string or file");
+ modify.setToolTipText("Choosing a linearization method");
+ alpha.setToolTipText("Performing alpha-conversion");
+ random.setToolTipText("Generating random refinement");
+ undo.setToolTipText("Going back to the previous state");
+ downPanel.add(gfCommand);
+ //downPanel.add(parse);
+ //downPanel.add(term);
+ downPanel.add(read);
+ downPanel.add(modify);
+ downPanel.add(alpha);
+ downPanel.add(random);
+ downPanel.add(undo);
+
+ leftMeta.setToolTipText("Moving the focus to the previous metavariable");
+ rightMeta.setToolTipText("Moving the focus to the next metavariable");
+ left.setToolTipText("Moving the focus to the previous term");
+ right.setToolTipText("Moving the focus to the next term");
+ top.setToolTipText("Moving the focus to the top term");
+ middlePanelUp.add(leftMeta);
+ middlePanelUp.add(left);
+ middlePanelUp.add(top);
+ middlePanelUp.add(right);
+ middlePanelUp.add(rightMeta);
+ middlePanelDown.add(new JLabel("Select Action on Subterm"));
+ middlePanel.setLayout(new BorderLayout());
+ middlePanel.add(middlePanelUp, BorderLayout.NORTH);
+ middlePanel.add(middlePanelDown, BorderLayout.CENTER);
+
+ menu.setToolTipText("The list of available categories to start editing");
+ open.setToolTipText("Reading both a new environment and an editing object from file. Current editing will be discarded");
+ save.setToolTipText("Writing the current editing object to file in the term or text format");
+ grammar.setToolTipText("Current Topic");
+ newTopic.setToolTipText("Reading a new environment from file. Current editing will be discarded.");
+ upPanel.add(grammar);
+ upPanel.add(menu);
+ upPanel.add(open);
+ upPanel.add(save);
+ upPanel.add(newTopic);
+ upPanel.add(filter);
+
+ filter.setToolTipText("Choosing the linearization representation format");
+ modeMenu.setToolTipText("Choosing the refinement options' representation");
+ statusLabel.setToolTipText("The current focus type");
+ list.setToolTipText("The list of current refinment options");
+
+ GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ envfonts = gEnv.getAvailableFontFamilyNames();
+ fontObjs = new Font[envfonts.length];
+ for (int fi = 0; fi < envfonts.length; fi++) {
+ fontObjs[fi] = new Font(envfonts[fi], Font.PLAIN, DEFAULT_FONT_SIZE);
+ }
+ fontList = new JComboBox(envfonts);
+ fontList.addActionListener(this);
+ fontList.setToolTipText("Changing font type");
+
+ sizeList = new JComboBox();
+ sizeList.setToolTipText("Changing font size");
+ for (int i = 0; i and tags
+ and fills the corrsponding GUI list -"Select Action".
+ */
+
+ public static void formSelectMenu (){
+ if (debug) System.out.println("list model changing! ");
+ String s ="";
+ try {
+ //read item
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ listModel.clear();
+ commands.clear();
+ while (result.indexOf("/menu")==-1){
+ //read show
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ while (result.indexOf("/show")==-1){
+ result = fromProc.readLine();
+ if (debug) System.out.println("9 "+result);
+ if (result.indexOf("/show")==-1)
+ {
+ if (result.length()>8)
+ s+=result.trim();
+ else
+ s+=result;
+ }
+ }
+// if (s.charAt(0)!='d')
+// listModel.addElement("Refine " + s);
+// else
+ listModel.addElement(s);
+ s="";
+ //read /show
+ //read send
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ saveCommand();
+ // read /item
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ }
+ } catch(IOException e){ }
+ }
+
+ /* put the command into the list of commands */
+ public static void saveCommand(){
+ if (newObject) commands.add(result);
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("9 "+result);
+ } catch(IOException e){ }
+ }
+
+ /*
+ Accumulates the GF-output between tags
+ */
+
+ public void readLin(){
+ try {
+ linearization="";
+ linearization += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ while ((result!=null)&&(result.indexOf("/linearization")==-1)){
+ linearization += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ }
+ if (newObject) formLin();
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ } catch(IOException e){ }
+ }
+
+ /*
+ Accumulates the GF-output between tags
+ */
+
+ public static void readTree(){
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ while (result.indexOf("/tree")==-1){
+ treeString += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ }
+ if (treeChanged && (newObject)) {
+ formTree(tree);
+ treeChanged = false;
+ }
+ treeString="";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ } catch(IOException e){ }
+ }
+
+ /*
+ Parses the GF-output between tags
+ and puts it in the linearization area.
+ */
+
+ public static void readMessage(){
+ String s ="";
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("7 "+result);
+ while (result.indexOf("/message")==-1){
+ s += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("7 "+result);
+ }
+ if (s.length()>1)
+ appendMarked("-------------"+'\n'+s,-1,-1);
+ result = fromProc.readLine();
+ if (debug) System.out.println("7 "+result);
+ } catch(IOException e){ }
+ }
+ /*
+ Parses the GF-output between tags
+ and fill the New combobox in the GUI.
+ */
+
+ public void formNewMenu () {
+ boolean more = true;
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+
+ while (more){
+ if (result.indexOf("topic")==-1) {
+ menu.addItem(result.substring(6));
+ }
+ else
+ more = false;
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("3 "+result);
+ if (result.indexOf("topic")!=-1)
+ more = false;
+ result = fromProc.readLine();
+ if (debug) System.out.println("4 "+result);
+ }
+
+ grammar.setText(result.substring(4)+" ");
+
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("3 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("4 "+result);
+
+ more = true;
+ while (more){
+ if ((result.indexOf("/gfinit")==-1)&&(result.indexOf("lin")==-1)) {
+ //form lang and Menu menu:
+ cbMenuItem = new JCheckBoxMenuItem(result.substring(4));
+ if (debug) System.out.println ("menu item: "+result.substring(4));
+ if ((result.substring(4)).equals("Abstract"))
+ cbMenuItem.setSelected(false);
+ else
+ cbMenuItem.setSelected(true);
+ cbMenuItem.setActionCommand("lang");
+ cbMenuItem.addActionListener(myListener);
+ langMenu.add(cbMenuItem);
+/*
+ {
+ submenu.add(rbMenuItemAbs);
+ if (selectedMenuLanguage.equals("Abstract"))
+ rbMenuItemAbs.setSelected(true);
+ languageGroup.add(rbMenuItemAbs);
+ }
+ else
+ {
+*/
+ rbMenuItem = new JRadioButtonMenuItem(result.substring(4));
+ rbMenuItem.setActionCommand(result.substring(4));
+ rbMenuItem.addActionListener(myListener);
+ languageGroup.add(rbMenuItem);
+ if ((result.substring(4)).equals(selectedMenuLanguage))
+ {
+ if (debug) System.out.println("Selecting "+selectedMenuLanguage);
+ rbMenuItem.setSelected(true);
+ }
+
+ submenu.add(rbMenuItem);
+// }
+ }
+ else
+ more = false;
+ // read
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+ // read or
+ result = fromProc.readLine();
+ if (debug) System.out.println("3 "+result);
+ if ((result.indexOf("/gfinit")!=-1)||(result.indexOf("lin")!=-1))
+ more = false;
+ if (result.indexOf("/gfinit")!=-1)
+ finished = true;
+ // registering the file name:
+ if (result.indexOf("language")!=-1) {
+ String path = result.substring(result.indexOf('=')+1,
+ result.indexOf('>'));
+ path =path.substring(path.lastIndexOf('/')+1);
+ if (debug) System.out.println("name: "+path);
+ fileString +="--" + path +"\n";
+ if (path.lastIndexOf('.')!=path.indexOf('.'))
+ grammar.setText(path.substring(0,
+ path.indexOf('.')).toUpperCase()+" ");
+ }
+ result = fromProc.readLine();
+ if (debug) System.out.println("4 "+result);
+ }
+ if (debug)
+ System.out.println("languageGroupElement formed"+
+ languageGroup.getButtonCount());
+ langMenu.addSeparator();
+ fileMenuItem = new JMenuItem("Add...");
+ fileMenuItem.setActionCommand("import");
+ fileMenuItem.addActionListener(this);
+ langMenu.add(fileMenuItem);
+ // in order to get back in main in the beggining of while:
+ result = fromProc.readLine();
+ } catch(IOException e){ }
+ }
+
+ /*
+ Parses the GF-output between tags
+ and puts the string in the linearization area on the screen
+ */
+
+ public void outputAppend(){
+ int i, j, j2, k, l, l2, selectionLength, m=0, n=0;
+ //result=result.replace('\n',' ');
+ if (debug2)
+ System.out.println("INPUT:"+result);
+ l = result.indexOf("',i);
+ // status incorrect ?:
+ if (result.substring(i,j).indexOf("incorrect")!=-1)
+ {
+ j2 = result.indexOf("status");
+ color = Color.red;
+ }
+ else
+ {
+ j2 = j;
+ color = Color.green;
+ }
+ l2 = result.indexOf("focus");
+ if (l2!=-1){
+ // in case focus tag is cut into two lines:
+ if (l==-1) l=l2-7;
+ m=result.indexOf("position",l);
+ if (debug2) System.out.println("POSITION START: "+m);
+ n=result.indexOf("]",m);
+ if (debug2) System.out.println("POSITION END: "+n);
+ if (debug)
+ System.out.println("form Lin1: "+result);
+ focusPosition = new LinPosition(result.substring(m+9,n+1),
+ result.substring(m,j).indexOf("incorrect")==-1);
+ statusLabel.setText(" "+result.substring(i+5,j2));
+ //cutting
+ result= result.substring(0,l)+result.substring(j+2);
+ i=result.indexOf("/focus",l);
+ selectionLength = i-l-1;
+ if (debug2)
+ System.out.println("selection length: "+selectionLength);
+ j=result.indexOf('>',i);
+ k=result.length()-j-1;
+ if (debug) System.out.println("form Lin2: "+result);
+
+ if (debug)
+ System.out.println("char at the previous position"+result.charAt(i-1));
+ //cutting
+ // in case focus tag is cut into two lines:
+ if (result.charAt(i-1)!='<')
+ // check if punktualtion marks like . ! ? are at the end of a sentence:
+ if (result.charAt(j+1)==' ')
+ result= result.substring(0,i-8)+result.substring(j+2);
+ else
+ result= result.substring(0,i-9)+result.substring(j+1);
+ else
+ if (result.charAt(j+1)==' ')
+ result= result.substring(0,i-1)+result.substring(j+2);
+ else
+ result= result.substring(0,i-2)+result.substring(j+1);
+ j= result.indexOf(" tags
+ */
+ public void formLin(){
+ boolean visible=true;
+ firstLin=true;
+ result = linearization.substring(0,linearization.indexOf('\n'));
+ String lin = linearization.substring(linearization.indexOf('\n')+1);
+ //extract the language from result
+ int ind = result.indexOf('=');
+ int ind2 = result.indexOf('>');
+ String s = result.substring(ind+1,ind2);
+ result = lin.substring(0,lin.indexOf(""));
+ lin = lin.substring(lin.indexOf(""));
+ while (lin.length()>1) {
+ //check if the language is on
+ if (!visible) visible = true;
+ // in the list?
+ for (int i=0; i
+ lin = lin.substring(lin.indexOf('\n')+1);
+ // read lin or 'end'
+ if (lin.length()<1) break;
+
+ result = lin.substring(0,lin.indexOf('\n'));
+ lin = lin.substring(lin.indexOf('\n')+1);
+ if (result.indexOf("');
+ s = result.substring(ind+1,ind2);
+ result = lin.substring(0,lin.indexOf(""));
+ lin = lin.substring(lin.indexOf(""));
+ }
+ }
+ for (int i = 0; i0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ if (debug) System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ if (debug) System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+ submenu.removeAll();
+
+
+ File file = fc1.getSelectedFile();
+ // opening the file for editing :
+ if (debug) System.out.println("opening: "+ file.getPath().replace('\\','/'));
+ if (group.getSelection().getActionCommand().equals("term")) {
+ if (debug) System.out.println(" opening as a term ");
+ send("open "+ file.getPath().replace('\\','/'));
+ }
+ else {
+ if (debug) System.out.println(" opening as a linearization ");
+ send("openstring "+ file.getPath().replace('\\','/'));
+ }
+
+ fileString ="";
+ grammar.setText("No Topic ");
+ }
+ }
+
+ if ( name.equals("import") ) {
+ if (fc.getChoosableFileFilters().length<2)
+ fc.addChoosableFileFilter(new GrammarFilter());
+ int returnVal = fc.showOpenDialog(GFEditor2.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc.getSelectedFile();
+ // importing a new language :
+ langMenu.removeAll();
+ AbstractButton ab = null;
+ while (languageGroup.getButtonCount()>0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ if (debug) System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ if (debug) System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+
+ submenu.removeAll();
+ while (1< menu.getItemCount())
+ menu.removeItemAt(1);
+ if (debug) System.out.println("importing: "+ file.getPath().replace('\\','/'));
+
+ fileString ="";
+ send("i "+ file.getPath().replace('\\','/'));
+
+ }
+ }
+ if ( name.equals("newTopic") ) {
+ if (fc.getChoosableFileFilters().length<2)
+ fc.addChoosableFileFilter(new GrammarFilter());
+ int returnVal = fc.showOpenDialog(GFEditor2.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ int n = JOptionPane.showConfirmDialog(this,
+ "This will dismiss the previous editing. Would you like to continue?",
+ "Starting a new topic", JOptionPane.YES_NO_OPTION);
+ if (n == JOptionPane.YES_OPTION){
+ File file = fc.getSelectedFile();
+ // importing a new grammar :
+ newObject = false;
+ statusLabel.setText(status);
+ listModel.clear();
+ tree.clear();
+ populateTree(tree);
+ while (1< menu.getItemCount())
+ menu.removeItemAt(1);
+ langMenu.removeAll();
+
+ AbstractButton ab = null;
+
+ while (languageGroup.getButtonCount()>0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ if (debug) System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ if (debug) System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+
+ selectedMenuLanguage = "Abstract";
+ rbMenuItemLong.setSelected(true);
+ rbMenuItemUnTyped.setSelected(true);
+ submenu.removeAll();
+
+ fileString="";
+ grammar.setText("No Topic ");
+ send(" e "+ file.getPath().replace('\\','/'));
+ }
+ }
+ }
+
+ if ( obj == gfCommand ){
+ String s = JOptionPane.showInputDialog("Command:", parseInput);
+ if (s!=null) {
+ parseInput = s;
+ //s = "gf "+s; This is for debugging, otherwise shift the comment to the next line.
+ treeChanged = true;
+ if (debug) System.out.println("sending: "+ s);
+ send(s);
+ }
+ }
+
+ if ( name.equals("reset") ) {
+ newObject = false;
+ statusLabel.setText(status);
+ listModel.clear();
+ tree.clear();
+ populateTree(tree);
+ while (1< menu.getItemCount())
+ menu.removeItemAt(1);
+ langMenu.removeAll();
+
+ AbstractButton ab = null;
+
+ while (languageGroup.getButtonCount()>0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ if (debug) System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ if (debug) System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+
+ selectedMenuLanguage = "Abstract";
+
+ submenu.removeAll();
+ rbMenuItemLong.setSelected(true);
+ rbMenuItemUnTyped.setSelected(true);
+
+ fileString="";
+ grammar.setText("No Topic ");
+ send("e");
+ }
+
+ if ( obj == leftMeta ) {
+ treeChanged = true;
+ send("<<");
+ }
+ if ( obj == left ) {
+ treeChanged = true;
+ send("<");
+ }
+ if ( obj == top ) {
+ treeChanged = true;
+ send("'");
+ }
+ if ( obj == right ) {
+ treeChanged = true;
+ send(">");
+ }
+ if ( obj == rightMeta ) {
+ treeChanged = true;
+ send(">>");
+ }
+
+ if ( obj == cancel ) {
+ dialog.hide();
+ }
+
+ if ( obj == browse ) {
+ if (fc.getChoosableFileFilters().length<2)
+ fc.addChoosableFileFilter(new GrammarFilter());
+ int returnVal = fc.showOpenDialog(GFEditor2.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc.getSelectedFile();
+ inputField.setText(file.getPath().replace('\\','/'));
+ }
+ }
+
+ if ( obj == ok ) {
+ treeChanged = true;
+ if (termReadButton.isSelected()) {
+ termInput = inputField.getText();
+ if (termInput.indexOf('/')==-1){
+ send("g "+termInput);
+ if (debug) System.out.println("sending term string");
+ }
+ else {
+ send("tfile "+termInput);
+ System.out.println("sending file term: "+termInput);
+ }
+ }
+ else {
+ parseInput = inputField.getText();
+ if (parseInput.indexOf('/')==-1){
+ send("p "+parseInput);
+ if (debug) System.out.println("sending parse string: "+parseInput);
+ }
+ else {
+ send("pfile "+parseInput);
+ if (debug) System.out.println("sending file parse string: "+parseInput);
+ }
+ }
+ dialog.hide();
+ }
+
+ if ( obj == read ) {
+ if (stringReadButton.isSelected())
+ inputField.setText(parseInput);
+ else
+ inputField.setText(termInput);
+ dialog.show();
+ }
+
+/* if ( obj == term ) {
+ inputLabel.setText("Term:");
+ inputField.setText(termInput);
+ dialog.show();
+ }
+ if ( obj == parse ) {
+ inputLabel.setText("Parse:");
+ inputField.setText(parseInput);
+ dialog.show();
+ }
+*/
+ if ( obj == alpha){
+ String s = JOptionPane.showInputDialog("Type string:", alphaInput);
+ if (s!=null) {
+ alphaInput = s;
+ treeChanged = true;
+ send("x "+s);
+ }
+ }
+ if ( obj == random){
+ treeChanged = true;
+ send("a");
+ }
+ if ( obj == undo){
+ treeChanged = true;
+ send("u");
+ }
+ }
+ } catch (Exception e){}
+ }
+ static void writeOutput(String str, String fileName) {
+
+ try {
+ FileOutputStream fos = new FileOutputStream(fileName);
+ Writer out = new OutputStreamWriter(fos, "UTF8");
+ out.write(str);
+ out.close();
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(null,
+ "Document is empty!","Error", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ /* Form a dummy tree in treePanel */
+ public static void populateTree(DynamicTree2 treePanel) {
+ String p1Name = new String("Root");
+ DefaultMutableTreeNode p1;
+ p1 = treePanel.addObject(null, p1Name);
+ }
+
+ /*
+ Parses the GF-output between tags
+ and build the corresponding tree.
+ */
+
+ public static void formTree(DynamicTree2 treePanel) {
+ Hashtable table = new Hashtable();
+ TreePath path=null;
+ boolean treeStarted = false, selected = false;
+ String s = treeString;
+ String name ="";
+ treePanel.clear();
+ int j, shift=0, star=0, index = 0;
+ DefaultMutableTreeNode p2=null, p1=null;
+ if (debug) System.out.print("treeString: "+ s);
+ if (s.indexOf('*')!=-1) star = 1;
+ while (s.length()>0) {
+ while ((s.length()>0) && ((s.charAt(0)=='*')||(s.charAt(0)==' '))){
+ if (s.charAt(0) == '*') selected = true;
+ s = s.substring(1);
+ shift++;
+ }
+ if (s.length()>0) {
+ j = s.indexOf("\n");
+ name = s.substring(0, j);
+ index++;
+ s = s.substring(j+1);
+ shift = (shift - star)/2;
+
+ p1 = (DefaultMutableTreeNode)table.get(new Integer(shift));
+ p2 = treePanel.addObject(p1, name);
+ table.put(new Integer(shift+1), p2);
+ path = new TreePath(p2.getPath());
+ nodeTable.put(path, new Integer(index));
+ if (selected) {
+ treePanel.tree.setSelectionPath(path);
+ treePanel.oldSelection = index;
+ if (debug) System.out.println("new selected index "+ index);
+ selected = false;
+ }
+ treeStarted=true;
+ }
+ shift = 0;
+ }
+ if ((p2!=null)) {
+ treePanel.tree.makeVisible(path);
+ gui2.toFront();
+ index = 0;
+ }
+ }
+
+ /** Listens to the radio buttons. */
+ class RadioListener implements ActionListener {
+ public void actionPerformed(ActionEvent e) {
+ String action = e.getActionCommand();
+ if (action.equals("split") ) {
+ coverPanel.remove(centerPanel);
+ centerPanel2.add(middlePanelUp, BorderLayout.SOUTH);
+ if (((JCheckBoxMenuItem)viewMenu.getItem(0)).isSelected()) {
+ centerPanel2.add(treePanel, BorderLayout.CENTER);
+ }
+ else {
+ centerPanel2.add(outputPanelUp, BorderLayout.CENTER);
+ }
+ coverPanel.add(centerPanel2, BorderLayout.CENTER);
+ gui2.getContentPane().add(outputPanelDown);
+ gui2.setVisible(true);
+ pack();
+ repaint();
+ }
+ if (action.equals("combine") ) {
+ coverPanel.remove(centerPanel2);
+ middlePanel.add(middlePanelUp, BorderLayout.NORTH);
+ if (((JCheckBoxMenuItem)viewMenu.getItem(0)).isSelected()) { gui2.setVisible(false);
+ centerPanel.setLeftComponent(treePanel);
+ }
+ else {
+ centerPanel.setLeftComponent(outputPanelUp);
+ gui2.setVisible(false);
+ }
+ coverPanel.add(centerPanel, BorderLayout.CENTER);
+ centerPanelDown.add(outputPanelDown, BorderLayout.CENTER);
+ pack();
+ repaint();
+ }
+
+ if (action.equals("showTree") ) {
+ if (!((JCheckBoxMenuItem)e.getSource()).isSelected()){
+ if (debug) System.out.println("was selected");
+ treeCbMenuItem.setSelected(false);
+ if (((JRadioButtonMenuItem)viewMenu.getItem(2)).isSelected()) {
+ centerPanel.remove(treePanel);
+ centerPanel.setLeftComponent(outputPanelUp);
+ }
+ else {
+ centerPanel2.remove(treePanel);
+ centerPanel2.add(outputPanelUp, BorderLayout.CENTER);
+ }
+ }
+ else {
+ if (debug) System.out.println("was not selected");
+ treeCbMenuItem.setSelected(true);
+ if (((JRadioButtonMenuItem)viewMenu.getItem(2)).isSelected()) {
+ centerPanel.remove(outputPanelUp);
+ treePanel.setRightComponent(outputPanelUp);
+ centerPanel.setLeftComponent(treePanel);
+ }
+ else {
+ centerPanel2.remove(outputPanelUp);
+ treePanel.setRightComponent(outputPanelUp);
+ centerPanel2.add(treePanel, BorderLayout.CENTER);
+ }
+ }
+ pack();
+ repaint();
+ }
+ if (action.equals("lang")) {
+ if (newObject) {
+ output.setText("");
+ formLin();
+ }
+ if (debug)
+ System.out.println("language option has changed "+((JCheckBoxMenuItem)e.getSource()).getText());
+ if (((JCheckBoxMenuItem)e.getSource()).isSelected()){
+ if (debug) System.out.println("turning on");
+ send("on "+((JCheckBoxMenuItem)e.getSource()).getText());
+ }
+ else{
+ if (debug) System.out.println("turning off");
+ send("off "+((JCheckBoxMenuItem)e.getSource()).getText());
+ }
+ }
+ //modeMenus actions:
+ else {
+ if ((action.equals("long")) || (action.equals("short")))
+ {
+ send("ms " + action);
+ }
+ else
+ if ((action.equals("typed")) || (action.equals("untyped")))
+ {
+ send("mt " + action);
+ }
+ else
+ {
+ selectedMenuLanguage = action;
+ if (action.equals("Abstract"))
+ {
+ send("ml Abs");
+ }
+ else
+ if (!action.equals("split")&&!action.equals("combine")&&!action.equals("showTree"))
+ {
+ if (debug) System.out.println("sending "+action);
+ send("ml " + action);
+ }
+ }
+ }
+ }
+ }
+
+ /** Handle the key pressed event. */
+ public void keyPressed(KeyEvent e) {
+ int keyCode = e.getKeyCode();
+ Object obj = e.getSource();
+ if ((keyCode == 10)&&(obj==list)) {
+ listAction(list.getSelectedIndex());
+ }
+ // Processing Enter:
+ if ((keyCode == 10)&&(obj==field)) {
+ getLayeredPane().remove(field);
+ treeChanged = true;
+ send("p "+field.getText());
+ if (debug) System.out.println("sending parse string: "+field.getText());
+ repaint();
+ }
+ // Processing Escape:
+ if ((keyCode == 27)&&(obj==field)) {
+ getLayeredPane().remove(field);
+ repaint();
+ }
+
+ }
+ /** Handle the key typed event. */
+ public void keyTyped(KeyEvent e) {
+ }
+ /** Handle the key released event. */
+ public void keyReleased(KeyEvent e) {
+ }
+
+ /**
+ Returns the biggest position of first and second.
+ Each word in the linearization area has the corresponding
+ position in the tree. The position-notion is taken from
+ GF-Haskell, where empty position ("[]")
+ represents tree-root, "[0]" represents first child of the root,
+ "[0,0]" represents the first grandchild of the root etc.
+ So comparePositions("[0]","[0,0]")="[0]"
+
+ */
+ public String comparePositions(String first, String second)
+ {
+ String common ="[]";
+ int i = 1;
+ while ((i0&&(end-1)&&(start=0)&&(((MarkedArea)outputVector.elementAt(i)).begin > start))
+ i--;
+ if (debug2)
+ System.out.println("i: "+i+" j: "+j);
+ if ((j=jElement.begin)
+ {
+ iElement = (MarkedArea)outputVector.elementAt(0);
+ iPosition = iElement.position.position;
+ if (debug2)
+ System.out.println("Less: "+jPosition+" and "+iPosition);
+ position = findMax(0,j);
+ if (debug2)
+ System.out.println("SELECTEDTEXT: "+position+"\n");
+ treeChanged = true;
+ send("mp "+position);
+ }
+ // before:
+ else
+ if (debug2)
+ System.out.println("BEFORE vector of size: "+outputVector.size());
+ }
+ // just:
+ else
+ {
+ iElement = (MarkedArea)outputVector.elementAt(i);
+ iPosition = iElement.position.position;
+ if (debug2)
+ System.out.println("SELECTED TEXT Just: "+iPosition +" and "+jPosition+"\n");
+ position = findMax(i,j);
+ if (debug2)
+ System.out.println("SELECTEDTEXT: "+position+"\n");
+ treeChanged = true;
+ send("mp "+position);
+ }
+ }
+ else
+ // more && after:
+ if (i>=0)
+ {
+ iElement = (MarkedArea)outputVector.elementAt(i);
+ iPosition = iElement.position.position;
+ // more
+ if (start<=iElement.end)
+ {
+ jElement = (MarkedArea)outputVector.elementAt(outputVector.size()-1);
+ jPosition = jElement.position.position;
+ if (debug2)
+ System.out.println("MORE: "+iPosition+ " and "+jPosition);
+ position = findMax(i,outputVector.size()-1);
+ if (debug2)
+ System.out.println("SELECTEDTEXT: "+position+"\n");
+ treeChanged = true;
+ send("mp "+position);
+ }
+ else
+ // after:
+ if (debug2)
+ System.out.println("AFTER vector of size: "+outputVector.size());
+ }
+ else
+ // bigger:
+ {
+ iElement = (MarkedArea)outputVector.elementAt(0);
+ iPosition = iElement.position.position;
+ jElement = (MarkedArea)outputVector.elementAt(outputVector.size()-1);
+ jPosition = jElement.position.position;
+ if (debug2)
+ System.out.println("BIGGER: "+iPosition +" and "+jPosition+"\n");
+ if (debug2)
+ System.out.println("SELECTEDTEXT: []\n");
+ treeChanged = true;
+ send("mp []");
+ }
+ }//not null selection
+ }
+
+ /*
+ Appends the string s to the text in the linearization area
+ on the screen.
+ s - string to append
+ selectionStart, selectionEnd - selection coordinates
+ (focus tag is already cut)
+ */
+ public static void appendMarked(String s, int selectionStart, int selectionEnd)
+ { if (s.length()>0)
+ {
+ if (debug2)
+ {
+ System.out.println("STRING: "+s);
+ System.out.println("where selection start is: "+selectionStart);
+ System.out.println("where selection end is: "+selectionEnd);
+ if ((selectionStart>-1)&&(selectionEnd>selectionStart))
+ System.out.println("where selection is: "+s.substring(selectionStart,selectionEnd));
+ }
+ currentLength = 0;
+ newLength=0;
+ oldLength = output.getText().length();
+ int j, l, l2, n, pos, selStartTotal, selEndTotal, selEndT;
+ restString = s;
+ int m2, m1;
+ LinPosition position ;
+
+ if (selectionStart>-1)
+ {
+ selStart = selectionStart;
+ selEnd = selectionEnd;
+ if (debug2)
+ System.out.println("SELECTION: " + selStart + " "+selEnd+ "TOTAL: "+s.length());
+ if (selEnd>selStart)
+ selectionCheck = (getCharacter(s.substring(selStart, selEnd),"<",0)==-1);
+ l = restString.indexOf("-1)||(l>-1))
+ {
+ if ((l2==-1)||((l-1)))
+ {
+ j = restString.indexOf('>',l);
+ n = getCharacter(restString,"<",j);
+ m1 = restString.indexOf('[',l);
+ m2 = restString.indexOf(']',l);
+ //getting position:
+ position = new LinPosition(restString.substring(m1,m2+1),
+ restString.substring(l,j).indexOf("incorrect")==-1);
+ // something before the tag:
+ if (l-currentLength>1)
+ {
+ if (debug2)
+ System.out.println("SOMETHING BEFORE THE TAG");
+ if (currentPosition.size()>0)
+ register(currentLength, l, (LinPosition)currentPosition.elementAt(currentPosition.size()-1));
+ else
+ register(currentLength, l, new LinPosition("[]",
+ restString.substring(l,j).indexOf("incorrect")==-1));
+ }
+ // nothing before the tag:
+ else
+ {
+ if (debug2)
+ System.out.println("NOTHING BEFORE THE TAG");
+ if (n>0)
+ register(j+2, n, position);
+ else
+ register(j+2, restString.length(), position);
+ removeSubTreeTag(l,j+1);
+ }
+ currentLength += newLength ;
+ } // l tag:
+ if (l2-currentLength>1)
+ {
+ if (debug2)
+ System.out.println("SOMETHING BEFORE THE TAG");
+ if (currentPosition.size()>0)
+ register(currentLength, l2, (LinPosition)currentPosition.elementAt(currentPosition.size()-1));
+ else
+ register(currentLength, l2, new LinPosition("[]",
+ restString.substring(l,l2).indexOf("incorrect")==-1));
+ currentLength += newLength ;
+ }
+ // nothing before the tag:
+ else
+ // punctuation after the tag:
+ if (restString.substring(l2+10,l2+11).trim().length()>0)
+ {
+ if (debug2)
+ System.out.println("PUNCTUATION AFTER THE TAG");
+ if (debug2) System.out.println("STRING: "+restString);
+ //cutting the tag first!:
+ if (l2>0)
+ removeSubTreeTag(l2-1,l2+9);
+ else
+ removeSubTreeTag(l2,l2+9);
+ if (debug2) System.out.println("STRING after cutting the tag: "+restString);
+ // cutting the space in the last registered component:
+ if (outputVector.size()>0)
+ {
+ ((MarkedArea)outputVector.elementAt(outputVector.size()-1)).end -=1;
+ if (currentLength>0) currentLength -=1;
+ }
+ if (debug2) System.out.println("currentLength: "+currentLength +" old length " +oldLength);
+ // register the punctuation:
+ if (currentPosition.size()>0)
+ register(currentLength, currentLength+2, (LinPosition)currentPosition.elementAt(currentPosition.size()-1));
+ else
+ register(currentLength, currentLength+2, new LinPosition("[]",
+ true));
+ currentLength += newLength ;
+ }
+ else
+ // just cutting the tag:
+ removeSubTreeTag(l2,l2+10);
+ }
+ l2 = restString.indexOf("=selStart)&&(outputVector.size()>0))
+ {
+ // exclamation sign etc.:
+ if (currentLength>selEnd)
+ selStartTotal = selStart+oldLength;
+ else
+ selStartTotal = currentLength+oldLength;
+ selEndTotal = selEnd+oldLength;
+ selEndT = selEndTotal+1;
+ pos = ((MarkedArea)outputVector.elementAt(outputVector.size()-1)).end;
+ if (debug2)
+ System.out.print("the last registered position: "+ pos);
+ if (debug2)
+ System.out.println(" selStart: "+ selStartTotal+ " selEnd: "+selEndTotal);
+ if (selEnd+oldLength>pos)
+ {
+ addedLength = selEndTotal-selStartTotal+2;
+ outputVector.addElement(new MarkedArea(selStartTotal, selEndTotal+1, focusPosition,restString.substring(currentLength)));
+ if (debug2)
+ System.out.println("APPENDING Selection Last:"+restString.substring(currentLength)+
+ "Length: "+addedLength+" POSITION: "+selStartTotal + " "+selEndT);
+ }
+ }
+ } //if selectionStart>-1
+ else
+ {
+ if (debug2) System.out.println("NO SELECTION IN THE TEXT TO BE APPENDED!");
+ //cutting tags from previous focuses if any:
+ int r = restString.indexOf("");
+ while (r>-1)
+ {
+ // check if punktualtion marks like . ! ? are at the end of a sentence:
+ if (restString.charAt(r+10)==' ')
+ restString = restString.substring(0,r)+restString.substring(r+11);
+ else
+ restString = restString.substring(0,r)+restString.substring(r+10);
+ r = restString.indexOf("");
+ }
+ r = restString.indexOf("-1)
+ {
+ int t = getCharacter(restString,">",r);
+ if (t";
+ String less = "\\"+"<";
+ restString = replaceSubstring(restString,more,"> ");
+ restString = replaceSubstring(restString,less," <");
+ restString= replaceSubstring(restString,"\\\\"," \\");
+ if (debug4)
+ System.out.println(restString);
+ output.append(restString.replaceAll("&-","\n "));
+ if ((selectionEnd>=selectionStart)&&(selectionStart>-1))
+ try {
+ output.getHighlighter().addHighlight(selStart+oldLength, selEnd+oldLength+1, new DefaultHighlighter.DefaultHighlightPainter(color) );
+ selectedText = output.getText().substring(selStart+oldLength, selEnd+oldLength+1);
+ // output.getHighlighter().addHighlight(selStart+oldLength, selEnd+oldLength+1, new DefaultHighlighter.DefaultHighlightPainter(Color.white) );
+ } catch (Exception e) {System.out.println("highlighting problem!");}
+ }// s.length()>0
+ }
+
+ /*
+ Replaces the occurences of old by newString in the s
+ */
+ public static String replaceSubstring(String s, String old, String newString)
+ {
+ String ss = s;
+ int i =ss.indexOf(old);
+ while (i!=-1)
+ {
+ ss = ss.substring(0,i) + newString + ss.substring(i+old.length());
+ i =ss.indexOf(old);
+ }
+ return ss;
+ }
+
+ /*
+ Finding position of the charactern not starting with escape symbol (//)
+ in the string s from position.
+ */
+ public static int getCharacter(String s, String character, int position)
+ {
+ int t = restString.indexOf(character, position);
+ int i = t-1;
+ int k = 0;
+ while ((i>-1)&&(restString.charAt(i)=='\\'))
+ {
+ k++;
+ i--;
+ }
+ if (k % 2 == 0)
+ return t;
+ else
+ return getCharacter(s, character, t+1);
+ }
+
+ /* Assigns the position to the substring from start to end in the linearization */
+ public static void register(int start, int end, LinPosition position)
+ {
+ oldLength = output.getText().length();
+ addedLength = 0;
+ int resultCurrent = 0;
+ int resultNew = 0;
+ newLength = end-start;
+ // the tag has some words to register:
+ if (newLength>0)
+ {
+ //focus has a separate position:
+ if (selectionCheck&&(end>selStart))
+ {
+ selectionCheck=false;
+ if (debug2)
+ System.out.println("SELECTION HAS A SEPARATE POSITION");
+ if (debug2)
+ System.out.println("SELECTION: "+ selStart+" "+selEnd);
+ if (debug2)
+ System.out.println("TEXT to REGISTER: "+ start+" "+end);
+ if (debug2)
+ System.out.println("CURRLENGTH: "+ currentLength);
+
+ resultCurrent = currentLength+oldLength;
+
+ if (selStart>start+1)
+ {
+ // register text before selection:
+ addedLength = selStart - start;
+ resultNew = resultCurrent+ addedLength -1;
+ outputVector.addElement(new MarkedArea(resultCurrent, resultNew, position, restString.substring(start,start+addedLength)));
+ if (debug2)
+ System.out.println("APPENDING ZONE Before selection:"+restString.substring(start,start+addedLength)+
+ "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
+ }
+
+ //selection:
+ resultCurrent += addedLength;
+ addedLength = selEnd - selStart + 2;
+ resultNew = resultCurrent + addedLength - 1;
+ outputVector.addElement(new MarkedArea(resultCurrent, resultNew, focusPosition,restString.substring(selStart,selEnd+2)));
+ if (debug2)
+ System.out.println("APPENDING SelectedZONE: "+restString.substring(selStart,selEnd+2)+
+ "Length: "+newLength+" POSITION: "+resultCurrent + " "+resultNew);
+
+
+ if (end>selEnd+2)
+ {
+ // register the rest:
+ resultCurrent += addedLength;
+ addedLength = end-selEnd-2;
+ resultNew = resultCurrent + addedLength -1;
+ outputVector.addElement(new MarkedArea(resultCurrent, resultNew, position,restString.substring(selEnd+2,end)));
+ if (debug2)
+ System.out.println("APPENDING ZONE after:"+
+ restString.substring(selEnd+2,end)+
+ "Length: "+newLength+" POSITION: "+resultCurrent + " "+resultNew);
+ }
+ }// focus has a separate position
+ else
+ {
+ resultCurrent = currentLength + oldLength ;
+ resultNew = newLength + resultCurrent - 1;
+ if (debug2) System.out.println("Start: "+ start + " end: "+end);
+ if (debug2) System.out.println("STRING: "+ restString + " which length is: "+restString.length());
+ stringToAppend = restString.substring(start,end);
+ if (stringToAppend.trim().length()>0)
+ {
+ outputVector.addElement(new MarkedArea(resultCurrent, resultNew, position,stringToAppend));
+ if (debug2)
+ System.out.println("APPENDING ZONE:"+stringToAppend+
+ "Length: "+newLength+" POSITION: "+resultCurrent + " "+resultNew+" "+position.position);
+ }
+ else
+ if (debug2)
+ System.out.println("whiteSpaces: "+newLength);
+ }
+ } //some words to register
+ }
+
+ /* removing subtree-tag in the interval start-end
+ and updating the coordinates after that
+ */
+ public static void removeSubTreeTag (int start, int end)
+ {
+ if (debug2)
+ System.out.println("removing: "+ start +" to "+ end);
+ int difference =end-start+1;
+ int positionStart, positionEnd;
+ if (difference>20)
+ {
+ positionStart = restString.indexOf("[", start);
+ positionEnd = restString.indexOf("]", start);
+
+ currentPosition.addElement(new LinPosition(
+ restString.substring(positionStart, positionEnd+1),
+ restString.substring(start,end).indexOf("incorrect")==-1));
+ }
+ else
+ if (currentPosition.size()>0)
+ currentPosition.removeElementAt(currentPosition.size()-1);
+ if (start>0)
+ restString = restString.substring(0,start)+restString.substring(end+1);
+ else
+ restString = restString.substring(end+1);
+ if (selStart > end)
+ { selStart -=difference;
+ selEnd -=difference;
+ }
+ else
+ if (selEnd < start) ;
+ else selEnd -=difference;
+ }
+
+ /* handling the event of choosing the action at index from the list*/
+ public void listAction(int index) {
+ if (index == -1)
+ {if (debug) System.out.println("no selection");}
+ else {
+ treeChanged = true;
+ send((String)commands.elementAt(list.getSelectedIndex()));
+ }
+ }
+
+ // pop-up menu (adapted from DynamicTree2):
+ class PopupListener extends MouseAdapter {
+ public void mousePressed(MouseEvent e) {
+// int selStart = tree.getRowForLocation(e.getX(), e.getY());
+// output.setSelectionRow(selStart);
+ if (debug3)
+ System.out.println("mouse pressed2: "+output.getSelectionStart()+" "+output.getSelectionEnd());
+ //maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ if (debug3) System.out.println("mouse released2!"+output.getSelectionStart()+" "+output.getSelectionEnd());
+ maybeShowPopup(e);
+ }
+ }
+ void maybeShowPopup(MouseEvent e) {
+ int i=outputVector.size()-1;
+ // right click:
+ if (e.isPopupTrigger()) {
+ m2 = e;
+ timer2.start();
+ }
+ // middle click
+ if (e.getButton() == MouseEvent.BUTTON2)
+ {
+ // selection Exists:
+ if (!selectedText.equals(""))
+ {
+ if (debug3) System.out.println(e.getX() + " " + e.getY());
+ if (selectedText.length()<5)
+ if (treeCbMenuItem.isSelected())
+ field.setBounds(e.getX()+(int)Math.round(tree.getBounds().getWidth()), e.getY()+80, 400, 40);
+ else
+ field.setBounds(e.getX(), e.getY()+80, 400, 40);
+ else
+ if (treeCbMenuItem.isSelected())
+ field.setBounds(e.getX()+(int)Math.round(tree.getBounds().getWidth()), e.getY()+80, selectedText.length()*20, 40);
+ else
+ field.setBounds(e.getX(), e.getY()+80, selectedText.length()*20, 40);
+ getLayeredPane().add(field, new Integer(1), 0);
+ field.setText(selectedText);
+ field.requestFocusInWindow();
+ }
+ }
+ }
+ void addMenuItem(String name){
+ menuItem2 = new JMenuItem(name);
+ menuItem2.setFont(font);
+ menuItem2.setActionCommand("popupMenuItem");
+ menuItem2.addActionListener(this);
+ popup2.add(menuItem2);
+
+ }
+ public void focusGained(FocusEvent e)
+ {
+ }
+ public void focusLost(FocusEvent e)
+ {
+ getLayeredPane().remove(field);
+ repaint();
+ }
+}
+
+ /*focus has a separate position:
+ if (selectionCheck&&(selEnd");
+ private JButton rightMeta = new JButton(">?");
+ private JButton read = new JButton("Read");
+ // private JButton parse = new JButton("Parse");
+ // private JButton term = new JButton("Term");
+ private JButton alpha = new JButton("Alpha");
+ private JButton random = new JButton("Random");
+ private JButton undo = new JButton("Undo");
+
+ private JPanel inputPanel = new JPanel();
+ private JPanel inputPanel2 = new JPanel();
+ private JPanel inputPanel3 = new JPanel();
+ private JButton ok = new JButton("OK");
+ private JButton cancel = new JButton("Cancel");
+ private JTextField inputField = new JTextField();
+ private JLabel inputLabel = new JLabel("Read: ");
+ private JButton browse = new JButton("Browse...");
+ private ButtonGroup readGroup = new ButtonGroup();
+ private JRadioButton termReadButton = new JRadioButton("Term");
+ private JRadioButton stringReadButton = new JRadioButton("String");
+
+ private JDialog dialog;
+
+ private static JComboBox menu = new JComboBox(newMenu);
+ private JComboBox filter = new JComboBox(filterMenu);
+ private JComboBox modify = new JComboBox(modifyMenu);
+ // private JComboBox mode = new JComboBox(modeMenu);
+
+ private JPanel downPanel = new JPanel();
+ private JSplitPane treePanel;
+ private JPanel upPanel = new JPanel();
+ private JPanel middlePanel = new JPanel();
+ private JPanel middlePanelUp = new JPanel();
+ private JPanel middlePanelDown = new JPanel();
+ private JSplitPane centerPanel;
+ private static JFrame gui2 = new JFrame();
+ private JPanel centerPanel2= new JPanel();
+ private JPanel centerPanelDown = new JPanel();
+ private JScrollPane outputPanelDown = new JScrollPane(list);
+ private JScrollPane outputPanelCenter = new JScrollPane(output);
+ private JPanel outputPanelUp = new JPanel();
+ private JPanel statusPanel = new JPanel();
+ private static JLabel statusLabel = new JLabel(status);
+ private Container cp;
+
+ private static JMenuBar menuBar= new JMenuBar();;
+ private static ButtonGroup menuGroup = new ButtonGroup();
+ private JMenu viewMenu= new JMenu("View");
+ private JMenu submenu= new JMenu("Language");
+ private JMenu submenuFont= new JMenu("TextSize");
+ private JMenu modeMenu= new JMenu("Menus");
+ private static JMenu langMenu= new JMenu("Languages");
+ private static JMenu fileMenu= new JMenu("File");
+ private JRadioButtonMenuItem rbMenuItem;
+ private JRadioButtonMenuItem rbMenuItemLong;
+ // private JRadioButtonMenuItem rbMenuItemAbs;
+ private JRadioButtonMenuItem rbMenuItemUnTyped;
+ private static JMenuItem fileMenuItem;
+ private static JCheckBoxMenuItem cbMenuItem;
+ private static RadioListener myListener ;
+ private static ButtonGroup group = new ButtonGroup();
+ private static ButtonGroup languageGroup = new ButtonGroup();
+ private static ButtonGroup fontGroup = new ButtonGroup();
+
+ public Numerals()
+ {
+ this.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ endProgram();
+ }
+ });
+ setJMenuBar(menuBar);
+ setTitle("Numerals");
+
+ GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ String envfonts[] = gEnv.getAvailableFontFamilyNames();
+ fontList = new JComboBox(envfonts);
+ fontList.addActionListener(this);
+ //fontList.setFont(font);
+ //fontLabel.setFont(font);
+ up.add(fontLabel);
+ up.add(fontList);
+
+ viewMenu.setToolTipText("View settings");
+ fileMenu.setToolTipText("File operations");
+ langMenu.setToolTipText("Language settings");
+ menuBar.add(fileMenu);
+ menuBar.add(langMenu);
+ menuBar.add(viewMenu);
+ //menuBar.add(modeMenu);
+
+ //cbMenuItem = new JCheckBoxMenuItem("Tree");
+ //cbMenuItem.setActionCommand("showTree");
+ myListener = new RadioListener();
+ //cbMenuItem.addActionListener(myListener);
+ //cbMenuItem.setSelected(true);
+ //viewMenu.add(cbMenuItem);
+ //viewMenu.addSeparator();
+ rbMenuItem = new JRadioButtonMenuItem("large");
+ rbMenuItem.setActionCommand("large");
+ rbMenuItem.addActionListener(myListener);
+ fontGroup.add(rbMenuItem);
+ rbMenuItem.setSelected(false);
+ submenuFont.add(rbMenuItem);
+ rbMenuItem = new JRadioButtonMenuItem("medium");
+ rbMenuItem.setActionCommand("medium");
+ rbMenuItem.addActionListener(myListener);
+ fontGroup.add(rbMenuItem);
+ rbMenuItem.setSelected(true);
+ submenuFont.add(rbMenuItem);
+ rbMenuItem = new JRadioButtonMenuItem("small");
+ rbMenuItem.setActionCommand("small");
+ rbMenuItem.addActionListener(myListener);
+ fontGroup.add(rbMenuItem);
+ rbMenuItem.setSelected(false);
+ submenuFont.add(rbMenuItem);
+
+ viewMenu.add(submenuFont);
+ //viewMenu.addSeparator();
+
+ /* fileMenuItem = new JMenuItem("Open...");
+ fileMenuItem.setActionCommand("open");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenuItem = new JMenuItem("New Topic...");
+ fileMenuItem.setActionCommand("newTopic");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenuItem = new JMenuItem("Reset");
+ fileMenuItem.setActionCommand("reset");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ */
+ fileMenuItem = new JMenuItem("Save As...");
+ fileMenuItem.setActionCommand("save");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+ fileMenu.addSeparator();
+ fileMenuItem = new JMenuItem("Exit");
+ fileMenuItem.setActionCommand("quit");
+ fileMenuItem.addActionListener(this);
+ fileMenu.add(fileMenuItem);
+
+ // rbMenuItem = new JRadioButtonMenuItem("One window");
+ // rbMenuItem.setActionCommand("combine");
+ // rbMenuItem.addActionListener(myListener);
+ // rbMenuItem.setSelected(true);
+/* rbMenuItem.setMnemonic(KeyEvent.VK_R);
+ rbMenuItem.setAccelerator(KeyStroke.getKeyStroke(
+ KeyEvent.VK_1, ActionEvent.ALT_MASK));
+ rbMenuItem.getAccessibleContext().setAccessibleDescription(
+ "This doesn't really do anything");
+*/
+ /* menuGroup.add(rbMenuItem);
+ viewMenu.add(rbMenuItem);
+
+ rbMenuItem = new JRadioButtonMenuItem("Split windows");
+ rbMenuItem.setMnemonic(KeyEvent.VK_O);
+ rbMenuItem.setActionCommand("split");
+ rbMenuItem.addActionListener(myListener);
+ menuGroup.add(rbMenuItem);
+ viewMenu.add(rbMenuItem);
+
+ modeMenu.add(submenu);
+ */
+
+ /* rbMenuItemAbs = new JRadioButtonMenuItem("Abstract");
+ rbMenuItemAbs.setActionCommand("Abstract");
+ rbMenuItemAbs.addActionListener(myListener);
+ languageGroup.add(rbMenuItemAbs);
+ */
+
+ /* modeMenu.addSeparator();
+ menuGroup = new ButtonGroup();
+ rbMenuItemLong = new JRadioButtonMenuItem("long");
+ rbMenuItemLong.setActionCommand("long");
+ rbMenuItemLong.setSelected(true);
+ rbMenuItemLong.addActionListener(myListener);
+ menuGroup.add(rbMenuItemLong);
+ modeMenu.add(rbMenuItemLong);
+ rbMenuItem = new JRadioButtonMenuItem("short");
+ rbMenuItem.setActionCommand("short");
+ rbMenuItem.addActionListener(myListener);
+ menuGroup.add(rbMenuItem);
+ modeMenu.add(rbMenuItem);
+ modeMenu.addSeparator();
+
+ menuGroup = new ButtonGroup();
+ rbMenuItem = new JRadioButtonMenuItem("typed");
+ rbMenuItem.setActionCommand("typed");
+ rbMenuItem.addActionListener(myListener);
+ rbMenuItem.setSelected(false);
+ menuGroup.add(rbMenuItem);
+ modeMenu.add(rbMenuItem);
+ rbMenuItemUnTyped = new JRadioButtonMenuItem("untyped");
+ rbMenuItemUnTyped.setSelected(true);
+ rbMenuItemUnTyped.setActionCommand("untyped");
+ rbMenuItemUnTyped.addActionListener(myListener);
+ menuGroup.add(rbMenuItemUnTyped);
+ modeMenu.add(rbMenuItemUnTyped);
+ */
+ cp = getContentPane();
+ cp.setLayout(new BorderLayout());
+ cp.add(outputPanelCenter, BorderLayout.CENTER);
+ cp.add(downPanel, BorderLayout.SOUTH);
+ cp.add(up, BorderLayout.NORTH);
+ downPanel.add(random);
+ downPanel.add(input);
+ input.addKeyListener(this);
+ downPanel.add(send);
+
+ // output.setToolTipText("Linearizations' display area");
+ output.setEditable(false);
+ output.setLineWrap(true);
+ output.setWrapStyleWord(true);
+// output.setSelectionColor(Color.green);
+ output.setSelectionColor(Color.white);
+// output.setFont(new Font("Arial Unicode MS", Font.PLAIN, 17));
+ output.setFont(new Font(null, Font.PLAIN, 17));
+// System.out.println(output.getFont().getFontName());
+ send.setToolTipText("Showing the translation of a numeral");
+ random.setToolTipText("Generating a random numeral");
+/* gfCommand.setToolTipText("Sending a command to GF");
+ read.setToolTipText("Refining with term or linearization from typed string or file");
+ modify.setToolTipText("Choosing a linearization method");
+ alpha.setToolTipText("Performing alpha-conversion");
+ random.setToolTipText("Generating random refinement");
+ undo.setToolTipText("Going back to the previous state");
+ downPanel.add(gfCommand);
+ //downPanel.add(parse);
+ //downPanel.add(term);
+ downPanel.add(read);
+ downPanel.add(modify);
+ downPanel.add(alpha);
+ downPanel.add(random);
+ downPanel.add(undo);
+
+ leftMeta.setToolTipText("Moving the focus to the previous metavariable");
+ rightMeta.setToolTipText("Moving the focus to the next metavariable");
+ left.setToolTipText("Moving the focus to the previous term");
+ right.setToolTipText("Moving the focus to the next term");
+ top.setToolTipText("Moving the focus to the top term");
+ middlePanelUp.add(leftMeta);
+ middlePanelUp.add(left);
+ middlePanelUp.add(top);
+ middlePanelUp.add(right);
+ middlePanelUp.add(rightMeta);
+ middlePanelDown.add(new JLabel("Select Action on Subterm"));
+ middlePanel.setLayout(new BorderLayout());
+ middlePanel.add(middlePanelUp, BorderLayout.NORTH);
+ middlePanel.add(middlePanelDown, BorderLayout.CENTER);
+
+ menu.setToolTipText("The list of available categories to start editing");
+ open.setToolTipText("Reading both a new environment and an editing object from file. Current editing will be discarded");
+ save.setToolTipText("Writing the current editing object to file in the term or text format");
+ grammar.setToolTipText("Current Topic");
+ newTopic.setToolTipText("Reading a new environment from file. Current editing will be discarded.");
+ upPanel.add(grammar);
+ upPanel.add(menu);
+ upPanel.add(open);
+ upPanel.add(save);
+ upPanel.add(newTopic);
+
+ filter.setToolTipText("Choosing the linearization representation format");
+ modeMenu.setToolTipText("Choosing the refinement options' representation");
+ statusLabel.setToolTipText("The current focus type");
+ list.setToolTipText("The list of current refinment options");
+ tree.setToolTipText("The abstract syntax tree representation of the current editing object");
+ upPanel.add(filter);
+ //upPanel.add(mode);
+ populateTree(tree);
+ outputPanelUp.setLayout(new BorderLayout());
+ outputPanelUp.add(outputPanelCenter, BorderLayout.CENTER);
+ outputPanelUp.add(statusPanel, BorderLayout.SOUTH);
+ statusPanel.setLayout(new GridLayout(1,1));
+ statusPanel.add(statusLabel);
+ treePanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
+ tree, outputPanelUp);
+ treePanel.setDividerSize(5);
+ treePanel.setDividerLocation(100);
+ centerPanel2.setLayout(new BorderLayout());
+ gui2.setSize(500,150);
+ gui2.setTitle("Select Action on Subterm");
+ gui2.setLocationRelativeTo(treePanel);
+ centerPanelDown.setLayout(new BorderLayout());
+ centerPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
+ treePanel, centerPanelDown);
+ centerPanel.addKeyListener(tree);
+ centerPanel.setOneTouchExpandable(true);
+ centerPanelDown.add(middlePanel, BorderLayout.NORTH);
+ centerPanelDown.add(outputPanelDown, BorderLayout.CENTER);
+ cp.add(centerPanel, BorderLayout.CENTER);
+ cp.add(upPanel, BorderLayout.NORTH);
+ cp.add(downPanel, BorderLayout.SOUTH);
+
+ list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+
+ MouseListener mouseListener = new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ listAction(list.locationToIndex(e.getPoint()));
+ }
+ }
+ };
+ list.addMouseListener(mouseListener);
+ list.addKeyListener(this);
+ menu.addActionListener(this);
+ save.addActionListener(this);
+ open.addActionListener(this);
+ newTopic.addActionListener(this);
+ gfCommand.addActionListener(this);
+
+ filter.addActionListener(this);
+ filter.setMaximumRowCount(9);
+ leftMeta.addActionListener(this);
+ left.addActionListener(this);
+
+ menu.setFocusable(false);
+ save.setFocusable(false);
+ save.setActionCommand("save");
+ open.setFocusable(false);
+ open.setActionCommand("open");
+ newTopic.setFocusable(false);
+ newTopic.setActionCommand("newTopic");
+ gfCommand.setFocusable(false);
+
+ filter.setFocusable(false);
+ leftMeta.setFocusable(false);
+ left.setFocusable(false);
+
+ top.addActionListener(this);
+ right.addActionListener(this);
+ rightMeta.addActionListener(this);
+ //parse.addActionListener(this);
+ //term.addActionListener(this);
+ read.addActionListener(this);
+ modify.addActionListener(this);
+ //mode.addActionListener(this);
+ alpha.addActionListener(this);
+ random.addActionListener(this);
+ undo.addActionListener(this);
+
+ top.setFocusable(false);
+ right.setFocusable(false);
+ rightMeta.setFocusable(false);
+ //parse.setFocusable(false);
+ //term.setFocusable(false);
+ read.setFocusable(false);
+ modify.setFocusable(false);
+ //mode.setFocusable(false);
+ alpha.setFocusable(false);
+ random.setFocusable(false);
+ undo.setFocusable(false);
+
+ output.addKeyListener(tree);
+
+ outputPanelUp.setPreferredSize(new Dimension(500,300));
+ treePanel.setDividerLocation(0.3);
+ nodeTable.put(new TreePath(DynamicTree.rootNode.getPath()), new Integer(0));
+
+ JRadioButton termButton = new JRadioButton("Term");
+ termButton.setActionCommand("term");
+ termButton.setSelected(true);
+ JRadioButton linButton = new JRadioButton("Text");
+ linButton.setActionCommand("lin");
+ // Group the radio buttons.
+ group.add(linButton);
+ group.add(termButton);
+ JPanel buttonPanel = new JPanel();
+ buttonPanel.setPreferredSize(new Dimension(70, 70));
+ buttonPanel.add(new JLabel("Format:"));
+ buttonPanel.add(linButton);
+ buttonPanel.add(termButton);
+ fc1.setAccessory(buttonPanel);
+
+ termReadButton.setActionCommand("term");
+ stringReadButton.setSelected(true);
+ stringReadButton.setActionCommand("lin");
+ // Group the radio buttons.
+ readGroup.add(stringReadButton);
+ readGroup.add(termReadButton);
+ JPanel readButtonPanel = new JPanel();
+ readButtonPanel.setLayout(new GridLayout(3,1));
+ readButtonPanel.setPreferredSize(new Dimension(70, 70));
+ readButtonPanel.add(new JLabel("Format:"));
+ readButtonPanel.add(stringReadButton);
+ readButtonPanel.add(termReadButton);
+ dialog= new JDialog(this, "Input");
+ dialog.setLocationRelativeTo(this);
+ dialog.getContentPane().add(inputPanel);
+ inputPanel.setLayout(new BorderLayout(10,10));
+ inputPanel3.setLayout(new GridLayout(2,1,5,5));
+ inputPanel3.add(inputLabel);
+ inputPanel3.add(inputField);
+ ok.addActionListener(this);
+ browse.addActionListener(this);
+ cancel.addActionListener(this);
+ inputField.setPreferredSize(new Dimension(300,23));
+ inputPanel.add(inputPanel3, BorderLayout.CENTER);
+ inputPanel.add(new JLabel(" "), BorderLayout.WEST);
+ inputPanel.add(readButtonPanel, BorderLayout.EAST);
+ inputPanel.add(inputPanel2, BorderLayout.SOUTH);
+ inputPanel2.add(ok);
+ inputPanel2.add(cancel);
+ inputPanel2.add(browse);
+ dialog.setSize(350,135);
+ */
+ send.addActionListener(this);
+ random.addActionListener(this);
+ setSize(400,700);
+ setVisible(true);
+
+ try {
+ result = fromProc.readLine();
+ boolean firstCall = true;
+ while(result != null) {
+ boolean newCommand = true;
+ finished = false;
+ if (debug) System.out.println("01 "+result);
+ while (result.indexOf("gf")==-1){
+ outputString +=result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("001 "+result);
+ }
+ output.append(outputString);
+ if (newCommand)
+ {
+ if (firstCall)
+ {
+ output.setText("Welcome to Numerals! \n Print a number in the text field below and \n press Enter or use the Random button.");
+ firstCall = false;
+ }
+ else
+ output.setText("");
+ System.out.println("!!!!!!! output cleared !");
+ newCommand = false;
+ }
+
+ while ((result.indexOf("newcat")==-1)&&(result.indexOf("8)
+ s+=result.trim();
+ else
+ s+=result;
+ }
+ }
+// if (s.charAt(0)!='d')
+// listModel.addElement("Refine " + s);
+// else
+ listModel.addElement(s);
+ s="";
+ //read /show
+ //read send
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ saveCommand();
+ // read /item
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("8 "+result);
+ }
+ } catch(IOException e){ }
+ }
+
+ public static void saveCommand(){
+ if (newObject) commands.add(result);
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("9 "+result);
+ } catch(IOException e){ }
+ }
+
+ public void readLin(){
+ try {
+ linearization="";
+ linearization += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ while (result.indexOf("/linearization")==-1){
+ linearization += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ }
+ if (newObject) formLin();
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ } catch(IOException e){ }
+ }
+
+ public static void readTree(){
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ while (result.indexOf("/tree")==-1){
+ treeString += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ }
+ if (treeChanged && (newObject)) {
+ formTree(tree);
+ treeChanged = false;
+ }
+ treeString="";
+ result = fromProc.readLine();
+ if (debug) System.out.println("6 "+result);
+ } catch(IOException e){ }
+ }
+
+ public static void readMessage(){
+ String s ="";
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("7 "+result);
+ while (result.indexOf("/message")==-1){
+ s += result+"\n";
+ result = fromProc.readLine();
+ if (debug) System.out.println("7 "+result);
+ }
+ if ((s.length()>1)&&(s.indexOf("to start")==-1))
+ output.append("-------------"+'\n'+s);
+ result = fromProc.readLine();
+ if (debug) System.out.println("7 "+result);
+ } catch(IOException e){ }
+ }
+
+ public void formNewMenu () {
+ boolean more = true;
+ try {
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+
+ while (more){
+ if (result.indexOf("language")==-1) {
+ menu.addItem(result.substring(6));
+ }
+ else
+ more = false;
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+ result = fromProc.readLine();
+ if (debug) System.out.println("3 "+result);
+ if (result.indexOf("language")!=-1)
+ more = false;
+ result = fromProc.readLine();
+ if (debug) System.out.println("4 "+result);
+ }
+
+ more = true;
+ while (more){
+ if ((result.indexOf("/gf")==-1)&&(result.indexOf("lin")==-1)) {
+ //form lang and Menu menu:
+ cbMenuItem = new JCheckBoxMenuItem(result.substring(4));
+ System.out.println ("menu item: "+result.substring(4));
+ if (!(result.substring(4).equals("Abstract")))
+ cbMenuItem.setSelected(true);
+ cbMenuItem.setActionCommand("lang");
+ cbMenuItem.addActionListener(myListener);
+ langMenu.add(cbMenuItem);
+/* if ((result.substring(4)).equals("Abstract"))
+ {
+ submenu.add(rbMenuItemAbs);
+ if (selectedMenuLanguage.equals("Abstract"))
+ rbMenuItemAbs.setSelected(true);
+ languageGroup.add(rbMenuItemAbs);
+ }
+ else
+ {
+*/
+ rbMenuItem = new JRadioButtonMenuItem(result.substring(4));
+ rbMenuItem.setActionCommand("language"+result.substring(4));
+ rbMenuItem.addActionListener(myListener);
+ languageGroup.add(rbMenuItem);
+ if ((result.substring(4)).equals(selectedMenuLanguage))
+ {
+ if (debug) System.out.println("Selecting "+selectedMenuLanguage);
+ rbMenuItem.setSelected(true);
+ }
+
+ submenu.add(rbMenuItem);
+// }
+ }
+ else
+ more = false;
+ // read
+ result = fromProc.readLine();
+ if (debug) System.out.println("2 "+result);
+ // read or
+ result = fromProc.readLine();
+ if (debug) System.out.println("3 "+result);
+ if ((result.indexOf("/gf")!=-1)||(result.indexOf("lin")!=-1))
+ more = false;
+ if (result.indexOf("/gf")!=-1)
+ finished = true;
+ // registering the file name:
+ if (result.indexOf("language")!=-1) {
+ String path = result.substring(result.indexOf('=')+1,
+ result.indexOf('>'));
+ path =path.substring(path.lastIndexOf('/')+1);
+ if (debug) System.out.println("name: "+path);
+ fileString +="--" + path +"\n";
+ if (path.lastIndexOf('.')!=path.indexOf('.'))
+ grammar.setText(path.substring(0,
+ path.indexOf('.')).toUpperCase()+" ");
+ }
+ result = fromProc.readLine();
+ if (debug) System.out.println("4 "+result);
+ }
+ if (debug) System.out.println("languageGroupElement formed"+
+ languageGroup.getButtonCount());
+ langMenu.addSeparator();
+ fileMenuItem = new JMenuItem("Add...");
+ fileMenuItem.setActionCommand("import");
+ fileMenuItem.addActionListener(this);
+ langMenu.add(fileMenuItem);
+ // in order to get back in main in the beggining of while:
+ result = fromProc.readLine();
+ } catch(IOException e){ }
+ }
+
+ public void outputAppend(){
+ int i, j, k, l, l2, m;
+ i=result.indexOf("type=");
+ j=result.indexOf('>',i);
+ l = result.indexOf("
+ result= result.substring(0,l)+result.substring(j+1);
+ i=result.indexOf("/f",l);
+ if (debug) System.out.println("/ is at the position"+i);
+ j=result.indexOf('>',i);
+ k=result.length()-j;
+ if (debug) System.out.println("form Lin2: "+result);
+ m = output.getText().length();
+
+ //cutting
+ // in case focus tag is cut into two lines:
+ if (debug)
+ System.out.println("char at the previous position"+result.charAt(i-1));
+ if (result.charAt(i-1)!='<')
+ result= result.substring(0,i-8)+result.substring(j+1);
+ else
+ result= result.substring(0,i-1)+result.substring(j+1);
+ j= result.indexOf("');
+ String s = result.substring(ind+1,ind2);
+ result = lin.substring(0,lin.indexOf(""));
+ lin = lin.substring(lin.indexOf(""));
+ while (lin.length()>1) {
+ //check if the language is on
+ if (!visible) visible = true;
+ // in the list?
+ for (int i=0; i
+ lin = lin.substring(lin.indexOf('\n')+1);
+ // read lin or 'end'
+ if (lin.length()<1) break;
+
+ result = lin.substring(0,lin.indexOf('\n'));
+ lin = lin.substring(lin.indexOf('\n')+1);
+ if (result.indexOf("');
+ s = result.substring(ind+1,ind2);
+ result = lin.substring(0,lin.indexOf(""));
+ lin = lin.substring(lin.indexOf(""));
+ }
+ }
+ }
+
+ public void showAction(){
+ treeChanged = true;
+ send("n Numeral");
+ newObject = true;
+ System.out.println("!!!!!!!sending newNumeral");
+ treeChanged = true;
+ send("p "+ input.getText());
+ System.out.println("!!!!!!!sending parse string: "+input.getText());
+ }
+
+ public void actionPerformed(ActionEvent ae)
+ {
+ boolean abs = true;
+ Object obj = ae.getSource();
+
+ if ( obj == fontList ) {
+ Font font = new Font((String)fontList.getSelectedItem(), Font.PLAIN, 13);
+ output.setFont(font);
+ }
+
+ if ( obj == send ) {
+ showAction();
+ }
+
+ if ( obj == menu ) {
+ if (menu.getItemCount()>0)
+ if (!menu.getSelectedItem().equals("New"))
+ {
+ treeChanged = true;
+ send("n " + menu.getSelectedItem());
+ newObject = true;
+ menu.setSelectedIndex(0);
+ }
+ }
+
+ if ( obj == filter ) {
+ if (!filter.getSelectedItem().equals("Filter"))
+ {
+ send("f " + filter.getSelectedItem());
+ filter.setSelectedIndex(0);
+ }
+ }
+ if ( obj == modify ) {
+ if (!modify.getSelectedItem().equals("Modify"))
+ {
+ treeChanged = true;
+ send("c " + modify.getSelectedItem());
+ modify.setSelectedIndex(0);
+ }
+ }
+/* if ( obj == mode ) {
+ if (!mode.getSelectedItem().equals("Menus"))
+ {
+ send("o " + mode.getSelectedItem());
+ mode.setSelectedIndex(0);
+ }
+ }
+*/
+ // buttons and menu items:
+ boolean objectInstance = false;
+ try {
+ objectInstance =
+ Class.forName("javax.swing.AbstractButton").isInstance(obj);
+ } catch (Exception e) {System.out.println("Class not found!");}
+
+ if (objectInstance) {
+ String name =((AbstractButton)obj).getActionCommand();
+
+ if ( name.equals("quit")) {
+ endProgram();
+ }
+
+ if ( name.equals("save") ) {
+
+ if (fc1.getChoosableFileFilters().length<2)
+ fc1.addChoosableFileFilter(new GrammarFilter());
+ fc1.setFileFilter(fc1.getAcceptAllFileFilter());
+ int returnVal = fc1.showSaveDialog(Numerals.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc1.getSelectedFile();
+ if (debug) System.out.println("saving ... ");
+
+ /* // checking if the abstract syntax is on:
+ for (int i=0; i0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ if (debug) System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ if (debug) System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+ submenu.removeAll();
+
+ File file = fc1.getSelectedFile();
+ // opening the file for editing :
+ if (debug) System.out.println("opening: "+ file.getPath().replace('\\','/'));
+ if (group.getSelection().getActionCommand().equals("term")) {
+ if (debug) System.out.println(" opening as a term ");
+ send("open "+ file.getPath().replace('\\','/'));
+ }
+ else {
+ if (debug) System.out.println(" opening as a linearization ");
+ send("openstring "+ file.getPath().replace('\\','/'));
+ }
+
+ fileString ="";
+ grammar.setText("No Topic ");
+ }
+ }
+ }
+
+ if ( name.equals("import") ) {
+ if (fc.getChoosableFileFilters().length<2)
+ fc.addChoosableFileFilter(new GrammarFilter());
+ fc.setFileFilter(fc.getAcceptAllFileFilter());
+ int returnVal = fc.showOpenDialog(Numerals.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc.getSelectedFile();
+ // importing a new language :
+ if (debug) System.out.println("importing: "+ file.getPath());
+
+ langMenu.removeAll();
+
+ AbstractButton ab = null;
+
+ while (languageGroup.getButtonCount()>0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ if (debug) System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ if (debug) System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+
+ submenu.removeAll();
+
+ menu.removeAllItems();
+ menu.addItem("New");
+ fileString ="";
+ send("i "+ file.getPath().replace('\\','/'));
+
+ }
+ }
+ if ( name.equals("newTopic") ) {
+ if (fc.getChoosableFileFilters().length<2)
+ fc.addChoosableFileFilter(new GrammarFilter());
+ fc.setFileFilter(fc.getAcceptAllFileFilter());
+ int returnVal = fc.showOpenDialog(Numerals.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ int n = JOptionPane.showConfirmDialog(this,
+ "This will dismiss the previous editing. Would you like to continue?",
+ "Starting a new topic", JOptionPane.YES_NO_OPTION);
+ if (n == JOptionPane.YES_OPTION){
+ File file = fc.getSelectedFile();
+ // importing a new grammar :
+ newObject = false;
+ statusLabel.setText(status);
+ listModel.clear();
+ tree.clear();
+ populateTree(tree);
+ System.out.println("tree populated!");
+ menu.removeAllItems();
+ System.out.println("removed all from menu!"+menu);
+ menu.addItem("New");
+ System.out.println("added new!");
+ langMenu.removeAll();
+
+ AbstractButton ab = null;
+
+ while (languageGroup.getButtonCount()>0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ if (debug) System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ if (debug) System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+
+ selectedMenuLanguage = "Abstract";
+ rbMenuItemLong.setSelected(true);
+ rbMenuItemUnTyped.setSelected(true);
+ submenu.removeAll();
+
+ fileString="";
+ grammar.setText("No Topic ");
+ System.out.println("e "+ file.getPath().replace('\\','/'));
+ //send("e \""+ file.getPath().replace('\\','/')+"\"");
+ send("e "+ file.getPath().replace('\\','/'));
+ }
+ }
+ }
+
+ if ( obj == gfCommand ){
+ String s = JOptionPane.showInputDialog("Command:", parseInput);
+ if (s!=null) {
+ parseInput = s;
+ s = "gf "+s;
+ //treeChanged = true;
+ send(s);
+ }
+ }
+
+ if ( name.equals("reset") ) {
+ newObject = false;
+ statusLabel.setText(status);
+ listModel.clear();
+ tree.clear();
+ populateTree(tree);
+ menu.removeAllItems();
+ menu.addItem("New");
+ langMenu.removeAll();
+
+ AbstractButton ab = null;
+
+ while (languageGroup.getButtonCount()>0)
+ {
+ for (Enumeration e = languageGroup.getElements();
+ e.hasMoreElements() ;)
+ {
+ ab = (AbstractButton)e.nextElement();
+ if (debug) System.out.println("more to remove ! "+ab.getText());
+ languageGroup.remove(ab);
+ }
+ if (debug) System.out.println("languageGroupElement after import removal "+
+ languageGroup.getButtonCount());
+ }
+
+ selectedMenuLanguage = "Abstract";
+
+ submenu.removeAll();
+ rbMenuItemLong.setSelected(true);
+ rbMenuItemUnTyped.setSelected(true);
+
+ fileString="";
+ grammar.setText("No Topic ");
+ send("e");
+ }
+
+ if ( obj == leftMeta ) {
+ treeChanged = true;
+ send("<<");
+ }
+ if ( obj == left ) {
+ treeChanged = true;
+ send("<");
+ }
+ if ( obj == top ) {
+ treeChanged = true;
+ send("'");
+ }
+ if ( obj == right ) {
+ treeChanged = true;
+ send(">");
+ }
+ if ( obj == rightMeta ) {
+ treeChanged = true;
+ send(">>");
+ }
+
+ if ( obj == cancel ) {
+ dialog.hide();
+ }
+
+ if ( obj == browse ) {
+ if (fc.getChoosableFileFilters().length<2)
+ fc.addChoosableFileFilter(new GrammarFilter());
+ fc.setFileFilter(fc.getAcceptAllFileFilter());
+ int returnVal = fc.showOpenDialog(Numerals.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc.getSelectedFile();
+ inputField.setText(file.getPath().replace('\\','/'));
+ }
+ }
+
+ if ( obj == ok ) {
+ treeChanged = true;
+ if (termReadButton.isSelected()) {
+ termInput = inputField.getText();
+ if (termInput.indexOf('/')==-1){
+ send("g "+termInput);
+ if (debug) System.out.println("sending term string");
+ }
+ else {
+ send("tfile "+termInput);
+ if (debug) System.out.println("sending file term: "+termInput);
+ }
+ }
+ else {
+ parseInput = inputField.getText();
+ if (parseInput.indexOf('/')==-1){
+ send("p "+parseInput);
+ if (debug) System.out.println("sending parse string"+parseInput);
+ }
+ else {
+ send("pfile "+parseInput);
+ if (debug) System.out.println("sending file parse string: "+parseInput);
+ }
+ }
+ dialog.hide();
+ }
+
+ if ( obj == read ) {
+ if (stringReadButton.isSelected())
+ inputField.setText(parseInput);
+ else
+ inputField.setText(termInput);
+ dialog.show();
+ }
+
+/* if ( obj == term ) {
+ inputLabel.setText("Term:");
+ inputField.setText(termInput);
+ dialog.show();
+ }
+ if ( obj == parse ) {
+ inputLabel.setText("Parse:");
+ inputField.setText(parseInput);
+ dialog.show();
+ }
+*/
+ if ( obj == alpha){
+ String s = JOptionPane.showInputDialog("Type string:", alphaInput);
+ if (s!=null) {
+ alphaInput = s;
+ treeChanged = true;
+ send("x "+s);
+ }
+ }
+ if ( obj == random){
+ treeChanged = true;
+ send("n Numeral");
+ newObject = true;
+ System.out.println("!!!!!!!sending newNumeral");
+ treeChanged = true;
+ send("a");
+ }
+ if ( obj == undo){
+ treeChanged = true;
+ send("u");
+ }
+ }
+ //} catch (Exception e) { System.out.println("exception!!!"); }
+ }
+ static void writeOutput(String str, String fileName) {
+
+ try {
+ FileOutputStream fos = new FileOutputStream(fileName);
+ Writer out = new OutputStreamWriter(fos, "UTF8");
+ out.write(str);
+ out.close();
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(null,
+ "Document is empty!","Error", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ public static void populateTree(DynamicTree treePanel) {
+ String p1Name = new String("Root");
+ DefaultMutableTreeNode p1;
+ p1 = treePanel.addObject(null, p1Name);
+ }
+
+ public static void formTree(DynamicTree treePanel) {
+ Hashtable table = new Hashtable();
+ TreePath path=null;
+ boolean treeStarted = false, selected = false;
+ String s = treeString;
+ String name ="";
+ treePanel.clear();
+ int j, shift=0, star=0, index = 0;
+ DefaultMutableTreeNode p2=null, p1=null;
+ if (debug) System.out.print("treeString: "+ s);
+ if (s.indexOf('*')!=-1) star = 1;
+ while (s.length()>0) {
+ while ((s.length()>0) && ((s.charAt(0)=='*')||(s.charAt(0)==' '))){
+ if (s.charAt(0) == '*') selected = true;
+ s = s.substring(1);
+ shift++;
+ }
+ if (s.length()>0) {
+ j = s.indexOf("\n");
+ name = s.substring(0, j);
+ index++;
+ s = s.substring(j+1);
+ shift = (shift - star)/2;
+
+ p1 = (DefaultMutableTreeNode)table.get(new Integer(shift));
+ p2 = treePanel.addObject(p1, name);
+ table.put(new Integer(shift+1), p2);
+ path = new TreePath(p2.getPath());
+ nodeTable.put(path, new Integer(index));
+ if (selected) {
+ treePanel.tree.setSelectionPath(path);
+ treePanel.oldSelection = index;
+ if (debug) System.out.println("new selected index "+ index);
+ selected = false;
+ }
+ treeStarted=true;
+ }
+ shift = 0;
+ }
+ if ((p2!=null)) {
+ treePanel.tree.makeVisible(path);
+ gui2.toFront();
+ index = 0;
+ }
+ }
+
+ /** Listens to the radio buttons. */
+ class RadioListener implements ActionListener {
+ public void actionPerformed(ActionEvent e) {
+ String action = e.getActionCommand();
+ if (action.equals("large") )
+ {
+ output.setFont(new Font((String)fontList.getSelectedItem(), Font.PLAIN, 26));
+ }
+ if (action.equals("medium") )
+ {
+ output.setFont(new Font((String)fontList.getSelectedItem(), Font.PLAIN, 17));
+ }
+ if (action.equals("small") )
+ {
+ output.setFont(new Font((String)fontList.getSelectedItem(), Font.PLAIN, 12));
+ }
+
+ if (action.equals("split") ) {
+ cp.remove(centerPanel);
+ centerPanel2.add(middlePanelUp, BorderLayout.SOUTH);
+ if (((JCheckBoxMenuItem)viewMenu.getItem(0)).isSelected()) {
+ centerPanel2.add(treePanel, BorderLayout.CENTER);
+ }
+ else {
+ centerPanel2.add(outputPanelUp, BorderLayout.CENTER);
+ }
+ cp.add(centerPanel2, BorderLayout.CENTER);
+ gui2.getContentPane().add(outputPanelDown);
+ gui2.setVisible(true);
+ pack();
+ repaint();
+ }
+
+ if (action.equals("combine") ) {
+ cp.remove(centerPanel2);
+ middlePanel.add(middlePanelUp, BorderLayout.NORTH);
+ if (((JCheckBoxMenuItem)viewMenu.getItem(0)).isSelected()) { gui2.setVisible(false);
+ centerPanel.setLeftComponent(treePanel);
+ }
+ else {
+ centerPanel.setLeftComponent(outputPanelUp);
+ gui2.setVisible(false);
+ }
+ cp.add(centerPanel, BorderLayout.CENTER);
+ centerPanelDown.add(outputPanelDown, BorderLayout.CENTER);
+ pack();
+ repaint();
+ }
+
+ if (action.equals("showTree") ) {
+ if (!((JCheckBoxMenuItem)e.getSource()).isSelected()){
+ if (debug) System.out.println("was selected");
+ cbMenuItem.setSelected(false);
+ if (((JRadioButtonMenuItem)viewMenu.getItem(2)).isSelected()) {
+ centerPanel.remove(treePanel);
+ centerPanel.setLeftComponent(outputPanelUp);
+ }
+ else {
+ centerPanel2.remove(treePanel);
+ centerPanel2.add(outputPanelUp, BorderLayout.CENTER);
+ }
+ }
+ else {
+ if (debug) System.out.println("was not selected");
+ cbMenuItem.setSelected(true);
+ if (((JRadioButtonMenuItem)viewMenu.getItem(2)).isSelected()) {
+ centerPanel.remove(outputPanelUp);
+ treePanel.setRightComponent(outputPanelUp);
+ centerPanel.setLeftComponent(treePanel);
+ }
+ else {
+ centerPanel2.remove(outputPanelUp);
+ treePanel.setRightComponent(outputPanelUp);
+ centerPanel2.add(treePanel, BorderLayout.CENTER);
+ }
+ }
+ pack();
+ repaint();
+ }
+
+ if (action.equals("lang")) {
+ if (newObject) {
+ output.setText("");
+ formLin();
+ }
+ if (debug)
+ System.out.println("language option has changed "+((JCheckBoxMenuItem)e.getSource()).getText());
+ if (((JCheckBoxMenuItem)e.getSource()).isSelected()){
+ if (debug) System.out.println("turning on");
+ send("on "+((JCheckBoxMenuItem)e.getSource()).getText());
+ }
+ else{
+ if (debug) System.out.println("turning off");
+ send("off "+((JCheckBoxMenuItem)e.getSource()).getText());
+ }
+ }
+
+ //modeMenus actions:
+
+ if ((action.equals("long")) || (action.equals("short")))
+ {
+ send("ms " + action);
+ }
+
+ if ((action.equals("typed")) || (action.equals("untyped")))
+ {
+ send("mt " + action);
+ }
+ if (action.equals("languageAbstract"))
+ {
+ send("ml Abs");
+ }
+ else if (action.length()>7)
+ if (action.substring(0,8).equals("language"))
+ {
+ selectedMenuLanguage = action.substring(8);
+ if (debug) System.out.println("sending ml "+selectedMenuLanguage);
+ send("ml " + selectedMenuLanguage);
+ }
+ }
+ }
+
+ /** Handle the key pressed event. */
+ public void keyPressed(KeyEvent e) {
+ int keyCode = e.getKeyCode();
+ if (keyCode == 10) {
+ //listAction(list.getSelectedIndex());
+ showAction();
+ }
+ }
+ /** Handle the key typed event. */
+ public void keyTyped(KeyEvent e) {
+ }
+ /** Handle the key released event. */
+ public void keyReleased(KeyEvent e) {
+ }
+
+ public void listAction(int index) {
+ if (index == -1)
+ {if (debug) System.out.println("no selection");}
+ else {
+ treeChanged = true;
+ send((String)commands.elementAt(list.getSelectedIndex()));
+ }
+ }
+}
diff --git a/src-2.9/JavaGUI/Utils.java b/src-2.9/JavaGUI/Utils.java
new file mode 100644
index 000000000..b10f54712
--- /dev/null
+++ b/src-2.9/JavaGUI/Utils.java
@@ -0,0 +1,22 @@
+
+import java.io.File;
+
+public class Utils {
+
+ public final static String gf = "gf";
+ public final static String gfcm = "gfcm";
+
+ /*
+ * Get the extension of a file.
+ */
+ public static String getExtension(File f) {
+ String ext = null;
+ String s = f.getName();
+ int i = s.lastIndexOf('.');
+
+ if (i > 0 && i < s.length() - 1) {
+ ext = s.substring(i+1).toLowerCase();
+ }
+ return ext;
+ }
+}
diff --git a/src-2.9/JavaGUI/manifest.txt b/src-2.9/JavaGUI/manifest.txt
new file mode 100644
index 000000000..006d8adfd
--- /dev/null
+++ b/src-2.9/JavaGUI/manifest.txt
@@ -0,0 +1 @@
+Main-Class: GFEditor2
diff --git a/src-2.9/JavaGUI/runNumerals b/src-2.9/JavaGUI/runNumerals
new file mode 100644
index 000000000..3445220cc
--- /dev/null
+++ b/src-2.9/JavaGUI/runNumerals
@@ -0,0 +1 @@
+java -cp ./ Numerals "GF +java ../../grammars/numerals/old/numerals.Ita.gf ../../grammars/numerals/old/numerals.Mag.gf ../../grammars/numerals/old/numerals.Tam.gf ../../grammars/numerals/old/numerals.Suo.gf ../../grammars/numerals/old/numerals.NorB.gf ../../grammars/numerals/old/numerals.Slo.gf ../../grammars/numerals/old/numerals.Spa.gf ../../grammars/numerals/old/numerals.Swe.gf ../../grammars/numerals/old/numerals.Deu.gf ../../grammars/numerals/old/numerals.Fra.gf ../../grammars/numerals/old/numerals.Malay.gf ../../grammars/numerals/old/numerals.Ned.gf ../../grammars/numerals/old/numerals.Pol.gf ../../grammars/numerals/old/numerals.ChiU.gf ../../grammars/numerals/old/numerals.Dec.gf "
diff --git a/src-2.9/JavaGUI2/LICENCE_jargs b/src-2.9/JavaGUI2/LICENCE_jargs
new file mode 100644
index 000000000..509c1b7cb
--- /dev/null
+++ b/src-2.9/JavaGUI2/LICENCE_jargs
@@ -0,0 +1,29 @@
+Copyright (c) 2001-2003 Steve Purcell.
+Copyright (c) 2002 Vidar Holen.
+Copyright (c) 2002 Michal Ceresna.
+Copyright (c) 2005 Ewan Mellor.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met: Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer. Redistributions in
+binary form must reproduce the above copyright notice, this list of
+conditions and the following disclaimer in the documentation and/or other
+materials provided with the distribution. Neither the name of the copyright
+holder nor the names of its contributors may be used to endorse or promote
+products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/src-2.9/JavaGUI2/ManifestMain.txt b/src-2.9/JavaGUI2/ManifestMain.txt
new file mode 100644
index 000000000..b398ff78d
--- /dev/null
+++ b/src-2.9/JavaGUI2/ManifestMain.txt
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: de.uka.ilkd.key.ocl.gf.GFEditor2
+Class-Path: log4j-1.2.8.jar jargs-1.0.jar
diff --git a/src-2.9/JavaGUI2/gf-icon.gif b/src-2.9/JavaGUI2/gf-icon.gif
new file mode 100644
index 000000000..5e8863d76
Binary files /dev/null and b/src-2.9/JavaGUI2/gf-icon.gif differ
diff --git a/src-2.9/JavaGUI2/jargs-1.0.jar b/src-2.9/JavaGUI2/jargs-1.0.jar
new file mode 100644
index 000000000..cdbc80bb3
Binary files /dev/null and b/src-2.9/JavaGUI2/jargs-1.0.jar differ
diff --git a/src-2.9/Makefile b/src-2.9/Makefile
new file mode 100644
index 000000000..421409280
--- /dev/null
+++ b/src-2.9/Makefile
@@ -0,0 +1,324 @@
+include config.mk
+
+
+GHMAKE=$(GHC) --make
+GHCXMAKE=ghcxmake
+GHCFLAGS+= -fglasgow-exts
+GHCOPTFLAGS=-O2
+GHCFUDFLAG=
+JAVAFLAGS=-target 1.4 -source 1.4
+GFEDITOR=JavaGUI2
+
+DIST_DIR=GF-$(PACKAGE_VERSION)
+NOT_IN_DIST= \
+ grammars \
+ download \
+ doc/release2.html \
+ src/tools/AlphaConvGF.hs
+
+BIN_DIST_DIR=$(DIST_DIR)-$(host)
+
+GRAMMAR_PACKAGE_VERSION=$(shell date +%Y%m%d)
+GRAMMAR_DIST_DIR=gf-grammars-$(GRAMMAR_PACKAGE_VERSION)
+
+MSI_FILE=gf-$(subst .,_,$(PACKAGE_VERSION)).msi
+
+GF_DATA_DIR=$(datadir)/GF-$(PACKAGE_VERSION)
+GF_LIB_DIR=$(GF_DATA_DIR)/lib
+
+EMBED = GF/Embed/TemplateApp
+
+# use the temporary binary file name 'gf-bin' to not clash with directory 'GF'
+# on case insensitive file systems (such as FAT)
+GF_EXE=gf$(EXEEXT)
+GF_EXE_TMP=gf-bin$(EXEEXT)
+GF_DOC_EXE=gfdoc$(EXEEXT)
+GF3_EXE=gf3$(EXEEXT)
+TESTGF3_EXE=testgf3$(EXEEXT)
+
+
+ifeq ("$(READLINE)","readline")
+ GHCFLAGS += -package readline -DUSE_READLINE
+endif
+
+ifneq ("$(CPPFLAGS)","")
+ GHCFLAGS += $(addprefix -optP, $(CPPFLAGS))
+endif
+
+ifneq ("$(LDFLAGS)","")
+ GHCFLAGS += $(addprefix -optl, $(LDFLAGS))
+endif
+
+ifeq ("$(INTERRUPT)","yes")
+ GHCFLAGS += -DUSE_INTERRUPT
+endif
+
+ifeq ("$(ATK)","yes")
+ GHCFLAGS += -DUSE_ATK
+endif
+
+ifeq ("$(ENABLE_JAVA)", "yes")
+ BUILD_JAR=jar
+else
+ BUILD_JAR=
+endif
+
+.PHONY: all unix jar tags gfdoc windows install install-gf \
+ lib temp install-gfdoc install-editor \
+ today help clean windows-msi dist
+
+all: unix gfdoc $(BUILD_JAR) lib
+
+static: GHCFLAGS += -optl-static
+static: unix
+
+
+gf: unix
+
+unix: today opt
+
+windows: unix
+
+temp: today noopt
+
+
+
+build:
+ $(GHMAKE) $(GHCFLAGS) GF.hs -o $(GF_EXE_TMP)
+ strip $(GF_EXE_TMP)
+ mv $(GF_EXE_TMP) ../bin/$(GF_EXE)
+
+opt: GHCFLAGS += $(GHCOPTFLAGS)
+opt: build
+
+embed: GHCFLAGS += $(GHCOPTFLAGS)
+embed:
+ $(GHMAKE) $(GHCFLAGS) $(EMBED) -o $(EMBED)
+ strip $(EMBED)
+
+noopt: build
+
+ghci: ghci-nofud
+
+fud:
+ $(GHCXMAKE) $(GHCFLAGS) $(GHCFUDFLAG) GF.hs -o fgf
+ strip fgf
+ mv fgf ../bin/
+
+gft:
+ $(GHMAKE) $(GHCFLAGS) -itranslate translate/GFT.hs -o gft-bin
+ strip gft-bin
+ mv gft-bin ../bin/gft
+
+api:
+ $(GHMAKE) $(GHCFLAGS) $(GHCOPTFLAGS) GF/API.hs
+
+shell:
+ $(GHMAKE) $(GHCFLAGS) $(GHCOPTFLAGS) GF/Shell.hs
+
+clean:
+ find . '(' -name '*~' -o -name '*.hi' -o -name '*.ghi' -o -name '*.o' ')' -exec rm -f '{}' ';'
+ -rm -f JavaGUI/*.class
+ -rm -f $(GFEDITOR)/de/uka/ilkd/key/ocl/gf/*.class
+ -rm -f gf.wixobj
+ -rm -f ../bin/$(GF_EXE)
+ $(MAKE) -C tools/c clean
+ $(MAKE) -C ../lib/c clean
+ -rm -f ../bin/gfcc2c
+
+distclean: clean
+ -rm -f JavaGUI/gf-java.jar jgf
+ -rm -f $(GFEDITOR)/gfeditor.jar jgf
+ -rm -f tools/$(GF_DOC_EXE)
+ -rm -f config.status config.mk config.log
+ -rm -f *.tgz *.zip
+ -rm -rf $(DIST_DIR) $(BIN_DIST_DIR)
+ -rm -rf gf.wxs *.msi
+
+ghci-nofud:
+ $(GHCI) $(GHCFLAGS)
+
+today:
+ echo 'module GF.Today (today,version,libdir) where' > GF/Today.hs
+ echo '{-# NOINLINE today #-}' >> GF/Today.hs
+ echo 'today :: String' >> GF/Today.hs
+ echo 'today = "'`date`'"' >> GF/Today.hs
+ echo '{-# NOINLINE version #-}' >> GF/Today.hs
+ echo 'version :: String' >> GF/Today.hs
+ echo 'version = "'$(PACKAGE_VERSION)'"' >> GF/Today.hs
+ echo '{-# NOINLINE libdir #-}' >> GF/Today.hs
+ echo 'libdir :: String' >> GF/Today.hs
+ echo 'libdir = "'$(GF_LIB_DIR)'"' >> GF/Today.hs
+
+javac:
+ $(JAVAC) $(JAVAFLAGS) -classpath $(GFEDITOR)/jargs-1.0.jar $(GFEDITOR)/de/uka/ilkd/key/ocl/gf/*.java
+ $(JAVAC) $(JAVAFLAGS) JavaGUI/*.java
+
+jar: javac
+ cd JavaGUI; $(JAR) -cmf manifest.txt gf-java.jar *.class ; cd ..
+ cd $(GFEDITOR) ; rm -rf jarcontents ; mkdir jarcontents ; cp -r de ManifestMain.txt ../../LICENSE LICENCE_jargs gf-icon.gif jarcontents ; cat jargs-1.0.jar | (cd jarcontents; jar -x jargs) ; cd jarcontents ; $(JAR) -cmf ManifestMain.txt ../gfeditor.jar de/uka/ilkd/key/ocl/gf/*.class jargs LICENSE LICENCE_jargs gf-icon.gif ; cd .. ; cd ..
+
+showflags:
+ @echo $(GHCFLAGS)
+
+# added by peb:
+tracing: GHCFLAGS += -DTRACING
+tracing: temp
+
+ghci-trace: GHCFLAGS += -DTRACING
+ghci-trace: ghci
+
+#touch-files:
+# rm -f GF/System/Tracing.{hi,o}
+# touch GF/System/Tracing.hs
+
+# profiling
+prof: GHCOPTFLAGS += -prof -auto-all -auto-dicts
+prof: all
+
+tags:
+ find GF Transfer -name '*.hs' | xargs hasktags
+
+#
+# Help file
+#
+
+tools/MkHelpFile: tools/MkHelpFile.hs
+ $(GHMAKE) -o $@ $^
+
+help: GF/Shell/HelpFile.hs
+
+GF/Shell/HelpFile.hs: tools/MkHelpFile HelpFile
+ tools/MkHelpFile
+
+#
+# Tools
+#
+
+gfdoc: tools/$(GF_DOC_EXE)
+
+tools/$(GF_DOC_EXE): tools/GFDoc.hs
+ $(GHMAKE) $(GHCOPTFLAGS) -o $@ $^
+
+gfc: gf3
+ cp -f gfc ../bin/
+ chmod a+x ../bin/gfc
+
+gfi: gf3
+
+gf3:
+ $(GHMAKE) $(GHCOPTFLAGS) -o gf3 GF/Devel/GF.hs
+ strip $(GF3_EXE)
+ mv $(GF3_EXE) ../bin/
+
+testgf3:
+ $(GHMAKE) $(GHCOPTFLAGS) -o testgf3 GF/Devel/TestGF3.hs
+ strip $(TESTGF3_EXE)
+ mv $(TESTGF3_EXE) ../bin/
+
+gfcc2c:
+ $(MAKE) -C tools/c
+ $(MAKE) -C ../lib/c
+ mv tools/c/gfcc2c ../bin
+
+#
+# Resource grammars
+#
+
+lib:
+ $(MAKE) -C ../lib/resource clean new
+
+#
+# Distribution
+#
+
+dist:
+ -rm -rf $(DIST_DIR)
+ darcs dist --dist-name=$(DIST_DIR)
+ tar -zxf ../$(DIST_DIR).tar.gz
+ rm ../$(DIST_DIR).tar.gz
+ cd $(DIST_DIR)/src && perl -pi -e "s/^AC_INIT\(\[GF\],\[[^\]]*\]/AC_INIT([GF],[$(PACKAGE_VERSION)]/" configure.ac
+ cd $(DIST_DIR)/src && autoconf && rm -rf autom4te.cache
+# cd $(DIST_DIR)/grammars && sh mkLib.sh
+ cd $(DIST_DIR) && rm -rf $(NOT_IN_DIST)
+ $(TAR) -zcf $(DIST_DIR).tgz $(DIST_DIR)
+ rm -rf $(DIST_DIR)
+
+snapshot: PACKAGE_VERSION=$(shell date +%Y%m%d)
+snapshot: DIST_DIR=GF-$(PACKAGE_VERSION)
+snapshot: dist
+
+rpm: dist
+ rpmbuild -ta $(DIST_DIR).tgz
+
+
+binary-dist:
+ rm -rf $(BIN_DIST_DIR)
+ mkdir $(BIN_DIST_DIR)
+ mkdir $(BIN_DIST_DIR)/lib
+ ./configure --host="$(host)" --build="$(build)"
+ $(MAKE) all
+ $(INSTALL) ../bin/$(GF_EXE) tools/$(GF_DOC_EXE) $(BIN_DIST_DIR)
+ $(INSTALL) -m 0644 JavaGUI/gf-java.jar $(BIN_DIST_DIR)
+ $(INSTALL) -m 0644 $(GFEDITOR)/gfeditor.jar $(BIN_DIST_DIR)
+ $(INSTALL) configure config.guess config.sub install-sh $(BIN_DIST_DIR)
+ $(INSTALL) -m 0644 config.mk.in jgf.in gfeditor.in $(BIN_DIST_DIR)
+ $(INSTALL) -m 0644 ../README ../LICENSE $(BIN_DIST_DIR)
+ $(INSTALL) -m 0644 INSTALL.binary $(BIN_DIST_DIR)/INSTALL
+ $(INSTALL) -m 0644 Makefile.binary $(BIN_DIST_DIR)/Makefile
+ $(MAKE) lib
+ $(TAR) -C $(BIN_DIST_DIR)/lib -zxf ../lib/compiled.tgz
+ $(TAR) -zcf GF-$(PACKAGE_VERSION)-$(host).tgz $(BIN_DIST_DIR)
+ rm -rf $(BIN_DIST_DIR)
+
+grammar-dist:
+ -rm -rf $(GRAMMAR_DIST_DIR)
+ mkdir $(GRAMMAR_DIST_DIR)
+ cp -r ../_darcs/current/{lib,examples} $(GRAMMAR_DIST_DIR)
+ $(MAKE) GF_LIB_PATH=.. -C $(GRAMMAR_DIST_DIR)/lib/resource-1.0 show-path prelude present alltenses mathematical api multimodal langs
+ $(TAR) -zcf $(GRAMMAR_DIST_DIR).tgz $(GRAMMAR_DIST_DIR)
+ rm -rf $(GRAMMAR_DIST_DIR)
+
+gf.wxs: config.status gf.wxs.in
+ ./config.status --file=$@
+
+windows-msi: gf.wxs
+ candle -nologo gf.wxs
+ light -nologo -o $(MSI_FILE) gf.wixobj
+
+#
+# Installation
+#
+
+install: install-gf install-gfdoc install-lib install-editor
+
+install-gf:
+ $(INSTALL) -d $(bindir)
+ $(INSTALL) ../bin/$(GF_EXE) $(bindir)
+
+install-gf3:
+ $(INSTALL) -d $(bindir)
+ $(INSTALL) ../bin/$(GF3_EXE) $(bindir)
+ $(INSTALL) ../bin/gfc $(bindir)
+
+install-gfdoc:
+ $(INSTALL) -d $(bindir)
+ $(INSTALL) tools/$(GF_DOC_EXE) $(bindir)
+
+install-lib:
+ $(INSTALL) -d $(GF_LIB_DIR)
+ $(TAR) -C $(GF_LIB_DIR) -zxf ../lib/compiled.tgz
+
+install-editor:
+ $(INSTALL) -d $(GF_DATA_DIR)
+ $(INSTALL) jgf $(bindir)
+ $(INSTALL) -m 0644 JavaGUI/gf-java.jar $(GF_DATA_DIR)
+ $(INSTALL) gfeditor $(bindir)
+ $(INSTALL) -m 0644 $(GFEDITOR)/gfeditor.jar $(GF_DATA_DIR)
+
+install-java:
+ -rm -f ../bin/JavaGUI
+ ln -s ../src/JavaGUI ../bin
+ @echo "PLEASE set GFHOME and GF_LIB_PATH in your environment"
+ -rm -f ../bin/$(GFEDITOR)
+ ln -s ../src/$(GFEDITOR) ../bin
diff --git a/src-2.9/Makefile.binary b/src-2.9/Makefile.binary
new file mode 100644
index 000000000..ab52185fd
--- /dev/null
+++ b/src-2.9/Makefile.binary
@@ -0,0 +1,23 @@
+include config.mk
+
+GF_DATA_DIR=$(datadir)/GF-$(PACKAGE_VERSION)
+GF_LIB_DIR=$(GF_DATA_DIR)/lib
+
+.PHONY: install uninstall
+
+install:
+ $(INSTALL) -d $(bindir)
+ $(INSTALL) gf$(EXEEXT) gfdoc$(EXEEXT) jgf gfeditor $(bindir)
+ $(INSTALL) -d $(GF_DATA_DIR)
+ $(INSTALL) -m 0644 gf-java.jar $(GF_DATA_DIR)
+ $(INSTALL) -m 0644 gfeditor.jar $(GF_DATA_DIR)
+ cp -r lib $(GF_DATA_DIR)
+
+uninstall:
+ -rm -f $(bindir)/gf$(EXEEXT) $(bindir)/gfdoc$(EXEEXT) $(bindir)/jgf $(bindir)/gfeditor
+ -rm -f $(GF_DATA_DIR)/gf-java.jar
+ -rm -f $(GF_DATA_DIR)/gfeditor.jar
+ -rm -f $GF_LIB_DIR)/*/*.gf{c,r,cm}
+ -rmdir $(GF_LIB_DIR)/*
+ -rmdir $(GF_LIB_DIR)
+ -rmdir $(GF_DATA_DIR)
diff --git a/src-2.9/ReleaseProcedure b/src-2.9/ReleaseProcedure
new file mode 100644
index 000000000..c04f2a065
--- /dev/null
+++ b/src-2.9/ReleaseProcedure
@@ -0,0 +1,153 @@
+Procedure for making a GF release:
+
+1. Make sure everything that should be in the release has been
+ checked in.
+
+2. Go to the src/ dir.
+
+ $ cd src
+
+3. Edit configure.ac to set the right version number
+ (the second argument to the AC_INIT macro).
+
+4. Edit gf.spec to set the version and release numbers
+ (change %define version and %define release).
+
+5. Commit configure.ac and gf.spec:
+
+ $ darcs record -m 'Updated version numbers.' configure.ac gf.spec
+
+6. Run autoconf to generate configure with the right version number:
+
+ $ autoconf
+
+7. Go back to the root of the tree.
+
+ $ cd ..
+
+8. Tag the release. (X_X should be replaced by the version number, with
+ _ instead of ., e.g. 2_0)
+
+ $ darcs tag -m RELEASE-X_X
+
+9. Push the changes that you made for the release to the main repo:
+
+ $ darcs push
+
+10. Build a source package:
+
+ $ cd src
+ $ ./configure
+ $ make dist
+
+11. (Only if releasing a new grammars distribution)
+ Build a grammar tarball:
+
+ $ cd src
+ $ ./configure && make grammar-dist
+
+12. Build an x86/linux RPM (should be done on a Mandrake Linux box):
+
+ Setup for building RPMs (first time only):
+
+ - Make sure that you have the directories neccessary to build
+ RPMs:
+
+ $ mkdir -p ~/rpm/{BUILD,RPMS/i586,RPMS/noarch,SOURCES,SRPMS,SPECS,tmp}
+
+ - Create ~/.rpmrc with the following contents:
+
+buildarchtranslate: i386: i586
+buildarchtranslate: i486: i586
+buildarchtranslate: i586: i586
+buildarchtranslate: i686: i586
+
+ - Create ~/.rpmmacros with the following contents:
+
+%_topdir %(echo ${HOME}/rpm)
+%_tmppath %{_topdir}/tmp
+
+%packager Your Name
+
+ Build the RPM:
+
+ $ cd src
+ $ ./configure && make rpm
+
+13. Build a generic binary x86/linux package (should be done on a Linux box,
+ e.g. banded.medic.chalmers.se):
+
+ $ cd src
+ $ ./configure --host=i386-pc-linux-gnu && make binary-dist
+
+14. Build a generic binary sparc/solaris package (should be done
+ on a Solaris box, e.g. remote1.cs.chalmers.se):
+
+ $ cd src
+ $ ./configure --host=sparc-sun-solaris2 && gmake binary-dist
+
+15. Build a Mac OS X package (should be done on a Mac OS X box,
+ e.g. csmisc99.cs.chalmers.se):
+
+ $ cd src
+ $ ./configure && make binary-dist
+
+ Note that to run GHC-compiled binaries on OS X, you need
+ a "Haskell Support Framework". This should be available
+ separately from the GF download page.
+
+ TODO: Use OS X PackageMaker to build a .pkg-file which can
+ be installed using the standard OS X Installer program.
+
+16. Build a binary Cygwin package (should be done on a Windows
+ machine with Cygwin):
+
+ $ cd src
+ $ ./configure && make binary-dist
+
+17. Build a Windows MSI package (FIXME: This doesn't work right,
+ pathnames with backslashes and spaces are not handled
+ correctly in Windows. We only release a binary tarball
+ for Cygwin right now.):
+
+ $ cd src
+ $ ./configure && make all windows-msi
+
+18. Add new GF package release to SourceForge:
+
+ - https://sourceforge.net/projects/gf-tools
+
+ - Project page -> Admin -> File releases -> Add release (for the
+ GF package)
+
+ - New release name: X.X (just the version number, e.g. 2.2)
+
+ - Paste in release notes
+
+ - Upload files using anonymous FTP to upload.sourceforge.net
+ in the incoming directory.
+
+ - Add the files to the release and set the processor
+ and file type for each file (remember to press
+ Update/Refresh for each file):
+ * x86 rpm -> i386/.rpm
+ * source rpm -> Any/Source .rpm
+ * x86 binary tarball -> i386/.gz
+ * sparc binary tarball -> Sparc/.gz
+ * source package -> Any/Source .gz
+
+19. Add new GF-editor release. Repeat the steps above, but
+ with GF-editor:
+
+ - Add files and set properties:
+
+ * editor rpm -> i386/.rpm (not really true, but I haven't
+ figured out how to make noarch rpms from the same spec as
+ arch-specific ones)
+
+20. Mail to gf-tools-users@lists.sourceforge.net
+
+21. Update website.
+
+22. Party!
+
diff --git a/src-2.9/Setup.lhs b/src-2.9/Setup.lhs
new file mode 100644
index 000000000..e2c31e7ca
--- /dev/null
+++ b/src-2.9/Setup.lhs
@@ -0,0 +1,8 @@
+#!/usr/bin/env runghc
+
+> module Main where
+
+> import Distribution.Simple
+
+> main :: IO ()
+> main = defaultMain
diff --git a/src-2.9/Transfer/CompilerAPI.hs b/src-2.9/Transfer/CompilerAPI.hs
new file mode 100644
index 000000000..38cb58dd0
--- /dev/null
+++ b/src-2.9/Transfer/CompilerAPI.hs
@@ -0,0 +1,75 @@
+module Transfer.CompilerAPI where
+
+import Transfer.Syntax.Lex
+import Transfer.Syntax.Par
+import Transfer.Syntax.Print
+import Transfer.Syntax.Abs
+import Transfer.Syntax.Layout
+
+import Transfer.ErrM
+import Transfer.SyntaxToCore
+
+import Transfer.PathUtil
+
+import Data.List
+import System.Directory
+
+
+-- | Compile a source module file to a a code file.
+compileFile :: [FilePath] -- ^ directories to look for imported modules in
+ -> FilePath -- ^ source module file
+ -> IO FilePath -- ^ path to the core file that was written
+compileFile path f = do
+ ds <- loadModule path f
+ s <- compile ds
+ writeFile coreFile s
+ return coreFile
+ where coreFile = replaceFilenameSuffix f "trc"
+
+-- | Compile a self-contained list of declarations to a core program.
+compile :: Monad m => [Decl] -> m String
+compile m = return (printTree $ declsToCore m)
+
+-- | Load a source module file and all its dependencies.
+loadModule :: [FilePath] -- ^ directories to look for imported modules in
+ -> FilePath -- ^ source module file
+ -> IO [Decl]
+loadModule = loadModule_ []
+ where
+ loadModule_ ms path f =
+ do
+ s <- readFile f
+ Module is ds <- case pModule (myLLexer s) of
+ Bad e -> fail $ "Parse error in " ++ f ++ ": " ++ e
+ Ok m -> return m
+ let load = [ i | Import (Ident i) <- is ] \\ ms
+ let path' = directoryOf f : path
+ files <- mapM (findFile path' . (++".tra")) load
+ dss <- mapM (loadModule_ (load++ms) path) files
+ return $ concat (dss++[ds])
+
+myLLexer :: String -> [Token]
+myLLexer = resolveLayout True . myLexer
+
+-- | Find a file in one of the given directories.
+-- Fails if the file was not found.
+findFile :: [FilePath] -- ^ directories to look in
+ -> FilePath -- ^ file name to find
+ -> IO FilePath
+findFile path f =
+ do
+ mf <- findFileM path f
+ case mf of
+ Nothing -> fail $ f ++ " not found in path: " ++ show path
+ Just f' -> return f'
+
+-- | Find a file in one of the given directories.
+findFileM :: [FilePath] -- ^ directories to look in
+ -> FilePath -- ^ file name to find
+ -> IO (Maybe FilePath)
+findFileM [] _ = return Nothing
+findFileM (p:ps) f =
+ do
+ let f' = p ++ "/" ++ f
+ e <- doesFileExist f'
+ if e then return (Just f') else findFileM ps f
diff --git a/src-2.9/Transfer/Core/Abs.hs b/src-2.9/Transfer/Core/Abs.hs
new file mode 100644
index 000000000..8306d5b46
--- /dev/null
+++ b/src-2.9/Transfer/Core/Abs.hs
@@ -0,0 +1,267 @@
+{-# OPTIONS_GHC -fglasgow-exts #-}
+module Transfer.Core.Abs (Tree(..), Module, Decl, ConsDecl, Pattern, FieldPattern, PatternVariable, Exp, LetDef, Case, FieldType, FieldValue, TMeta, CIdent, composOp, composOpM, composOpM_, composOpMPlus, composOpMonoid, composOpFold, compos, johnMajorEq) where
+
+import Control.Monad (ap,MonadPlus,msum,mplus,mzero)
+import Control.Monad.Identity
+import Data.Monoid
+
+-- Haskell module generated by the BNF converter
+
+data Module_
+type Module = Tree Module_
+data Decl_
+type Decl = Tree Decl_
+data ConsDecl_
+type ConsDecl = Tree ConsDecl_
+data Pattern_
+type Pattern = Tree Pattern_
+data FieldPattern_
+type FieldPattern = Tree FieldPattern_
+data PatternVariable_
+type PatternVariable = Tree PatternVariable_
+data Exp_
+type Exp = Tree Exp_
+data LetDef_
+type LetDef = Tree LetDef_
+data Case_
+type Case = Tree Case_
+data FieldType_
+type FieldType = Tree FieldType_
+data FieldValue_
+type FieldValue = Tree FieldValue_
+data TMeta_
+type TMeta = Tree TMeta_
+data CIdent_
+type CIdent = Tree CIdent_
+
+data Tree :: * -> * where
+ Module :: [Decl] -> Tree Module_
+ DataDecl :: CIdent -> Exp -> [ConsDecl] -> Tree Decl_
+ TypeDecl :: CIdent -> Exp -> Tree Decl_
+ ValueDecl :: CIdent -> Exp -> Tree Decl_
+ ConsDecl :: CIdent -> Exp -> Tree ConsDecl_
+ PCons :: CIdent -> [Pattern] -> Tree Pattern_
+ PVar :: PatternVariable -> Tree Pattern_
+ PRec :: [FieldPattern] -> Tree Pattern_
+ PStr :: String -> Tree Pattern_
+ PInt :: Integer -> Tree Pattern_
+ FieldPattern :: CIdent -> Pattern -> Tree FieldPattern_
+ PVVar :: CIdent -> Tree PatternVariable_
+ PVWild :: Tree PatternVariable_
+ ELet :: [LetDef] -> Exp -> Tree Exp_
+ ECase :: Exp -> [Case] -> Tree Exp_
+ EAbs :: PatternVariable -> Exp -> Tree Exp_
+ EPi :: PatternVariable -> Exp -> Exp -> Tree Exp_
+ EApp :: Exp -> Exp -> Tree Exp_
+ EProj :: Exp -> CIdent -> Tree Exp_
+ ERecType :: [FieldType] -> Tree Exp_
+ ERec :: [FieldValue] -> Tree Exp_
+ EVar :: CIdent -> Tree Exp_
+ EType :: Tree Exp_
+ EStr :: String -> Tree Exp_
+ EInteger :: Integer -> Tree Exp_
+ EDouble :: Double -> Tree Exp_
+ EMeta :: TMeta -> Tree Exp_
+ LetDef :: CIdent -> Exp -> Tree LetDef_
+ Case :: Pattern -> Exp -> Exp -> Tree Case_
+ FieldType :: CIdent -> Exp -> Tree FieldType_
+ FieldValue :: CIdent -> Exp -> Tree FieldValue_
+ TMeta :: String -> Tree TMeta_
+ CIdent :: String -> Tree CIdent_
+
+composOp :: (forall a. Tree a -> Tree a) -> Tree c -> Tree c
+composOp f = runIdentity . composOpM (Identity . f)
+
+composOpM :: Monad m => (forall a. Tree a -> m (Tree a)) -> Tree c -> m (Tree c)
+composOpM = compos return ap
+
+composOpM_ :: Monad m => (forall a. Tree a -> m ()) -> Tree c -> m ()
+composOpM_ = composOpFold (return ()) (>>)
+
+composOpMPlus :: MonadPlus m => (forall a. Tree a -> m b) -> Tree c -> m b
+composOpMPlus = composOpFold mzero mplus
+
+composOpMonoid :: Monoid m => (forall a. Tree a -> m) -> Tree c -> m
+composOpMonoid = composOpFold mempty mappend
+
+newtype C b a = C { unC :: b }
+composOpFold :: b -> (b -> b -> b) -> (forall a. Tree a -> b) -> Tree c -> b
+composOpFold z c f = unC . compos (\_ -> C z) (\(C x) (C y) -> C (c x y)) (C . f)
+
+compos :: (forall a. a -> m a)
+ -> (forall a b. m (a -> b) -> m a -> m b)
+ -> (forall a. Tree a -> m (Tree a)) -> Tree c -> m (Tree c)
+compos r a f t = case t of
+ Module decls -> r Module `a` foldr (a . a (r (:)) . f) (r []) decls
+ DataDecl cident exp consdecls -> r DataDecl `a` f cident `a` f exp `a` foldr (a . a (r (:)) . f) (r []) consdecls
+ TypeDecl cident exp -> r TypeDecl `a` f cident `a` f exp
+ ValueDecl cident exp -> r ValueDecl `a` f cident `a` f exp
+ ConsDecl cident exp -> r ConsDecl `a` f cident `a` f exp
+ PCons cident patterns -> r PCons `a` f cident `a` foldr (a . a (r (:)) . f) (r []) patterns
+ PVar patternvariable -> r PVar `a` f patternvariable
+ PRec fieldpatterns -> r PRec `a` foldr (a . a (r (:)) . f) (r []) fieldpatterns
+ FieldPattern cident pattern -> r FieldPattern `a` f cident `a` f pattern
+ PVVar cident -> r PVVar `a` f cident
+ ELet letdefs exp -> r ELet `a` foldr (a . a (r (:)) . f) (r []) letdefs `a` f exp
+ ECase exp cases -> r ECase `a` f exp `a` foldr (a . a (r (:)) . f) (r []) cases
+ EAbs patternvariable exp -> r EAbs `a` f patternvariable `a` f exp
+ EPi patternvariable exp0 exp1 -> r EPi `a` f patternvariable `a` f exp0 `a` f exp1
+ EApp exp0 exp1 -> r EApp `a` f exp0 `a` f exp1
+ EProj exp cident -> r EProj `a` f exp `a` f cident
+ ERecType fieldtypes -> r ERecType `a` foldr (a . a (r (:)) . f) (r []) fieldtypes
+ ERec fieldvalues -> r ERec `a` foldr (a . a (r (:)) . f) (r []) fieldvalues
+ EVar cident -> r EVar `a` f cident
+ EMeta tmeta -> r EMeta `a` f tmeta
+ LetDef cident exp -> r LetDef `a` f cident `a` f exp
+ Case pattern exp0 exp1 -> r Case `a` f pattern `a` f exp0 `a` f exp1
+ FieldType cident exp -> r FieldType `a` f cident `a` f exp
+ FieldValue cident exp -> r FieldValue `a` f cident `a` f exp
+ _ -> r t
+
+instance Show (Tree c) where
+ showsPrec n t = case t of
+ Module decls -> opar n . showString "Module" . showChar ' ' . showsPrec 1 decls . cpar n
+ DataDecl cident exp consdecls -> opar n . showString "DataDecl" . showChar ' ' . showsPrec 1 cident . showChar ' ' . showsPrec 1 exp . showChar ' ' . showsPrec 1 consdecls . cpar n
+ TypeDecl cident exp -> opar n . showString "TypeDecl" . showChar ' ' . showsPrec 1 cident . showChar ' ' . showsPrec 1 exp . cpar n
+ ValueDecl cident exp -> opar n . showString "ValueDecl" . showChar ' ' . showsPrec 1 cident . showChar ' ' . showsPrec 1 exp . cpar n
+ ConsDecl cident exp -> opar n . showString "ConsDecl" . showChar ' ' . showsPrec 1 cident . showChar ' ' . showsPrec 1 exp . cpar n
+ PCons cident patterns -> opar n . showString "PCons" . showChar ' ' . showsPrec 1 cident . showChar ' ' . showsPrec 1 patterns . cpar n
+ PVar patternvariable -> opar n . showString "PVar" . showChar ' ' . showsPrec 1 patternvariable . cpar n
+ PRec fieldpatterns -> opar n . showString "PRec" . showChar ' ' . showsPrec 1 fieldpatterns . cpar n
+ PStr str -> opar n . showString "PStr" . showChar ' ' . showsPrec 1 str . cpar n
+ PInt n -> opar n . showString "PInt" . showChar ' ' . showsPrec 1 n . cpar n
+ FieldPattern cident pattern -> opar n . showString "FieldPattern" . showChar ' ' . showsPrec 1 cident . showChar ' ' . showsPrec 1 pattern . cpar n
+ PVVar cident -> opar n . showString "PVVar" . showChar ' ' . showsPrec 1 cident . cpar n
+ PVWild -> showString "PVWild"
+ ELet letdefs exp -> opar n . showString "ELet" . showChar ' ' . showsPrec 1 letdefs . showChar ' ' . showsPrec 1 exp . cpar n
+ ECase exp cases -> opar n . showString "ECase" . showChar ' ' . showsPrec 1 exp . showChar ' ' . showsPrec 1 cases . cpar n
+ EAbs patternvariable exp -> opar n . showString "EAbs" . showChar ' ' . showsPrec 1 patternvariable . showChar ' ' . showsPrec 1 exp . cpar n
+ EPi patternvariable exp0 exp1 -> opar n . showString "EPi" . showChar ' ' . showsPrec 1 patternvariable . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EApp exp0 exp1 -> opar n . showString "EApp" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EProj exp cident -> opar n . showString "EProj" . showChar ' ' . showsPrec 1 exp . showChar ' ' . showsPrec 1 cident . cpar n
+ ERecType fieldtypes -> opar n . showString "ERecType" . showChar ' ' . showsPrec 1 fieldtypes . cpar n
+ ERec fieldvalues -> opar n . showString "ERec" . showChar ' ' . showsPrec 1 fieldvalues . cpar n
+ EVar cident -> opar n . showString "EVar" . showChar ' ' . showsPrec 1 cident . cpar n
+ EType -> showString "EType"
+ EStr str -> opar n . showString "EStr" . showChar ' ' . showsPrec 1 str . cpar n
+ EInteger n -> opar n . showString "EInteger" . showChar ' ' . showsPrec 1 n . cpar n
+ EDouble d -> opar n . showString "EDouble" . showChar ' ' . showsPrec 1 d . cpar n
+ EMeta tmeta -> opar n . showString "EMeta" . showChar ' ' . showsPrec 1 tmeta . cpar n
+ LetDef cident exp -> opar n . showString "LetDef" . showChar ' ' . showsPrec 1 cident . showChar ' ' . showsPrec 1 exp . cpar n
+ Case pattern exp0 exp1 -> opar n . showString "Case" . showChar ' ' . showsPrec 1 pattern . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ FieldType cident exp -> opar n . showString "FieldType" . showChar ' ' . showsPrec 1 cident . showChar ' ' . showsPrec 1 exp . cpar n
+ FieldValue cident exp -> opar n . showString "FieldValue" . showChar ' ' . showsPrec 1 cident . showChar ' ' . showsPrec 1 exp . cpar n
+ TMeta str -> opar n . showString "TMeta" . showChar ' ' . showsPrec 1 str . cpar n
+ CIdent str -> opar n . showString "CIdent" . showChar ' ' . showsPrec 1 str . cpar n
+ where opar n = if n > 0 then showChar '(' else id
+ cpar n = if n > 0 then showChar ')' else id
+
+instance Eq (Tree c) where (==) = johnMajorEq
+
+johnMajorEq :: Tree a -> Tree b -> Bool
+johnMajorEq (Module decls) (Module decls_) = decls == decls_
+johnMajorEq (DataDecl cident exp consdecls) (DataDecl cident_ exp_ consdecls_) = cident == cident_ && exp == exp_ && consdecls == consdecls_
+johnMajorEq (TypeDecl cident exp) (TypeDecl cident_ exp_) = cident == cident_ && exp == exp_
+johnMajorEq (ValueDecl cident exp) (ValueDecl cident_ exp_) = cident == cident_ && exp == exp_
+johnMajorEq (ConsDecl cident exp) (ConsDecl cident_ exp_) = cident == cident_ && exp == exp_
+johnMajorEq (PCons cident patterns) (PCons cident_ patterns_) = cident == cident_ && patterns == patterns_
+johnMajorEq (PVar patternvariable) (PVar patternvariable_) = patternvariable == patternvariable_
+johnMajorEq (PRec fieldpatterns) (PRec fieldpatterns_) = fieldpatterns == fieldpatterns_
+johnMajorEq (PStr str) (PStr str_) = str == str_
+johnMajorEq (PInt n) (PInt n_) = n == n_
+johnMajorEq (FieldPattern cident pattern) (FieldPattern cident_ pattern_) = cident == cident_ && pattern == pattern_
+johnMajorEq (PVVar cident) (PVVar cident_) = cident == cident_
+johnMajorEq PVWild PVWild = True
+johnMajorEq (ELet letdefs exp) (ELet letdefs_ exp_) = letdefs == letdefs_ && exp == exp_
+johnMajorEq (ECase exp cases) (ECase exp_ cases_) = exp == exp_ && cases == cases_
+johnMajorEq (EAbs patternvariable exp) (EAbs patternvariable_ exp_) = patternvariable == patternvariable_ && exp == exp_
+johnMajorEq (EPi patternvariable exp0 exp1) (EPi patternvariable_ exp0_ exp1_) = patternvariable == patternvariable_ && exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EApp exp0 exp1) (EApp exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EProj exp cident) (EProj exp_ cident_) = exp == exp_ && cident == cident_
+johnMajorEq (ERecType fieldtypes) (ERecType fieldtypes_) = fieldtypes == fieldtypes_
+johnMajorEq (ERec fieldvalues) (ERec fieldvalues_) = fieldvalues == fieldvalues_
+johnMajorEq (EVar cident) (EVar cident_) = cident == cident_
+johnMajorEq EType EType = True
+johnMajorEq (EStr str) (EStr str_) = str == str_
+johnMajorEq (EInteger n) (EInteger n_) = n == n_
+johnMajorEq (EDouble d) (EDouble d_) = d == d_
+johnMajorEq (EMeta tmeta) (EMeta tmeta_) = tmeta == tmeta_
+johnMajorEq (LetDef cident exp) (LetDef cident_ exp_) = cident == cident_ && exp == exp_
+johnMajorEq (Case pattern exp0 exp1) (Case pattern_ exp0_ exp1_) = pattern == pattern_ && exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (FieldType cident exp) (FieldType cident_ exp_) = cident == cident_ && exp == exp_
+johnMajorEq (FieldValue cident exp) (FieldValue cident_ exp_) = cident == cident_ && exp == exp_
+johnMajorEq (TMeta str) (TMeta str_) = str == str_
+johnMajorEq (CIdent str) (CIdent str_) = str == str_
+johnMajorEq _ _ = False
+
+instance Ord (Tree c) where
+ compare x y = compare (index x) (index y) `mappend` compareSame x y
+index :: Tree c -> Int
+index (Module _) = 0
+index (DataDecl _ _ _) = 1
+index (TypeDecl _ _) = 2
+index (ValueDecl _ _) = 3
+index (ConsDecl _ _) = 4
+index (PCons _ _) = 5
+index (PVar _) = 6
+index (PRec _) = 7
+index (PStr _) = 8
+index (PInt _) = 9
+index (FieldPattern _ _) = 10
+index (PVVar _) = 11
+index (PVWild ) = 12
+index (ELet _ _) = 13
+index (ECase _ _) = 14
+index (EAbs _ _) = 15
+index (EPi _ _ _) = 16
+index (EApp _ _) = 17
+index (EProj _ _) = 18
+index (ERecType _) = 19
+index (ERec _) = 20
+index (EVar _) = 21
+index (EType ) = 22
+index (EStr _) = 23
+index (EInteger _) = 24
+index (EDouble _) = 25
+index (EMeta _) = 26
+index (LetDef _ _) = 27
+index (Case _ _ _) = 28
+index (FieldType _ _) = 29
+index (FieldValue _ _) = 30
+index (TMeta _) = 31
+index (CIdent _) = 32
+compareSame :: Tree c -> Tree c -> Ordering
+compareSame (Module decls) (Module decls_) = compare decls decls_
+compareSame (DataDecl cident exp consdecls) (DataDecl cident_ exp_ consdecls_) = mappend (compare cident cident_) (mappend (compare exp exp_) (compare consdecls consdecls_))
+compareSame (TypeDecl cident exp) (TypeDecl cident_ exp_) = mappend (compare cident cident_) (compare exp exp_)
+compareSame (ValueDecl cident exp) (ValueDecl cident_ exp_) = mappend (compare cident cident_) (compare exp exp_)
+compareSame (ConsDecl cident exp) (ConsDecl cident_ exp_) = mappend (compare cident cident_) (compare exp exp_)
+compareSame (PCons cident patterns) (PCons cident_ patterns_) = mappend (compare cident cident_) (compare patterns patterns_)
+compareSame (PVar patternvariable) (PVar patternvariable_) = compare patternvariable patternvariable_
+compareSame (PRec fieldpatterns) (PRec fieldpatterns_) = compare fieldpatterns fieldpatterns_
+compareSame (PStr str) (PStr str_) = compare str str_
+compareSame (PInt n) (PInt n_) = compare n n_
+compareSame (FieldPattern cident pattern) (FieldPattern cident_ pattern_) = mappend (compare cident cident_) (compare pattern pattern_)
+compareSame (PVVar cident) (PVVar cident_) = compare cident cident_
+compareSame PVWild PVWild = EQ
+compareSame (ELet letdefs exp) (ELet letdefs_ exp_) = mappend (compare letdefs letdefs_) (compare exp exp_)
+compareSame (ECase exp cases) (ECase exp_ cases_) = mappend (compare exp exp_) (compare cases cases_)
+compareSame (EAbs patternvariable exp) (EAbs patternvariable_ exp_) = mappend (compare patternvariable patternvariable_) (compare exp exp_)
+compareSame (EPi patternvariable exp0 exp1) (EPi patternvariable_ exp0_ exp1_) = mappend (compare patternvariable patternvariable_) (mappend (compare exp0 exp0_) (compare exp1 exp1_))
+compareSame (EApp exp0 exp1) (EApp exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EProj exp cident) (EProj exp_ cident_) = mappend (compare exp exp_) (compare cident cident_)
+compareSame (ERecType fieldtypes) (ERecType fieldtypes_) = compare fieldtypes fieldtypes_
+compareSame (ERec fieldvalues) (ERec fieldvalues_) = compare fieldvalues fieldvalues_
+compareSame (EVar cident) (EVar cident_) = compare cident cident_
+compareSame EType EType = EQ
+compareSame (EStr str) (EStr str_) = compare str str_
+compareSame (EInteger n) (EInteger n_) = compare n n_
+compareSame (EDouble d) (EDouble d_) = compare d d_
+compareSame (EMeta tmeta) (EMeta tmeta_) = compare tmeta tmeta_
+compareSame (LetDef cident exp) (LetDef cident_ exp_) = mappend (compare cident cident_) (compare exp exp_)
+compareSame (Case pattern exp0 exp1) (Case pattern_ exp0_ exp1_) = mappend (compare pattern pattern_) (mappend (compare exp0 exp0_) (compare exp1 exp1_))
+compareSame (FieldType cident exp) (FieldType cident_ exp_) = mappend (compare cident cident_) (compare exp exp_)
+compareSame (FieldValue cident exp) (FieldValue cident_ exp_) = mappend (compare cident cident_) (compare exp exp_)
+compareSame (TMeta str) (TMeta str_) = compare str str_
+compareSame (CIdent str) (CIdent str_) = compare str str_
+compareSame x y = error "BNFC error:" compareSame
diff --git a/src-2.9/Transfer/Core/Core.cf b/src-2.9/Transfer/Core/Core.cf
new file mode 100644
index 000000000..cd4c20569
--- /dev/null
+++ b/src-2.9/Transfer/Core/Core.cf
@@ -0,0 +1,93 @@
+-- This is a subset of the front-end language
+
+entrypoints Module, Exp ;
+
+comment "--" ;
+comment "{-" "-}" ;
+
+Module. Module ::= [Decl] ;
+separator Decl ";" ;
+
+DataDecl. Decl ::= "data" CIdent ":" Exp "where" "{" [ConsDecl] "}" ;
+TypeDecl. Decl ::= CIdent ":" Exp ;
+ValueDecl. Decl ::= CIdent "=" Exp ;
+
+ConsDecl. ConsDecl ::= CIdent ":" Exp ;
+separator ConsDecl ";" ;
+
+separator Pattern "";
+
+-- Constructor patterns.
+PCons. Pattern ::= "(" CIdent [Pattern] ")" ;
+
+-- Variable patterns. Note that in the core language,
+-- constructor patterns must have parantheses.
+PVar. Pattern ::= PatternVariable ;
+-- Record patterns.
+PRec. Pattern ::= "rec" "{" [FieldPattern] "}";
+-- String literal patterns.
+PStr. Pattern ::= String ;
+-- Integer literal patterns.
+PInt. Pattern ::= Integer ;
+
+FieldPattern. FieldPattern ::= CIdent "=" Pattern ;
+separator FieldPattern ";" ;
+
+-- Variable patterns
+PVVar. PatternVariable ::= CIdent ;
+-- Wild card patterns
+PVWild. PatternVariable ::= "_" ;
+
+-- Let expressions.
+ELet. Exp ::= "let" "{" [LetDef] "}" "in" Exp ;
+LetDef. LetDef ::= CIdent "=" Exp ;
+separator LetDef ";" ;
+
+-- Case expressions.
+ECase. Exp ::= "case" Exp "of" "{" [Case] "}" ;
+Case. Case ::= Pattern "|" Exp "->" Exp ;
+separator Case ";" ;
+
+-- Lambda abstractions.
+EAbs. Exp1 ::= "\\" PatternVariable "->" Exp ;
+-- Function types.
+EPi. Exp1 ::= "(" PatternVariable ":" Exp ")" "->" Exp ;
+
+-- Function application.
+EApp. Exp3 ::= Exp3 Exp4 ;
+
+-- Record field projection.
+EProj. Exp4 ::= Exp4 "." CIdent ;
+
+-- Record types.
+ERecType. Exp5 ::= "sig" "{" [FieldType] "}" ;
+FieldType. FieldType ::= CIdent ":" Exp ;
+separator FieldType ";" ;
+
+-- Record expressions.
+ERec. Exp5 ::= "rec" "{" [FieldValue] "}" ;
+FieldValue.FieldValue ::= CIdent "=" Exp ;
+separator FieldValue ";" ;
+
+
+-- Functions, constructors and local variables.
+EVar. Exp5 ::= CIdent ;
+-- The constant Type.
+EType. Exp5 ::= "Type" ;
+-- String literal expressions.
+EStr. Exp5 ::= String ;
+-- Integer literal expressions.
+EInteger. Exp5 ::= Integer ;
+-- Double literal expressions.
+EDouble. Exp5 ::= Double ;
+-- Meta variables
+EMeta. Exp5 ::= TMeta ;
+
+token TMeta ('?' digit+) ;
+
+coercions Exp 5 ;
+
+
+-- Identifiers in core can start with underscore to allow
+-- generating unique identifiers easily.
+token CIdent ((letter | '_') (letter | digit | '_' | '\'')*) ;
diff --git a/src-2.9/Transfer/Core/Doc.tex b/src-2.9/Transfer/Core/Doc.tex
new file mode 100644
index 000000000..4ba6f93ed
--- /dev/null
+++ b/src-2.9/Transfer/Core/Doc.tex
@@ -0,0 +1,215 @@
+\batchmode
+%This Latex file is machine-generated by the BNF-converter
+
+\documentclass[a4paper,11pt]{article}
+\author{BNF-converter}
+\title{The Language Core}
+\setlength{\parindent}{0mm}
+\setlength{\parskip}{1mm}
+\begin{document}
+
+\maketitle
+
+\newcommand{\emptyP}{\mbox{$\epsilon$}}
+\newcommand{\terminal}[1]{\mbox{{\texttt {#1}}}}
+\newcommand{\nonterminal}[1]{\mbox{$\langle \mbox{{\sl #1 }} \! \rangle$}}
+\newcommand{\arrow}{\mbox{::=}}
+\newcommand{\delimit}{\mbox{$|$}}
+\newcommand{\reserved}[1]{\mbox{{\texttt {#1}}}}
+\newcommand{\literal}[1]{\mbox{{\texttt {#1}}}}
+\newcommand{\symb}[1]{\mbox{{\texttt {#1}}}}
+
+This document was automatically generated by the {\em BNF-Converter}. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place).
+
+\section*{The lexical structure of Core}
+
+\subsection*{Literals}
+String literals \nonterminal{String}\ have the form
+\terminal{"}$x$\terminal{"}, where $x$ is any sequence of any characters
+except \terminal{"}\ unless preceded by \verb6\6.
+
+
+Integer literals \nonterminal{Int}\ are nonempty sequences of digits.
+
+
+Double-precision float literals \nonterminal{Double}\ have the structure
+indicated by the regular expression $\nonterminal{digit}+ \mbox{{\it `.'}} \nonterminal{digit}+ (\mbox{{\it `e'}} \mbox{{\it `-'}}? \nonterminal{digit}+)?$ i.e.\
+two sequences of digits separated by a decimal point, optionally
+followed by an unsigned or negative exponent.
+
+
+
+
+
+TMeta literals are recognized by the regular expression
+\(\mbox{`?'} {\nonterminal{digit}}+\)
+
+CIdent literals are recognized by the regular expression
+\(({\nonterminal{letter}} \mid \mbox{`\_'}) ({\nonterminal{letter}} \mid {\nonterminal{digit}} \mid \mbox{`\_'} \mid \mbox{`''})*\)
+
+
+\subsection*{Reserved words and symbols}
+The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions.
+
+The reserved words used in Core are the following: \\
+
+\begin{tabular}{lll}
+{\reserved{Type}} &{\reserved{case}} &{\reserved{data}} \\
+{\reserved{in}} &{\reserved{let}} &{\reserved{of}} \\
+{\reserved{rec}} &{\reserved{sig}} &{\reserved{where}} \\
+\end{tabular}\\
+
+The symbols used in Core are the following: \\
+
+\begin{tabular}{lll}
+{\symb{;}} &{\symb{:}} &{\symb{\{}} \\
+{\symb{\}}} &{\symb{{$=$}}} &{\symb{(}} \\
+{\symb{)}} &{\symb{\_}} &{\symb{{$|$}}} \\
+{\symb{{$-$}{$>$}}} &{\symb{$\backslash$}} &{\symb{.}} \\
+\end{tabular}\\
+
+\subsection*{Comments}
+Single-line comments begin with {\symb{{$-$}{$-$}}}. \\Multiple-line comments are enclosed with {\symb{\{{$-$}}} and {\symb{{$-$}\}}}.
+
+\section*{The syntactic structure of Core}
+Non-terminals are enclosed between $\langle$ and $\rangle$.
+The symbols {\arrow} (production), {\delimit} (union)
+and {\emptyP} (empty rule) belong to the BNF notation.
+All other symbols are terminals.\\
+
+\begin{tabular}{lll}
+{\nonterminal{Module}} & {\arrow} &{\nonterminal{ListDecl}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListDecl}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{Decl}} \\
+ & {\delimit} &{\nonterminal{Decl}} {\terminal{;}} {\nonterminal{ListDecl}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Decl}} & {\arrow} &{\terminal{data}} {\nonterminal{CIdent}} {\terminal{:}} {\nonterminal{Exp}} {\terminal{where}} {\terminal{\{}} {\nonterminal{ListConsDecl}} {\terminal{\}}} \\
+ & {\delimit} &{\nonterminal{CIdent}} {\terminal{:}} {\nonterminal{Exp}} \\
+ & {\delimit} &{\nonterminal{CIdent}} {\terminal{{$=$}}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ConsDecl}} & {\arrow} &{\nonterminal{CIdent}} {\terminal{:}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListConsDecl}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{ConsDecl}} \\
+ & {\delimit} &{\nonterminal{ConsDecl}} {\terminal{;}} {\nonterminal{ListConsDecl}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListPattern}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{Pattern}} {\nonterminal{ListPattern}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Pattern}} & {\arrow} &{\terminal{(}} {\nonterminal{CIdent}} {\nonterminal{ListPattern}} {\terminal{)}} \\
+ & {\delimit} &{\nonterminal{PatternVariable}} \\
+ & {\delimit} &{\terminal{rec}} {\terminal{\{}} {\nonterminal{ListFieldPattern}} {\terminal{\}}} \\
+ & {\delimit} &{\nonterminal{String}} \\
+ & {\delimit} &{\nonterminal{Integer}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{FieldPattern}} & {\arrow} &{\nonterminal{CIdent}} {\terminal{{$=$}}} {\nonterminal{Pattern}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListFieldPattern}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{FieldPattern}} \\
+ & {\delimit} &{\nonterminal{FieldPattern}} {\terminal{;}} {\nonterminal{ListFieldPattern}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{PatternVariable}} & {\arrow} &{\nonterminal{CIdent}} \\
+ & {\delimit} &{\terminal{\_}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp}} & {\arrow} &{\terminal{let}} {\terminal{\{}} {\nonterminal{ListLetDef}} {\terminal{\}}} {\terminal{in}} {\nonterminal{Exp}} \\
+ & {\delimit} &{\terminal{case}} {\nonterminal{Exp}} {\terminal{of}} {\terminal{\{}} {\nonterminal{ListCase}} {\terminal{\}}} \\
+ & {\delimit} &{\nonterminal{Exp1}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{LetDef}} & {\arrow} &{\nonterminal{CIdent}} {\terminal{{$=$}}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListLetDef}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{LetDef}} \\
+ & {\delimit} &{\nonterminal{LetDef}} {\terminal{;}} {\nonterminal{ListLetDef}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Case}} & {\arrow} &{\nonterminal{Pattern}} {\terminal{{$|$}}} {\nonterminal{Exp}} {\terminal{{$-$}{$>$}}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListCase}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{Case}} \\
+ & {\delimit} &{\nonterminal{Case}} {\terminal{;}} {\nonterminal{ListCase}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp1}} & {\arrow} &{\terminal{$\backslash$}} {\nonterminal{PatternVariable}} {\terminal{{$-$}{$>$}}} {\nonterminal{Exp}} \\
+ & {\delimit} &{\terminal{(}} {\nonterminal{PatternVariable}} {\terminal{:}} {\nonterminal{Exp}} {\terminal{)}} {\terminal{{$-$}{$>$}}} {\nonterminal{Exp}} \\
+ & {\delimit} &{\nonterminal{Exp2}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp3}} & {\arrow} &{\nonterminal{Exp3}} {\nonterminal{Exp4}} \\
+ & {\delimit} &{\nonterminal{Exp4}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp4}} & {\arrow} &{\nonterminal{Exp4}} {\terminal{.}} {\nonterminal{CIdent}} \\
+ & {\delimit} &{\nonterminal{Exp5}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp5}} & {\arrow} &{\terminal{sig}} {\terminal{\{}} {\nonterminal{ListFieldType}} {\terminal{\}}} \\
+ & {\delimit} &{\terminal{rec}} {\terminal{\{}} {\nonterminal{ListFieldValue}} {\terminal{\}}} \\
+ & {\delimit} &{\nonterminal{CIdent}} \\
+ & {\delimit} &{\terminal{Type}} \\
+ & {\delimit} &{\nonterminal{String}} \\
+ & {\delimit} &{\nonterminal{Integer}} \\
+ & {\delimit} &{\nonterminal{Double}} \\
+ & {\delimit} &{\nonterminal{TMeta}} \\
+ & {\delimit} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{FieldType}} & {\arrow} &{\nonterminal{CIdent}} {\terminal{:}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListFieldType}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{FieldType}} \\
+ & {\delimit} &{\nonterminal{FieldType}} {\terminal{;}} {\nonterminal{ListFieldType}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{FieldValue}} & {\arrow} &{\nonterminal{CIdent}} {\terminal{{$=$}}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListFieldValue}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{FieldValue}} \\
+ & {\delimit} &{\nonterminal{FieldValue}} {\terminal{;}} {\nonterminal{ListFieldValue}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp2}} & {\arrow} &{\nonterminal{Exp3}} \\
+\end{tabular}\\
+
+
+
+\end{document}
+
diff --git a/src-2.9/Transfer/Core/Lex.hs b/src-2.9/Transfer/Core/Lex.hs
new file mode 100644
index 000000000..be1198508
--- /dev/null
+++ b/src-2.9/Transfer/Core/Lex.hs
@@ -0,0 +1,343 @@
+{-# OPTIONS -fglasgow-exts -cpp #-}
+{-# LINE 3 "Transfer/Core/Lex.x" #-}
+{-# OPTIONS -fno-warn-incomplete-patterns #-}
+module Transfer.Core.Lex where
+
+
+
+#if __GLASGOW_HASKELL__ >= 603
+#include "ghcconfig.h"
+#else
+#include "config.h"
+#endif
+#if __GLASGOW_HASKELL__ >= 503
+import Data.Array
+import Data.Char (ord)
+import Data.Array.Base (unsafeAt)
+#else
+import Array
+import Char (ord)
+#endif
+#if __GLASGOW_HASKELL__ >= 503
+import GHC.Exts
+#else
+import GlaExts
+#endif
+alex_base :: AlexAddr
+alex_base = AlexA# "\x01\x00\x00\x00\x15\x00\x00\x00\x39\x00\x00\x00\x3a\x00\x00\x00\x18\x00\x00\x00\x19\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x45\x00\x00\x00\x1b\x00\x00\x00\x1c\x00\x00\x00\x1d\x00\x00\x00\x42\x00\x00\x00\x00\x00\x00\x00\x9c\x00\x00\x00\x33\x00\x00\x00\xe7\x00\x00\x00\x6c\x01\x00\x00\x3c\x02\x00\x00\x00\x00\x00\x00\x17\x01\x00\x00\xd5\x00\x00\x00\xf4\x00\x00\x00\xb7\x01\x00\x00\x1a\x01\x00\x00\xc1\x01\x00\x00\xcb\x01\x00\x00\xd8\x01\x00\x00"#
+
+alex_table :: AlexAddr
+alex_table = AlexA# "\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0d\x00\xff\xff\x15\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0e\x00\x0e\x00\xff\xff\xff\xff\xff\xff\x05\x00\x0e\x00\xff\xff\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x0e\x00\x0e\x00\xff\xff\x0e\x00\xff\xff\x11\x00\xff\xff\x04\x00\xff\xff\xff\xff\x03\x00\x03\x00\x09\x00\x09\x00\x09\x00\x0b\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x0e\x00\xff\xff\xff\xff\x0f\x00\xff\xff\x0d\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x0e\x00\x0e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x06\x00\x07\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x15\x00\xff\xff\x00\x00\x00\x00\x12\x00\x15\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\x10\x00\xff\xff\x1a\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x16\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x1b\x00\x00\x00\x00\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x00\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x13\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x12\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x00\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x00\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00\x13\x00"#
+
+alex_check :: AlexAddr
+alex_check = AlexA# "\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x2d\x00\x0a\x00\x0a\x00\x2d\x00\x2d\x00\x2d\x00\x2d\x00\x2d\x00\x2d\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3e\x00\xff\xff\xff\xff\xff\xff\xff\xff\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x20\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\x2d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\x7d\x00\x7d\x00\x27\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xd7\x00\xff\xff\xff\xff\xff\xff\xff\xff\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x22\x00\xf7\x00\xff\xff\xff\xff\x5f\x00\x27\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x0a\x00\x2e\x00\xff\xff\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\x5c\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x22\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x6e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x74\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\x5c\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\x27\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\xff\xff\xff\xff\xff\xff\xff\xff\x5f\x00\xff\xff\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x2d\x00\xff\xff\xff\xff\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x65\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xff\xff\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\x27\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\xff\xff\xff\xff\xff\xff\xff\xff\x5f\x00\xff\xff\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xff\xff\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xff\xff\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00"#
+
+alex_deflt :: AlexAddr
+alex_deflt = AlexA# "\x13\x00\xff\xff\x02\x00\x02\x00\xff\xff\xff\xff\x0a\x00\xff\xff\x0a\x00\x0a\x00\x0a\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x15\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
+
+alex_accept = listArray (0::Int,28) [[],[],[(AlexAccSkip)],[(AlexAccSkip)],[],[],[(AlexAccSkip)],[(AlexAccSkip)],[],[],[],[],[(AlexAcc (alex_action_3))],[(AlexAccSkip)],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_4))],[],[(AlexAcc (alex_action_5))],[(AlexAcc (alex_action_5))],[(AlexAcc (alex_action_7))],[],[],[(AlexAcc (alex_action_8))],[(AlexAcc (alex_action_9))],[(AlexAcc (alex_action_9))],[],[],[]]
+{-# LINE 36 "Transfer/Core/Lex.x" #-}
+
+tok f p s = f p s
+
+share :: String -> String
+share = id
+
+data Tok =
+ TS !String -- reserved words and symbols
+ | TL !String -- string literals
+ | TI !String -- integer literals
+ | TV !String -- identifiers
+ | TD !String -- double precision float literals
+ | TC !String -- character literals
+ | T_TMeta !String
+ | T_CIdent !String
+
+ deriving (Eq,Show,Ord)
+
+data Token =
+ PT Posn Tok
+ | Err Posn
+ deriving (Eq,Show,Ord)
+
+tokenPos (PT (Pn _ l _) _ :_) = "line " ++ show l
+tokenPos (Err (Pn _ l _) :_) = "line " ++ show l
+tokenPos _ = "end of file"
+
+posLineCol (Pn _ l c) = (l,c)
+mkPosToken t@(PT p _) = (posLineCol p, prToken t)
+
+prToken t = case t of
+ PT _ (TS s) -> s
+ PT _ (TI s) -> s
+ PT _ (TV s) -> s
+ PT _ (TD s) -> s
+ PT _ (TC s) -> s
+ PT _ (T_TMeta s) -> s
+ PT _ (T_CIdent s) -> s
+
+ _ -> show t
+
+data BTree = N | B String Tok BTree BTree deriving (Show)
+
+eitherResIdent :: (String -> Tok) -> String -> Tok
+eitherResIdent tv s = treeFind resWords
+ where
+ treeFind N = tv s
+ treeFind (B a t left right) | s < a = treeFind left
+ | s > a = treeFind right
+ | s == a = t
+
+resWords = b "let" (b "data" (b "case" (b "Type" N N) N) (b "in" N N)) (b "sig" (b "rec" (b "of" N N) N) (b "where" N N))
+ where b s = B s (TS s)
+
+unescapeInitTail :: String -> String
+unescapeInitTail = unesc . tail where
+ unesc s = case s of
+ '\\':c:cs | elem c ['\"', '\\', '\''] -> c : unesc cs
+ '\\':'n':cs -> '\n' : unesc cs
+ '\\':'t':cs -> '\t' : unesc cs
+ '"':[] -> []
+ c:cs -> c : unesc cs
+ _ -> []
+
+-------------------------------------------------------------------
+-- Alex wrapper code.
+-- A modified "posn" wrapper.
+-------------------------------------------------------------------
+
+data Posn = Pn !Int !Int !Int
+ deriving (Eq, Show,Ord)
+
+alexStartPos :: Posn
+alexStartPos = Pn 0 1 1
+
+alexMove :: Posn -> Char -> Posn
+alexMove (Pn a l c) '\t' = Pn (a+1) l (((c+7) `div` 8)*8+1)
+alexMove (Pn a l c) '\n' = Pn (a+1) (l+1) 1
+alexMove (Pn a l c) _ = Pn (a+1) l (c+1)
+
+type AlexInput = (Posn, -- current position,
+ Char, -- previous char
+ String) -- current input string
+
+tokens :: String -> [Token]
+tokens str = go (alexStartPos, '\n', str)
+ where
+ go :: (Posn, Char, String) -> [Token]
+ go inp@(pos, _, str) =
+ case alexScan inp 0 of
+ AlexEOF -> []
+ AlexError (pos, _, _) -> fail $ show pos ++ ": lexical error"
+ AlexSkip inp' len -> go inp'
+ AlexToken inp' len act -> act pos (take len str) : (go inp')
+
+alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
+alexGetChar (p, c, []) = Nothing
+alexGetChar (p, _, (c:s)) =
+ let p' = alexMove p c
+ in p' `seq` Just (c, (p', c, s))
+
+alexInputPrevChar :: AlexInput -> Char
+alexInputPrevChar (p, c, s) = c
+
+alex_action_3 = tok (\p s -> PT p (TS $ share s))
+alex_action_4 = tok (\p s -> PT p (eitherResIdent (T_TMeta . share) s))
+alex_action_5 = tok (\p s -> PT p (eitherResIdent (T_CIdent . share) s))
+alex_action_6 = tok (\p s -> PT p (eitherResIdent (TV . share) s))
+alex_action_7 = tok (\p s -> PT p (TL $ share $ unescapeInitTail s))
+alex_action_8 = tok (\p s -> PT p (TI $ share s))
+alex_action_9 = tok (\p s -> PT p (TD $ share s))
+{-# LINE 1 "GenericTemplate.hs" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "GenericTemplate.hs" #-}
+-- -----------------------------------------------------------------------------
+-- ALEX TEMPLATE
+--
+-- This code is in the PUBLIC DOMAIN; you may copy it freely and use
+-- it for any purpose whatsoever.
+
+-- -----------------------------------------------------------------------------
+-- INTERNALS and main scanner engine
+
+{-# LINE 35 "GenericTemplate.hs" #-}
+
+{-# LINE 45 "GenericTemplate.hs" #-}
+
+
+data AlexAddr = AlexA# Addr#
+
+#if __GLASGOW_HASKELL__ < 503
+uncheckedShiftL# = shiftL#
+#endif
+
+{-# INLINE alexIndexInt16OffAddr #-}
+alexIndexInt16OffAddr (AlexA# arr) off =
+#ifdef WORDS_BIGENDIAN
+ narrow16Int# i
+ where
+ i = word2Int# ((high `uncheckedShiftL#` 8#) `or#` low)
+ high = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
+ low = int2Word# (ord# (indexCharOffAddr# arr off'))
+ off' = off *# 2#
+#else
+ indexInt16OffAddr# arr off
+#endif
+
+
+
+
+
+{-# INLINE alexIndexInt32OffAddr #-}
+alexIndexInt32OffAddr (AlexA# arr) off =
+#ifdef WORDS_BIGENDIAN
+ narrow32Int# i
+ where
+ i = word2Int# ((b3 `uncheckedShiftL#` 24#) `or#`
+ (b2 `uncheckedShiftL#` 16#) `or#`
+ (b1 `uncheckedShiftL#` 8#) `or#` b0)
+ b3 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 3#)))
+ b2 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 2#)))
+ b1 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
+ b0 = int2Word# (ord# (indexCharOffAddr# arr off'))
+ off' = off *# 4#
+#else
+ indexInt32OffAddr# arr off
+#endif
+
+
+
+
+
+#if __GLASGOW_HASKELL__ < 503
+quickIndex arr i = arr ! i
+#else
+-- GHC >= 503, unsafeAt is available from Data.Array.Base.
+quickIndex = unsafeAt
+#endif
+
+
+
+
+-- -----------------------------------------------------------------------------
+-- Main lexing routines
+
+data AlexReturn a
+ = AlexEOF
+ | AlexError !AlexInput
+ | AlexSkip !AlexInput !Int
+ | AlexToken !AlexInput !Int a
+
+-- alexScan :: AlexInput -> StartCode -> Maybe (AlexInput,Int,act)
+alexScan input (I# (sc))
+ = alexScanUser undefined input (I# (sc))
+
+alexScanUser user input (I# (sc))
+ = case alex_scan_tkn user input 0# input sc AlexNone of
+ (AlexNone, input') ->
+ case alexGetChar input of
+ Nothing ->
+
+
+
+ AlexEOF
+ Just _ ->
+
+
+
+ AlexError input'
+
+ (AlexLastSkip input len, _) ->
+
+
+
+ AlexSkip input len
+
+ (AlexLastAcc k input len, _) ->
+
+
+
+ AlexToken input len k
+
+
+-- Push the input through the DFA, remembering the most recent accepting
+-- state it encountered.
+
+alex_scan_tkn user orig_input len input s last_acc =
+ input `seq` -- strict in the input
+ case s of
+ -1# -> (last_acc, input)
+ _ -> alex_scan_tkn' user orig_input len input s last_acc
+
+alex_scan_tkn' user orig_input len input s last_acc =
+ let
+ new_acc = check_accs (alex_accept `quickIndex` (I# (s)))
+ in
+ new_acc `seq`
+ case alexGetChar input of
+ Nothing -> (new_acc, input)
+ Just (c, new_input) ->
+
+
+
+ let
+ base = alexIndexInt32OffAddr alex_base s
+ (I# (ord_c)) = ord c
+ offset = (base +# ord_c)
+ check = alexIndexInt16OffAddr alex_check offset
+
+ new_s = if (offset >=# 0#) && (check ==# ord_c)
+ then alexIndexInt16OffAddr alex_table offset
+ else alexIndexInt16OffAddr alex_deflt s
+ in
+ alex_scan_tkn user orig_input (len +# 1#) new_input new_s new_acc
+
+ where
+ check_accs [] = last_acc
+ check_accs (AlexAcc a : _) = AlexLastAcc a input (I# (len))
+ check_accs (AlexAccSkip : _) = AlexLastSkip input (I# (len))
+ check_accs (AlexAccPred a pred : rest)
+ | pred user orig_input (I# (len)) input
+ = AlexLastAcc a input (I# (len))
+ check_accs (AlexAccSkipPred pred : rest)
+ | pred user orig_input (I# (len)) input
+ = AlexLastSkip input (I# (len))
+ check_accs (_ : rest) = check_accs rest
+
+data AlexLastAcc a
+ = AlexNone
+ | AlexLastAcc a !AlexInput !Int
+ | AlexLastSkip !AlexInput !Int
+
+data AlexAcc a user
+ = AlexAcc a
+ | AlexAccSkip
+ | AlexAccPred a (AlexAccPred user)
+ | AlexAccSkipPred (AlexAccPred user)
+
+type AlexAccPred user = user -> AlexInput -> Int -> AlexInput -> Bool
+
+-- -----------------------------------------------------------------------------
+-- Predicates on a rule
+
+alexAndPred p1 p2 user in1 len in2
+ = p1 user in1 len in2 && p2 user in1 len in2
+
+--alexPrevCharIsPred :: Char -> AlexAccPred _
+alexPrevCharIs c _ input _ _ = c == alexInputPrevChar input
+
+--alexPrevCharIsOneOfPred :: Array Char Bool -> AlexAccPred _
+alexPrevCharIsOneOf arr _ input _ _ = arr ! alexInputPrevChar input
+
+--alexRightContext :: Int -> AlexAccPred _
+alexRightContext (I# (sc)) user _ _ input =
+ case alex_scan_tkn user input 0# input sc AlexNone of
+ (AlexNone, _) -> False
+ _ -> True
+ -- TODO: there's no need to find the longest
+ -- match when checking the right context, just
+ -- the first match will do.
+
+-- used by wrappers
+iUnbox (I# (i)) = i
diff --git a/src-2.9/Transfer/Core/Lex.x b/src-2.9/Transfer/Core/Lex.x
new file mode 100644
index 000000000..480f366ae
--- /dev/null
+++ b/src-2.9/Transfer/Core/Lex.x
@@ -0,0 +1,140 @@
+-- -*- haskell -*-
+-- This Alex file was machine-generated by the BNF converter
+{
+{-# OPTIONS -fno-warn-incomplete-patterns #-}
+module Transfer.Core.Lex where
+
+
+}
+
+
+$l = [a-zA-Z\192 - \255] # [\215 \247] -- isolatin1 letter FIXME
+$c = [A-Z\192-\221] # [\215] -- capital isolatin1 letter FIXME
+$s = [a-z\222-\255] # [\247] -- small isolatin1 letter FIXME
+$d = [0-9] -- digit
+$i = [$l $d _ '] -- identifier character
+$u = [\0-\255] -- universal: any character
+
+@rsyms = -- symbols and non-identifier-like reserved words
+ \; | \: | \{ | \} | \= | \( | \) | \_ | \| | \- \> | \\ | \.
+
+:-
+"--" [.]* ; -- Toss single line comments
+"{-" ([$u # \-] | \- [$u # \}])* ("-")+ "}" ;
+
+$white+ ;
+@rsyms { tok (\p s -> PT p (TS $ share s)) }
+\? $d + { tok (\p s -> PT p (eitherResIdent (T_TMeta . share) s)) }
+($l | \_)($l | $d | \_ | \')* { tok (\p s -> PT p (eitherResIdent (T_CIdent . share) s)) }
+
+$l $i* { tok (\p s -> PT p (eitherResIdent (TV . share) s)) }
+\" ([$u # [\" \\ \n]] | (\\ (\" | \\ | \' | n | t)))* \"{ tok (\p s -> PT p (TL $ share $ unescapeInitTail s)) }
+
+$d+ { tok (\p s -> PT p (TI $ share s)) }
+$d+ \. $d+ (e (\-)? $d+)? { tok (\p s -> PT p (TD $ share s)) }
+
+{
+
+tok f p s = f p s
+
+share :: String -> String
+share = id
+
+data Tok =
+ TS !String -- reserved words and symbols
+ | TL !String -- string literals
+ | TI !String -- integer literals
+ | TV !String -- identifiers
+ | TD !String -- double precision float literals
+ | TC !String -- character literals
+ | T_TMeta !String
+ | T_CIdent !String
+
+ deriving (Eq,Show,Ord)
+
+data Token =
+ PT Posn Tok
+ | Err Posn
+ deriving (Eq,Show,Ord)
+
+tokenPos (PT (Pn _ l _) _ :_) = "line " ++ show l
+tokenPos (Err (Pn _ l _) :_) = "line " ++ show l
+tokenPos _ = "end of file"
+
+posLineCol (Pn _ l c) = (l,c)
+mkPosToken t@(PT p _) = (posLineCol p, prToken t)
+
+prToken t = case t of
+ PT _ (TS s) -> s
+ PT _ (TI s) -> s
+ PT _ (TV s) -> s
+ PT _ (TD s) -> s
+ PT _ (TC s) -> s
+ PT _ (T_TMeta s) -> s
+ PT _ (T_CIdent s) -> s
+
+ _ -> show t
+
+data BTree = N | B String Tok BTree BTree deriving (Show)
+
+eitherResIdent :: (String -> Tok) -> String -> Tok
+eitherResIdent tv s = treeFind resWords
+ where
+ treeFind N = tv s
+ treeFind (B a t left right) | s < a = treeFind left
+ | s > a = treeFind right
+ | s == a = t
+
+resWords = b "let" (b "data" (b "case" (b "Type" N N) N) (b "in" N N)) (b "sig" (b "rec" (b "of" N N) N) (b "where" N N))
+ where b s = B s (TS s)
+
+unescapeInitTail :: String -> String
+unescapeInitTail = unesc . tail where
+ unesc s = case s of
+ '\\':c:cs | elem c ['\"', '\\', '\''] -> c : unesc cs
+ '\\':'n':cs -> '\n' : unesc cs
+ '\\':'t':cs -> '\t' : unesc cs
+ '"':[] -> []
+ c:cs -> c : unesc cs
+ _ -> []
+
+-------------------------------------------------------------------
+-- Alex wrapper code.
+-- A modified "posn" wrapper.
+-------------------------------------------------------------------
+
+data Posn = Pn !Int !Int !Int
+ deriving (Eq, Show,Ord)
+
+alexStartPos :: Posn
+alexStartPos = Pn 0 1 1
+
+alexMove :: Posn -> Char -> Posn
+alexMove (Pn a l c) '\t' = Pn (a+1) l (((c+7) `div` 8)*8+1)
+alexMove (Pn a l c) '\n' = Pn (a+1) (l+1) 1
+alexMove (Pn a l c) _ = Pn (a+1) l (c+1)
+
+type AlexInput = (Posn, -- current position,
+ Char, -- previous char
+ String) -- current input string
+
+tokens :: String -> [Token]
+tokens str = go (alexStartPos, '\n', str)
+ where
+ go :: (Posn, Char, String) -> [Token]
+ go inp@(pos, _, str) =
+ case alexScan inp 0 of
+ AlexEOF -> []
+ AlexError (pos, _, _) -> fail $ show pos ++ ": lexical error"
+ AlexSkip inp' len -> go inp'
+ AlexToken inp' len act -> act pos (take len str) : (go inp')
+
+alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
+alexGetChar (p, c, []) = Nothing
+alexGetChar (p, _, (c:s)) =
+ let p' = alexMove p c
+ in p' `seq` Just (c, (p', c, s))
+
+alexInputPrevChar :: AlexInput -> Char
+alexInputPrevChar (p, c, s) = c
+}
diff --git a/src-2.9/Transfer/Core/Par.hs b/src-2.9/Transfer/Core/Par.hs
new file mode 100644
index 000000000..fec63662a
--- /dev/null
+++ b/src-2.9/Transfer/Core/Par.hs
@@ -0,0 +1,1149 @@
+{-# OPTIONS -fglasgow-exts -cpp #-}
+{-# OPTIONS -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
+module Transfer.Core.Par where
+import Transfer.Core.Abs
+import Transfer.Core.Lex
+import Transfer.ErrM
+import Array
+#if __GLASGOW_HASKELL__ >= 503
+import GHC.Exts
+#else
+import GlaExts
+#endif
+
+-- parser produced by Happy Version 1.15
+
+newtype HappyAbsSyn = HappyAbsSyn (() -> ())
+happyIn5 :: (String) -> (HappyAbsSyn )
+happyIn5 x = unsafeCoerce# x
+{-# INLINE happyIn5 #-}
+happyOut5 :: (HappyAbsSyn ) -> (String)
+happyOut5 x = unsafeCoerce# x
+{-# INLINE happyOut5 #-}
+happyIn6 :: (Integer) -> (HappyAbsSyn )
+happyIn6 x = unsafeCoerce# x
+{-# INLINE happyIn6 #-}
+happyOut6 :: (HappyAbsSyn ) -> (Integer)
+happyOut6 x = unsafeCoerce# x
+{-# INLINE happyOut6 #-}
+happyIn7 :: (Double) -> (HappyAbsSyn )
+happyIn7 x = unsafeCoerce# x
+{-# INLINE happyIn7 #-}
+happyOut7 :: (HappyAbsSyn ) -> (Double)
+happyOut7 x = unsafeCoerce# x
+{-# INLINE happyOut7 #-}
+happyIn8 :: (TMeta) -> (HappyAbsSyn )
+happyIn8 x = unsafeCoerce# x
+{-# INLINE happyIn8 #-}
+happyOut8 :: (HappyAbsSyn ) -> (TMeta)
+happyOut8 x = unsafeCoerce# x
+{-# INLINE happyOut8 #-}
+happyIn9 :: (CIdent) -> (HappyAbsSyn )
+happyIn9 x = unsafeCoerce# x
+{-# INLINE happyIn9 #-}
+happyOut9 :: (HappyAbsSyn ) -> (CIdent)
+happyOut9 x = unsafeCoerce# x
+{-# INLINE happyOut9 #-}
+happyIn10 :: (Module) -> (HappyAbsSyn )
+happyIn10 x = unsafeCoerce# x
+{-# INLINE happyIn10 #-}
+happyOut10 :: (HappyAbsSyn ) -> (Module)
+happyOut10 x = unsafeCoerce# x
+{-# INLINE happyOut10 #-}
+happyIn11 :: ([Decl]) -> (HappyAbsSyn )
+happyIn11 x = unsafeCoerce# x
+{-# INLINE happyIn11 #-}
+happyOut11 :: (HappyAbsSyn ) -> ([Decl])
+happyOut11 x = unsafeCoerce# x
+{-# INLINE happyOut11 #-}
+happyIn12 :: (Decl) -> (HappyAbsSyn )
+happyIn12 x = unsafeCoerce# x
+{-# INLINE happyIn12 #-}
+happyOut12 :: (HappyAbsSyn ) -> (Decl)
+happyOut12 x = unsafeCoerce# x
+{-# INLINE happyOut12 #-}
+happyIn13 :: (ConsDecl) -> (HappyAbsSyn )
+happyIn13 x = unsafeCoerce# x
+{-# INLINE happyIn13 #-}
+happyOut13 :: (HappyAbsSyn ) -> (ConsDecl)
+happyOut13 x = unsafeCoerce# x
+{-# INLINE happyOut13 #-}
+happyIn14 :: ([ConsDecl]) -> (HappyAbsSyn )
+happyIn14 x = unsafeCoerce# x
+{-# INLINE happyIn14 #-}
+happyOut14 :: (HappyAbsSyn ) -> ([ConsDecl])
+happyOut14 x = unsafeCoerce# x
+{-# INLINE happyOut14 #-}
+happyIn15 :: ([Pattern]) -> (HappyAbsSyn )
+happyIn15 x = unsafeCoerce# x
+{-# INLINE happyIn15 #-}
+happyOut15 :: (HappyAbsSyn ) -> ([Pattern])
+happyOut15 x = unsafeCoerce# x
+{-# INLINE happyOut15 #-}
+happyIn16 :: (Pattern) -> (HappyAbsSyn )
+happyIn16 x = unsafeCoerce# x
+{-# INLINE happyIn16 #-}
+happyOut16 :: (HappyAbsSyn ) -> (Pattern)
+happyOut16 x = unsafeCoerce# x
+{-# INLINE happyOut16 #-}
+happyIn17 :: (FieldPattern) -> (HappyAbsSyn )
+happyIn17 x = unsafeCoerce# x
+{-# INLINE happyIn17 #-}
+happyOut17 :: (HappyAbsSyn ) -> (FieldPattern)
+happyOut17 x = unsafeCoerce# x
+{-# INLINE happyOut17 #-}
+happyIn18 :: ([FieldPattern]) -> (HappyAbsSyn )
+happyIn18 x = unsafeCoerce# x
+{-# INLINE happyIn18 #-}
+happyOut18 :: (HappyAbsSyn ) -> ([FieldPattern])
+happyOut18 x = unsafeCoerce# x
+{-# INLINE happyOut18 #-}
+happyIn19 :: (PatternVariable) -> (HappyAbsSyn )
+happyIn19 x = unsafeCoerce# x
+{-# INLINE happyIn19 #-}
+happyOut19 :: (HappyAbsSyn ) -> (PatternVariable)
+happyOut19 x = unsafeCoerce# x
+{-# INLINE happyOut19 #-}
+happyIn20 :: (Exp) -> (HappyAbsSyn )
+happyIn20 x = unsafeCoerce# x
+{-# INLINE happyIn20 #-}
+happyOut20 :: (HappyAbsSyn ) -> (Exp)
+happyOut20 x = unsafeCoerce# x
+{-# INLINE happyOut20 #-}
+happyIn21 :: (LetDef) -> (HappyAbsSyn )
+happyIn21 x = unsafeCoerce# x
+{-# INLINE happyIn21 #-}
+happyOut21 :: (HappyAbsSyn ) -> (LetDef)
+happyOut21 x = unsafeCoerce# x
+{-# INLINE happyOut21 #-}
+happyIn22 :: ([LetDef]) -> (HappyAbsSyn )
+happyIn22 x = unsafeCoerce# x
+{-# INLINE happyIn22 #-}
+happyOut22 :: (HappyAbsSyn ) -> ([LetDef])
+happyOut22 x = unsafeCoerce# x
+{-# INLINE happyOut22 #-}
+happyIn23 :: (Case) -> (HappyAbsSyn )
+happyIn23 x = unsafeCoerce# x
+{-# INLINE happyIn23 #-}
+happyOut23 :: (HappyAbsSyn ) -> (Case)
+happyOut23 x = unsafeCoerce# x
+{-# INLINE happyOut23 #-}
+happyIn24 :: ([Case]) -> (HappyAbsSyn )
+happyIn24 x = unsafeCoerce# x
+{-# INLINE happyIn24 #-}
+happyOut24 :: (HappyAbsSyn ) -> ([Case])
+happyOut24 x = unsafeCoerce# x
+{-# INLINE happyOut24 #-}
+happyIn25 :: (Exp) -> (HappyAbsSyn )
+happyIn25 x = unsafeCoerce# x
+{-# INLINE happyIn25 #-}
+happyOut25 :: (HappyAbsSyn ) -> (Exp)
+happyOut25 x = unsafeCoerce# x
+{-# INLINE happyOut25 #-}
+happyIn26 :: (Exp) -> (HappyAbsSyn )
+happyIn26 x = unsafeCoerce# x
+{-# INLINE happyIn26 #-}
+happyOut26 :: (HappyAbsSyn ) -> (Exp)
+happyOut26 x = unsafeCoerce# x
+{-# INLINE happyOut26 #-}
+happyIn27 :: (Exp) -> (HappyAbsSyn )
+happyIn27 x = unsafeCoerce# x
+{-# INLINE happyIn27 #-}
+happyOut27 :: (HappyAbsSyn ) -> (Exp)
+happyOut27 x = unsafeCoerce# x
+{-# INLINE happyOut27 #-}
+happyIn28 :: (Exp) -> (HappyAbsSyn )
+happyIn28 x = unsafeCoerce# x
+{-# INLINE happyIn28 #-}
+happyOut28 :: (HappyAbsSyn ) -> (Exp)
+happyOut28 x = unsafeCoerce# x
+{-# INLINE happyOut28 #-}
+happyIn29 :: (FieldType) -> (HappyAbsSyn )
+happyIn29 x = unsafeCoerce# x
+{-# INLINE happyIn29 #-}
+happyOut29 :: (HappyAbsSyn ) -> (FieldType)
+happyOut29 x = unsafeCoerce# x
+{-# INLINE happyOut29 #-}
+happyIn30 :: ([FieldType]) -> (HappyAbsSyn )
+happyIn30 x = unsafeCoerce# x
+{-# INLINE happyIn30 #-}
+happyOut30 :: (HappyAbsSyn ) -> ([FieldType])
+happyOut30 x = unsafeCoerce# x
+{-# INLINE happyOut30 #-}
+happyIn31 :: (FieldValue) -> (HappyAbsSyn )
+happyIn31 x = unsafeCoerce# x
+{-# INLINE happyIn31 #-}
+happyOut31 :: (HappyAbsSyn ) -> (FieldValue)
+happyOut31 x = unsafeCoerce# x
+{-# INLINE happyOut31 #-}
+happyIn32 :: ([FieldValue]) -> (HappyAbsSyn )
+happyIn32 x = unsafeCoerce# x
+{-# INLINE happyIn32 #-}
+happyOut32 :: (HappyAbsSyn ) -> ([FieldValue])
+happyOut32 x = unsafeCoerce# x
+{-# INLINE happyOut32 #-}
+happyIn33 :: (Exp) -> (HappyAbsSyn )
+happyIn33 x = unsafeCoerce# x
+{-# INLINE happyIn33 #-}
+happyOut33 :: (HappyAbsSyn ) -> (Exp)
+happyOut33 x = unsafeCoerce# x
+{-# INLINE happyOut33 #-}
+happyInTok :: Token -> (HappyAbsSyn )
+happyInTok x = unsafeCoerce# x
+{-# INLINE happyInTok #-}
+happyOutTok :: (HappyAbsSyn ) -> Token
+happyOutTok x = unsafeCoerce# x
+{-# INLINE happyOutTok #-}
+
+happyActOffsets :: HappyAddr
+happyActOffsets = HappyA# "\x15\x00\x5f\x01\xcd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd0\x00\x00\x00\x7c\x01\xde\x00\x00\x00\x00\x00\x4a\x01\x09\x00\x00\x00\x5f\x01\xdf\x00\xd7\x00\xd6\x00\x00\x00\x00\x00\x00\x00\x00\x00\x35\x00\xbc\x00\x00\x00\xd1\x00\xc7\x00\xcf\x00\x15\x00\x5f\x01\x5f\x01\xc6\x00\xc6\x00\xc6\x00\xbe\x00\x00\x00\xc5\x00\x00\x00\x74\x01\xcb\x00\xc0\x00\xac\x00\xb9\x00\x5f\x01\x00\x00\x00\x00\x5f\x01\x5f\x01\xc1\x00\xb8\x00\xbb\x00\xb7\x00\xb5\x00\xb3\x00\xaf\x00\xb0\x00\xa9\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x5f\x01\x94\x00\x00\x00\x86\x00\x5f\x01\x00\x00\x86\x00\x5f\x01\x8f\x00\x84\x00\x5f\x01\x96\x01\x00\x00\x90\x00\x8b\x00\x00\x00\x00\x00\x8d\x00\x00\x00\x8c\x00\x8a\x00\x7a\x00\x89\x00\x00\x00\x00\x00\x5f\x01\x00\x00\x00\x00\x00\x00\x00\x00\x81\x00\x69\x00\x00\x00\x69\x00\x00\x00\x00\x00\x96\x01\x5f\x01\x5f\x01\x00\x00\x71\x00\x00\x00\x91\x01\x75\x00\x78\x00\x74\x00\x6d\x00\x65\x00\x5c\x00\x00\x00\x43\x00\x5f\x01\x00\x00\x43\x00\x96\x01\x00\x00\x00\x00\x5f\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
+
+happyGotoOffsets :: HappyAddr
+happyGotoOffsets = HappyA# "\x4e\x00\x31\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x38\x01\x00\x00\x00\x00\x00\x00\x01\x00\x04\x00\x00\x00\x14\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x45\x00\x00\x00\x6a\x00\x0b\x01\xee\x00\x28\x00\x44\x00\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x31\x00\x00\x00\xe5\x00\x00\x00\x00\x00\xc8\x00\xbf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa2\x00\x00\x00\x00\x00\x02\x00\x99\x00\x00\x00\x1e\x00\x7c\x00\x00\x00\x03\x00\x73\x00\xb4\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x56\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa3\x00\x00\x00\x3e\x00\xff\xff\x00\x00\xae\x01\x4d\x00\x30\x00\x00\x00\x00\x00\x00\x00\xba\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7d\x00\x27\x00\x00\x00\x21\x00\x3e\x01\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
+
+happyDefActions :: HappyAddr
+happyDefActions = HappyA# "\xf7\xff\x00\x00\x00\x00\xfd\xff\xca\xff\xc9\xff\xc8\xff\xc7\xff\xcc\xff\x00\x00\xde\xff\xbd\xff\xd1\xff\xcf\xff\xd3\xff\x00\x00\x00\x00\xcb\xff\x00\x00\x00\x00\x00\x00\x00\x00\xfc\xff\xfb\xff\xfa\xff\xf9\xff\x00\x00\x00\x00\xf8\xff\xf6\xff\x00\x00\x00\x00\xf7\xff\x00\x00\x00\x00\xc4\xff\xc0\xff\xdc\xff\x00\x00\xe2\xff\x00\x00\xe1\xff\xe2\xff\x00\x00\x00\x00\x00\x00\xd2\xff\x00\x00\xd0\xff\xc6\xff\x00\x00\x00\x00\x00\x00\x00\x00\xdb\xff\x00\x00\x00\x00\xbf\xff\x00\x00\x00\x00\xc3\xff\x00\x00\xf2\xff\xf3\xff\xf5\xff\x00\x00\x00\x00\xce\xff\xc4\xff\x00\x00\xcd\xff\xc0\xff\x00\x00\x00\x00\xdc\xff\x00\x00\xd8\xff\xd5\xff\x00\x00\x00\x00\xe8\xff\xe7\xff\x00\x00\xea\xff\xd7\xff\x00\x00\x00\x00\x00\x00\xdd\xff\xda\xff\x00\x00\xc1\xff\xbe\xff\xc5\xff\xc2\xff\x00\x00\xf0\xff\xe0\xff\xe5\xff\xed\xff\xdf\xff\xd8\xff\x00\x00\x00\x00\xd4\xff\x00\x00\xd6\xff\x00\x00\x00\x00\xe4\xff\x00\x00\x00\x00\xef\xff\x00\x00\xf4\xff\xf0\xff\x00\x00\xe9\xff\xe5\xff\x00\x00\xec\xff\xeb\xff\x00\x00\xd9\xff\xe6\xff\xe3\xff\xf1\xff\xee\xff"#
+
+happyCheck :: HappyAddr
+happyCheck = HappyA# "\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x04\x00\x04\x00\x04\x00\x0a\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x0e\x00\x0f\x00\x08\x00\x0e\x00\x10\x00\x11\x00\x14\x00\x15\x00\x16\x00\x17\x00\x0f\x00\x18\x00\x19\x00\x04\x00\x1c\x00\x14\x00\x15\x00\x16\x00\x17\x00\x04\x00\x1a\x00\x0f\x00\x04\x00\x1c\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x04\x00\x0c\x00\x0d\x00\x1a\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x04\x00\x0f\x00\x02\x00\x1a\x00\x1b\x00\x05\x00\x14\x00\x15\x00\x16\x00\x17\x00\x0f\x00\x18\x00\x19\x00\x04\x00\x1c\x00\x14\x00\x15\x00\x16\x00\x17\x00\x04\x00\x04\x00\x0c\x00\x0d\x00\x1c\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x04\x00\x0f\x00\x1a\x00\x1a\x00\x1b\x00\x04\x00\x14\x00\x15\x00\x16\x00\x17\x00\x0f\x00\x01\x00\x10\x00\x11\x00\x1c\x00\x14\x00\x15\x00\x16\x00\x17\x00\x04\x00\x02\x00\x06\x00\x07\x00\x1c\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x04\x00\x01\x00\x05\x00\x0a\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x04\x00\x0f\x00\x1a\x00\x03\x00\x08\x00\x09\x00\x14\x00\x15\x00\x16\x00\x17\x00\x0f\x00\x03\x00\x01\x00\x04\x00\x1c\x00\x14\x00\x15\x00\x16\x00\x17\x00\x1a\x00\x0a\x00\x09\x00\x07\x00\x1c\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x1a\x00\x10\x00\x1a\x00\x04\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x04\x00\x0f\x00\x15\x00\x01\x00\x08\x00\x09\x00\x14\x00\x15\x00\x16\x00\x17\x00\x0f\x00\x02\x00\x04\x00\x01\x00\x1c\x00\x14\x00\x15\x00\x16\x00\x17\x00\x05\x00\x04\x00\x01\x00\x05\x00\x1c\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x03\x00\x0c\x00\x1a\x00\x07\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x02\x00\x0f\x00\x0a\x00\x12\x00\x02\x00\x01\x00\x14\x00\x15\x00\x16\x00\x17\x00\x0f\x00\x1c\x00\x03\x00\x03\x00\x1c\x00\x14\x00\x15\x00\x16\x00\x17\x00\x1a\x00\x1a\x00\x03\x00\x16\x00\x1c\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x0c\x00\xff\xff\x1c\x00\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\xff\xff\x0f\x00\xff\xff\xff\xff\xff\xff\xff\xff\x14\x00\x15\x00\x16\x00\x17\x00\x0f\x00\xff\xff\xff\xff\xff\xff\x1c\x00\x14\x00\x15\x00\x16\x00\x17\x00\xff\xff\xff\xff\xff\xff\xff\xff\x1c\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\xff\xff\x0f\x00\xff\xff\xff\xff\xff\xff\xff\xff\x14\x00\x15\x00\x16\x00\x17\x00\x0f\x00\xff\xff\xff\xff\xff\xff\x1c\x00\x14\x00\x15\x00\x16\x00\x17\x00\xff\xff\xff\xff\xff\xff\xff\xff\x1c\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\xff\xff\x00\x00\x01\x00\x0f\x00\xff\xff\x04\x00\xff\xff\xff\xff\x14\x00\x15\x00\x16\x00\x17\x00\x0b\x00\xff\xff\xff\xff\x0e\x00\x1c\x00\x16\x00\x17\x00\x06\x00\xff\xff\x08\x00\xff\xff\xff\xff\x0b\x00\xff\xff\x0d\x00\x0e\x00\xff\xff\xff\xff\x11\x00\xff\xff\x13\x00\x14\x00\xff\xff\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x06\x00\xff\xff\xff\xff\xff\xff\xff\xff\x0b\x00\xff\xff\x0d\x00\x0e\x00\xff\xff\xff\xff\x11\x00\xff\xff\x13\x00\x14\x00\xff\xff\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x06\x00\x07\x00\xff\xff\xff\xff\xff\xff\xff\xff\x0c\x00\x0d\x00\x06\x00\xff\xff\xff\xff\xff\xff\xff\xff\x13\x00\x14\x00\x0d\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x13\x00\x14\x00\xff\xff\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x06\x00\x07\x00\x08\x00\xff\xff\xff\xff\x06\x00\xff\xff\x08\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x13\x00\xff\xff\xff\xff\x16\x00\x17\x00\x13\x00\xff\xff\x1a\x00\x16\x00\x17\x00\x00\x00\x01\x00\x1a\x00\xff\xff\x04\x00\xff\xff\x00\x00\x01\x00\xff\xff\xff\xff\x04\x00\x0b\x00\x00\x00\x01\x00\x0e\x00\xff\xff\x04\x00\x0b\x00\x12\x00\x13\x00\x0e\x00\xff\xff\xff\xff\x0b\x00\x12\x00\x13\x00\x0e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
+
+happyTable :: HappyAddr
+happyTable = HappyA# "\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x2a\x00\x3b\x00\x35\x00\x27\x00\x6b\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x2b\x00\x2c\x00\x2a\x00\x28\x00\x36\x00\x59\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x7b\x00\x3c\x00\x5e\x00\x63\x00\x0e\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x38\x00\x1a\x00\x1f\x00\x6c\x00\x0e\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x3b\x00\x6d\x00\x7d\x00\x1a\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x30\x00\x7e\x00\x22\x00\x39\x00\x5c\x00\x23\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x68\x00\x3c\x00\x3d\x00\x6c\x00\x0e\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x38\x00\x1f\x00\x6d\x00\x6e\x00\x0e\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x35\x00\x69\x00\x1a\x00\x39\x00\x3a\x00\x73\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x61\x00\x74\x00\x36\x00\x37\x00\x0e\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x1a\x00\x75\x00\x40\x00\x1d\x00\x0e\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x76\x00\x77\x00\x78\x00\x7b\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x6f\x00\x58\x00\x1a\x00\x61\x00\x70\x00\x7f\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x5b\x00\x63\x00\x66\x00\x65\x00\x0e\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x1a\x00\x68\x00\x67\x00\x50\x00\x0e\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x1a\x00\x5b\x00\x1a\x00\x44\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x6f\x00\x5d\x00\x60\x00\x45\x00\x70\x00\x71\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x42\x00\x46\x00\x47\x00\x48\x00\x0e\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x0e\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x4d\x00\x2e\x00\x1a\x00\x32\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x33\x00\x4d\x00\x34\x00\x35\x00\x42\x00\x21\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x4e\x00\xff\xff\x24\x00\x25\x00\x0e\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x1a\x00\x1a\x00\x26\x00\x04\x00\x0e\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x2e\x00\x00\x00\xff\xff\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x00\x00\x2c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x00\x00\x3f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x26\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x00\x00\x50\x00\x51\x00\x09\x00\x00\x00\x27\x00\x00\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x7c\x00\x00\x00\x00\x00\x53\x00\x0e\x00\x2e\x00\x0d\x00\x10\x00\x00\x00\x2a\x00\x00\x00\x00\x00\x11\x00\x00\x00\x12\x00\x13\x00\x00\x00\x00\x00\x14\x00\x00\x00\x15\x00\x16\x00\x00\x00\x04\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x00\x00\x00\x12\x00\x13\x00\x00\x00\x00\x00\x14\x00\x00\x00\x15\x00\x16\x00\x00\x00\x04\x00\x17\x00\x18\x00\x19\x00\x1a\x00\xcc\xff\xcc\xff\x00\x00\x00\x00\x00\x00\x00\x00\xcc\xff\xcc\xff\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\xcc\xff\xcc\xff\x12\x00\xcc\xff\xcc\xff\xcc\xff\xcc\xff\xcc\xff\x15\x00\x16\x00\x00\x00\x04\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x57\x00\x7a\x00\x2a\x00\x00\x00\x00\x00\x57\x00\x00\x00\x2a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x58\x00\x00\x00\x00\x00\x04\x00\x17\x00\x58\x00\x00\x00\x1a\x00\x04\x00\x17\x00\x50\x00\x51\x00\x1a\x00\x00\x00\x27\x00\x00\x00\x50\x00\x51\x00\x00\x00\x00\x00\x27\x00\x52\x00\x50\x00\x51\x00\x53\x00\x00\x00\x27\x00\x52\x00\x54\x00\x6a\x00\x53\x00\x00\x00\x00\x00\x78\x00\x54\x00\x55\x00\x53\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
+
+happyReduceArr = array (2, 66) [
+ (2 , happyReduce_2),
+ (3 , happyReduce_3),
+ (4 , happyReduce_4),
+ (5 , happyReduce_5),
+ (6 , happyReduce_6),
+ (7 , happyReduce_7),
+ (8 , happyReduce_8),
+ (9 , happyReduce_9),
+ (10 , happyReduce_10),
+ (11 , happyReduce_11),
+ (12 , happyReduce_12),
+ (13 , happyReduce_13),
+ (14 , happyReduce_14),
+ (15 , happyReduce_15),
+ (16 , happyReduce_16),
+ (17 , happyReduce_17),
+ (18 , happyReduce_18),
+ (19 , happyReduce_19),
+ (20 , happyReduce_20),
+ (21 , happyReduce_21),
+ (22 , happyReduce_22),
+ (23 , happyReduce_23),
+ (24 , happyReduce_24),
+ (25 , happyReduce_25),
+ (26 , happyReduce_26),
+ (27 , happyReduce_27),
+ (28 , happyReduce_28),
+ (29 , happyReduce_29),
+ (30 , happyReduce_30),
+ (31 , happyReduce_31),
+ (32 , happyReduce_32),
+ (33 , happyReduce_33),
+ (34 , happyReduce_34),
+ (35 , happyReduce_35),
+ (36 , happyReduce_36),
+ (37 , happyReduce_37),
+ (38 , happyReduce_38),
+ (39 , happyReduce_39),
+ (40 , happyReduce_40),
+ (41 , happyReduce_41),
+ (42 , happyReduce_42),
+ (43 , happyReduce_43),
+ (44 , happyReduce_44),
+ (45 , happyReduce_45),
+ (46 , happyReduce_46),
+ (47 , happyReduce_47),
+ (48 , happyReduce_48),
+ (49 , happyReduce_49),
+ (50 , happyReduce_50),
+ (51 , happyReduce_51),
+ (52 , happyReduce_52),
+ (53 , happyReduce_53),
+ (54 , happyReduce_54),
+ (55 , happyReduce_55),
+ (56 , happyReduce_56),
+ (57 , happyReduce_57),
+ (58 , happyReduce_58),
+ (59 , happyReduce_59),
+ (60 , happyReduce_60),
+ (61 , happyReduce_61),
+ (62 , happyReduce_62),
+ (63 , happyReduce_63),
+ (64 , happyReduce_64),
+ (65 , happyReduce_65),
+ (66 , happyReduce_66)
+ ]
+
+happy_n_terms = 29 :: Int
+happy_n_nonterms = 29 :: Int
+
+happyReduce_2 = happySpecReduce_1 0# happyReduction_2
+happyReduction_2 happy_x_1
+ = case happyOutTok happy_x_1 of { (PT _ (TL happy_var_1)) ->
+ happyIn5
+ (happy_var_1
+ )}
+
+happyReduce_3 = happySpecReduce_1 1# happyReduction_3
+happyReduction_3 happy_x_1
+ = case happyOutTok happy_x_1 of { (PT _ (TI happy_var_1)) ->
+ happyIn6
+ ((read happy_var_1) :: Integer
+ )}
+
+happyReduce_4 = happySpecReduce_1 2# happyReduction_4
+happyReduction_4 happy_x_1
+ = case happyOutTok happy_x_1 of { (PT _ (TD happy_var_1)) ->
+ happyIn7
+ ((read happy_var_1) :: Double
+ )}
+
+happyReduce_5 = happySpecReduce_1 3# happyReduction_5
+happyReduction_5 happy_x_1
+ = case happyOutTok happy_x_1 of { (PT _ (T_TMeta happy_var_1)) ->
+ happyIn8
+ (TMeta (happy_var_1)
+ )}
+
+happyReduce_6 = happySpecReduce_1 4# happyReduction_6
+happyReduction_6 happy_x_1
+ = case happyOutTok happy_x_1 of { (PT _ (T_CIdent happy_var_1)) ->
+ happyIn9
+ (CIdent (happy_var_1)
+ )}
+
+happyReduce_7 = happySpecReduce_1 5# happyReduction_7
+happyReduction_7 happy_x_1
+ = case happyOut11 happy_x_1 of { happy_var_1 ->
+ happyIn10
+ (Module happy_var_1
+ )}
+
+happyReduce_8 = happySpecReduce_0 6# happyReduction_8
+happyReduction_8 = happyIn11
+ ([]
+ )
+
+happyReduce_9 = happySpecReduce_1 6# happyReduction_9
+happyReduction_9 happy_x_1
+ = case happyOut12 happy_x_1 of { happy_var_1 ->
+ happyIn11
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_10 = happySpecReduce_3 6# happyReduction_10
+happyReduction_10 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut12 happy_x_1 of { happy_var_1 ->
+ case happyOut11 happy_x_3 of { happy_var_3 ->
+ happyIn11
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_11 = happyReduce 8# 7# happyReduction_11
+happyReduction_11 (happy_x_8 `HappyStk`
+ happy_x_7 `HappyStk`
+ happy_x_6 `HappyStk`
+ happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut9 happy_x_2 of { happy_var_2 ->
+ case happyOut20 happy_x_4 of { happy_var_4 ->
+ case happyOut14 happy_x_7 of { happy_var_7 ->
+ happyIn12
+ (DataDecl happy_var_2 happy_var_4 happy_var_7
+ ) `HappyStk` happyRest}}}
+
+happyReduce_12 = happySpecReduce_3 7# happyReduction_12
+happyReduction_12 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut9 happy_x_1 of { happy_var_1 ->
+ case happyOut20 happy_x_3 of { happy_var_3 ->
+ happyIn12
+ (TypeDecl happy_var_1 happy_var_3
+ )}}
+
+happyReduce_13 = happySpecReduce_3 7# happyReduction_13
+happyReduction_13 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut9 happy_x_1 of { happy_var_1 ->
+ case happyOut20 happy_x_3 of { happy_var_3 ->
+ happyIn12
+ (ValueDecl happy_var_1 happy_var_3
+ )}}
+
+happyReduce_14 = happySpecReduce_3 8# happyReduction_14
+happyReduction_14 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut9 happy_x_1 of { happy_var_1 ->
+ case happyOut20 happy_x_3 of { happy_var_3 ->
+ happyIn13
+ (ConsDecl happy_var_1 happy_var_3
+ )}}
+
+happyReduce_15 = happySpecReduce_0 9# happyReduction_15
+happyReduction_15 = happyIn14
+ ([]
+ )
+
+happyReduce_16 = happySpecReduce_1 9# happyReduction_16
+happyReduction_16 happy_x_1
+ = case happyOut13 happy_x_1 of { happy_var_1 ->
+ happyIn14
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_17 = happySpecReduce_3 9# happyReduction_17
+happyReduction_17 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut13 happy_x_1 of { happy_var_1 ->
+ case happyOut14 happy_x_3 of { happy_var_3 ->
+ happyIn14
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_18 = happySpecReduce_0 10# happyReduction_18
+happyReduction_18 = happyIn15
+ ([]
+ )
+
+happyReduce_19 = happySpecReduce_2 10# happyReduction_19
+happyReduction_19 happy_x_2
+ happy_x_1
+ = case happyOut15 happy_x_1 of { happy_var_1 ->
+ case happyOut16 happy_x_2 of { happy_var_2 ->
+ happyIn15
+ (flip (:) happy_var_1 happy_var_2
+ )}}
+
+happyReduce_20 = happyReduce 4# 11# happyReduction_20
+happyReduction_20 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut9 happy_x_2 of { happy_var_2 ->
+ case happyOut15 happy_x_3 of { happy_var_3 ->
+ happyIn16
+ (PCons happy_var_2 (reverse happy_var_3)
+ ) `HappyStk` happyRest}}
+
+happyReduce_21 = happySpecReduce_1 11# happyReduction_21
+happyReduction_21 happy_x_1
+ = case happyOut19 happy_x_1 of { happy_var_1 ->
+ happyIn16
+ (PVar happy_var_1
+ )}
+
+happyReduce_22 = happyReduce 4# 11# happyReduction_22
+happyReduction_22 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut18 happy_x_3 of { happy_var_3 ->
+ happyIn16
+ (PRec happy_var_3
+ ) `HappyStk` happyRest}
+
+happyReduce_23 = happySpecReduce_1 11# happyReduction_23
+happyReduction_23 happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ happyIn16
+ (PStr happy_var_1
+ )}
+
+happyReduce_24 = happySpecReduce_1 11# happyReduction_24
+happyReduction_24 happy_x_1
+ = case happyOut6 happy_x_1 of { happy_var_1 ->
+ happyIn16
+ (PInt happy_var_1
+ )}
+
+happyReduce_25 = happySpecReduce_3 12# happyReduction_25
+happyReduction_25 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut9 happy_x_1 of { happy_var_1 ->
+ case happyOut16 happy_x_3 of { happy_var_3 ->
+ happyIn17
+ (FieldPattern happy_var_1 happy_var_3
+ )}}
+
+happyReduce_26 = happySpecReduce_0 13# happyReduction_26
+happyReduction_26 = happyIn18
+ ([]
+ )
+
+happyReduce_27 = happySpecReduce_1 13# happyReduction_27
+happyReduction_27 happy_x_1
+ = case happyOut17 happy_x_1 of { happy_var_1 ->
+ happyIn18
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_28 = happySpecReduce_3 13# happyReduction_28
+happyReduction_28 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut17 happy_x_1 of { happy_var_1 ->
+ case happyOut18 happy_x_3 of { happy_var_3 ->
+ happyIn18
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_29 = happySpecReduce_1 14# happyReduction_29
+happyReduction_29 happy_x_1
+ = case happyOut9 happy_x_1 of { happy_var_1 ->
+ happyIn19
+ (PVVar happy_var_1
+ )}
+
+happyReduce_30 = happySpecReduce_1 14# happyReduction_30
+happyReduction_30 happy_x_1
+ = happyIn19
+ (PVWild
+ )
+
+happyReduce_31 = happyReduce 6# 15# happyReduction_31
+happyReduction_31 (happy_x_6 `HappyStk`
+ happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut22 happy_x_3 of { happy_var_3 ->
+ case happyOut20 happy_x_6 of { happy_var_6 ->
+ happyIn20
+ (ELet happy_var_3 happy_var_6
+ ) `HappyStk` happyRest}}
+
+happyReduce_32 = happyReduce 6# 15# happyReduction_32
+happyReduction_32 (happy_x_6 `HappyStk`
+ happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut20 happy_x_2 of { happy_var_2 ->
+ case happyOut24 happy_x_5 of { happy_var_5 ->
+ happyIn20
+ (ECase happy_var_2 happy_var_5
+ ) `HappyStk` happyRest}}
+
+happyReduce_33 = happySpecReduce_1 15# happyReduction_33
+happyReduction_33 happy_x_1
+ = case happyOut25 happy_x_1 of { happy_var_1 ->
+ happyIn20
+ (happy_var_1
+ )}
+
+happyReduce_34 = happySpecReduce_3 16# happyReduction_34
+happyReduction_34 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut9 happy_x_1 of { happy_var_1 ->
+ case happyOut20 happy_x_3 of { happy_var_3 ->
+ happyIn21
+ (LetDef happy_var_1 happy_var_3
+ )}}
+
+happyReduce_35 = happySpecReduce_0 17# happyReduction_35
+happyReduction_35 = happyIn22
+ ([]
+ )
+
+happyReduce_36 = happySpecReduce_1 17# happyReduction_36
+happyReduction_36 happy_x_1
+ = case happyOut21 happy_x_1 of { happy_var_1 ->
+ happyIn22
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_37 = happySpecReduce_3 17# happyReduction_37
+happyReduction_37 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut21 happy_x_1 of { happy_var_1 ->
+ case happyOut22 happy_x_3 of { happy_var_3 ->
+ happyIn22
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_38 = happyReduce 5# 18# happyReduction_38
+happyReduction_38 (happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut16 happy_x_1 of { happy_var_1 ->
+ case happyOut20 happy_x_3 of { happy_var_3 ->
+ case happyOut20 happy_x_5 of { happy_var_5 ->
+ happyIn23
+ (Case happy_var_1 happy_var_3 happy_var_5
+ ) `HappyStk` happyRest}}}
+
+happyReduce_39 = happySpecReduce_0 19# happyReduction_39
+happyReduction_39 = happyIn24
+ ([]
+ )
+
+happyReduce_40 = happySpecReduce_1 19# happyReduction_40
+happyReduction_40 happy_x_1
+ = case happyOut23 happy_x_1 of { happy_var_1 ->
+ happyIn24
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_41 = happySpecReduce_3 19# happyReduction_41
+happyReduction_41 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut23 happy_x_1 of { happy_var_1 ->
+ case happyOut24 happy_x_3 of { happy_var_3 ->
+ happyIn24
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_42 = happyReduce 4# 20# happyReduction_42
+happyReduction_42 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut19 happy_x_2 of { happy_var_2 ->
+ case happyOut20 happy_x_4 of { happy_var_4 ->
+ happyIn25
+ (EAbs happy_var_2 happy_var_4
+ ) `HappyStk` happyRest}}
+
+happyReduce_43 = happyReduce 7# 20# happyReduction_43
+happyReduction_43 (happy_x_7 `HappyStk`
+ happy_x_6 `HappyStk`
+ happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut19 happy_x_2 of { happy_var_2 ->
+ case happyOut20 happy_x_4 of { happy_var_4 ->
+ case happyOut20 happy_x_7 of { happy_var_7 ->
+ happyIn25
+ (EPi happy_var_2 happy_var_4 happy_var_7
+ ) `HappyStk` happyRest}}}
+
+happyReduce_44 = happySpecReduce_1 20# happyReduction_44
+happyReduction_44 happy_x_1
+ = case happyOut33 happy_x_1 of { happy_var_1 ->
+ happyIn25
+ (happy_var_1
+ )}
+
+happyReduce_45 = happySpecReduce_2 21# happyReduction_45
+happyReduction_45 happy_x_2
+ happy_x_1
+ = case happyOut26 happy_x_1 of { happy_var_1 ->
+ case happyOut27 happy_x_2 of { happy_var_2 ->
+ happyIn26
+ (EApp happy_var_1 happy_var_2
+ )}}
+
+happyReduce_46 = happySpecReduce_1 21# happyReduction_46
+happyReduction_46 happy_x_1
+ = case happyOut27 happy_x_1 of { happy_var_1 ->
+ happyIn26
+ (happy_var_1
+ )}
+
+happyReduce_47 = happySpecReduce_3 22# happyReduction_47
+happyReduction_47 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut27 happy_x_1 of { happy_var_1 ->
+ case happyOut9 happy_x_3 of { happy_var_3 ->
+ happyIn27
+ (EProj happy_var_1 happy_var_3
+ )}}
+
+happyReduce_48 = happySpecReduce_1 22# happyReduction_48
+happyReduction_48 happy_x_1
+ = case happyOut28 happy_x_1 of { happy_var_1 ->
+ happyIn27
+ (happy_var_1
+ )}
+
+happyReduce_49 = happyReduce 4# 23# happyReduction_49
+happyReduction_49 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut30 happy_x_3 of { happy_var_3 ->
+ happyIn28
+ (ERecType happy_var_3
+ ) `HappyStk` happyRest}
+
+happyReduce_50 = happyReduce 4# 23# happyReduction_50
+happyReduction_50 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut32 happy_x_3 of { happy_var_3 ->
+ happyIn28
+ (ERec happy_var_3
+ ) `HappyStk` happyRest}
+
+happyReduce_51 = happySpecReduce_1 23# happyReduction_51
+happyReduction_51 happy_x_1
+ = case happyOut9 happy_x_1 of { happy_var_1 ->
+ happyIn28
+ (EVar happy_var_1
+ )}
+
+happyReduce_52 = happySpecReduce_1 23# happyReduction_52
+happyReduction_52 happy_x_1
+ = happyIn28
+ (EType
+ )
+
+happyReduce_53 = happySpecReduce_1 23# happyReduction_53
+happyReduction_53 happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ happyIn28
+ (EStr happy_var_1
+ )}
+
+happyReduce_54 = happySpecReduce_1 23# happyReduction_54
+happyReduction_54 happy_x_1
+ = case happyOut6 happy_x_1 of { happy_var_1 ->
+ happyIn28
+ (EInteger happy_var_1
+ )}
+
+happyReduce_55 = happySpecReduce_1 23# happyReduction_55
+happyReduction_55 happy_x_1
+ = case happyOut7 happy_x_1 of { happy_var_1 ->
+ happyIn28
+ (EDouble happy_var_1
+ )}
+
+happyReduce_56 = happySpecReduce_1 23# happyReduction_56
+happyReduction_56 happy_x_1
+ = case happyOut8 happy_x_1 of { happy_var_1 ->
+ happyIn28
+ (EMeta happy_var_1
+ )}
+
+happyReduce_57 = happySpecReduce_3 23# happyReduction_57
+happyReduction_57 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut20 happy_x_2 of { happy_var_2 ->
+ happyIn28
+ (happy_var_2
+ )}
+
+happyReduce_58 = happySpecReduce_3 24# happyReduction_58
+happyReduction_58 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut9 happy_x_1 of { happy_var_1 ->
+ case happyOut20 happy_x_3 of { happy_var_3 ->
+ happyIn29
+ (FieldType happy_var_1 happy_var_3
+ )}}
+
+happyReduce_59 = happySpecReduce_0 25# happyReduction_59
+happyReduction_59 = happyIn30
+ ([]
+ )
+
+happyReduce_60 = happySpecReduce_1 25# happyReduction_60
+happyReduction_60 happy_x_1
+ = case happyOut29 happy_x_1 of { happy_var_1 ->
+ happyIn30
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_61 = happySpecReduce_3 25# happyReduction_61
+happyReduction_61 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut29 happy_x_1 of { happy_var_1 ->
+ case happyOut30 happy_x_3 of { happy_var_3 ->
+ happyIn30
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_62 = happySpecReduce_3 26# happyReduction_62
+happyReduction_62 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut9 happy_x_1 of { happy_var_1 ->
+ case happyOut20 happy_x_3 of { happy_var_3 ->
+ happyIn31
+ (FieldValue happy_var_1 happy_var_3
+ )}}
+
+happyReduce_63 = happySpecReduce_0 27# happyReduction_63
+happyReduction_63 = happyIn32
+ ([]
+ )
+
+happyReduce_64 = happySpecReduce_1 27# happyReduction_64
+happyReduction_64 happy_x_1
+ = case happyOut31 happy_x_1 of { happy_var_1 ->
+ happyIn32
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_65 = happySpecReduce_3 27# happyReduction_65
+happyReduction_65 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut31 happy_x_1 of { happy_var_1 ->
+ case happyOut32 happy_x_3 of { happy_var_3 ->
+ happyIn32
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_66 = happySpecReduce_1 28# happyReduction_66
+happyReduction_66 happy_x_1
+ = case happyOut26 happy_x_1 of { happy_var_1 ->
+ happyIn33
+ (happy_var_1
+ )}
+
+happyNewToken action sts stk [] =
+ happyDoAction 28# (error "reading EOF!") action sts stk []
+
+happyNewToken action sts stk (tk:tks) =
+ let cont i = happyDoAction i tk action sts stk tks in
+ case tk of {
+ PT _ (TS ";") -> cont 1#;
+ PT _ (TS ":") -> cont 2#;
+ PT _ (TS "{") -> cont 3#;
+ PT _ (TS "}") -> cont 4#;
+ PT _ (TS "=") -> cont 5#;
+ PT _ (TS "(") -> cont 6#;
+ PT _ (TS ")") -> cont 7#;
+ PT _ (TS "_") -> cont 8#;
+ PT _ (TS "|") -> cont 9#;
+ PT _ (TS "->") -> cont 10#;
+ PT _ (TS "\\") -> cont 11#;
+ PT _ (TS ".") -> cont 12#;
+ PT _ (TS "Type") -> cont 13#;
+ PT _ (TS "case") -> cont 14#;
+ PT _ (TS "data") -> cont 15#;
+ PT _ (TS "in") -> cont 16#;
+ PT _ (TS "let") -> cont 17#;
+ PT _ (TS "of") -> cont 18#;
+ PT _ (TS "rec") -> cont 19#;
+ PT _ (TS "sig") -> cont 20#;
+ PT _ (TS "where") -> cont 21#;
+ PT _ (TL happy_dollar_dollar) -> cont 22#;
+ PT _ (TI happy_dollar_dollar) -> cont 23#;
+ PT _ (TD happy_dollar_dollar) -> cont 24#;
+ PT _ (T_TMeta happy_dollar_dollar) -> cont 25#;
+ PT _ (T_CIdent happy_dollar_dollar) -> cont 26#;
+ _ -> cont 27#;
+ _ -> happyError' (tk:tks)
+ }
+
+happyError_ tk tks = happyError' (tk:tks)
+
+happyThen :: () => Err a -> (a -> Err b) -> Err b
+happyThen = (thenM)
+happyReturn :: () => a -> Err a
+happyReturn = (returnM)
+happyThen1 m k tks = (thenM) m (\a -> k a tks)
+happyReturn1 :: () => a -> b -> Err a
+happyReturn1 = \a tks -> (returnM) a
+happyError' :: () => [Token] -> Err a
+happyError' = happyError
+
+pModule tks = happySomeParser where
+ happySomeParser = happyThen (happyParse 0# tks) (\x -> happyReturn (happyOut10 x))
+
+pExp tks = happySomeParser where
+ happySomeParser = happyThen (happyParse 1# tks) (\x -> happyReturn (happyOut20 x))
+
+happySeq = happyDontSeq
+
+returnM :: a -> Err a
+returnM = return
+
+thenM :: Err a -> (a -> Err b) -> Err b
+thenM = (>>=)
+
+happyError :: [Token] -> Err a
+happyError ts =
+ Bad $ "syntax error at " ++ tokenPos ts ++ if null ts then [] else (" before " ++ unwords (map prToken (take 4 ts)))
+
+myLexer = tokens
+{-# LINE 1 "GenericTemplate.hs" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "GenericTemplate.hs" #-}
+-- $Id$
+
+{-# LINE 28 "GenericTemplate.hs" #-}
+
+
+data Happy_IntList = HappyCons Int# Happy_IntList
+
+
+
+
+
+{-# LINE 49 "GenericTemplate.hs" #-}
+
+{-# LINE 59 "GenericTemplate.hs" #-}
+
+{-# LINE 68 "GenericTemplate.hs" #-}
+
+infixr 9 `HappyStk`
+data HappyStk a = HappyStk a (HappyStk a)
+
+-----------------------------------------------------------------------------
+-- starting the parse
+
+happyParse start_state = happyNewToken start_state notHappyAtAll notHappyAtAll
+
+-----------------------------------------------------------------------------
+-- Accepting the parse
+
+-- If the current token is 0#, it means we've just accepted a partial
+-- parse (a %partial parser). We must ignore the saved token on the top of
+-- the stack in this case.
+happyAccept 0# tk st sts (_ `HappyStk` ans `HappyStk` _) =
+ happyReturn1 ans
+happyAccept j tk st sts (HappyStk ans _) =
+ (happyTcHack j (happyTcHack st)) (happyReturn1 ans)
+
+-----------------------------------------------------------------------------
+-- Arrays only: do the next action
+
+
+
+happyDoAction i tk st
+ = {- nothing -}
+
+
+ case action of
+ 0# -> {- nothing -}
+ happyFail i tk st
+ -1# -> {- nothing -}
+ happyAccept i tk st
+ n | (n <# (0# :: Int#)) -> {- nothing -}
+
+ (happyReduceArr ! rule) i tk st
+ where rule = (I# ((negateInt# ((n +# (1# :: Int#))))))
+ n -> {- nothing -}
+
+
+ happyShift new_state i tk st
+ where new_state = (n -# (1# :: Int#))
+ where off = indexShortOffAddr happyActOffsets st
+ off_i = (off +# i)
+ check = if (off_i >=# (0# :: Int#))
+ then (indexShortOffAddr happyCheck off_i ==# i)
+ else False
+ action | check = indexShortOffAddr happyTable off_i
+ | otherwise = indexShortOffAddr happyDefActions st
+
+{-# LINE 127 "GenericTemplate.hs" #-}
+
+
+indexShortOffAddr (HappyA# arr) off =
+#if __GLASGOW_HASKELL__ > 500
+ narrow16Int# i
+#elif __GLASGOW_HASKELL__ == 500
+ intToInt16# i
+#else
+ (i `iShiftL#` 16#) `iShiftRA#` 16#
+#endif
+ where
+#if __GLASGOW_HASKELL__ >= 503
+ i = word2Int# ((high `uncheckedShiftL#` 8#) `or#` low)
+#else
+ i = word2Int# ((high `shiftL#` 8#) `or#` low)
+#endif
+ high = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
+ low = int2Word# (ord# (indexCharOffAddr# arr off'))
+ off' = off *# 2#
+
+
+
+
+
+data HappyAddr = HappyA# Addr#
+
+
+
+
+-----------------------------------------------------------------------------
+-- HappyState data type (not arrays)
+
+{-# LINE 170 "GenericTemplate.hs" #-}
+
+-----------------------------------------------------------------------------
+-- Shifting a token
+
+happyShift new_state 0# tk st sts stk@(x `HappyStk` _) =
+ let i = (case unsafeCoerce# x of { (I# (i)) -> i }) in
+-- trace "shifting the error token" $
+ happyDoAction i tk new_state (HappyCons (st) (sts)) (stk)
+
+happyShift new_state i tk st sts stk =
+ happyNewToken new_state (HappyCons (st) (sts)) ((happyInTok (tk))`HappyStk`stk)
+
+-- happyReduce is specialised for the common cases.
+
+happySpecReduce_0 i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happySpecReduce_0 nt fn j tk st@((action)) sts stk
+ = happyGoto nt j tk st (HappyCons (st) (sts)) (fn `HappyStk` stk)
+
+happySpecReduce_1 i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happySpecReduce_1 nt fn j tk _ sts@((HappyCons (st@(action)) (_))) (v1`HappyStk`stk')
+ = let r = fn v1 in
+ happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))
+
+happySpecReduce_2 i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happySpecReduce_2 nt fn j tk _ (HappyCons (_) (sts@((HappyCons (st@(action)) (_))))) (v1`HappyStk`v2`HappyStk`stk')
+ = let r = fn v1 v2 in
+ happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))
+
+happySpecReduce_3 i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happySpecReduce_3 nt fn j tk _ (HappyCons (_) ((HappyCons (_) (sts@((HappyCons (st@(action)) (_))))))) (v1`HappyStk`v2`HappyStk`v3`HappyStk`stk')
+ = let r = fn v1 v2 v3 in
+ happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))
+
+happyReduce k i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happyReduce k nt fn j tk st sts stk
+ = case happyDrop (k -# (1# :: Int#)) sts of
+ sts1@((HappyCons (st1@(action)) (_))) ->
+ let r = fn stk in -- it doesn't hurt to always seq here...
+ happyDoSeq r (happyGoto nt j tk st1 sts1 r)
+
+happyMonadReduce k nt fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happyMonadReduce k nt fn j tk st sts stk =
+ happyThen1 (fn stk) (\r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk))
+ where sts1@((HappyCons (st1@(action)) (_))) = happyDrop k (HappyCons (st) (sts))
+ drop_stk = happyDropStk k stk
+
+happyDrop 0# l = l
+happyDrop n (HappyCons (_) (t)) = happyDrop (n -# (1# :: Int#)) t
+
+happyDropStk 0# l = l
+happyDropStk n (x `HappyStk` xs) = happyDropStk (n -# (1#::Int#)) xs
+
+-----------------------------------------------------------------------------
+-- Moving to a new state after a reduction
+
+
+happyGoto nt j tk st =
+ {- nothing -}
+ happyDoAction j tk new_state
+ where off = indexShortOffAddr happyGotoOffsets st
+ off_i = (off +# nt)
+ new_state = indexShortOffAddr happyTable off_i
+
+
+
+
+-----------------------------------------------------------------------------
+-- Error recovery (0# is the error token)
+
+-- parse error if we are in recovery and we fail again
+happyFail 0# tk old_st _ stk =
+-- trace "failing" $
+ happyError_ tk
+
+{- We don't need state discarding for our restricted implementation of
+ "error". In fact, it can cause some bogus parses, so I've disabled it
+ for now --SDM
+
+-- discard a state
+happyFail 0# tk old_st (HappyCons ((action)) (sts))
+ (saved_tok `HappyStk` _ `HappyStk` stk) =
+-- trace ("discarding state, depth " ++ show (length stk)) $
+ happyDoAction 0# tk action sts ((saved_tok`HappyStk`stk))
+-}
+
+-- Enter error recovery: generate an error token,
+-- save the old token and carry on.
+happyFail i tk (action) sts stk =
+-- trace "entering error recovery" $
+ happyDoAction 0# tk action sts ( (unsafeCoerce# (I# (i))) `HappyStk` stk)
+
+-- Internal happy errors:
+
+notHappyAtAll = error "Internal Happy error\n"
+
+-----------------------------------------------------------------------------
+-- Hack to get the typechecker to accept our action functions
+
+
+happyTcHack :: Int# -> a -> a
+happyTcHack x y = y
+{-# INLINE happyTcHack #-}
+
+
+-----------------------------------------------------------------------------
+-- Seq-ing. If the --strict flag is given, then Happy emits
+-- happySeq = happyDoSeq
+-- otherwise it emits
+-- happySeq = happyDontSeq
+
+happyDoSeq, happyDontSeq :: a -> b -> b
+happyDoSeq a b = a `seq` b
+happyDontSeq a b = b
+
+-----------------------------------------------------------------------------
+-- Don't inline any functions from the template. GHC has a nasty habit
+-- of deciding to inline happyGoto everywhere, which increases the size of
+-- the generated parser quite a bit.
+
+
+{-# NOINLINE happyDoAction #-}
+{-# NOINLINE happyTable #-}
+{-# NOINLINE happyCheck #-}
+{-# NOINLINE happyActOffsets #-}
+{-# NOINLINE happyGotoOffsets #-}
+{-# NOINLINE happyDefActions #-}
+
+{-# NOINLINE happyShift #-}
+{-# NOINLINE happySpecReduce_0 #-}
+{-# NOINLINE happySpecReduce_1 #-}
+{-# NOINLINE happySpecReduce_2 #-}
+{-# NOINLINE happySpecReduce_3 #-}
+{-# NOINLINE happyReduce #-}
+{-# NOINLINE happyMonadReduce #-}
+{-# NOINLINE happyGoto #-}
+{-# NOINLINE happyFail #-}
+
+-- end of Happy Template.
diff --git a/src-2.9/Transfer/Core/Par.y b/src-2.9/Transfer/Core/Par.y
new file mode 100644
index 000000000..ceeaa313f
--- /dev/null
+++ b/src-2.9/Transfer/Core/Par.y
@@ -0,0 +1,203 @@
+-- This Happy file was machine-generated by the BNF converter
+{
+{-# OPTIONS -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
+module Transfer.Core.Par where
+import Transfer.Core.Abs
+import Transfer.Core.Lex
+import Transfer.ErrM
+}
+
+%name pModule Module
+%name pExp Exp
+
+-- no lexer declaration
+%monad { Err } { thenM } { returnM }
+%tokentype { Token }
+
+%token
+ ';' { PT _ (TS ";") }
+ ':' { PT _ (TS ":") }
+ '{' { PT _ (TS "{") }
+ '}' { PT _ (TS "}") }
+ '=' { PT _ (TS "=") }
+ '(' { PT _ (TS "(") }
+ ')' { PT _ (TS ")") }
+ '_' { PT _ (TS "_") }
+ '|' { PT _ (TS "|") }
+ '->' { PT _ (TS "->") }
+ '\\' { PT _ (TS "\\") }
+ '.' { PT _ (TS ".") }
+ 'Type' { PT _ (TS "Type") }
+ 'case' { PT _ (TS "case") }
+ 'data' { PT _ (TS "data") }
+ 'in' { PT _ (TS "in") }
+ 'let' { PT _ (TS "let") }
+ 'of' { PT _ (TS "of") }
+ 'rec' { PT _ (TS "rec") }
+ 'sig' { PT _ (TS "sig") }
+ 'where' { PT _ (TS "where") }
+
+L_quoted { PT _ (TL $$) }
+L_integ { PT _ (TI $$) }
+L_doubl { PT _ (TD $$) }
+L_TMeta { PT _ (T_TMeta $$) }
+L_CIdent { PT _ (T_CIdent $$) }
+L_err { _ }
+
+
+%%
+
+String :: { String } : L_quoted { $1 }
+Integer :: { Integer } : L_integ { (read $1) :: Integer }
+Double :: { Double } : L_doubl { (read $1) :: Double }
+TMeta :: { TMeta} : L_TMeta { TMeta ($1)}
+CIdent :: { CIdent} : L_CIdent { CIdent ($1)}
+
+Module :: { Module }
+Module : ListDecl { Module $1 }
+
+
+ListDecl :: { [Decl] }
+ListDecl : {- empty -} { [] }
+ | Decl { (:[]) $1 }
+ | Decl ';' ListDecl { (:) $1 $3 }
+
+
+Decl :: { Decl }
+Decl : 'data' CIdent ':' Exp 'where' '{' ListConsDecl '}' { DataDecl $2 $4 $7 }
+ | CIdent ':' Exp { TypeDecl $1 $3 }
+ | CIdent '=' Exp { ValueDecl $1 $3 }
+
+
+ConsDecl :: { ConsDecl }
+ConsDecl : CIdent ':' Exp { ConsDecl $1 $3 }
+
+
+ListConsDecl :: { [ConsDecl] }
+ListConsDecl : {- empty -} { [] }
+ | ConsDecl { (:[]) $1 }
+ | ConsDecl ';' ListConsDecl { (:) $1 $3 }
+
+
+ListPattern :: { [Pattern] }
+ListPattern : {- empty -} { [] }
+ | ListPattern Pattern { flip (:) $1 $2 }
+
+
+Pattern :: { Pattern }
+Pattern : '(' CIdent ListPattern ')' { PCons $2 (reverse $3) }
+ | PatternVariable { PVar $1 }
+ | 'rec' '{' ListFieldPattern '}' { PRec $3 }
+ | String { PStr $1 }
+ | Integer { PInt $1 }
+
+
+FieldPattern :: { FieldPattern }
+FieldPattern : CIdent '=' Pattern { FieldPattern $1 $3 }
+
+
+ListFieldPattern :: { [FieldPattern] }
+ListFieldPattern : {- empty -} { [] }
+ | FieldPattern { (:[]) $1 }
+ | FieldPattern ';' ListFieldPattern { (:) $1 $3 }
+
+
+PatternVariable :: { PatternVariable }
+PatternVariable : CIdent { PVVar $1 }
+ | '_' { PVWild }
+
+
+Exp :: { Exp }
+Exp : 'let' '{' ListLetDef '}' 'in' Exp { ELet $3 $6 }
+ | 'case' Exp 'of' '{' ListCase '}' { ECase $2 $5 }
+ | Exp1 { $1 }
+
+
+LetDef :: { LetDef }
+LetDef : CIdent '=' Exp { LetDef $1 $3 }
+
+
+ListLetDef :: { [LetDef] }
+ListLetDef : {- empty -} { [] }
+ | LetDef { (:[]) $1 }
+ | LetDef ';' ListLetDef { (:) $1 $3 }
+
+
+Case :: { Case }
+Case : Pattern '|' Exp '->' Exp { Case $1 $3 $5 }
+
+
+ListCase :: { [Case] }
+ListCase : {- empty -} { [] }
+ | Case { (:[]) $1 }
+ | Case ';' ListCase { (:) $1 $3 }
+
+
+Exp1 :: { Exp }
+Exp1 : '\\' PatternVariable '->' Exp { EAbs $2 $4 }
+ | '(' PatternVariable ':' Exp ')' '->' Exp { EPi $2 $4 $7 }
+ | Exp2 { $1 }
+
+
+Exp3 :: { Exp }
+Exp3 : Exp3 Exp4 { EApp $1 $2 }
+ | Exp4 { $1 }
+
+
+Exp4 :: { Exp }
+Exp4 : Exp4 '.' CIdent { EProj $1 $3 }
+ | Exp5 { $1 }
+
+
+Exp5 :: { Exp }
+Exp5 : 'sig' '{' ListFieldType '}' { ERecType $3 }
+ | 'rec' '{' ListFieldValue '}' { ERec $3 }
+ | CIdent { EVar $1 }
+ | 'Type' { EType }
+ | String { EStr $1 }
+ | Integer { EInteger $1 }
+ | Double { EDouble $1 }
+ | TMeta { EMeta $1 }
+ | '(' Exp ')' { $2 }
+
+
+FieldType :: { FieldType }
+FieldType : CIdent ':' Exp { FieldType $1 $3 }
+
+
+ListFieldType :: { [FieldType] }
+ListFieldType : {- empty -} { [] }
+ | FieldType { (:[]) $1 }
+ | FieldType ';' ListFieldType { (:) $1 $3 }
+
+
+FieldValue :: { FieldValue }
+FieldValue : CIdent '=' Exp { FieldValue $1 $3 }
+
+
+ListFieldValue :: { [FieldValue] }
+ListFieldValue : {- empty -} { [] }
+ | FieldValue { (:[]) $1 }
+ | FieldValue ';' ListFieldValue { (:) $1 $3 }
+
+
+Exp2 :: { Exp }
+Exp2 : Exp3 { $1 }
+
+
+
+{
+
+returnM :: a -> Err a
+returnM = return
+
+thenM :: Err a -> (a -> Err b) -> Err b
+thenM = (>>=)
+
+happyError :: [Token] -> Err a
+happyError ts =
+ Bad $ "syntax error at " ++ tokenPos ts ++ if null ts then [] else (" before " ++ unwords (map prToken (take 4 ts)))
+
+myLexer = tokens
+}
+
diff --git a/src-2.9/Transfer/Core/Print.hs b/src-2.9/Transfer/Core/Print.hs
new file mode 100644
index 000000000..50929716a
--- /dev/null
+++ b/src-2.9/Transfer/Core/Print.hs
@@ -0,0 +1,155 @@
+{-# OPTIONS_GHC -fglasgow-exts #-}
+module Transfer.Core.Print where
+
+-- pretty-printer generated by the BNF converter
+
+import Transfer.Core.Abs
+import Data.Char
+import Data.List (intersperse)
+
+-- the top-level printing method
+printTree :: Print a => a -> String
+printTree = render . prt 0
+
+type Doc = [ShowS] -> [ShowS]
+
+doc :: ShowS -> Doc
+doc = (:)
+
+render :: Doc -> String
+render d = rend 0 (map ($ "") $ d []) "" where
+ rend i ss = case ss of
+ "[" :ts -> showChar '[' . rend i ts
+ "(" :ts -> showChar '(' . rend i ts
+ "{" :ts -> showChar '{' . new (i+1) . rend (i+1) ts
+ "}" : ";":ts -> new (i-1) . space "}" . showChar ';' . new (i-1) . rend (i-1) ts
+ "}" :ts -> new (i-1) . showChar '}' . new (i-1) . rend (i-1) ts
+ ";" :ts -> showChar ';' . new i . rend i ts
+ t : "," :ts -> showString t . space "," . rend i ts
+ t : ")" :ts -> showString t . showChar ')' . rend i ts
+ t : "]" :ts -> showString t . showChar ']' . rend i ts
+ t :ts -> space t . rend i ts
+ _ -> id
+ new i = showChar '\n' . replicateS (2*i) (showChar ' ') . dropWhile isSpace
+ space t = showString t . (\s -> if null s then "" else (' ':s))
+
+parenth :: Doc -> Doc
+parenth ss = doc (showChar '(') . ss . doc (showChar ')')
+
+concatS :: [ShowS] -> ShowS
+concatS = foldr (.) id
+
+concatD :: [Doc] -> Doc
+concatD = foldr (.) id
+
+unwordsD :: [Doc] -> Doc
+unwordsD = concatD . intersperse (doc (showChar ' '))
+
+replicateS :: Int -> ShowS -> ShowS
+replicateS n f = concatS (replicate n f)
+
+-- the printer class does the job
+class Print a where
+ prt :: Int -> a -> Doc
+
+instance Print Char where
+ prt _ s = doc (showChar '\'' . mkEsc '\'' s . showChar '\'')
+
+instance Print String where
+ prt _ s = doc (showChar '"' . concatS (map (mkEsc '"') s) . showChar '"')
+
+mkEsc :: Char -> Char -> ShowS
+mkEsc q s = case s of
+ _ | s == q -> showChar '\\' . showChar s
+ '\\'-> showString "\\\\"
+ '\n' -> showString "\\n"
+ '\t' -> showString "\\t"
+ _ -> showChar s
+
+prPrec :: Int -> Int -> Doc -> Doc
+prPrec i j = if j prPrec _i 0 (concatD [prt 0 decls])
+ DataDecl cident exp consdecls -> prPrec _i 0 (concatD [doc (showString "data") , prt 0 cident , doc (showString ":") , prt 0 exp , doc (showString "where") , doc (showString "{") , prt 0 consdecls , doc (showString "}")])
+ TypeDecl cident exp -> prPrec _i 0 (concatD [prt 0 cident , doc (showString ":") , prt 0 exp])
+ ValueDecl cident exp -> prPrec _i 0 (concatD [prt 0 cident , doc (showString "=") , prt 0 exp])
+ ConsDecl cident exp -> prPrec _i 0 (concatD [prt 0 cident , doc (showString ":") , prt 0 exp])
+ PCons cident patterns -> prPrec _i 0 (concatD [doc (showString "(") , prt 0 cident , prt 0 patterns , doc (showString ")")])
+ PVar patternvariable -> prPrec _i 0 (concatD [prt 0 patternvariable])
+ PRec fieldpatterns -> prPrec _i 0 (concatD [doc (showString "rec") , doc (showString "{") , prt 0 fieldpatterns , doc (showString "}")])
+ PStr str -> prPrec _i 0 (concatD [prt 0 str])
+ PInt n -> prPrec _i 0 (concatD [prt 0 n])
+ FieldPattern cident pattern -> prPrec _i 0 (concatD [prt 0 cident , doc (showString "=") , prt 0 pattern])
+ PVVar cident -> prPrec _i 0 (concatD [prt 0 cident])
+ PVWild -> prPrec _i 0 (concatD [doc (showString "_")])
+ ELet letdefs exp -> prPrec _i 0 (concatD [doc (showString "let") , doc (showString "{") , prt 0 letdefs , doc (showString "}") , doc (showString "in") , prt 0 exp])
+ ECase exp cases -> prPrec _i 0 (concatD [doc (showString "case") , prt 0 exp , doc (showString "of") , doc (showString "{") , prt 0 cases , doc (showString "}")])
+ EAbs patternvariable exp -> prPrec _i 1 (concatD [doc (showString "\\") , prt 0 patternvariable , doc (showString "->") , prt 0 exp])
+ EPi patternvariable exp0 exp1 -> prPrec _i 1 (concatD [doc (showString "(") , prt 0 patternvariable , doc (showString ":") , prt 0 exp0 , doc (showString ")") , doc (showString "->") , prt 0 exp1])
+ EApp exp0 exp1 -> prPrec _i 3 (concatD [prt 3 exp0 , prt 4 exp1])
+ EProj exp cident -> prPrec _i 4 (concatD [prt 4 exp , doc (showString ".") , prt 0 cident])
+ ERecType fieldtypes -> prPrec _i 5 (concatD [doc (showString "sig") , doc (showString "{") , prt 0 fieldtypes , doc (showString "}")])
+ ERec fieldvalues -> prPrec _i 5 (concatD [doc (showString "rec") , doc (showString "{") , prt 0 fieldvalues , doc (showString "}")])
+ EVar cident -> prPrec _i 5 (concatD [prt 0 cident])
+ EType -> prPrec _i 5 (concatD [doc (showString "Type")])
+ EStr str -> prPrec _i 5 (concatD [prt 0 str])
+ EInteger n -> prPrec _i 5 (concatD [prt 0 n])
+ EDouble d -> prPrec _i 5 (concatD [prt 0 d])
+ EMeta tmeta -> prPrec _i 5 (concatD [prt 0 tmeta])
+ LetDef cident exp -> prPrec _i 0 (concatD [prt 0 cident , doc (showString "=") , prt 0 exp])
+ Case pattern exp0 exp1 -> prPrec _i 0 (concatD [prt 0 pattern , doc (showString "|") , prt 0 exp0 , doc (showString "->") , prt 0 exp1])
+ FieldType cident exp -> prPrec _i 0 (concatD [prt 0 cident , doc (showString ":") , prt 0 exp])
+ FieldValue cident exp -> prPrec _i 0 (concatD [prt 0 cident , doc (showString "=") , prt 0 exp])
+ TMeta str -> prPrec _i 0 (doc (showString str))
+ CIdent str -> prPrec _i 0 (doc (showString str))
+
+instance Print [Decl] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [ConsDecl] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [Pattern] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ x:xs -> (concatD [prt 0 x , prt 0 xs])
+instance Print [FieldPattern] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [LetDef] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [Case] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [FieldType] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [FieldValue] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
diff --git a/src-2.9/Transfer/Core/Skel.hs b/src-2.9/Transfer/Core/Skel.hs
new file mode 100644
index 000000000..005ae92b1
--- /dev/null
+++ b/src-2.9/Transfer/Core/Skel.hs
@@ -0,0 +1,119 @@
+module Transfer.Core.Skel where
+
+-- Haskell module generated by the BNF converter
+
+import Transfer.Core.Abs
+import Transfer.ErrM
+type Result = Err String
+
+failure :: Show a => a -> Result
+failure x = Bad $ "Undefined case: " ++ show x
+
+transTree :: Tree c -> Result
+transTree t = case t of
+ Module decls -> failure t
+ DataDecl cident exp consdecls -> failure t
+ TypeDecl cident exp -> failure t
+ ValueDecl cident exp -> failure t
+ ConsDecl cident exp -> failure t
+ PCons cident patterns -> failure t
+ PVar patternvariable -> failure t
+ PRec fieldpatterns -> failure t
+ PStr str -> failure t
+ PInt n -> failure t
+ FieldPattern cident pattern -> failure t
+ PVVar cident -> failure t
+ PVWild -> failure t
+ ELet letdefs exp -> failure t
+ ECase exp cases -> failure t
+ EAbs patternvariable exp -> failure t
+ EPi patternvariable exp0 exp1 -> failure t
+ EApp exp0 exp1 -> failure t
+ EProj exp cident -> failure t
+ ERecType fieldtypes -> failure t
+ ERec fieldvalues -> failure t
+ EVar cident -> failure t
+ EType -> failure t
+ EStr str -> failure t
+ EInteger n -> failure t
+ EDouble d -> failure t
+ EMeta tmeta -> failure t
+ LetDef cident exp -> failure t
+ Case pattern exp0 exp1 -> failure t
+ FieldType cident exp -> failure t
+ FieldValue cident exp -> failure t
+ TMeta str -> failure t
+ CIdent str -> failure t
+
+transModule :: Module -> Result
+transModule t = case t of
+ Module decls -> failure t
+
+transDecl :: Decl -> Result
+transDecl t = case t of
+ DataDecl cident exp consdecls -> failure t
+ TypeDecl cident exp -> failure t
+ ValueDecl cident exp -> failure t
+
+transConsDecl :: ConsDecl -> Result
+transConsDecl t = case t of
+ ConsDecl cident exp -> failure t
+
+transPattern :: Pattern -> Result
+transPattern t = case t of
+ PCons cident patterns -> failure t
+ PVar patternvariable -> failure t
+ PRec fieldpatterns -> failure t
+ PStr str -> failure t
+ PInt n -> failure t
+
+transFieldPattern :: FieldPattern -> Result
+transFieldPattern t = case t of
+ FieldPattern cident pattern -> failure t
+
+transPatternVariable :: PatternVariable -> Result
+transPatternVariable t = case t of
+ PVVar cident -> failure t
+ PVWild -> failure t
+
+transExp :: Exp -> Result
+transExp t = case t of
+ ELet letdefs exp -> failure t
+ ECase exp cases -> failure t
+ EAbs patternvariable exp -> failure t
+ EPi patternvariable exp0 exp1 -> failure t
+ EApp exp0 exp1 -> failure t
+ EProj exp cident -> failure t
+ ERecType fieldtypes -> failure t
+ ERec fieldvalues -> failure t
+ EVar cident -> failure t
+ EType -> failure t
+ EStr str -> failure t
+ EInteger n -> failure t
+ EDouble d -> failure t
+ EMeta tmeta -> failure t
+
+transLetDef :: LetDef -> Result
+transLetDef t = case t of
+ LetDef cident exp -> failure t
+
+transCase :: Case -> Result
+transCase t = case t of
+ Case pattern exp0 exp1 -> failure t
+
+transFieldType :: FieldType -> Result
+transFieldType t = case t of
+ FieldType cident exp -> failure t
+
+transFieldValue :: FieldValue -> Result
+transFieldValue t = case t of
+ FieldValue cident exp -> failure t
+
+transTMeta :: TMeta -> Result
+transTMeta t = case t of
+ TMeta str -> failure t
+
+transCIdent :: CIdent -> Result
+transCIdent t = case t of
+ CIdent str -> failure t
+
diff --git a/src-2.9/Transfer/Core/Test.hs b/src-2.9/Transfer/Core/Test.hs
new file mode 100644
index 000000000..570beed51
--- /dev/null
+++ b/src-2.9/Transfer/Core/Test.hs
@@ -0,0 +1,58 @@
+-- automatically generated by BNF Converter
+module Main where
+
+
+import IO ( stdin, hGetContents )
+import System ( getArgs, getProgName )
+
+import Transfer.Core.Lex
+import Transfer.Core.Par
+import Transfer.Core.Skel
+import Transfer.Core.Print
+import Transfer.Core.Abs
+
+
+
+
+import Transfer.ErrM
+
+type ParseFun a = [Token] -> Err a
+
+myLLexer = myLexer
+
+type Verbosity = Int
+
+putStrV :: Verbosity -> String -> IO ()
+putStrV v s = if v > 1 then putStrLn s else return ()
+
+runFile :: (Print a, Show a) => Verbosity -> ParseFun a -> FilePath -> IO ()
+runFile v p f = putStrLn f >> readFile f >>= run v p
+
+run :: (Print a, Show a) => Verbosity -> ParseFun a -> String -> IO ()
+run v p s = let ts = myLLexer s in case p ts of
+ Bad s -> do putStrLn "\nParse Failed...\n"
+ putStrV v "Tokens:"
+ putStrV v $ show ts
+ putStrLn s
+ Ok tree -> do putStrLn "\nParse Successful!"
+ showTree v tree
+
+
+
+showTree :: (Show a, Print a) => Int -> a -> IO ()
+showTree v tree
+ = do
+ putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
+ putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
+
+main :: IO ()
+main = do args <- getArgs
+ case args of
+ [] -> hGetContents stdin >>= run 2 pModule
+ "-s":fs -> mapM_ (runFile 0 pModule) fs
+ fs -> mapM_ (runFile 2 pModule) fs
+
+
+
+
+
diff --git a/src-2.9/Transfer/ErrM.hs b/src-2.9/Transfer/ErrM.hs
new file mode 100644
index 000000000..1f3c566fd
--- /dev/null
+++ b/src-2.9/Transfer/ErrM.hs
@@ -0,0 +1,16 @@
+-- BNF Converter: Error Monad
+-- Copyright (C) 2004 Author: Aarne Ranta
+
+-- This file comes with NO WARRANTY and may be used FOR ANY PURPOSE.
+module Transfer.ErrM where
+
+-- the Error monad: like Maybe type with error msgs
+
+data Err a = Ok a | Bad String
+ deriving (Read, Show, Eq)
+
+instance Monad Err where
+ return = Ok
+ fail = Bad
+ Ok a >>= f = f a
+ Bad s >>= f = Bad s
diff --git a/src-2.9/Transfer/Interpreter.hs b/src-2.9/Transfer/Interpreter.hs
new file mode 100644
index 000000000..926b7bd3a
--- /dev/null
+++ b/src-2.9/Transfer/Interpreter.hs
@@ -0,0 +1,240 @@
+module Transfer.Interpreter where
+
+import Transfer.Core.Abs
+import Transfer.Core.Print
+
+import Control.Monad
+import Data.List
+import Data.Maybe
+
+import Debug.Trace
+
+data Value = VStr String
+ | VInt Integer
+ | VDbl Double
+ | VType
+ | VRec [(CIdent,Value)]
+ | VClos Env Exp
+ | VCons CIdent [Value]
+ | VPrim (Value -> Value)
+ | VMeta Integer
+ deriving (Show)
+
+instance Show (a -> b) where
+ show _ = "<>"
+
+--
+-- * Environment
+--
+
+newtype Env = Env [(CIdent,Value)]
+ deriving Show
+
+mkEnv :: [(CIdent,Value)] -> Env
+mkEnv = Env
+
+addToEnv :: [(CIdent,Value)] -> Env -> Env
+addToEnv bs (Env e) = Env (bs ++ e)
+
+lookupEnv :: Env -> CIdent -> Value
+lookupEnv (Env e) id =
+ case lookup id e of
+ Just x -> x
+ Nothing -> error $ "Variable " ++ printTree id ++ " not in environment."
+ ++ " Environment contains: " ++ show (map (printTree . fst) e)
+
+prEnv :: Env -> String
+prEnv (Env e) = unlines [ printTree id ++ ": " ++ printValue v | (id,v) <- e ]
+
+seqEnv :: Env -> Env
+seqEnv (Env e) = Env $! deepSeqList [ fst p `seq` p | p <- e ]
+
+-- | The built-in types and functions.
+builtin :: Env
+builtin =
+ mkEnv [(CIdent "Integer",VType),
+ (CIdent "Double",VType),
+ (CIdent "String",VType),
+ mkIntUn "neg" negate toInt,
+ mkIntBin "add" (+) toInt,
+ mkIntBin "sub" (-) toInt,
+ mkIntBin "mul" (*) toInt,
+ mkIntBin "div" div toInt,
+ mkIntBin "mod" mod toInt,
+ mkIntBin "eq" (==) toBool,
+ mkIntBin "cmp" compare toOrd,
+ mkIntUn "show" show toStr,
+ mkDblUn "neg" negate toDbl,
+ mkDblBin "add" (+) toDbl,
+ mkDblBin "sub" (-) toDbl,
+ mkDblBin "mul" (*) toDbl,
+ mkDblBin "div" (/) toDbl,
+ mkDblBin "mod" (\_ _ -> 0.0) toDbl,
+ mkDblBin "eq" (==) toBool,
+ mkDblBin "cmp" compare toOrd,
+ mkDblUn "show" show toStr,
+ mkStrBin "add" (++) toStr,
+ mkStrBin "eq" (==) toBool,
+ mkStrBin "cmp" compare toOrd,
+ mkStrUn "show" show toStr
+ ]
+ where
+ toInt i = VInt i
+ toDbl i = VDbl i
+ toBool b = VCons (CIdent (show b)) []
+ toOrd o = VCons (CIdent (show o)) []
+ toStr s = VStr s
+ mkUn t a x f g = let c = CIdent ("prim_" ++ x ++ "_" ++ t)
+ in (c, VPrim (\n -> a f g n))
+ mkBin t a x f g = let c = CIdent ("prim_" ++ x ++ "_" ++ t)
+ in (c, VPrim (\n -> VPrim (\m -> a f g n m )))
+ mkIntUn = mkUn "Integer" $ \ f g x ->
+ case x of
+ VInt n -> g (f n)
+ _ -> error $ printValue x ++ " is not an integer"
+ mkIntBin = mkBin "Integer" $ \ f g x y ->
+ case (x,y) of
+ (VInt n,VInt m) -> g (f n m)
+ _ -> error $ printValue x ++ " and " ++ printValue y
+ ++ " are not both integers"
+ mkDblUn = mkUn "Double" $ \ f g x ->
+ case x of
+ VDbl n -> g (f n)
+ _ -> error $ printValue x ++ " is not a double"
+ mkDblBin = mkBin "Double" $ \ f g x y ->
+ case (x,y) of
+ (VDbl n,VDbl m) -> g (f n m)
+ _ -> error $ printValue x ++ " and " ++ printValue y
+ ++ " are not both doubles"
+ mkStrUn = mkUn "String" $ \ f g x ->
+ case x of
+ VStr n -> g (f n)
+ _ -> error $ printValue x ++ " is not a string"
+ mkStrBin = mkBin "String" $ \ f g x y ->
+ case (x,y) of
+ (VStr n,VStr m) -> g (f n m)
+ _ -> error $ printValue x ++ " and " ++ printValue y
+ ++ " are not both strings"
+
+addModuleEnv :: Env -> Module -> Env
+addModuleEnv env (Module ds) =
+ let bs = [ (c,VCons c []) | DataDecl _ _ cs <- ds, ConsDecl c _ <- cs ]
+ ++ [ (t,VCons t []) | DataDecl t _ _ <- ds ]
+ ++ [ (x,eval env' e) | ValueDecl x e <- ds]
+ env' = addToEnv bs env
+ in env'
+
+--
+-- * Evaluation.
+--
+
+eval :: Env -> Exp -> Value
+eval env x = case x of
+ ELet defs exp2 ->
+ let env' = [ (id, v) | LetDef id e <- defs,
+ let v = eval env' e]
+ `addToEnv` env
+ in eval (seqEnv env') exp2
+ ECase exp cases ->
+ let v = eval env exp
+ r = case firstMatch env v cases of
+ Nothing -> error $ "No pattern matched " ++ printValue v
+ Just (e,env') -> eval env' e
+ in v `seq` r
+ EAbs _ _ -> VClos env x
+ EPi _ _ _ -> VClos env x
+ EApp exp1 exp2 ->
+ let v1 = eval env exp1
+ v2 = eval env exp2
+ in case v1 of
+ VClos env' (EAbs id e) -> eval (bind id v2 `addToEnv` env') e
+ VPrim f -> f $! v2
+ VCons c vs -> (VCons $! c) $! ((++) $! vs) $! [v2]
+ _ -> error $ "Bad application (" ++ printValue v1
+ ++ ") (" ++ printValue v2 ++ ")"
+ EProj exp id -> let v = eval env exp
+ in case v of
+ VRec fs -> recLookup id fs
+ _ -> error $ printValue v ++ " is not a record, "
+ ++ "cannot get field " ++ printTree id
+
+ ERecType fts -> VRec $! deepSeqList $! [v `seq` (f,v) | FieldType f e <- fts,
+ let v = eval env e]
+ ERec fvs -> VRec $! deepSeqList $! [v `seq` (f,v) | FieldValue f e <- fvs,
+ let v = eval env e]
+ EVar id -> lookupEnv env id
+ EType -> VType
+ EStr str -> VStr str
+ EInteger n -> VInt n
+ EDouble n -> VDbl n
+ EMeta (TMeta t) -> VMeta (read $ drop 1 t)
+
+firstMatch :: Env -> Value -> [Case] -> Maybe (Exp,Env)
+firstMatch _ _ [] = Nothing
+firstMatch env v (Case p g e:cs) =
+ case match p v of
+ Nothing -> firstMatch env v cs
+ Just bs -> let env' = bs `addToEnv` env
+ in case eval env' g of
+ VCons (CIdent "True") [] -> Just (e,env')
+ VCons (CIdent "False") [] -> firstMatch env v cs
+ x -> error $ "Error in guard: " ++ printValue x
+ ++ " is not a Bool"
+
+bind :: PatternVariable -> Value -> [(CIdent,Value)]
+bind (PVVar x) v = [(x,v)]
+bind PVWild _ = []
+
+match :: Pattern -> Value -> Maybe [(CIdent,Value)]
+match (PCons c' ps) (VCons c vs)
+ | c == c' = if length vs == length ps
+ then concatM $ zipWith match ps vs
+ else error $ "Wrong number of arguments to " ++ printTree c
+match (PVar x) v = Just (bind x v)
+match (PRec fps) (VRec fs) = concatM [ match p (recLookup f fs) | FieldPattern f p <- fps ]
+match (PInt i) (VInt i') | i == i' = Just []
+match (PStr s) (VStr s') | s == s' = Just []
+match (PInt i) (VInt i') | i == i' = Just []
+match _ _ = Nothing
+
+
+recLookup :: CIdent -> [(CIdent,Value)] -> Value
+recLookup l fs =
+ case lookup l fs of
+ Just x -> x
+ Nothing -> error $ printValue (VRec fs) ++ " has no field " ++ printTree l
+
+--
+-- * Utilities
+--
+
+concatM :: Monad m => [m [a]] -> m [a]
+concatM = liftM concat . sequence
+
+-- | Force a list and its values.
+deepSeqList :: [a] -> [a]
+deepSeqList = foldr (\x xs -> x `seq` xs `seq` (x:xs)) []
+
+--
+-- * Convert values to expressions
+--
+
+valueToExp :: Value -> Exp
+valueToExp v =
+ case v of
+ VStr s -> EStr s
+ VInt i -> EInteger i
+ VDbl i -> EDouble i
+ VType -> EType
+ VRec fs -> ERec [ FieldValue f (valueToExp v) | (f,v) <- fs]
+ VClos env e -> e
+ VCons c vs -> foldl EApp (EVar c) (map valueToExp vs)
+ VPrim _ -> EVar (CIdent "<>") -- FIXME: what to return here?
+ VMeta n -> EMeta $ TMeta $ "?" ++ show n
+
+--
+-- * Pretty printing of values
+--
+
+printValue :: Value -> String
+printValue v = printTree (valueToExp v)
diff --git a/src-2.9/Transfer/InterpreterAPI.hs b/src-2.9/Transfer/InterpreterAPI.hs
new file mode 100644
index 000000000..2fe04e8f3
--- /dev/null
+++ b/src-2.9/Transfer/InterpreterAPI.hs
@@ -0,0 +1,39 @@
+module Transfer.InterpreterAPI (Env, builtin,
+ load, loadFile,
+ evaluateString, evaluateExp
+ ) where
+
+import Transfer.Core.Abs
+import Transfer.Core.Lex
+import Transfer.Core.Par
+import Transfer.Core.Print
+import Transfer.Interpreter
+import Transfer.ErrM
+
+-- | Read a transfer module in core format from a string.
+load :: Monad m =>
+ String -- ^ Input source name, for error messages.
+ -> String -- ^ Module contents.
+ -> m Env
+load n s = case pModule (myLexer s) of
+ Bad e -> fail $ "Parse error in " ++ n ++ ": " ++ e
+ Ok m -> return $ addModuleEnv builtin m
+
+-- | Read a transfer module in core format from a file.
+-- Fails in the IO monad if there is a problem loading the file.
+loadFile :: FilePath -> IO Env
+loadFile f = readFile f >>= load f
+
+-- | Read a transfer expression from a string and evaluate it.
+-- Returns the result as a string.
+evaluateString :: Monad m => Env -> String -> m String
+evaluateString env s =
+ case pExp (myLexer s) of
+ Bad e -> fail $ "Parse error: " ++ e
+ Ok e -> do
+ let v = eval env e
+ return $ printValue v
+
+-- | Evaluate an expression in the given environment.
+evaluateExp :: Env -> Exp -> Exp
+evaluateExp env exp = valueToExp $ eval env exp
diff --git a/src-2.9/Transfer/PathUtil.hs b/src-2.9/Transfer/PathUtil.hs
new file mode 100644
index 000000000..b344563c6
--- /dev/null
+++ b/src-2.9/Transfer/PathUtil.hs
@@ -0,0 +1,110 @@
+{-# OPTIONS_GHC -cpp #-}
+
+-----------------------------------------------------------------------------
+-- File name and directory utilities. Stolen from
+-- ghc-6.4.1/ghc/compiler/main/DriverUtil.hs
+--
+-- (c) The University of Glasgow 2000
+--
+-----------------------------------------------------------------------------
+
+module Transfer.PathUtil (
+ Suffix, splitFilename, getFileSuffix,
+ splitFilename3, remove_suffix, split_longest_prefix,
+ replaceFilenameSuffix, directoryOf, filenameOf,
+ replaceFilenameDirectory, replaceFilename, remove_spaces, escapeSpaces,
+ ) where
+
+import Data.Char (isSpace)
+
+type Suffix = String
+
+splitFilename :: String -> (String,Suffix)
+splitFilename f = split_longest_prefix f (=='.')
+
+getFileSuffix :: String -> Suffix
+getFileSuffix f = drop_longest_prefix f (=='.')
+
+-- "foo/bar/xyzzy.ext" -> ("foo/bar", "xyzzy.ext")
+splitFilenameDir :: String -> (String,String)
+splitFilenameDir str
+ = let (dir, rest) = split_longest_prefix str isPathSeparator
+ real_dir | null dir = "."
+ | otherwise = dir
+ in (real_dir, rest)
+
+-- "foo/bar/xyzzy.ext" -> ("foo/bar", "xyzzy", ".ext")
+splitFilename3 :: String -> (String,String,Suffix)
+splitFilename3 str
+ = let (dir, rest) = split_longest_prefix str isPathSeparator
+ (name, ext) = splitFilename rest
+ real_dir | null dir = "."
+ | otherwise = dir
+ in (real_dir, name, ext)
+
+remove_suffix :: Char -> String -> Suffix
+remove_suffix c s
+ | null pre = s
+ | otherwise = reverse pre
+ where (suf,pre) = break (==c) (reverse s)
+
+drop_longest_prefix :: String -> (Char -> Bool) -> String
+drop_longest_prefix s pred = reverse suf
+ where (suf,_pre) = break pred (reverse s)
+
+take_longest_prefix :: String -> (Char -> Bool) -> String
+take_longest_prefix s pred = reverse pre
+ where (_suf,pre) = break pred (reverse s)
+
+-- split a string at the last character where 'pred' is True,
+-- returning a pair of strings. The first component holds the string
+-- up (but not including) the last character for which 'pred' returned
+-- True, the second whatever comes after (but also not including the
+-- last character).
+--
+-- If 'pred' returns False for all characters in the string, the original
+-- string is returned in the second component (and the first one is just
+-- empty).
+split_longest_prefix :: String -> (Char -> Bool) -> (String,String)
+split_longest_prefix s pred
+ = case pre of
+ [] -> ([], reverse suf)
+ (_:pre) -> (reverse pre, reverse suf)
+ where (suf,pre) = break pred (reverse s)
+
+replaceFilenameSuffix :: FilePath -> Suffix -> FilePath
+replaceFilenameSuffix s suf = remove_suffix '.' s ++ suf
+
+-- directoryOf strips the filename off the input string, returning
+-- the directory.
+directoryOf :: FilePath -> String
+directoryOf = fst . splitFilenameDir
+
+-- filenameOf strips the directory off the input string, returning
+-- the filename.
+filenameOf :: FilePath -> String
+filenameOf = snd . splitFilenameDir
+
+replaceFilenameDirectory :: FilePath -> String -> FilePath
+replaceFilenameDirectory s dir
+ = dir ++ '/':drop_longest_prefix s isPathSeparator
+
+replaceFilename :: FilePath -> String -> FilePath
+replaceFilename f n
+ = case directoryOf f of
+ "" -> n
+ d -> d ++ '/' : n
+
+remove_spaces :: String -> String
+remove_spaces = reverse . dropWhile isSpace . reverse . dropWhile isSpace
+
+escapeSpaces :: String -> String
+escapeSpaces = foldr (\c s -> if isSpace c then '\\':c:s else c:s) ""
+
+isPathSeparator :: Char -> Bool
+isPathSeparator ch =
+#ifdef mingw32_TARGET_OS
+ ch == '/' || ch == '\\'
+#else
+ ch == '/'
+#endif
diff --git a/src-2.9/Transfer/Syntax/Abs.hs b/src-2.9/Transfer/Syntax/Abs.hs
new file mode 100644
index 000000000..0ccf9ab12
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Abs.hs
@@ -0,0 +1,485 @@
+{-# OPTIONS_GHC -fglasgow-exts #-}
+module Transfer.Syntax.Abs (Tree(..), Module, Import, Decl, ConsDecl, Guard, Pattern, CommaPattern, FieldPattern, Exp, VarOrWild, LetDef, Case, Bind, FieldType, FieldValue, Ident, composOp, composOpM, composOpM_, composOpMPlus, composOpMonoid, composOpFold, compos, johnMajorEq) where
+
+import Control.Monad (ap,MonadPlus,msum,mplus,mzero)
+import Control.Monad.Identity
+import Data.Monoid
+
+-- Haskell module generated by the BNF converter
+
+data Module_
+type Module = Tree Module_
+data Import_
+type Import = Tree Import_
+data Decl_
+type Decl = Tree Decl_
+data ConsDecl_
+type ConsDecl = Tree ConsDecl_
+data Guard_
+type Guard = Tree Guard_
+data Pattern_
+type Pattern = Tree Pattern_
+data CommaPattern_
+type CommaPattern = Tree CommaPattern_
+data FieldPattern_
+type FieldPattern = Tree FieldPattern_
+data Exp_
+type Exp = Tree Exp_
+data VarOrWild_
+type VarOrWild = Tree VarOrWild_
+data LetDef_
+type LetDef = Tree LetDef_
+data Case_
+type Case = Tree Case_
+data Bind_
+type Bind = Tree Bind_
+data FieldType_
+type FieldType = Tree FieldType_
+data FieldValue_
+type FieldValue = Tree FieldValue_
+data Ident_
+type Ident = Tree Ident_
+
+data Tree :: * -> * where
+ Module :: [Import] -> [Decl] -> Tree Module_
+ Import :: Ident -> Tree Import_
+ DataDecl :: Ident -> Exp -> [ConsDecl] -> Tree Decl_
+ TypeDecl :: Ident -> Exp -> Tree Decl_
+ ValueDecl :: Ident -> [Pattern] -> Guard -> Exp -> Tree Decl_
+ DeriveDecl :: Ident -> Ident -> Tree Decl_
+ ConsDecl :: Ident -> Exp -> Tree ConsDecl_
+ GuardExp :: Exp -> Tree Guard_
+ GuardNo :: Tree Guard_
+ POr :: Pattern -> Pattern -> Tree Pattern_
+ PListCons :: Pattern -> Pattern -> Tree Pattern_
+ PConsTop :: Ident -> Pattern -> [Pattern] -> Tree Pattern_
+ PCons :: Ident -> [Pattern] -> Tree Pattern_
+ PRec :: [FieldPattern] -> Tree Pattern_
+ PEmptyList :: Tree Pattern_
+ PList :: [CommaPattern] -> Tree Pattern_
+ PTuple :: CommaPattern -> [CommaPattern] -> Tree Pattern_
+ PStr :: String -> Tree Pattern_
+ PInt :: Integer -> Tree Pattern_
+ PVar :: Ident -> Tree Pattern_
+ PWild :: Tree Pattern_
+ CommaPattern :: Pattern -> Tree CommaPattern_
+ FieldPattern :: Ident -> Pattern -> Tree FieldPattern_
+ EPi :: VarOrWild -> Exp -> Exp -> Tree Exp_
+ EPiNoVar :: Exp -> Exp -> Tree Exp_
+ EAbs :: VarOrWild -> Exp -> Tree Exp_
+ ELet :: [LetDef] -> Exp -> Tree Exp_
+ ECase :: Exp -> [Case] -> Tree Exp_
+ EIf :: Exp -> Exp -> Exp -> Tree Exp_
+ EDo :: [Bind] -> Exp -> Tree Exp_
+ EBind :: Exp -> Exp -> Tree Exp_
+ EBindC :: Exp -> Exp -> Tree Exp_
+ EOr :: Exp -> Exp -> Tree Exp_
+ EAnd :: Exp -> Exp -> Tree Exp_
+ EEq :: Exp -> Exp -> Tree Exp_
+ ENe :: Exp -> Exp -> Tree Exp_
+ ELt :: Exp -> Exp -> Tree Exp_
+ ELe :: Exp -> Exp -> Tree Exp_
+ EGt :: Exp -> Exp -> Tree Exp_
+ EGe :: Exp -> Exp -> Tree Exp_
+ EListCons :: Exp -> Exp -> Tree Exp_
+ EAdd :: Exp -> Exp -> Tree Exp_
+ ESub :: Exp -> Exp -> Tree Exp_
+ EMul :: Exp -> Exp -> Tree Exp_
+ EDiv :: Exp -> Exp -> Tree Exp_
+ EMod :: Exp -> Exp -> Tree Exp_
+ ENeg :: Exp -> Tree Exp_
+ EApp :: Exp -> Exp -> Tree Exp_
+ EProj :: Exp -> Ident -> Tree Exp_
+ ERecType :: [FieldType] -> Tree Exp_
+ ERec :: [FieldValue] -> Tree Exp_
+ EEmptyList :: Tree Exp_
+ EList :: [Exp] -> Tree Exp_
+ ETuple :: Exp -> [Exp] -> Tree Exp_
+ EVar :: Ident -> Tree Exp_
+ EType :: Tree Exp_
+ EStr :: String -> Tree Exp_
+ EInteger :: Integer -> Tree Exp_
+ EDouble :: Double -> Tree Exp_
+ EMeta :: Tree Exp_
+ VVar :: Ident -> Tree VarOrWild_
+ VWild :: Tree VarOrWild_
+ LetDef :: Ident -> Exp -> Tree LetDef_
+ Case :: Pattern -> Guard -> Exp -> Tree Case_
+ BindVar :: VarOrWild -> Exp -> Tree Bind_
+ BindNoVar :: Exp -> Tree Bind_
+ FieldType :: Ident -> Exp -> Tree FieldType_
+ FieldValue :: Ident -> Exp -> Tree FieldValue_
+ Ident :: String -> Tree Ident_
+
+composOp :: (forall a. Tree a -> Tree a) -> Tree c -> Tree c
+composOp f = runIdentity . composOpM (Identity . f)
+
+composOpM :: Monad m => (forall a. Tree a -> m (Tree a)) -> Tree c -> m (Tree c)
+composOpM = compos return ap
+
+composOpM_ :: Monad m => (forall a. Tree a -> m ()) -> Tree c -> m ()
+composOpM_ = composOpFold (return ()) (>>)
+
+composOpMPlus :: MonadPlus m => (forall a. Tree a -> m b) -> Tree c -> m b
+composOpMPlus = composOpFold mzero mplus
+
+composOpMonoid :: Monoid m => (forall a. Tree a -> m) -> Tree c -> m
+composOpMonoid = composOpFold mempty mappend
+
+newtype C b a = C { unC :: b }
+composOpFold :: b -> (b -> b -> b) -> (forall a. Tree a -> b) -> Tree c -> b
+composOpFold z c f = unC . compos (\_ -> C z) (\(C x) (C y) -> C (c x y)) (C . f)
+
+compos :: (forall a. a -> m a)
+ -> (forall a b. m (a -> b) -> m a -> m b)
+ -> (forall a. Tree a -> m (Tree a)) -> Tree c -> m (Tree c)
+compos r a f t = case t of
+ Module imports decls -> r Module `a` foldr (a . a (r (:)) . f) (r []) imports `a` foldr (a . a (r (:)) . f) (r []) decls
+ Import i -> r Import `a` f i
+ DataDecl i exp consdecls -> r DataDecl `a` f i `a` f exp `a` foldr (a . a (r (:)) . f) (r []) consdecls
+ TypeDecl i exp -> r TypeDecl `a` f i `a` f exp
+ ValueDecl i patterns guard exp -> r ValueDecl `a` f i `a` foldr (a . a (r (:)) . f) (r []) patterns `a` f guard `a` f exp
+ DeriveDecl i0 i1 -> r DeriveDecl `a` f i0 `a` f i1
+ ConsDecl i exp -> r ConsDecl `a` f i `a` f exp
+ GuardExp exp -> r GuardExp `a` f exp
+ POr pattern0 pattern1 -> r POr `a` f pattern0 `a` f pattern1
+ PListCons pattern0 pattern1 -> r PListCons `a` f pattern0 `a` f pattern1
+ PConsTop i pattern patterns -> r PConsTop `a` f i `a` f pattern `a` foldr (a . a (r (:)) . f) (r []) patterns
+ PCons i patterns -> r PCons `a` f i `a` foldr (a . a (r (:)) . f) (r []) patterns
+ PRec fieldpatterns -> r PRec `a` foldr (a . a (r (:)) . f) (r []) fieldpatterns
+ PList commapatterns -> r PList `a` foldr (a . a (r (:)) . f) (r []) commapatterns
+ PTuple commapattern commapatterns -> r PTuple `a` f commapattern `a` foldr (a . a (r (:)) . f) (r []) commapatterns
+ PVar i -> r PVar `a` f i
+ CommaPattern pattern -> r CommaPattern `a` f pattern
+ FieldPattern i pattern -> r FieldPattern `a` f i `a` f pattern
+ EPi varorwild exp0 exp1 -> r EPi `a` f varorwild `a` f exp0 `a` f exp1
+ EPiNoVar exp0 exp1 -> r EPiNoVar `a` f exp0 `a` f exp1
+ EAbs varorwild exp -> r EAbs `a` f varorwild `a` f exp
+ ELet letdefs exp -> r ELet `a` foldr (a . a (r (:)) . f) (r []) letdefs `a` f exp
+ ECase exp cases -> r ECase `a` f exp `a` foldr (a . a (r (:)) . f) (r []) cases
+ EIf exp0 exp1 exp2 -> r EIf `a` f exp0 `a` f exp1 `a` f exp2
+ EDo binds exp -> r EDo `a` foldr (a . a (r (:)) . f) (r []) binds `a` f exp
+ EBind exp0 exp1 -> r EBind `a` f exp0 `a` f exp1
+ EBindC exp0 exp1 -> r EBindC `a` f exp0 `a` f exp1
+ EOr exp0 exp1 -> r EOr `a` f exp0 `a` f exp1
+ EAnd exp0 exp1 -> r EAnd `a` f exp0 `a` f exp1
+ EEq exp0 exp1 -> r EEq `a` f exp0 `a` f exp1
+ ENe exp0 exp1 -> r ENe `a` f exp0 `a` f exp1
+ ELt exp0 exp1 -> r ELt `a` f exp0 `a` f exp1
+ ELe exp0 exp1 -> r ELe `a` f exp0 `a` f exp1
+ EGt exp0 exp1 -> r EGt `a` f exp0 `a` f exp1
+ EGe exp0 exp1 -> r EGe `a` f exp0 `a` f exp1
+ EListCons exp0 exp1 -> r EListCons `a` f exp0 `a` f exp1
+ EAdd exp0 exp1 -> r EAdd `a` f exp0 `a` f exp1
+ ESub exp0 exp1 -> r ESub `a` f exp0 `a` f exp1
+ EMul exp0 exp1 -> r EMul `a` f exp0 `a` f exp1
+ EDiv exp0 exp1 -> r EDiv `a` f exp0 `a` f exp1
+ EMod exp0 exp1 -> r EMod `a` f exp0 `a` f exp1
+ ENeg exp -> r ENeg `a` f exp
+ EApp exp0 exp1 -> r EApp `a` f exp0 `a` f exp1
+ EProj exp i -> r EProj `a` f exp `a` f i
+ ERecType fieldtypes -> r ERecType `a` foldr (a . a (r (:)) . f) (r []) fieldtypes
+ ERec fieldvalues -> r ERec `a` foldr (a . a (r (:)) . f) (r []) fieldvalues
+ EList exps -> r EList `a` foldr (a . a (r (:)) . f) (r []) exps
+ ETuple exp exps -> r ETuple `a` f exp `a` foldr (a . a (r (:)) . f) (r []) exps
+ EVar i -> r EVar `a` f i
+ VVar i -> r VVar `a` f i
+ LetDef i exp -> r LetDef `a` f i `a` f exp
+ Case pattern guard exp -> r Case `a` f pattern `a` f guard `a` f exp
+ BindVar varorwild exp -> r BindVar `a` f varorwild `a` f exp
+ BindNoVar exp -> r BindNoVar `a` f exp
+ FieldType i exp -> r FieldType `a` f i `a` f exp
+ FieldValue i exp -> r FieldValue `a` f i `a` f exp
+ _ -> r t
+
+instance Show (Tree c) where
+ showsPrec n t = case t of
+ Module imports decls -> opar n . showString "Module" . showChar ' ' . showsPrec 1 imports . showChar ' ' . showsPrec 1 decls . cpar n
+ Import i -> opar n . showString "Import" . showChar ' ' . showsPrec 1 i . cpar n
+ DataDecl i exp consdecls -> opar n . showString "DataDecl" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 exp . showChar ' ' . showsPrec 1 consdecls . cpar n
+ TypeDecl i exp -> opar n . showString "TypeDecl" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 exp . cpar n
+ ValueDecl i patterns guard exp -> opar n . showString "ValueDecl" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 patterns . showChar ' ' . showsPrec 1 guard . showChar ' ' . showsPrec 1 exp . cpar n
+ DeriveDecl i0 i1 -> opar n . showString "DeriveDecl" . showChar ' ' . showsPrec 1 i0 . showChar ' ' . showsPrec 1 i1 . cpar n
+ ConsDecl i exp -> opar n . showString "ConsDecl" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 exp . cpar n
+ GuardExp exp -> opar n . showString "GuardExp" . showChar ' ' . showsPrec 1 exp . cpar n
+ GuardNo -> showString "GuardNo"
+ POr pattern0 pattern1 -> opar n . showString "POr" . showChar ' ' . showsPrec 1 pattern0 . showChar ' ' . showsPrec 1 pattern1 . cpar n
+ PListCons pattern0 pattern1 -> opar n . showString "PListCons" . showChar ' ' . showsPrec 1 pattern0 . showChar ' ' . showsPrec 1 pattern1 . cpar n
+ PConsTop i pattern patterns -> opar n . showString "PConsTop" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 pattern . showChar ' ' . showsPrec 1 patterns . cpar n
+ PCons i patterns -> opar n . showString "PCons" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 patterns . cpar n
+ PRec fieldpatterns -> opar n . showString "PRec" . showChar ' ' . showsPrec 1 fieldpatterns . cpar n
+ PEmptyList -> showString "PEmptyList"
+ PList commapatterns -> opar n . showString "PList" . showChar ' ' . showsPrec 1 commapatterns . cpar n
+ PTuple commapattern commapatterns -> opar n . showString "PTuple" . showChar ' ' . showsPrec 1 commapattern . showChar ' ' . showsPrec 1 commapatterns . cpar n
+ PStr str -> opar n . showString "PStr" . showChar ' ' . showsPrec 1 str . cpar n
+ PInt n -> opar n . showString "PInt" . showChar ' ' . showsPrec 1 n . cpar n
+ PVar i -> opar n . showString "PVar" . showChar ' ' . showsPrec 1 i . cpar n
+ PWild -> showString "PWild"
+ CommaPattern pattern -> opar n . showString "CommaPattern" . showChar ' ' . showsPrec 1 pattern . cpar n
+ FieldPattern i pattern -> opar n . showString "FieldPattern" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 pattern . cpar n
+ EPi varorwild exp0 exp1 -> opar n . showString "EPi" . showChar ' ' . showsPrec 1 varorwild . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EPiNoVar exp0 exp1 -> opar n . showString "EPiNoVar" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EAbs varorwild exp -> opar n . showString "EAbs" . showChar ' ' . showsPrec 1 varorwild . showChar ' ' . showsPrec 1 exp . cpar n
+ ELet letdefs exp -> opar n . showString "ELet" . showChar ' ' . showsPrec 1 letdefs . showChar ' ' . showsPrec 1 exp . cpar n
+ ECase exp cases -> opar n . showString "ECase" . showChar ' ' . showsPrec 1 exp . showChar ' ' . showsPrec 1 cases . cpar n
+ EIf exp0 exp1 exp2 -> opar n . showString "EIf" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . showChar ' ' . showsPrec 1 exp2 . cpar n
+ EDo binds exp -> opar n . showString "EDo" . showChar ' ' . showsPrec 1 binds . showChar ' ' . showsPrec 1 exp . cpar n
+ EBind exp0 exp1 -> opar n . showString "EBind" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EBindC exp0 exp1 -> opar n . showString "EBindC" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EOr exp0 exp1 -> opar n . showString "EOr" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EAnd exp0 exp1 -> opar n . showString "EAnd" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EEq exp0 exp1 -> opar n . showString "EEq" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ ENe exp0 exp1 -> opar n . showString "ENe" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ ELt exp0 exp1 -> opar n . showString "ELt" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ ELe exp0 exp1 -> opar n . showString "ELe" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EGt exp0 exp1 -> opar n . showString "EGt" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EGe exp0 exp1 -> opar n . showString "EGe" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EListCons exp0 exp1 -> opar n . showString "EListCons" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EAdd exp0 exp1 -> opar n . showString "EAdd" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ ESub exp0 exp1 -> opar n . showString "ESub" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EMul exp0 exp1 -> opar n . showString "EMul" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EDiv exp0 exp1 -> opar n . showString "EDiv" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EMod exp0 exp1 -> opar n . showString "EMod" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ ENeg exp -> opar n . showString "ENeg" . showChar ' ' . showsPrec 1 exp . cpar n
+ EApp exp0 exp1 -> opar n . showString "EApp" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
+ EProj exp i -> opar n . showString "EProj" . showChar ' ' . showsPrec 1 exp . showChar ' ' . showsPrec 1 i . cpar n
+ ERecType fieldtypes -> opar n . showString "ERecType" . showChar ' ' . showsPrec 1 fieldtypes . cpar n
+ ERec fieldvalues -> opar n . showString "ERec" . showChar ' ' . showsPrec 1 fieldvalues . cpar n
+ EEmptyList -> showString "EEmptyList"
+ EList exps -> opar n . showString "EList" . showChar ' ' . showsPrec 1 exps . cpar n
+ ETuple exp exps -> opar n . showString "ETuple" . showChar ' ' . showsPrec 1 exp . showChar ' ' . showsPrec 1 exps . cpar n
+ EVar i -> opar n . showString "EVar" . showChar ' ' . showsPrec 1 i . cpar n
+ EType -> showString "EType"
+ EStr str -> opar n . showString "EStr" . showChar ' ' . showsPrec 1 str . cpar n
+ EInteger n -> opar n . showString "EInteger" . showChar ' ' . showsPrec 1 n . cpar n
+ EDouble d -> opar n . showString "EDouble" . showChar ' ' . showsPrec 1 d . cpar n
+ EMeta -> showString "EMeta"
+ VVar i -> opar n . showString "VVar" . showChar ' ' . showsPrec 1 i . cpar n
+ VWild -> showString "VWild"
+ LetDef i exp -> opar n . showString "LetDef" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 exp . cpar n
+ Case pattern guard exp -> opar n . showString "Case" . showChar ' ' . showsPrec 1 pattern . showChar ' ' . showsPrec 1 guard . showChar ' ' . showsPrec 1 exp . cpar n
+ BindVar varorwild exp -> opar n . showString "BindVar" . showChar ' ' . showsPrec 1 varorwild . showChar ' ' . showsPrec 1 exp . cpar n
+ BindNoVar exp -> opar n . showString "BindNoVar" . showChar ' ' . showsPrec 1 exp . cpar n
+ FieldType i exp -> opar n . showString "FieldType" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 exp . cpar n
+ FieldValue i exp -> opar n . showString "FieldValue" . showChar ' ' . showsPrec 1 i . showChar ' ' . showsPrec 1 exp . cpar n
+ Ident str -> opar n . showString "Ident" . showChar ' ' . showsPrec 1 str . cpar n
+ where opar n = if n > 0 then showChar '(' else id
+ cpar n = if n > 0 then showChar ')' else id
+
+instance Eq (Tree c) where (==) = johnMajorEq
+
+johnMajorEq :: Tree a -> Tree b -> Bool
+johnMajorEq (Module imports decls) (Module imports_ decls_) = imports == imports_ && decls == decls_
+johnMajorEq (Import i) (Import i_) = i == i_
+johnMajorEq (DataDecl i exp consdecls) (DataDecl i_ exp_ consdecls_) = i == i_ && exp == exp_ && consdecls == consdecls_
+johnMajorEq (TypeDecl i exp) (TypeDecl i_ exp_) = i == i_ && exp == exp_
+johnMajorEq (ValueDecl i patterns guard exp) (ValueDecl i_ patterns_ guard_ exp_) = i == i_ && patterns == patterns_ && guard == guard_ && exp == exp_
+johnMajorEq (DeriveDecl i0 i1) (DeriveDecl i0_ i1_) = i0 == i0_ && i1 == i1_
+johnMajorEq (ConsDecl i exp) (ConsDecl i_ exp_) = i == i_ && exp == exp_
+johnMajorEq (GuardExp exp) (GuardExp exp_) = exp == exp_
+johnMajorEq GuardNo GuardNo = True
+johnMajorEq (POr pattern0 pattern1) (POr pattern0_ pattern1_) = pattern0 == pattern0_ && pattern1 == pattern1_
+johnMajorEq (PListCons pattern0 pattern1) (PListCons pattern0_ pattern1_) = pattern0 == pattern0_ && pattern1 == pattern1_
+johnMajorEq (PConsTop i pattern patterns) (PConsTop i_ pattern_ patterns_) = i == i_ && pattern == pattern_ && patterns == patterns_
+johnMajorEq (PCons i patterns) (PCons i_ patterns_) = i == i_ && patterns == patterns_
+johnMajorEq (PRec fieldpatterns) (PRec fieldpatterns_) = fieldpatterns == fieldpatterns_
+johnMajorEq PEmptyList PEmptyList = True
+johnMajorEq (PList commapatterns) (PList commapatterns_) = commapatterns == commapatterns_
+johnMajorEq (PTuple commapattern commapatterns) (PTuple commapattern_ commapatterns_) = commapattern == commapattern_ && commapatterns == commapatterns_
+johnMajorEq (PStr str) (PStr str_) = str == str_
+johnMajorEq (PInt n) (PInt n_) = n == n_
+johnMajorEq (PVar i) (PVar i_) = i == i_
+johnMajorEq PWild PWild = True
+johnMajorEq (CommaPattern pattern) (CommaPattern pattern_) = pattern == pattern_
+johnMajorEq (FieldPattern i pattern) (FieldPattern i_ pattern_) = i == i_ && pattern == pattern_
+johnMajorEq (EPi varorwild exp0 exp1) (EPi varorwild_ exp0_ exp1_) = varorwild == varorwild_ && exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EPiNoVar exp0 exp1) (EPiNoVar exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EAbs varorwild exp) (EAbs varorwild_ exp_) = varorwild == varorwild_ && exp == exp_
+johnMajorEq (ELet letdefs exp) (ELet letdefs_ exp_) = letdefs == letdefs_ && exp == exp_
+johnMajorEq (ECase exp cases) (ECase exp_ cases_) = exp == exp_ && cases == cases_
+johnMajorEq (EIf exp0 exp1 exp2) (EIf exp0_ exp1_ exp2_) = exp0 == exp0_ && exp1 == exp1_ && exp2 == exp2_
+johnMajorEq (EDo binds exp) (EDo binds_ exp_) = binds == binds_ && exp == exp_
+johnMajorEq (EBind exp0 exp1) (EBind exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EBindC exp0 exp1) (EBindC exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EOr exp0 exp1) (EOr exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EAnd exp0 exp1) (EAnd exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EEq exp0 exp1) (EEq exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (ENe exp0 exp1) (ENe exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (ELt exp0 exp1) (ELt exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (ELe exp0 exp1) (ELe exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EGt exp0 exp1) (EGt exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EGe exp0 exp1) (EGe exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EListCons exp0 exp1) (EListCons exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EAdd exp0 exp1) (EAdd exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (ESub exp0 exp1) (ESub exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EMul exp0 exp1) (EMul exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EDiv exp0 exp1) (EDiv exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EMod exp0 exp1) (EMod exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (ENeg exp) (ENeg exp_) = exp == exp_
+johnMajorEq (EApp exp0 exp1) (EApp exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
+johnMajorEq (EProj exp i) (EProj exp_ i_) = exp == exp_ && i == i_
+johnMajorEq (ERecType fieldtypes) (ERecType fieldtypes_) = fieldtypes == fieldtypes_
+johnMajorEq (ERec fieldvalues) (ERec fieldvalues_) = fieldvalues == fieldvalues_
+johnMajorEq EEmptyList EEmptyList = True
+johnMajorEq (EList exps) (EList exps_) = exps == exps_
+johnMajorEq (ETuple exp exps) (ETuple exp_ exps_) = exp == exp_ && exps == exps_
+johnMajorEq (EVar i) (EVar i_) = i == i_
+johnMajorEq EType EType = True
+johnMajorEq (EStr str) (EStr str_) = str == str_
+johnMajorEq (EInteger n) (EInteger n_) = n == n_
+johnMajorEq (EDouble d) (EDouble d_) = d == d_
+johnMajorEq EMeta EMeta = True
+johnMajorEq (VVar i) (VVar i_) = i == i_
+johnMajorEq VWild VWild = True
+johnMajorEq (LetDef i exp) (LetDef i_ exp_) = i == i_ && exp == exp_
+johnMajorEq (Case pattern guard exp) (Case pattern_ guard_ exp_) = pattern == pattern_ && guard == guard_ && exp == exp_
+johnMajorEq (BindVar varorwild exp) (BindVar varorwild_ exp_) = varorwild == varorwild_ && exp == exp_
+johnMajorEq (BindNoVar exp) (BindNoVar exp_) = exp == exp_
+johnMajorEq (FieldType i exp) (FieldType i_ exp_) = i == i_ && exp == exp_
+johnMajorEq (FieldValue i exp) (FieldValue i_ exp_) = i == i_ && exp == exp_
+johnMajorEq (Ident str) (Ident str_) = str == str_
+johnMajorEq _ _ = False
+
+instance Ord (Tree c) where
+ compare x y = compare (index x) (index y) `mappend` compareSame x y
+index :: Tree c -> Int
+index (Module _ _) = 0
+index (Import _) = 1
+index (DataDecl _ _ _) = 2
+index (TypeDecl _ _) = 3
+index (ValueDecl _ _ _ _) = 4
+index (DeriveDecl _ _) = 5
+index (ConsDecl _ _) = 6
+index (GuardExp _) = 7
+index (GuardNo ) = 8
+index (POr _ _) = 9
+index (PListCons _ _) = 10
+index (PConsTop _ _ _) = 11
+index (PCons _ _) = 12
+index (PRec _) = 13
+index (PEmptyList ) = 14
+index (PList _) = 15
+index (PTuple _ _) = 16
+index (PStr _) = 17
+index (PInt _) = 18
+index (PVar _) = 19
+index (PWild ) = 20
+index (CommaPattern _) = 21
+index (FieldPattern _ _) = 22
+index (EPi _ _ _) = 23
+index (EPiNoVar _ _) = 24
+index (EAbs _ _) = 25
+index (ELet _ _) = 26
+index (ECase _ _) = 27
+index (EIf _ _ _) = 28
+index (EDo _ _) = 29
+index (EBind _ _) = 30
+index (EBindC _ _) = 31
+index (EOr _ _) = 32
+index (EAnd _ _) = 33
+index (EEq _ _) = 34
+index (ENe _ _) = 35
+index (ELt _ _) = 36
+index (ELe _ _) = 37
+index (EGt _ _) = 38
+index (EGe _ _) = 39
+index (EListCons _ _) = 40
+index (EAdd _ _) = 41
+index (ESub _ _) = 42
+index (EMul _ _) = 43
+index (EDiv _ _) = 44
+index (EMod _ _) = 45
+index (ENeg _) = 46
+index (EApp _ _) = 47
+index (EProj _ _) = 48
+index (ERecType _) = 49
+index (ERec _) = 50
+index (EEmptyList ) = 51
+index (EList _) = 52
+index (ETuple _ _) = 53
+index (EVar _) = 54
+index (EType ) = 55
+index (EStr _) = 56
+index (EInteger _) = 57
+index (EDouble _) = 58
+index (EMeta ) = 59
+index (VVar _) = 60
+index (VWild ) = 61
+index (LetDef _ _) = 62
+index (Case _ _ _) = 63
+index (BindVar _ _) = 64
+index (BindNoVar _) = 65
+index (FieldType _ _) = 66
+index (FieldValue _ _) = 67
+index (Ident _) = 68
+compareSame :: Tree c -> Tree c -> Ordering
+compareSame (Module imports decls) (Module imports_ decls_) = mappend (compare imports imports_) (compare decls decls_)
+compareSame (Import i) (Import i_) = compare i i_
+compareSame (DataDecl i exp consdecls) (DataDecl i_ exp_ consdecls_) = mappend (compare i i_) (mappend (compare exp exp_) (compare consdecls consdecls_))
+compareSame (TypeDecl i exp) (TypeDecl i_ exp_) = mappend (compare i i_) (compare exp exp_)
+compareSame (ValueDecl i patterns guard exp) (ValueDecl i_ patterns_ guard_ exp_) = mappend (compare i i_) (mappend (compare patterns patterns_) (mappend (compare guard guard_) (compare exp exp_)))
+compareSame (DeriveDecl i0 i1) (DeriveDecl i0_ i1_) = mappend (compare i0 i0_) (compare i1 i1_)
+compareSame (ConsDecl i exp) (ConsDecl i_ exp_) = mappend (compare i i_) (compare exp exp_)
+compareSame (GuardExp exp) (GuardExp exp_) = compare exp exp_
+compareSame GuardNo GuardNo = EQ
+compareSame (POr pattern0 pattern1) (POr pattern0_ pattern1_) = mappend (compare pattern0 pattern0_) (compare pattern1 pattern1_)
+compareSame (PListCons pattern0 pattern1) (PListCons pattern0_ pattern1_) = mappend (compare pattern0 pattern0_) (compare pattern1 pattern1_)
+compareSame (PConsTop i pattern patterns) (PConsTop i_ pattern_ patterns_) = mappend (compare i i_) (mappend (compare pattern pattern_) (compare patterns patterns_))
+compareSame (PCons i patterns) (PCons i_ patterns_) = mappend (compare i i_) (compare patterns patterns_)
+compareSame (PRec fieldpatterns) (PRec fieldpatterns_) = compare fieldpatterns fieldpatterns_
+compareSame PEmptyList PEmptyList = EQ
+compareSame (PList commapatterns) (PList commapatterns_) = compare commapatterns commapatterns_
+compareSame (PTuple commapattern commapatterns) (PTuple commapattern_ commapatterns_) = mappend (compare commapattern commapattern_) (compare commapatterns commapatterns_)
+compareSame (PStr str) (PStr str_) = compare str str_
+compareSame (PInt n) (PInt n_) = compare n n_
+compareSame (PVar i) (PVar i_) = compare i i_
+compareSame PWild PWild = EQ
+compareSame (CommaPattern pattern) (CommaPattern pattern_) = compare pattern pattern_
+compareSame (FieldPattern i pattern) (FieldPattern i_ pattern_) = mappend (compare i i_) (compare pattern pattern_)
+compareSame (EPi varorwild exp0 exp1) (EPi varorwild_ exp0_ exp1_) = mappend (compare varorwild varorwild_) (mappend (compare exp0 exp0_) (compare exp1 exp1_))
+compareSame (EPiNoVar exp0 exp1) (EPiNoVar exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EAbs varorwild exp) (EAbs varorwild_ exp_) = mappend (compare varorwild varorwild_) (compare exp exp_)
+compareSame (ELet letdefs exp) (ELet letdefs_ exp_) = mappend (compare letdefs letdefs_) (compare exp exp_)
+compareSame (ECase exp cases) (ECase exp_ cases_) = mappend (compare exp exp_) (compare cases cases_)
+compareSame (EIf exp0 exp1 exp2) (EIf exp0_ exp1_ exp2_) = mappend (compare exp0 exp0_) (mappend (compare exp1 exp1_) (compare exp2 exp2_))
+compareSame (EDo binds exp) (EDo binds_ exp_) = mappend (compare binds binds_) (compare exp exp_)
+compareSame (EBind exp0 exp1) (EBind exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EBindC exp0 exp1) (EBindC exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EOr exp0 exp1) (EOr exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EAnd exp0 exp1) (EAnd exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EEq exp0 exp1) (EEq exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (ENe exp0 exp1) (ENe exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (ELt exp0 exp1) (ELt exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (ELe exp0 exp1) (ELe exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EGt exp0 exp1) (EGt exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EGe exp0 exp1) (EGe exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EListCons exp0 exp1) (EListCons exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EAdd exp0 exp1) (EAdd exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (ESub exp0 exp1) (ESub exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EMul exp0 exp1) (EMul exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EDiv exp0 exp1) (EDiv exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EMod exp0 exp1) (EMod exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (ENeg exp) (ENeg exp_) = compare exp exp_
+compareSame (EApp exp0 exp1) (EApp exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
+compareSame (EProj exp i) (EProj exp_ i_) = mappend (compare exp exp_) (compare i i_)
+compareSame (ERecType fieldtypes) (ERecType fieldtypes_) = compare fieldtypes fieldtypes_
+compareSame (ERec fieldvalues) (ERec fieldvalues_) = compare fieldvalues fieldvalues_
+compareSame EEmptyList EEmptyList = EQ
+compareSame (EList exps) (EList exps_) = compare exps exps_
+compareSame (ETuple exp exps) (ETuple exp_ exps_) = mappend (compare exp exp_) (compare exps exps_)
+compareSame (EVar i) (EVar i_) = compare i i_
+compareSame EType EType = EQ
+compareSame (EStr str) (EStr str_) = compare str str_
+compareSame (EInteger n) (EInteger n_) = compare n n_
+compareSame (EDouble d) (EDouble d_) = compare d d_
+compareSame EMeta EMeta = EQ
+compareSame (VVar i) (VVar i_) = compare i i_
+compareSame VWild VWild = EQ
+compareSame (LetDef i exp) (LetDef i_ exp_) = mappend (compare i i_) (compare exp exp_)
+compareSame (Case pattern guard exp) (Case pattern_ guard_ exp_) = mappend (compare pattern pattern_) (mappend (compare guard guard_) (compare exp exp_))
+compareSame (BindVar varorwild exp) (BindVar varorwild_ exp_) = mappend (compare varorwild varorwild_) (compare exp exp_)
+compareSame (BindNoVar exp) (BindNoVar exp_) = compare exp exp_
+compareSame (FieldType i exp) (FieldType i_ exp_) = mappend (compare i i_) (compare exp exp_)
+compareSame (FieldValue i exp) (FieldValue i_ exp_) = mappend (compare i i_) (compare exp exp_)
+compareSame (Ident str) (Ident str_) = compare str str_
+compareSame x y = error "BNFC error:" compareSame
diff --git a/src-2.9/Transfer/Syntax/Doc.tex b/src-2.9/Transfer/Syntax/Doc.tex
new file mode 100644
index 000000000..603940459
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Doc.tex
@@ -0,0 +1,333 @@
+\batchmode
+%This Latex file is machine-generated by the BNF-converter
+
+\documentclass[a4paper,11pt]{article}
+\author{BNF-converter}
+\title{The Language Syntax}
+\setlength{\parindent}{0mm}
+\setlength{\parskip}{1mm}
+\begin{document}
+
+\maketitle
+
+\newcommand{\emptyP}{\mbox{$\epsilon$}}
+\newcommand{\terminal}[1]{\mbox{{\texttt {#1}}}}
+\newcommand{\nonterminal}[1]{\mbox{$\langle \mbox{{\sl #1 }} \! \rangle$}}
+\newcommand{\arrow}{\mbox{::=}}
+\newcommand{\delimit}{\mbox{$|$}}
+\newcommand{\reserved}[1]{\mbox{{\texttt {#1}}}}
+\newcommand{\literal}[1]{\mbox{{\texttt {#1}}}}
+\newcommand{\symb}[1]{\mbox{{\texttt {#1}}}}
+
+This document was automatically generated by the {\em BNF-Converter}. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place).
+
+\section*{The lexical structure of Syntax}
+\subsection*{Identifiers}
+Identifiers \nonterminal{Ident} are unquoted strings beginning with a letter,
+followed by any combination of letters, digits, and the characters {\tt \_ '},
+reserved words excluded.
+
+
+\subsection*{Literals}
+String literals \nonterminal{String}\ have the form
+\terminal{"}$x$\terminal{"}, where $x$ is any sequence of any characters
+except \terminal{"}\ unless preceded by \verb6\6.
+
+
+Integer literals \nonterminal{Int}\ are nonempty sequences of digits.
+
+
+Double-precision float literals \nonterminal{Double}\ have the structure
+indicated by the regular expression $\nonterminal{digit}+ \mbox{{\it `.'}} \nonterminal{digit}+ (\mbox{{\it `e'}} \mbox{{\it `-'}}? \nonterminal{digit}+)?$ i.e.\
+two sequences of digits separated by a decimal point, optionally
+followed by an unsigned or negative exponent.
+
+
+
+
+\subsection*{Reserved words and symbols}
+The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions.
+
+The reserved words used in Syntax are the following: \\
+
+\begin{tabular}{lll}
+{\reserved{Type}} &{\reserved{case}} &{\reserved{data}} \\
+{\reserved{derive}} &{\reserved{do}} &{\reserved{else}} \\
+{\reserved{if}} &{\reserved{import}} &{\reserved{in}} \\
+{\reserved{let}} &{\reserved{of}} &{\reserved{rec}} \\
+{\reserved{sig}} &{\reserved{then}} &{\reserved{where}} \\
+\end{tabular}\\
+
+The symbols used in Syntax are the following: \\
+
+\begin{tabular}{lll}
+{\symb{;}} &{\symb{:}} &{\symb{\{}} \\
+{\symb{\}}} &{\symb{{$=$}}} &{\symb{{$|$}}} \\
+{\symb{{$|$}{$|$}}} &{\symb{::}} &{\symb{(}} \\
+{\symb{)}} &{\symb{[}} &{\symb{]}} \\
+{\symb{,}} &{\symb{\_}} &{\symb{{$-$}{$>$}}} \\
+{\symb{$\backslash$}} &{\symb{{$<$}{$-$}}} &{\symb{{$>$}{$>$}{$=$}}} \\
+{\symb{{$>$}{$>$}}} &{\symb{\&\&}} &{\symb{{$=$}{$=$}}} \\
+{\symb{/{$=$}}} &{\symb{{$<$}}} &{\symb{{$<$}{$=$}}} \\
+{\symb{{$>$}}} &{\symb{{$>$}{$=$}}} &{\symb{{$+$}}} \\
+{\symb{{$-$}}} &{\symb{*}} &{\symb{/}} \\
+{\symb{\%}} &{\symb{.}} &{\symb{?}} \\
+\end{tabular}\\
+
+\subsection*{Comments}
+Single-line comments begin with {\symb{{$-$}{$-$}}}. \\Multiple-line comments are enclosed with {\symb{\{{$-$}}} and {\symb{{$-$}\}}}.
+
+\section*{The syntactic structure of Syntax}
+Non-terminals are enclosed between $\langle$ and $\rangle$.
+The symbols {\arrow} (production), {\delimit} (union)
+and {\emptyP} (empty rule) belong to the BNF notation.
+All other symbols are terminals.\\
+
+\begin{tabular}{lll}
+{\nonterminal{Module}} & {\arrow} &{\nonterminal{ListImport}} {\nonterminal{ListDecl}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Import}} & {\arrow} &{\terminal{import}} {\nonterminal{Ident}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListImport}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{Import}} {\terminal{;}} {\nonterminal{ListImport}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Decl}} & {\arrow} &{\terminal{data}} {\nonterminal{Ident}} {\terminal{:}} {\nonterminal{Exp}} {\terminal{where}} {\terminal{\{}} {\nonterminal{ListConsDecl}} {\terminal{\}}} \\
+ & {\delimit} &{\nonterminal{Ident}} {\terminal{:}} {\nonterminal{Exp}} \\
+ & {\delimit} &{\nonterminal{Ident}} {\nonterminal{ListPattern}} {\nonterminal{Guard}} {\terminal{{$=$}}} {\nonterminal{Exp}} \\
+ & {\delimit} &{\terminal{derive}} {\nonterminal{Ident}} {\nonterminal{Ident}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListDecl}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{Decl}} {\terminal{;}} {\nonterminal{ListDecl}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ConsDecl}} & {\arrow} &{\nonterminal{Ident}} {\terminal{:}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListConsDecl}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{ConsDecl}} \\
+ & {\delimit} &{\nonterminal{ConsDecl}} {\terminal{;}} {\nonterminal{ListConsDecl}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Guard}} & {\arrow} &{\terminal{{$|$}}} {\nonterminal{Exp1}} \\
+ & {\delimit} &{\emptyP} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Pattern}} & {\arrow} &{\nonterminal{Pattern1}} {\terminal{{$|$}{$|$}}} {\nonterminal{Pattern}} \\
+ & {\delimit} &{\nonterminal{Pattern1}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Pattern1}} & {\arrow} &{\nonterminal{Pattern2}} {\terminal{::}} {\nonterminal{Pattern1}} \\
+ & {\delimit} &{\nonterminal{Pattern2}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Pattern2}} & {\arrow} &{\nonterminal{Ident}} {\nonterminal{Pattern3}} {\nonterminal{ListPattern}} \\
+ & {\delimit} &{\nonterminal{Pattern3}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Pattern3}} & {\arrow} &{\terminal{rec}} {\terminal{\{}} {\nonterminal{ListFieldPattern}} {\terminal{\}}} \\
+ & {\delimit} &{\terminal{[}} {\terminal{]}} \\
+ & {\delimit} &{\terminal{[}} {\nonterminal{ListCommaPattern}} {\terminal{]}} \\
+ & {\delimit} &{\terminal{(}} {\nonterminal{CommaPattern}} {\terminal{,}} {\nonterminal{ListCommaPattern}} {\terminal{)}} \\
+ & {\delimit} &{\nonterminal{String}} \\
+ & {\delimit} &{\nonterminal{Integer}} \\
+ & {\delimit} &{\nonterminal{Ident}} \\
+ & {\delimit} &{\terminal{\_}} \\
+ & {\delimit} &{\terminal{(}} {\nonterminal{Pattern}} {\terminal{)}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{CommaPattern}} & {\arrow} &{\nonterminal{Pattern}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListCommaPattern}} & {\arrow} &{\nonterminal{CommaPattern}} \\
+ & {\delimit} &{\nonterminal{CommaPattern}} {\terminal{,}} {\nonterminal{ListCommaPattern}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListPattern}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{Pattern3}} {\nonterminal{ListPattern}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{FieldPattern}} & {\arrow} &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Pattern}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListFieldPattern}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{FieldPattern}} \\
+ & {\delimit} &{\nonterminal{FieldPattern}} {\terminal{;}} {\nonterminal{ListFieldPattern}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp}} & {\arrow} &{\terminal{(}} {\nonterminal{VarOrWild}} {\terminal{:}} {\nonterminal{Exp}} {\terminal{)}} {\terminal{{$-$}{$>$}}} {\nonterminal{Exp}} \\
+ & {\delimit} &{\nonterminal{Exp1}} {\terminal{{$-$}{$>$}}} {\nonterminal{Exp}} \\
+ & {\delimit} &{\nonterminal{Exp1}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{VarOrWild}} & {\arrow} &{\nonterminal{Ident}} \\
+ & {\delimit} &{\terminal{\_}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp1}} & {\arrow} &{\terminal{$\backslash$}} {\nonterminal{VarOrWild}} {\terminal{{$-$}{$>$}}} {\nonterminal{Exp1}} \\
+ & {\delimit} &{\terminal{let}} {\terminal{\{}} {\nonterminal{ListLetDef}} {\terminal{\}}} {\terminal{in}} {\nonterminal{Exp1}} \\
+ & {\delimit} &{\terminal{case}} {\nonterminal{Exp}} {\terminal{of}} {\terminal{\{}} {\nonterminal{ListCase}} {\terminal{\}}} \\
+ & {\delimit} &{\terminal{if}} {\nonterminal{Exp}} {\terminal{then}} {\nonterminal{Exp}} {\terminal{else}} {\nonterminal{Exp1}} \\
+ & {\delimit} &{\terminal{do}} {\terminal{\{}} {\nonterminal{ListBind}} {\nonterminal{Exp}} {\terminal{\}}} \\
+ & {\delimit} &{\nonterminal{Exp2}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{LetDef}} & {\arrow} &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListLetDef}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{LetDef}} \\
+ & {\delimit} &{\nonterminal{LetDef}} {\terminal{;}} {\nonterminal{ListLetDef}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Case}} & {\arrow} &{\nonterminal{Pattern}} {\nonterminal{Guard}} {\terminal{{$-$}{$>$}}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListCase}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{Case}} \\
+ & {\delimit} &{\nonterminal{Case}} {\terminal{;}} {\nonterminal{ListCase}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Bind}} & {\arrow} &{\nonterminal{VarOrWild}} {\terminal{{$<$}{$-$}}} {\nonterminal{Exp}} \\
+ & {\delimit} &{\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListBind}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{Bind}} {\terminal{;}} {\nonterminal{ListBind}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp3}} & {\arrow} &{\nonterminal{Exp3}} {\terminal{{$>$}{$>$}{$=$}}} {\nonterminal{Exp4}} \\
+ & {\delimit} &{\nonterminal{Exp3}} {\terminal{{$>$}{$>$}}} {\nonterminal{Exp4}} \\
+ & {\delimit} &{\nonterminal{Exp4}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp4}} & {\arrow} &{\nonterminal{Exp5}} {\terminal{{$|$}{$|$}}} {\nonterminal{Exp4}} \\
+ & {\delimit} &{\nonterminal{Exp5}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp5}} & {\arrow} &{\nonterminal{Exp6}} {\terminal{\&\&}} {\nonterminal{Exp5}} \\
+ & {\delimit} &{\nonterminal{Exp6}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp6}} & {\arrow} &{\nonterminal{Exp7}} {\terminal{{$=$}{$=$}}} {\nonterminal{Exp7}} \\
+ & {\delimit} &{\nonterminal{Exp7}} {\terminal{/{$=$}}} {\nonterminal{Exp7}} \\
+ & {\delimit} &{\nonterminal{Exp7}} {\terminal{{$<$}}} {\nonterminal{Exp7}} \\
+ & {\delimit} &{\nonterminal{Exp7}} {\terminal{{$<$}{$=$}}} {\nonterminal{Exp7}} \\
+ & {\delimit} &{\nonterminal{Exp7}} {\terminal{{$>$}}} {\nonterminal{Exp7}} \\
+ & {\delimit} &{\nonterminal{Exp7}} {\terminal{{$>$}{$=$}}} {\nonterminal{Exp7}} \\
+ & {\delimit} &{\nonterminal{Exp7}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp7}} & {\arrow} &{\nonterminal{Exp8}} {\terminal{::}} {\nonterminal{Exp7}} \\
+ & {\delimit} &{\nonterminal{Exp8}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp8}} & {\arrow} &{\nonterminal{Exp8}} {\terminal{{$+$}}} {\nonterminal{Exp9}} \\
+ & {\delimit} &{\nonterminal{Exp8}} {\terminal{{$-$}}} {\nonterminal{Exp9}} \\
+ & {\delimit} &{\nonterminal{Exp9}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp9}} & {\arrow} &{\nonterminal{Exp9}} {\terminal{*}} {\nonterminal{Exp10}} \\
+ & {\delimit} &{\nonterminal{Exp9}} {\terminal{/}} {\nonterminal{Exp10}} \\
+ & {\delimit} &{\nonterminal{Exp9}} {\terminal{\%}} {\nonterminal{Exp10}} \\
+ & {\delimit} &{\nonterminal{Exp10}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp10}} & {\arrow} &{\terminal{{$-$}}} {\nonterminal{Exp10}} \\
+ & {\delimit} &{\nonterminal{Exp11}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp11}} & {\arrow} &{\nonterminal{Exp11}} {\nonterminal{Exp12}} \\
+ & {\delimit} &{\nonterminal{Exp12}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp12}} & {\arrow} &{\nonterminal{Exp12}} {\terminal{.}} {\nonterminal{Ident}} \\
+ & {\delimit} &{\nonterminal{Exp13}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp13}} & {\arrow} &{\terminal{sig}} {\terminal{\{}} {\nonterminal{ListFieldType}} {\terminal{\}}} \\
+ & {\delimit} &{\terminal{rec}} {\terminal{\{}} {\nonterminal{ListFieldValue}} {\terminal{\}}} \\
+ & {\delimit} &{\terminal{[}} {\terminal{]}} \\
+ & {\delimit} &{\terminal{[}} {\nonterminal{ListExp}} {\terminal{]}} \\
+ & {\delimit} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{,}} {\nonterminal{ListExp}} {\terminal{)}} \\
+ & {\delimit} &{\nonterminal{Ident}} \\
+ & {\delimit} &{\terminal{Type}} \\
+ & {\delimit} &{\nonterminal{String}} \\
+ & {\delimit} &{\nonterminal{Integer}} \\
+ & {\delimit} &{\nonterminal{Double}} \\
+ & {\delimit} &{\terminal{?}} \\
+ & {\delimit} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{FieldType}} & {\arrow} &{\nonterminal{Ident}} {\terminal{:}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListFieldType}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{FieldType}} \\
+ & {\delimit} &{\nonterminal{FieldType}} {\terminal{;}} {\nonterminal{ListFieldType}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{FieldValue}} & {\arrow} &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListFieldValue}} & {\arrow} &{\emptyP} \\
+ & {\delimit} &{\nonterminal{FieldValue}} \\
+ & {\delimit} &{\nonterminal{FieldValue}} {\terminal{;}} {\nonterminal{ListFieldValue}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp2}} & {\arrow} &{\nonterminal{Exp3}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{ListExp}} & {\arrow} &{\nonterminal{Exp}} \\
+ & {\delimit} &{\nonterminal{Exp}} {\terminal{,}} {\nonterminal{ListExp}} \\
+\end{tabular}\\
+
+
+
+\end{document}
+
diff --git a/src-2.9/Transfer/Syntax/Layout.hs b/src-2.9/Transfer/Syntax/Layout.hs
new file mode 100644
index 000000000..de5c99870
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Layout.hs
@@ -0,0 +1,227 @@
+module Transfer.Syntax.Layout where
+
+import Transfer.Syntax.Lex
+
+
+import Data.Maybe (isNothing, fromJust)
+
+-- Generated by the BNF Converter
+
+-- local parameters
+
+topLayout = True
+layoutWords = ["let","where","of","rec","sig","do"]
+layoutStopWords = ["in"]
+
+-- layout separators
+
+layoutOpen = "{"
+layoutClose = "}"
+layoutSep = ";"
+
+-- | Replace layout syntax with explicit layout tokens.
+resolveLayout :: Bool -- ^ Whether to use top-level layout.
+ -> [Token] -> [Token]
+resolveLayout tp = res Nothing [if tl then Implicit 1 else Explicit]
+ where
+ -- Do top-level layout if the function parameter and the grammar say so.
+ tl = tp && topLayout
+
+ res :: Maybe Token -- ^ The previous token, if any.
+ -> [Block] -- ^ A stack of layout blocks.
+ -> [Token] -> [Token]
+
+ -- The stack should never be empty.
+ res _ [] ts = error $ "Layout error: stack empty. Tokens: " ++ show ts
+
+ res _ st (t0:ts)
+ -- We found an open brace in the input,
+ -- put an explicit layout block on the stack.
+ -- This is done even if there was no layout word,
+ -- to keep opening and closing braces.
+ | isLayoutOpen t0 = moveAlong (Explicit:st) [t0] ts
+
+ res _ st (t0:ts)
+ -- Start a new layout block if the first token is a layout word
+ | isLayout t0 =
+ case ts of
+ -- Explicit layout, just move on. The case above
+ -- will push an explicit layout block.
+ t1:_ | isLayoutOpen t1 -> moveAlong st [t0] ts
+ -- at end of file, the start column doesn't matter
+ _ -> let col = if null ts then column t0 else column (head ts)
+ -- insert an open brace after the layout word
+ b:ts' = addToken (nextPos t0) layoutOpen ts
+ -- save the start column
+ st' = Implicit col:st
+ in moveAlong st' [t0,b] ts'
+
+ -- If we encounter a closing brace, exit the first explicit layout block.
+ | isLayoutClose t0 =
+ let st' = drop 1 (dropWhile isImplicit st)
+ in if null st'
+ then error $ "Layout error: Found " ++ layoutClose ++ " at ("
+ ++ show (line t0) ++ "," ++ show (column t0)
+ ++ ") without an explicit layout block."
+ else moveAlong st' [t0] ts
+
+ -- We are in an implicit layout block
+ res pt st@(Implicit n:ns) (t0:ts)
+
+ -- End of implicit block by a layout stop word
+ | isStop t0 =
+ -- Exit the current block and all implicit blocks
+ -- more indented than the current token
+ let (ebs,ns') = span (`moreIndent` column t0) ns
+ moreIndent (Implicit x) y = x > y
+ moreIndent Explicit _ = False
+ -- the number of blocks exited
+ b = 1 + length ebs
+ bs = replicate b layoutClose
+ -- Insert closing braces after the previous token.
+ (ts1,ts2) = splitAt (1+b) $ addTokens (afterPrev pt) bs (t0:ts)
+ in moveAlong ns' ts1 ts2
+
+ -- End of an implicit layout block
+ | newLine && column t0 < n =
+ -- Insert a closing brace after the previous token.
+ let b:t0':ts' = addToken (afterPrev pt) layoutClose (t0:ts)
+ -- Repeat, with the current block removed from the stack
+ in moveAlong ns [b] (t0':ts')
+
+ -- Encounted a new line in an implicit layout block.
+ | newLine && column t0 == n =
+ -- Insert a semicolon after the previous token.
+ -- unless we are the beginning of the file,
+ -- or the previous token is a semicolon or open brace.
+ if isNothing pt || isTokenIn [layoutSep,layoutOpen] (fromJust pt)
+ then moveAlong st [t0] ts
+ else let b:t0':ts' = addToken (afterPrev pt) layoutSep (t0:ts)
+ in moveAlong st [b,t0'] ts'
+ where newLine = case pt of
+ Nothing -> True
+ Just t -> line t /= line t0
+
+ -- Nothing to see here, move along.
+ res _ st (t:ts) = moveAlong st [t] ts
+
+ -- At EOF: skip explicit blocks.
+ res (Just t) (Explicit:bs) [] | null bs = []
+ | otherwise = res (Just t) bs []
+
+ -- If we are using top-level layout, insert a semicolon after
+ -- the last token, if there isn't one already
+ res (Just t) [Implicit n] []
+ | isTokenIn [layoutSep] t = []
+ | otherwise = addToken (nextPos t) layoutSep []
+
+ -- At EOF in an implicit, non-top-level block: close the block
+ res (Just t) (Implicit n:bs) [] =
+ let c = addToken (nextPos t) layoutClose []
+ in moveAlong bs c []
+
+ -- This should only happen if the input is empty.
+ res Nothing st [] = []
+
+ -- | Move on to the next token.
+ moveAlong :: [Block] -- ^ The layout stack.
+ -> [Token] -- ^ Any tokens just processed.
+ -> [Token] -- ^ the rest of the tokens.
+ -> [Token]
+ moveAlong st [] ts = error $ "Layout error: moveAlong got [] as old tokens"
+ moveAlong st ot ts = ot ++ res (Just $ last ot) st ts
+
+data Block = Implicit Int -- ^ An implicit layout block with its start column.
+ | Explicit
+ deriving Show
+
+type Position = Posn
+
+-- | Check if s block is implicit.
+isImplicit :: Block -> Bool
+isImplicit (Implicit _) = True
+isImplicit _ = False
+
+-- | Insert a number of tokens at the begninning of a list of tokens.
+addTokens :: Position -- ^ Position of the first new token.
+ -> [String] -- ^ Token symbols.
+ -> [Token] -- ^ The rest of the tokens. These will have their
+ -- positions updated to make room for the new tokens .
+ -> [Token]
+addTokens p ss ts = foldr (addToken p) ts ss
+
+-- | Insert a new symbol token at the begninning of a list of tokens.
+addToken :: Position -- ^ Position of the new token.
+ -> String -- ^ Symbol in the new token.
+ -> [Token] -- ^ The rest of the tokens. These will have their
+ -- positions updated to make room for the new token.
+ -> [Token]
+addToken p s ts = sToken p s : map (incrGlobal p (length s)) ts
+
+-- | Get the position immediately to the right of the given token.
+-- If no token is given, gets the first position in the file.
+afterPrev :: Maybe Token -> Position
+afterPrev = maybe (Pn 0 1 1) nextPos
+
+-- | Get the position immediately to the right of the given token.
+nextPos :: Token -> Position
+nextPos t = Pn (g + s) l (c + s + 1)
+ where Pn g l c = position t
+ s = tokenLength t
+
+-- | Add to the global and column positions of a token.
+-- The column position is only changed if the token is on
+-- the same line as the given position.
+incrGlobal :: Position -- ^ If the token is on the same line
+ -- as this position, update the column position.
+ -> Int -- ^ Number of characters to add to the position.
+ -> Token -> Token
+incrGlobal (Pn _ l0 _) i (PT (Pn g l c) t) =
+ if l /= l0 then PT (Pn (g + i) l c) t
+ else PT (Pn (g + i) l (c + i)) t
+incrGlobal _ _ p = error $ "cannot add token at " ++ show p
+
+-- | Create a symbol token.
+sToken :: Position -> String -> Token
+sToken p s = PT p (TS s) -- reserved word or symbol
+
+-- | Get the position of a token.
+position :: Token -> Position
+position t = case t of
+ PT p _ -> p
+ Err p -> p
+
+-- | Get the line number of a token.
+line :: Token -> Int
+line t = case position t of Pn _ l _ -> l
+
+-- | Get the column number of a token.
+column :: Token -> Int
+column t = case position t of Pn _ _ c -> c
+
+-- | Check if a token is one of the given symbols.
+isTokenIn :: [String] -> Token -> Bool
+isTokenIn ts t = case t of
+ PT _ (TS r) | elem r ts -> True
+ _ -> False
+
+-- | Check if a word is a layout start token.
+isLayout :: Token -> Bool
+isLayout = isTokenIn layoutWords
+
+-- | Check if a token is a layout stop token.
+isStop :: Token -> Bool
+isStop = isTokenIn layoutStopWords
+
+-- | Check if a token is the layout open token.
+isLayoutOpen :: Token -> Bool
+isLayoutOpen = isTokenIn [layoutOpen]
+
+-- | Check if a token is the layout close token.
+isLayoutClose :: Token -> Bool
+isLayoutClose = isTokenIn [layoutClose]
+
+-- | Get the number of characters in the token.
+tokenLength :: Token -> Int
+tokenLength t = length $ prToken t
+
diff --git a/src-2.9/Transfer/Syntax/Lex.hs b/src-2.9/Transfer/Syntax/Lex.hs
new file mode 100644
index 000000000..83c9e1a12
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Lex.hs
@@ -0,0 +1,337 @@
+{-# OPTIONS -fglasgow-exts -cpp #-}
+{-# LINE 3 "Transfer/Syntax/Lex.x" #-}
+{-# OPTIONS -fno-warn-incomplete-patterns #-}
+module Transfer.Syntax.Lex where
+
+
+
+#if __GLASGOW_HASKELL__ >= 603
+#include "ghcconfig.h"
+#else
+#include "config.h"
+#endif
+#if __GLASGOW_HASKELL__ >= 503
+import Data.Array
+import Data.Char (ord)
+import Data.Array.Base (unsafeAt)
+#else
+import Array
+import Char (ord)
+#endif
+#if __GLASGOW_HASKELL__ >= 503
+import GHC.Exts
+#else
+import GlaExts
+#endif
+alex_base :: AlexAddr
+alex_base = AlexA# "\x01\x00\x00\x00\x15\x00\x00\x00\x39\x00\x00\x00\x3a\x00\x00\x00\x18\x00\x00\x00\x19\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x45\x00\x00\x00\x1b\x00\x00\x00\x1c\x00\x00\x00\x1d\x00\x00\x00\x42\x00\x00\x00\x00\x00\x00\x00\xd4\xff\xff\xff\x17\x00\x00\x00\x26\x00\x00\x00\x1e\x00\x00\x00\x27\x00\x00\x00\x29\x00\x00\x00\x2a\x00\x00\x00\x2c\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x17\x01\x00\x00\xd5\x00\x00\x00\xf2\x00\x00\x00\x6c\x01\x00\x00\x1a\x01\x00\x00\x76\x01\x00\x00\x80\x01\x00\x00\x8d\x01\x00\x00"#
+
+alex_table :: AlexAddr
+alex_table = AlexA# "\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0d\x00\xff\xff\x19\x00\xff\xff\xff\xff\x0e\x00\x16\x00\xff\xff\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x05\x00\x0e\x00\x15\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x10\x00\x0e\x00\x11\x00\x14\x00\x13\x00\x0e\x00\xff\xff\x04\x00\xff\xff\xff\xff\x03\x00\x03\x00\x09\x00\x09\x00\x09\x00\x0b\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\xff\xff\x0e\x00\xff\xff\x0d\x00\x0e\x00\x0e\x00\x12\x00\x0e\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x0f\x00\x0e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x06\x00\x07\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x19\x00\xff\xff\x00\x00\x00\x00\x17\x00\x19\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1e\x00\xff\xff\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x1a\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x00\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x17\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1c\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1f\x00\x00\x00\x00\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
+
+alex_check :: AlexAddr
+alex_check = AlexA# "\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x2d\x00\x0a\x00\x0a\x00\x2d\x00\x2d\x00\x2d\x00\x2d\x00\x2d\x00\x2d\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x7c\x00\x3a\x00\x26\x00\x2d\x00\xff\xff\xff\xff\xff\xff\x3e\x00\xff\xff\xff\xff\xff\xff\x3d\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x20\x00\x3d\x00\x3d\x00\x3e\x00\x3d\x00\x3d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\x2d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\x7d\x00\x7d\x00\x27\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xd7\x00\xff\xff\xff\xff\xff\xff\xff\xff\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x22\x00\xf7\x00\xff\xff\xff\xff\x5f\x00\x27\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x2e\x00\x0a\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5c\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x22\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x6e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x74\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\x5c\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xff\xff\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x2d\x00\xff\xff\xff\xff\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x65\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
+
+alex_deflt :: AlexAddr
+alex_deflt = AlexA# "\x17\x00\xff\xff\x02\x00\x02\x00\xff\xff\xff\xff\x0a\x00\xff\xff\x0a\x00\x0a\x00\x0a\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x19\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
+
+alex_accept = listArray (0::Int,32) [[],[],[(AlexAccSkip)],[(AlexAccSkip)],[],[(AlexAcc (alex_action_3))],[(AlexAccSkip)],[(AlexAccSkip)],[],[],[],[],[(AlexAcc (alex_action_3))],[(AlexAccSkip)],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_3))],[],[(AlexAcc (alex_action_4))],[(AlexAcc (alex_action_5))],[],[],[(AlexAcc (alex_action_6))],[(AlexAcc (alex_action_7))],[(AlexAcc (alex_action_7))],[],[],[]]
+{-# LINE 34 "Transfer/Syntax/Lex.x" #-}
+
+tok f p s = f p s
+
+share :: String -> String
+share = id
+
+data Tok =
+ TS !String -- reserved words and symbols
+ | TL !String -- string literals
+ | TI !String -- integer literals
+ | TV !String -- identifiers
+ | TD !String -- double precision float literals
+ | TC !String -- character literals
+
+ deriving (Eq,Show,Ord)
+
+data Token =
+ PT Posn Tok
+ | Err Posn
+ deriving (Eq,Show,Ord)
+
+tokenPos (PT (Pn _ l _) _ :_) = "line " ++ show l
+tokenPos (Err (Pn _ l _) :_) = "line " ++ show l
+tokenPos _ = "end of file"
+
+posLineCol (Pn _ l c) = (l,c)
+mkPosToken t@(PT p _) = (posLineCol p, prToken t)
+
+prToken t = case t of
+ PT _ (TS s) -> s
+ PT _ (TI s) -> s
+ PT _ (TV s) -> s
+ PT _ (TD s) -> s
+ PT _ (TC s) -> s
+
+ _ -> show t
+
+data BTree = N | B String Tok BTree BTree deriving (Show)
+
+eitherResIdent :: (String -> Tok) -> String -> Tok
+eitherResIdent tv s = treeFind resWords
+ where
+ treeFind N = tv s
+ treeFind (B a t left right) | s < a = treeFind left
+ | s > a = treeFind right
+ | s == a = t
+
+resWords = b "import" (b "derive" (b "case" (b "Type" N N) (b "data" N N)) (b "else" (b "do" N N) (b "if" N N))) (b "rec" (b "let" (b "in" N N) (b "of" N N)) (b "then" (b "sig" N N) (b "where" N N)))
+ where b s = B s (TS s)
+
+unescapeInitTail :: String -> String
+unescapeInitTail = unesc . tail where
+ unesc s = case s of
+ '\\':c:cs | elem c ['\"', '\\', '\''] -> c : unesc cs
+ '\\':'n':cs -> '\n' : unesc cs
+ '\\':'t':cs -> '\t' : unesc cs
+ '"':[] -> []
+ c:cs -> c : unesc cs
+ _ -> []
+
+-------------------------------------------------------------------
+-- Alex wrapper code.
+-- A modified "posn" wrapper.
+-------------------------------------------------------------------
+
+data Posn = Pn !Int !Int !Int
+ deriving (Eq, Show,Ord)
+
+alexStartPos :: Posn
+alexStartPos = Pn 0 1 1
+
+alexMove :: Posn -> Char -> Posn
+alexMove (Pn a l c) '\t' = Pn (a+1) l (((c+7) `div` 8)*8+1)
+alexMove (Pn a l c) '\n' = Pn (a+1) (l+1) 1
+alexMove (Pn a l c) _ = Pn (a+1) l (c+1)
+
+type AlexInput = (Posn, -- current position,
+ Char, -- previous char
+ String) -- current input string
+
+tokens :: String -> [Token]
+tokens str = go (alexStartPos, '\n', str)
+ where
+ go :: (Posn, Char, String) -> [Token]
+ go inp@(pos, _, str) =
+ case alexScan inp 0 of
+ AlexEOF -> []
+ AlexError (pos, _, _) -> fail $ show pos ++ ": lexical error"
+ AlexSkip inp' len -> go inp'
+ AlexToken inp' len act -> act pos (take len str) : (go inp')
+
+alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
+alexGetChar (p, c, []) = Nothing
+alexGetChar (p, _, (c:s)) =
+ let p' = alexMove p c
+ in p' `seq` Just (c, (p', c, s))
+
+alexInputPrevChar :: AlexInput -> Char
+alexInputPrevChar (p, c, s) = c
+
+alex_action_3 = tok (\p s -> PT p (TS $ share s))
+alex_action_4 = tok (\p s -> PT p (eitherResIdent (TV . share) s))
+alex_action_5 = tok (\p s -> PT p (TL $ share $ unescapeInitTail s))
+alex_action_6 = tok (\p s -> PT p (TI $ share s))
+alex_action_7 = tok (\p s -> PT p (TD $ share s))
+{-# LINE 1 "GenericTemplate.hs" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "GenericTemplate.hs" #-}
+-- -----------------------------------------------------------------------------
+-- ALEX TEMPLATE
+--
+-- This code is in the PUBLIC DOMAIN; you may copy it freely and use
+-- it for any purpose whatsoever.
+
+-- -----------------------------------------------------------------------------
+-- INTERNALS and main scanner engine
+
+{-# LINE 35 "GenericTemplate.hs" #-}
+
+{-# LINE 45 "GenericTemplate.hs" #-}
+
+
+data AlexAddr = AlexA# Addr#
+
+#if __GLASGOW_HASKELL__ < 503
+uncheckedShiftL# = shiftL#
+#endif
+
+{-# INLINE alexIndexInt16OffAddr #-}
+alexIndexInt16OffAddr (AlexA# arr) off =
+#ifdef WORDS_BIGENDIAN
+ narrow16Int# i
+ where
+ i = word2Int# ((high `uncheckedShiftL#` 8#) `or#` low)
+ high = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
+ low = int2Word# (ord# (indexCharOffAddr# arr off'))
+ off' = off *# 2#
+#else
+ indexInt16OffAddr# arr off
+#endif
+
+
+
+
+
+{-# INLINE alexIndexInt32OffAddr #-}
+alexIndexInt32OffAddr (AlexA# arr) off =
+#ifdef WORDS_BIGENDIAN
+ narrow32Int# i
+ where
+ i = word2Int# ((b3 `uncheckedShiftL#` 24#) `or#`
+ (b2 `uncheckedShiftL#` 16#) `or#`
+ (b1 `uncheckedShiftL#` 8#) `or#` b0)
+ b3 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 3#)))
+ b2 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 2#)))
+ b1 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
+ b0 = int2Word# (ord# (indexCharOffAddr# arr off'))
+ off' = off *# 4#
+#else
+ indexInt32OffAddr# arr off
+#endif
+
+
+
+
+
+#if __GLASGOW_HASKELL__ < 503
+quickIndex arr i = arr ! i
+#else
+-- GHC >= 503, unsafeAt is available from Data.Array.Base.
+quickIndex = unsafeAt
+#endif
+
+
+
+
+-- -----------------------------------------------------------------------------
+-- Main lexing routines
+
+data AlexReturn a
+ = AlexEOF
+ | AlexError !AlexInput
+ | AlexSkip !AlexInput !Int
+ | AlexToken !AlexInput !Int a
+
+-- alexScan :: AlexInput -> StartCode -> Maybe (AlexInput,Int,act)
+alexScan input (I# (sc))
+ = alexScanUser undefined input (I# (sc))
+
+alexScanUser user input (I# (sc))
+ = case alex_scan_tkn user input 0# input sc AlexNone of
+ (AlexNone, input') ->
+ case alexGetChar input of
+ Nothing ->
+
+
+
+ AlexEOF
+ Just _ ->
+
+
+
+ AlexError input'
+
+ (AlexLastSkip input len, _) ->
+
+
+
+ AlexSkip input len
+
+ (AlexLastAcc k input len, _) ->
+
+
+
+ AlexToken input len k
+
+
+-- Push the input through the DFA, remembering the most recent accepting
+-- state it encountered.
+
+alex_scan_tkn user orig_input len input s last_acc =
+ input `seq` -- strict in the input
+ case s of
+ -1# -> (last_acc, input)
+ _ -> alex_scan_tkn' user orig_input len input s last_acc
+
+alex_scan_tkn' user orig_input len input s last_acc =
+ let
+ new_acc = check_accs (alex_accept `quickIndex` (I# (s)))
+ in
+ new_acc `seq`
+ case alexGetChar input of
+ Nothing -> (new_acc, input)
+ Just (c, new_input) ->
+
+
+
+ let
+ base = alexIndexInt32OffAddr alex_base s
+ (I# (ord_c)) = ord c
+ offset = (base +# ord_c)
+ check = alexIndexInt16OffAddr alex_check offset
+
+ new_s = if (offset >=# 0#) && (check ==# ord_c)
+ then alexIndexInt16OffAddr alex_table offset
+ else alexIndexInt16OffAddr alex_deflt s
+ in
+ alex_scan_tkn user orig_input (len +# 1#) new_input new_s new_acc
+
+ where
+ check_accs [] = last_acc
+ check_accs (AlexAcc a : _) = AlexLastAcc a input (I# (len))
+ check_accs (AlexAccSkip : _) = AlexLastSkip input (I# (len))
+ check_accs (AlexAccPred a pred : rest)
+ | pred user orig_input (I# (len)) input
+ = AlexLastAcc a input (I# (len))
+ check_accs (AlexAccSkipPred pred : rest)
+ | pred user orig_input (I# (len)) input
+ = AlexLastSkip input (I# (len))
+ check_accs (_ : rest) = check_accs rest
+
+data AlexLastAcc a
+ = AlexNone
+ | AlexLastAcc a !AlexInput !Int
+ | AlexLastSkip !AlexInput !Int
+
+data AlexAcc a user
+ = AlexAcc a
+ | AlexAccSkip
+ | AlexAccPred a (AlexAccPred user)
+ | AlexAccSkipPred (AlexAccPred user)
+
+type AlexAccPred user = user -> AlexInput -> Int -> AlexInput -> Bool
+
+-- -----------------------------------------------------------------------------
+-- Predicates on a rule
+
+alexAndPred p1 p2 user in1 len in2
+ = p1 user in1 len in2 && p2 user in1 len in2
+
+--alexPrevCharIsPred :: Char -> AlexAccPred _
+alexPrevCharIs c _ input _ _ = c == alexInputPrevChar input
+
+--alexPrevCharIsOneOfPred :: Array Char Bool -> AlexAccPred _
+alexPrevCharIsOneOf arr _ input _ _ = arr ! alexInputPrevChar input
+
+--alexRightContext :: Int -> AlexAccPred _
+alexRightContext (I# (sc)) user _ _ input =
+ case alex_scan_tkn user input 0# input sc AlexNone of
+ (AlexNone, _) -> False
+ _ -> True
+ -- TODO: there's no need to find the longest
+ -- match when checking the right context, just
+ -- the first match will do.
+
+-- used by wrappers
+iUnbox (I# (i)) = i
diff --git a/src-2.9/Transfer/Syntax/Lex.x b/src-2.9/Transfer/Syntax/Lex.x
new file mode 100644
index 000000000..107b67345
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Lex.x
@@ -0,0 +1,134 @@
+-- -*- haskell -*-
+-- This Alex file was machine-generated by the BNF converter
+{
+{-# OPTIONS -fno-warn-incomplete-patterns #-}
+module Transfer.Syntax.Lex where
+
+
+}
+
+
+$l = [a-zA-Z\192 - \255] # [\215 \247] -- isolatin1 letter FIXME
+$c = [A-Z\192-\221] # [\215] -- capital isolatin1 letter FIXME
+$s = [a-z\222-\255] # [\247] -- small isolatin1 letter FIXME
+$d = [0-9] -- digit
+$i = [$l $d _ '] -- identifier character
+$u = [\0-\255] -- universal: any character
+
+@rsyms = -- symbols and non-identifier-like reserved words
+ \; | \: | \{ | \} | \= | \| | \| \| | \: \: | \( | \) | \[ | \] | \, | \_ | \- \> | \\ | \< \- | \> \> \= | \> \> | \& \& | \= \= | \/ \= | \< | \< \= | \> | \> \= | \+ | \- | \* | \/ | \% | \. | \?
+
+:-
+"--" [.]* ; -- Toss single line comments
+"{-" ([$u # \-] | \- [$u # \}])* ("-")+ "}" ;
+
+$white+ ;
+@rsyms { tok (\p s -> PT p (TS $ share s)) }
+
+$l $i* { tok (\p s -> PT p (eitherResIdent (TV . share) s)) }
+\" ([$u # [\" \\ \n]] | (\\ (\" | \\ | \' | n | t)))* \"{ tok (\p s -> PT p (TL $ share $ unescapeInitTail s)) }
+
+$d+ { tok (\p s -> PT p (TI $ share s)) }
+$d+ \. $d+ (e (\-)? $d+)? { tok (\p s -> PT p (TD $ share s)) }
+
+{
+
+tok f p s = f p s
+
+share :: String -> String
+share = id
+
+data Tok =
+ TS !String -- reserved words and symbols
+ | TL !String -- string literals
+ | TI !String -- integer literals
+ | TV !String -- identifiers
+ | TD !String -- double precision float literals
+ | TC !String -- character literals
+
+ deriving (Eq,Show,Ord)
+
+data Token =
+ PT Posn Tok
+ | Err Posn
+ deriving (Eq,Show,Ord)
+
+tokenPos (PT (Pn _ l _) _ :_) = "line " ++ show l
+tokenPos (Err (Pn _ l _) :_) = "line " ++ show l
+tokenPos _ = "end of file"
+
+posLineCol (Pn _ l c) = (l,c)
+mkPosToken t@(PT p _) = (posLineCol p, prToken t)
+
+prToken t = case t of
+ PT _ (TS s) -> s
+ PT _ (TI s) -> s
+ PT _ (TV s) -> s
+ PT _ (TD s) -> s
+ PT _ (TC s) -> s
+
+ _ -> show t
+
+data BTree = N | B String Tok BTree BTree deriving (Show)
+
+eitherResIdent :: (String -> Tok) -> String -> Tok
+eitherResIdent tv s = treeFind resWords
+ where
+ treeFind N = tv s
+ treeFind (B a t left right) | s < a = treeFind left
+ | s > a = treeFind right
+ | s == a = t
+
+resWords = b "import" (b "derive" (b "case" (b "Type" N N) (b "data" N N)) (b "else" (b "do" N N) (b "if" N N))) (b "rec" (b "let" (b "in" N N) (b "of" N N)) (b "then" (b "sig" N N) (b "where" N N)))
+ where b s = B s (TS s)
+
+unescapeInitTail :: String -> String
+unescapeInitTail = unesc . tail where
+ unesc s = case s of
+ '\\':c:cs | elem c ['\"', '\\', '\''] -> c : unesc cs
+ '\\':'n':cs -> '\n' : unesc cs
+ '\\':'t':cs -> '\t' : unesc cs
+ '"':[] -> []
+ c:cs -> c : unesc cs
+ _ -> []
+
+-------------------------------------------------------------------
+-- Alex wrapper code.
+-- A modified "posn" wrapper.
+-------------------------------------------------------------------
+
+data Posn = Pn !Int !Int !Int
+ deriving (Eq, Show,Ord)
+
+alexStartPos :: Posn
+alexStartPos = Pn 0 1 1
+
+alexMove :: Posn -> Char -> Posn
+alexMove (Pn a l c) '\t' = Pn (a+1) l (((c+7) `div` 8)*8+1)
+alexMove (Pn a l c) '\n' = Pn (a+1) (l+1) 1
+alexMove (Pn a l c) _ = Pn (a+1) l (c+1)
+
+type AlexInput = (Posn, -- current position,
+ Char, -- previous char
+ String) -- current input string
+
+tokens :: String -> [Token]
+tokens str = go (alexStartPos, '\n', str)
+ where
+ go :: (Posn, Char, String) -> [Token]
+ go inp@(pos, _, str) =
+ case alexScan inp 0 of
+ AlexEOF -> []
+ AlexError (pos, _, _) -> fail $ show pos ++ ": lexical error"
+ AlexSkip inp' len -> go inp'
+ AlexToken inp' len act -> act pos (take len str) : (go inp')
+
+alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
+alexGetChar (p, c, []) = Nothing
+alexGetChar (p, _, (c:s)) =
+ let p' = alexMove p c
+ in p' `seq` Just (c, (p', c, s))
+
+alexInputPrevChar :: AlexInput -> Char
+alexInputPrevChar (p, c, s) = c
+}
diff --git a/src-2.9/Transfer/Syntax/Par.hs b/src-2.9/Transfer/Syntax/Par.hs
new file mode 100644
index 000000000..bd83f0a87
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Par.hs
@@ -0,0 +1,1822 @@
+{-# OPTIONS -fglasgow-exts -cpp #-}
+{-# OPTIONS -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
+module Transfer.Syntax.Par where
+import Transfer.Syntax.Abs
+import Transfer.Syntax.Lex
+import Transfer.ErrM
+import Array
+#if __GLASGOW_HASKELL__ >= 503
+import GHC.Exts
+#else
+import GlaExts
+#endif
+
+-- parser produced by Happy Version 1.15
+
+newtype HappyAbsSyn = HappyAbsSyn (() -> ())
+happyIn5 :: (Ident) -> (HappyAbsSyn )
+happyIn5 x = unsafeCoerce# x
+{-# INLINE happyIn5 #-}
+happyOut5 :: (HappyAbsSyn ) -> (Ident)
+happyOut5 x = unsafeCoerce# x
+{-# INLINE happyOut5 #-}
+happyIn6 :: (String) -> (HappyAbsSyn )
+happyIn6 x = unsafeCoerce# x
+{-# INLINE happyIn6 #-}
+happyOut6 :: (HappyAbsSyn ) -> (String)
+happyOut6 x = unsafeCoerce# x
+{-# INLINE happyOut6 #-}
+happyIn7 :: (Integer) -> (HappyAbsSyn )
+happyIn7 x = unsafeCoerce# x
+{-# INLINE happyIn7 #-}
+happyOut7 :: (HappyAbsSyn ) -> (Integer)
+happyOut7 x = unsafeCoerce# x
+{-# INLINE happyOut7 #-}
+happyIn8 :: (Double) -> (HappyAbsSyn )
+happyIn8 x = unsafeCoerce# x
+{-# INLINE happyIn8 #-}
+happyOut8 :: (HappyAbsSyn ) -> (Double)
+happyOut8 x = unsafeCoerce# x
+{-# INLINE happyOut8 #-}
+happyIn9 :: (Module) -> (HappyAbsSyn )
+happyIn9 x = unsafeCoerce# x
+{-# INLINE happyIn9 #-}
+happyOut9 :: (HappyAbsSyn ) -> (Module)
+happyOut9 x = unsafeCoerce# x
+{-# INLINE happyOut9 #-}
+happyIn10 :: (Import) -> (HappyAbsSyn )
+happyIn10 x = unsafeCoerce# x
+{-# INLINE happyIn10 #-}
+happyOut10 :: (HappyAbsSyn ) -> (Import)
+happyOut10 x = unsafeCoerce# x
+{-# INLINE happyOut10 #-}
+happyIn11 :: ([Import]) -> (HappyAbsSyn )
+happyIn11 x = unsafeCoerce# x
+{-# INLINE happyIn11 #-}
+happyOut11 :: (HappyAbsSyn ) -> ([Import])
+happyOut11 x = unsafeCoerce# x
+{-# INLINE happyOut11 #-}
+happyIn12 :: (Decl) -> (HappyAbsSyn )
+happyIn12 x = unsafeCoerce# x
+{-# INLINE happyIn12 #-}
+happyOut12 :: (HappyAbsSyn ) -> (Decl)
+happyOut12 x = unsafeCoerce# x
+{-# INLINE happyOut12 #-}
+happyIn13 :: ([Decl]) -> (HappyAbsSyn )
+happyIn13 x = unsafeCoerce# x
+{-# INLINE happyIn13 #-}
+happyOut13 :: (HappyAbsSyn ) -> ([Decl])
+happyOut13 x = unsafeCoerce# x
+{-# INLINE happyOut13 #-}
+happyIn14 :: (ConsDecl) -> (HappyAbsSyn )
+happyIn14 x = unsafeCoerce# x
+{-# INLINE happyIn14 #-}
+happyOut14 :: (HappyAbsSyn ) -> (ConsDecl)
+happyOut14 x = unsafeCoerce# x
+{-# INLINE happyOut14 #-}
+happyIn15 :: ([ConsDecl]) -> (HappyAbsSyn )
+happyIn15 x = unsafeCoerce# x
+{-# INLINE happyIn15 #-}
+happyOut15 :: (HappyAbsSyn ) -> ([ConsDecl])
+happyOut15 x = unsafeCoerce# x
+{-# INLINE happyOut15 #-}
+happyIn16 :: (Guard) -> (HappyAbsSyn )
+happyIn16 x = unsafeCoerce# x
+{-# INLINE happyIn16 #-}
+happyOut16 :: (HappyAbsSyn ) -> (Guard)
+happyOut16 x = unsafeCoerce# x
+{-# INLINE happyOut16 #-}
+happyIn17 :: (Pattern) -> (HappyAbsSyn )
+happyIn17 x = unsafeCoerce# x
+{-# INLINE happyIn17 #-}
+happyOut17 :: (HappyAbsSyn ) -> (Pattern)
+happyOut17 x = unsafeCoerce# x
+{-# INLINE happyOut17 #-}
+happyIn18 :: (Pattern) -> (HappyAbsSyn )
+happyIn18 x = unsafeCoerce# x
+{-# INLINE happyIn18 #-}
+happyOut18 :: (HappyAbsSyn ) -> (Pattern)
+happyOut18 x = unsafeCoerce# x
+{-# INLINE happyOut18 #-}
+happyIn19 :: (Pattern) -> (HappyAbsSyn )
+happyIn19 x = unsafeCoerce# x
+{-# INLINE happyIn19 #-}
+happyOut19 :: (HappyAbsSyn ) -> (Pattern)
+happyOut19 x = unsafeCoerce# x
+{-# INLINE happyOut19 #-}
+happyIn20 :: (Pattern) -> (HappyAbsSyn )
+happyIn20 x = unsafeCoerce# x
+{-# INLINE happyIn20 #-}
+happyOut20 :: (HappyAbsSyn ) -> (Pattern)
+happyOut20 x = unsafeCoerce# x
+{-# INLINE happyOut20 #-}
+happyIn21 :: (CommaPattern) -> (HappyAbsSyn )
+happyIn21 x = unsafeCoerce# x
+{-# INLINE happyIn21 #-}
+happyOut21 :: (HappyAbsSyn ) -> (CommaPattern)
+happyOut21 x = unsafeCoerce# x
+{-# INLINE happyOut21 #-}
+happyIn22 :: ([CommaPattern]) -> (HappyAbsSyn )
+happyIn22 x = unsafeCoerce# x
+{-# INLINE happyIn22 #-}
+happyOut22 :: (HappyAbsSyn ) -> ([CommaPattern])
+happyOut22 x = unsafeCoerce# x
+{-# INLINE happyOut22 #-}
+happyIn23 :: ([Pattern]) -> (HappyAbsSyn )
+happyIn23 x = unsafeCoerce# x
+{-# INLINE happyIn23 #-}
+happyOut23 :: (HappyAbsSyn ) -> ([Pattern])
+happyOut23 x = unsafeCoerce# x
+{-# INLINE happyOut23 #-}
+happyIn24 :: (FieldPattern) -> (HappyAbsSyn )
+happyIn24 x = unsafeCoerce# x
+{-# INLINE happyIn24 #-}
+happyOut24 :: (HappyAbsSyn ) -> (FieldPattern)
+happyOut24 x = unsafeCoerce# x
+{-# INLINE happyOut24 #-}
+happyIn25 :: ([FieldPattern]) -> (HappyAbsSyn )
+happyIn25 x = unsafeCoerce# x
+{-# INLINE happyIn25 #-}
+happyOut25 :: (HappyAbsSyn ) -> ([FieldPattern])
+happyOut25 x = unsafeCoerce# x
+{-# INLINE happyOut25 #-}
+happyIn26 :: (Exp) -> (HappyAbsSyn )
+happyIn26 x = unsafeCoerce# x
+{-# INLINE happyIn26 #-}
+happyOut26 :: (HappyAbsSyn ) -> (Exp)
+happyOut26 x = unsafeCoerce# x
+{-# INLINE happyOut26 #-}
+happyIn27 :: (VarOrWild) -> (HappyAbsSyn )
+happyIn27 x = unsafeCoerce# x
+{-# INLINE happyIn27 #-}
+happyOut27 :: (HappyAbsSyn ) -> (VarOrWild)
+happyOut27 x = unsafeCoerce# x
+{-# INLINE happyOut27 #-}
+happyIn28 :: (Exp) -> (HappyAbsSyn )
+happyIn28 x = unsafeCoerce# x
+{-# INLINE happyIn28 #-}
+happyOut28 :: (HappyAbsSyn ) -> (Exp)
+happyOut28 x = unsafeCoerce# x
+{-# INLINE happyOut28 #-}
+happyIn29 :: (LetDef) -> (HappyAbsSyn )
+happyIn29 x = unsafeCoerce# x
+{-# INLINE happyIn29 #-}
+happyOut29 :: (HappyAbsSyn ) -> (LetDef)
+happyOut29 x = unsafeCoerce# x
+{-# INLINE happyOut29 #-}
+happyIn30 :: ([LetDef]) -> (HappyAbsSyn )
+happyIn30 x = unsafeCoerce# x
+{-# INLINE happyIn30 #-}
+happyOut30 :: (HappyAbsSyn ) -> ([LetDef])
+happyOut30 x = unsafeCoerce# x
+{-# INLINE happyOut30 #-}
+happyIn31 :: (Case) -> (HappyAbsSyn )
+happyIn31 x = unsafeCoerce# x
+{-# INLINE happyIn31 #-}
+happyOut31 :: (HappyAbsSyn ) -> (Case)
+happyOut31 x = unsafeCoerce# x
+{-# INLINE happyOut31 #-}
+happyIn32 :: ([Case]) -> (HappyAbsSyn )
+happyIn32 x = unsafeCoerce# x
+{-# INLINE happyIn32 #-}
+happyOut32 :: (HappyAbsSyn ) -> ([Case])
+happyOut32 x = unsafeCoerce# x
+{-# INLINE happyOut32 #-}
+happyIn33 :: (Bind) -> (HappyAbsSyn )
+happyIn33 x = unsafeCoerce# x
+{-# INLINE happyIn33 #-}
+happyOut33 :: (HappyAbsSyn ) -> (Bind)
+happyOut33 x = unsafeCoerce# x
+{-# INLINE happyOut33 #-}
+happyIn34 :: ([Bind]) -> (HappyAbsSyn )
+happyIn34 x = unsafeCoerce# x
+{-# INLINE happyIn34 #-}
+happyOut34 :: (HappyAbsSyn ) -> ([Bind])
+happyOut34 x = unsafeCoerce# x
+{-# INLINE happyOut34 #-}
+happyIn35 :: (Exp) -> (HappyAbsSyn )
+happyIn35 x = unsafeCoerce# x
+{-# INLINE happyIn35 #-}
+happyOut35 :: (HappyAbsSyn ) -> (Exp)
+happyOut35 x = unsafeCoerce# x
+{-# INLINE happyOut35 #-}
+happyIn36 :: (Exp) -> (HappyAbsSyn )
+happyIn36 x = unsafeCoerce# x
+{-# INLINE happyIn36 #-}
+happyOut36 :: (HappyAbsSyn ) -> (Exp)
+happyOut36 x = unsafeCoerce# x
+{-# INLINE happyOut36 #-}
+happyIn37 :: (Exp) -> (HappyAbsSyn )
+happyIn37 x = unsafeCoerce# x
+{-# INLINE happyIn37 #-}
+happyOut37 :: (HappyAbsSyn ) -> (Exp)
+happyOut37 x = unsafeCoerce# x
+{-# INLINE happyOut37 #-}
+happyIn38 :: (Exp) -> (HappyAbsSyn )
+happyIn38 x = unsafeCoerce# x
+{-# INLINE happyIn38 #-}
+happyOut38 :: (HappyAbsSyn ) -> (Exp)
+happyOut38 x = unsafeCoerce# x
+{-# INLINE happyOut38 #-}
+happyIn39 :: (Exp) -> (HappyAbsSyn )
+happyIn39 x = unsafeCoerce# x
+{-# INLINE happyIn39 #-}
+happyOut39 :: (HappyAbsSyn ) -> (Exp)
+happyOut39 x = unsafeCoerce# x
+{-# INLINE happyOut39 #-}
+happyIn40 :: (Exp) -> (HappyAbsSyn )
+happyIn40 x = unsafeCoerce# x
+{-# INLINE happyIn40 #-}
+happyOut40 :: (HappyAbsSyn ) -> (Exp)
+happyOut40 x = unsafeCoerce# x
+{-# INLINE happyOut40 #-}
+happyIn41 :: (Exp) -> (HappyAbsSyn )
+happyIn41 x = unsafeCoerce# x
+{-# INLINE happyIn41 #-}
+happyOut41 :: (HappyAbsSyn ) -> (Exp)
+happyOut41 x = unsafeCoerce# x
+{-# INLINE happyOut41 #-}
+happyIn42 :: (Exp) -> (HappyAbsSyn )
+happyIn42 x = unsafeCoerce# x
+{-# INLINE happyIn42 #-}
+happyOut42 :: (HappyAbsSyn ) -> (Exp)
+happyOut42 x = unsafeCoerce# x
+{-# INLINE happyOut42 #-}
+happyIn43 :: (Exp) -> (HappyAbsSyn )
+happyIn43 x = unsafeCoerce# x
+{-# INLINE happyIn43 #-}
+happyOut43 :: (HappyAbsSyn ) -> (Exp)
+happyOut43 x = unsafeCoerce# x
+{-# INLINE happyOut43 #-}
+happyIn44 :: (Exp) -> (HappyAbsSyn )
+happyIn44 x = unsafeCoerce# x
+{-# INLINE happyIn44 #-}
+happyOut44 :: (HappyAbsSyn ) -> (Exp)
+happyOut44 x = unsafeCoerce# x
+{-# INLINE happyOut44 #-}
+happyIn45 :: (Exp) -> (HappyAbsSyn )
+happyIn45 x = unsafeCoerce# x
+{-# INLINE happyIn45 #-}
+happyOut45 :: (HappyAbsSyn ) -> (Exp)
+happyOut45 x = unsafeCoerce# x
+{-# INLINE happyOut45 #-}
+happyIn46 :: (FieldType) -> (HappyAbsSyn )
+happyIn46 x = unsafeCoerce# x
+{-# INLINE happyIn46 #-}
+happyOut46 :: (HappyAbsSyn ) -> (FieldType)
+happyOut46 x = unsafeCoerce# x
+{-# INLINE happyOut46 #-}
+happyIn47 :: ([FieldType]) -> (HappyAbsSyn )
+happyIn47 x = unsafeCoerce# x
+{-# INLINE happyIn47 #-}
+happyOut47 :: (HappyAbsSyn ) -> ([FieldType])
+happyOut47 x = unsafeCoerce# x
+{-# INLINE happyOut47 #-}
+happyIn48 :: (FieldValue) -> (HappyAbsSyn )
+happyIn48 x = unsafeCoerce# x
+{-# INLINE happyIn48 #-}
+happyOut48 :: (HappyAbsSyn ) -> (FieldValue)
+happyOut48 x = unsafeCoerce# x
+{-# INLINE happyOut48 #-}
+happyIn49 :: ([FieldValue]) -> (HappyAbsSyn )
+happyIn49 x = unsafeCoerce# x
+{-# INLINE happyIn49 #-}
+happyOut49 :: (HappyAbsSyn ) -> ([FieldValue])
+happyOut49 x = unsafeCoerce# x
+{-# INLINE happyOut49 #-}
+happyIn50 :: (Exp) -> (HappyAbsSyn )
+happyIn50 x = unsafeCoerce# x
+{-# INLINE happyIn50 #-}
+happyOut50 :: (HappyAbsSyn ) -> (Exp)
+happyOut50 x = unsafeCoerce# x
+{-# INLINE happyOut50 #-}
+happyIn51 :: ([Exp]) -> (HappyAbsSyn )
+happyIn51 x = unsafeCoerce# x
+{-# INLINE happyIn51 #-}
+happyOut51 :: (HappyAbsSyn ) -> ([Exp])
+happyOut51 x = unsafeCoerce# x
+{-# INLINE happyOut51 #-}
+happyInTok :: Token -> (HappyAbsSyn )
+happyInTok x = unsafeCoerce# x
+{-# INLINE happyInTok #-}
+happyOutTok :: (HappyAbsSyn ) -> Token
+happyOutTok x = unsafeCoerce# x
+{-# INLINE happyOutTok #-}
+
+happyActOffsets :: HappyAddr
+happyActOffsets = HappyA# "\x00\x00\x48\x03\x90\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x84\x01\xa8\x01\x34\x00\x00\x00\xaf\x01\xa1\x01\x6c\x00\x9f\x00\xb6\x00\x00\x00\x64\x03\x7d\x01\x00\x00\x00\x00\xd4\x02\xb8\x02\xf9\xff\x50\x03\x00\x00\x00\x00\x48\x03\xb1\x01\x48\x03\xa5\x01\xa0\x01\x9e\x01\x00\x00\x00\x00\x00\x00\x68\x01\x73\x01\x9a\x01\x7d\x00\x5e\x01\x5e\x01\x5e\x01\x5e\x01\x5b\x01\x00\x00\x5c\x01\x00\x00\x48\x03\x00\x00\x75\x01\x00\x00\x78\x01\x77\x01\x00\x00\x03\x00\x41\x00\x80\x01\x45\x01\x51\x01\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x50\x03\x48\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb6\x00\xb6\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x48\x03\x00\x00\x48\x03\x00\x00\x48\x03\x34\x03\x6c\x01\xa4\x02\x18\x03\x67\x01\x6a\x01\x66\x01\x58\x01\x57\x01\x65\x01\x54\x01\x52\x01\x4e\x01\x00\x00\x4f\x01\x3e\x01\x1f\x01\x1f\x01\x00\x00\x1f\x01\x3b\x01\x00\x00\x8c\x02\x18\x03\x00\x00\x13\x01\x18\x03\x00\x00\x13\x01\x18\x03\x10\x01\x08\x01\x18\x03\x04\x01\x34\x01\x26\x01\x20\x01\x85\x03\x00\x00\x00\x00\x1c\x01\x1a\x01\x11\x01\x00\x00\x85\x03\x00\x00\x00\x00\x19\x01\x17\x01\x0a\x01\x00\x00\x0c\x01\x07\x01\x85\x03\x7e\x03\x00\x00\x05\x01\x00\x00\x18\x03\x00\x00\x04\x03\x00\x00\x00\x00\x04\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x01\x00\x00\x04\x03\xe8\x02\x00\x00\xd6\x00\x00\x00\xe8\x02\x00\x00\x00\x00\x00\x00\xd4\x00\x00\x00\xec\x00\xe6\x00\x00\x00\xea\x00\xe2\x00\x00\x00\x85\x03\x85\x03\x85\x03\xde\x00\x00\x00\xe8\x02\x00\x00\x85\x03\xe8\x02\x00\x00\x00\x00\x00\x00\x85\x03\x00\x00\x00\x00\x85\x03\xe9\x00\xdf\x00\xe8\x00\x00\x00\xd8\x00\xa8\x00\x00\x00\xa8\x00\x85\x03\x00\x00\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc5\x00\xbb\x00\xa5\x00\x00\x00\x8c\x00\xe8\x02\x00\x00\x00\x00\x00\x00"#
+
+happyGotoOffsets :: HappyAddr
+happyGotoOffsets = HappyA# "\xbc\x00\x21\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6b\x04\x00\x00\x00\x00\x00\x00\x78\x00\x35\x00\x17\x00\x67\x04\x00\x00\x00\x00\x08\x02\x00\x00\xef\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0d\x00\x00\x00\x0a\x00\x95\x00\x60\x00\x19\x00\x67\x00\x00\x00\x6f\x00\x00\x00\x00\x00\xd6\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8b\x00\x00\x00\x63\x04\x5f\x04\x5b\x04\x29\x04\x57\x04\x52\x04\x22\x04\x1b\x04\x14\x04\x0d\x04\xe4\x03\xdd\x03\xd6\x03\xcd\x03\xa4\x03\x9a\x03\xbd\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x01\x00\x00\x1b\x00\x00\x00\x01\x00\x81\x02\x00\x00\x4f\x00\x8b\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5a\x00\x00\x00\x61\x00\x4d\x00\x00\x00\x0e\x00\x00\x00\x00\x00\xe5\x04\x72\x01\x00\x00\x5e\x00\x59\x01\x00\x00\x08\x00\x40\x01\x00\x00\x13\x00\x27\x01\x00\x00\x00\x00\x00\x00\x00\x00\x98\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x9b\x02\x00\x00\x00\x00\x26\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xcc\x04\xba\x04\x00\x00\x00\x00\x00\x00\x0e\x01\x00\x00\x69\x02\x00\x00\x00\x00\x51\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x39\x02\xf5\x00\x00\x00\x00\x00\x00\x00\xdc\x00\x00\x00\x00\x00\x00\x00\x90\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x94\x04\x9f\x03\xd5\x04\x00\x00\xf7\xff\xc3\x00\x00\x00\x0b\x00\xaa\x00\x00\x00\x00\x00\x00\x00\xb4\x04\x00\x00\x00\x00\x9c\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5f\x00\x00\x00\x6a\x00\xd1\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\x91\x00\x00\x00\x00\x00\x00\x00"#
+
+happyDefActions :: HappyAddr
+happyDefActions = HappyA# "\xf7\xff\x00\x00\x00\x00\xfd\xff\x98\xff\x96\xff\x95\xff\x94\xff\x00\x00\xcf\xff\x89\xff\xb8\xff\xb6\xff\xb4\xff\xad\xff\xab\xff\xa8\xff\xa4\xff\xa2\xff\xa0\xff\x9e\xff\xc7\xff\x00\x00\x00\x00\x00\x00\x00\x00\x93\xff\x97\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfc\xff\xfb\xff\xfa\xff\x00\x00\xf1\xff\x00\x00\xf9\xff\x00\x00\x90\xff\x8c\xff\xc5\xff\x00\x00\xbc\xff\x00\x00\xa3\xff\x00\x00\xce\xff\x00\x00\xcd\xff\x88\xff\x00\x00\x9b\xff\x98\xff\x00\x00\x00\x00\x00\x00\xa1\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd0\xff\xb9\xff\xba\xff\xb7\xff\xb5\xff\xae\xff\xaf\xff\xb0\xff\xb1\xff\xb2\xff\xb3\xff\xa9\xff\xaa\xff\xac\xff\xa5\xff\xa6\xff\xa7\xff\x9f\xff\x00\x00\x92\xff\x00\x00\x9a\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc4\xff\x00\x00\x00\x00\x8b\xff\x00\x00\x00\x00\x8f\xff\x00\x00\xf8\xff\xd7\xff\x00\x00\x00\x00\x00\x00\xf6\xff\x00\x00\x00\x00\xf0\xff\xea\xff\x00\x00\x9d\xff\x90\xff\x00\x00\x9c\xff\x8c\xff\x00\x00\x00\x00\xc5\xff\x00\x00\x00\x00\xbd\xff\x00\x00\x00\x00\xc1\xff\xcc\xff\x87\xff\x00\x00\x00\x00\x00\x00\x99\xff\xdd\xff\xdf\xff\xde\xff\xea\xff\xe8\xff\xe6\xff\xe4\xff\xc0\xff\x00\x00\x00\x00\x00\x00\xdc\xff\x00\x00\xbb\xff\x00\x00\xc8\xff\x00\x00\xc6\xff\xc3\xff\x00\x00\x8d\xff\x8a\xff\x91\xff\x8e\xff\xf4\xff\xdd\xff\x00\x00\xd6\xff\x00\x00\x00\x00\xf2\xff\x00\x00\xeb\xff\x00\x00\xcb\xff\xc9\xff\xbe\xff\xd4\xff\xda\xff\xd9\xff\x00\x00\xe2\xff\xda\xff\x00\x00\xca\xff\xc1\xff\x00\x00\x00\x00\x00\x00\xd7\xff\x00\x00\xd1\xff\xe5\xff\x00\x00\xe9\xff\xe7\xff\xbf\xff\x00\x00\xdb\xff\xe1\xff\x00\x00\x00\x00\xd3\xff\x00\x00\xf3\xff\x00\x00\xee\xff\xe3\xff\xd4\xff\x00\x00\xd8\xff\x00\x00\xc2\xff\xe0\xff\xd5\xff\xd2\xff\x00\x00\xed\xff\x00\x00\xf5\xff\xee\xff\x00\x00\xef\xff\xec\xff"#
+
+happyCheck :: HappyAddr
+happyCheck = HappyA# "\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x02\x00\x00\x00\x0e\x00\x00\x00\x12\x00\x00\x00\x00\x00\x01\x00\x02\x00\x00\x00\x09\x00\x0a\x00\x07\x00\x05\x00\x00\x00\x11\x00\x08\x00\x15\x00\x00\x00\x17\x00\x00\x00\x0f\x00\x00\x00\x01\x00\x02\x00\x03\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x31\x00\x18\x00\x19\x00\x16\x00\x2d\x00\x2e\x00\x15\x00\x0b\x00\x17\x00\x2b\x00\x2c\x00\x00\x00\x01\x00\x02\x00\x03\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x2b\x00\x2c\x00\x12\x00\x13\x00\x2d\x00\x2e\x00\x15\x00\x0a\x00\x17\x00\x00\x00\x0d\x00\x00\x00\x01\x00\x02\x00\x03\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2d\x00\x2e\x00\x15\x00\x16\x00\x17\x00\x00\x00\x09\x00\x0a\x00\x00\x00\x1c\x00\x12\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x00\x00\x01\x00\x02\x00\x03\x00\x2d\x00\x13\x00\x14\x00\x18\x00\x19\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x29\x00\x2a\x00\x29\x00\x2a\x00\x00\x00\x1d\x00\x15\x00\x16\x00\x17\x00\x00\x00\x00\x00\x01\x00\x02\x00\x03\x00\x00\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x24\x00\x25\x00\x13\x00\x14\x00\x2d\x00\x15\x00\x08\x00\x17\x00\x04\x00\x00\x00\x01\x00\x02\x00\x03\x00\x31\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x1b\x00\x1c\x00\x01\x00\x31\x00\x2d\x00\x15\x00\x04\x00\x17\x00\x06\x00\x00\x00\x01\x00\x02\x00\x03\x00\x02\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x1d\x00\x1e\x00\x1f\x00\x0a\x00\x2d\x00\x15\x00\x31\x00\x17\x00\x03\x00\x00\x00\x01\x00\x02\x00\x03\x00\x01\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x04\x00\x0f\x00\x05\x00\x0d\x00\x2d\x00\x15\x00\x0c\x00\x17\x00\x0a\x00\x00\x00\x01\x00\x02\x00\x03\x00\x0d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x31\x00\x30\x00\x05\x00\x03\x00\x2d\x00\x15\x00\x04\x00\x17\x00\x01\x00\x00\x00\x01\x00\x02\x00\x03\x00\x08\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x07\x00\x06\x00\x0f\x00\x01\x00\x2d\x00\x15\x00\x0a\x00\x17\x00\x0a\x00\x00\x00\x01\x00\x02\x00\x03\x00\x27\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x11\x00\x04\x00\x31\x00\x2a\x00\x2d\x00\x15\x00\x02\x00\x17\x00\x01\x00\x00\x00\x01\x00\x02\x00\x03\x00\x31\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x31\x00\x02\x00\x04\x00\x01\x00\x2d\x00\x15\x00\x02\x00\x17\x00\x01\x00\x00\x00\x01\x00\x02\x00\x03\x00\x05\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x04\x00\x04\x00\x01\x00\x05\x00\x2d\x00\x15\x00\x03\x00\x17\x00\x20\x00\x00\x00\x01\x00\x02\x00\x03\x00\x31\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x02\x00\x0c\x00\x0f\x00\x0d\x00\x2d\x00\x15\x00\x2c\x00\x17\x00\x2f\x00\x00\x00\x01\x00\x02\x00\x03\x00\x31\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x01\x00\x29\x00\x20\x00\x36\x00\x2d\x00\x15\x00\x03\x00\x17\x00\x03\x00\x00\x00\x01\x00\x02\x00\x03\x00\x03\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x03\x00\x14\x00\x07\x00\x0f\x00\x2d\x00\x15\x00\x36\x00\x17\x00\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x31\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\x15\x00\xff\xff\x17\x00\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\x15\x00\xff\xff\x17\x00\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\x15\x00\xff\xff\x17\x00\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\x15\x00\xff\xff\x17\x00\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\x15\x00\xff\xff\x17\x00\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\xff\xff\x17\x00\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\xff\xff\x17\x00\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\xff\xff\x17\x00\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x06\x00\xff\xff\xff\xff\x09\x00\x2d\x00\x0b\x00\x17\x00\xff\xff\x0e\x00\x00\x00\x01\x00\x02\x00\xff\xff\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x0f\x00\xff\xff\xff\xff\x09\x00\x2d\x00\x0b\x00\xff\xff\xff\xff\x0e\x00\xff\xff\x10\x00\xff\xff\xff\xff\xff\xff\xff\xff\x2d\x00\xff\xff\xff\xff\xff\xff\x31\x00\x32\x00\x33\x00\x1c\x00\x09\x00\xff\xff\x0b\x00\x0c\x00\x21\x00\x22\x00\x23\x00\x10\x00\xff\xff\x26\x00\xff\xff\x28\x00\xff\xff\xff\xff\x2b\x00\xff\xff\x2d\x00\x2e\x00\xff\xff\x1c\x00\x31\x00\x32\x00\x33\x00\x34\x00\x21\x00\x22\x00\x23\x00\xff\xff\x09\x00\x26\x00\x0b\x00\x28\x00\xff\xff\x0e\x00\x2b\x00\x10\x00\x2d\x00\x2e\x00\xff\xff\xff\xff\x31\x00\x32\x00\x33\x00\x34\x00\xff\xff\xff\xff\xff\xff\x1c\x00\x09\x00\xff\xff\x0b\x00\xff\xff\x21\x00\x22\x00\x23\x00\x10\x00\xff\xff\x26\x00\xff\xff\x28\x00\xff\xff\xff\xff\x2b\x00\xff\xff\x2d\x00\x2e\x00\xff\xff\x1c\x00\x31\x00\x32\x00\x33\x00\x34\x00\x21\x00\x22\x00\x23\x00\xff\xff\x09\x00\x26\x00\x0b\x00\x28\x00\xff\xff\xff\xff\x2b\x00\x10\x00\x2d\x00\x2e\x00\xff\xff\xff\xff\x31\x00\x32\x00\x33\x00\x34\x00\xff\xff\xff\xff\xff\xff\x1c\x00\x09\x00\xff\xff\x0b\x00\xff\xff\x21\x00\x22\x00\x23\x00\x10\x00\xff\xff\x26\x00\xff\xff\x28\x00\xff\xff\xff\xff\x2b\x00\xff\xff\x2d\x00\x2e\x00\xff\xff\x1c\x00\x31\x00\x32\x00\x33\x00\x34\x00\x21\x00\x22\x00\x23\x00\xff\xff\x09\x00\x26\x00\x0b\x00\x28\x00\xff\xff\xff\xff\x2b\x00\x10\x00\x2d\x00\x2e\x00\xff\xff\xff\xff\x31\x00\x32\x00\x33\x00\x34\x00\xff\xff\xff\xff\xff\xff\x1c\x00\x09\x00\xff\xff\x0b\x00\xff\xff\x21\x00\x22\x00\x23\x00\x10\x00\x09\x00\x26\x00\x0b\x00\x28\x00\xff\xff\xff\xff\x2b\x00\xff\xff\x2d\x00\x2e\x00\xff\xff\x1c\x00\x31\x00\x32\x00\x33\x00\x34\x00\x21\x00\x22\x00\x23\x00\x1c\x00\x09\x00\x26\x00\x0b\x00\x28\x00\x21\x00\x22\x00\x2b\x00\xff\xff\x2d\x00\x2e\x00\xff\xff\xff\xff\x31\x00\x32\x00\x33\x00\x34\x00\x2d\x00\x2e\x00\xff\xff\xff\xff\x31\x00\x32\x00\x33\x00\x34\x00\x21\x00\x22\x00\x09\x00\xff\xff\x0b\x00\x0c\x00\xff\xff\x0e\x00\xff\xff\x09\x00\xff\xff\x0b\x00\x2d\x00\x2e\x00\x0e\x00\xff\xff\x31\x00\x32\x00\x33\x00\x34\x00\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\x00\x00\x01\x00\x02\x00\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\x2d\x00\x0d\x00\x0e\x00\x0f\x00\x31\x00\x32\x00\x33\x00\x2d\x00\xff\xff\xff\xff\xff\xff\x31\x00\x32\x00\x33\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\xff\xff\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\x00\x00\x01\x00\x02\x00\x03\x00\x00\x00\x01\x00\x02\x00\x03\x00\x00\x00\x01\x00\x02\x00\x03\x00\x00\x00\x01\x00\x02\x00\x03\x00\x00\x00\x01\x00\x02\x00\x03\x00\x00\x00\x01\x00\x02\x00\x03\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x25\x00\x26\x00\x27\x00\x28\x00\x25\x00\x26\x00\x27\x00\x28\x00\x25\x00\x26\x00\x27\x00\x28\x00\x25\x00\x26\x00\x27\x00\x28\x00\xff\xff\xff\xff\x27\x00\x28\x00\x00\x00\x01\x00\x02\x00\xff\xff\x00\x00\x01\x00\x02\x00\xff\xff\x00\x00\x01\x00\x02\x00\xff\xff\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x1a\x00\x1b\x00\xff\xff\xff\xff\x1a\x00\x1b\x00\x00\x00\x01\x00\x02\x00\xff\xff\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\xff\xff\xff\xff\xff\xff\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x00\x00\x01\x00\x02\x00\xff\xff\xff\xff\x00\x00\x01\x00\x02\x00\xff\xff\x00\x00\x01\x00\x02\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x00\x00\x01\x00\x02\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0b\x00\xff\xff\xff\xff\xff\xff\x0f\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
+
+happyTable :: HappyAddr
+happyTable = HappyA# "\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\xce\xff\xdd\x00\x35\x00\x6c\x00\xc5\x00\x73\x00\xaa\x00\x92\x00\x93\x00\xaf\x00\xde\x00\xe4\x00\x74\x00\x27\x00\x69\x00\xce\xff\x28\x00\x35\x00\x32\x00\x09\x00\x6c\x00\xac\x00\x04\x00\x05\x00\x06\x00\x07\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x04\x00\x6a\x00\xa3\x00\x33\x00\x15\x00\x8c\x00\x35\x00\xc1\x00\x09\x00\x6d\x00\xa6\x00\x04\x00\x05\x00\x06\x00\x07\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x6d\x00\x6e\x00\x4c\x00\x4d\x00\x15\x00\x8d\x00\x35\x00\x62\x00\x09\x00\x78\x00\x63\x00\x38\x00\x05\x00\x06\x00\x07\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x6f\x00\xdd\x00\x6f\x00\x79\x00\x15\x00\x36\x00\x87\x00\x88\x00\x09\x00\x69\x00\xde\x00\xdf\x00\xce\x00\x89\x00\x7b\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x38\x00\x05\x00\x06\x00\x07\x00\x15\x00\xcf\x00\xdc\x00\x6a\x00\x6b\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x70\x00\xa8\x00\x70\x00\x71\x00\x5f\x00\x67\x00\x39\x00\x3a\x00\x09\x00\xce\x00\x04\x00\x05\x00\x06\x00\x07\x00\x72\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x76\x00\x77\x00\xcf\x00\xd0\x00\x15\x00\xe3\x00\x41\x00\x09\x00\xe1\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x42\x00\x43\x00\xe2\x00\x04\x00\x15\x00\xd9\x00\x25\x00\x09\x00\x26\x00\x04\x00\x05\x00\x06\x00\x07\x00\xe3\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x3e\x00\x3f\x00\x40\x00\xdb\x00\x15\x00\xc4\x00\x04\x00\x09\x00\xd4\x00\x04\x00\x05\x00\x06\x00\x07\x00\xd6\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\xd5\x00\xc7\x00\xd7\x00\xcb\x00\x15\x00\xd1\x00\xcd\x00\x09\x00\xcc\x00\x04\x00\x05\x00\x06\x00\x07\x00\xce\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x04\x00\xd3\x00\xb3\x00\xb7\x00\x15\x00\xb0\x00\xbe\x00\x09\x00\xbf\x00\x04\x00\x05\x00\x06\x00\x07\x00\xc0\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\xc1\x00\xae\x00\xc4\x00\x9f\x00\x15\x00\xb5\x00\x90\x00\x09\x00\x91\x00\x04\x00\x05\x00\x06\x00\x07\x00\xa2\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\xa0\x00\xa1\x00\x04\x00\xa5\x00\x15\x00\xa2\x00\xaf\x00\x09\x00\x7b\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x04\x00\x7d\x00\x7e\x00\x7f\x00\x15\x00\xa5\x00\x80\x00\x09\x00\x82\x00\x04\x00\x05\x00\x06\x00\x07\x00\x83\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x81\x00\x84\x00\x85\x00\x86\x00\x15\x00\xa7\x00\x8b\x00\x09\x00\x3c\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x61\x00\x64\x00\x66\x00\x65\x00\x15\x00\xa9\x00\x67\x00\x09\x00\x69\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x78\x00\x2a\x00\x3c\x00\xff\xff\x15\x00\x86\x00\x2b\x00\x09\x00\x2c\x00\x04\x00\x05\x00\x06\x00\x07\x00\x2d\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x2f\x00\x4a\x00\x4b\x00\x4e\x00\x15\x00\x8e\x00\xff\xff\x09\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x4e\x00\x00\x00\x09\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x39\x00\x00\x00\x09\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x2d\x00\x00\x00\x09\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x2f\x00\x00\x00\x09\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x08\x00\x00\x00\x09\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\xb1\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\xb3\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\xb4\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\xae\x00\x00\x00\x00\x00\x9b\x00\x15\x00\x9c\x00\x8b\x00\x00\x00\x9d\x00\xaa\x00\x92\x00\x93\x00\x00\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\xc2\x00\x00\x00\x00\x00\x17\x00\x15\x00\x18\x00\x00\x00\x00\x00\x35\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x9e\x00\x00\x00\x00\x00\x00\x00\x04\x00\x23\x00\x24\x00\x1a\x00\x17\x00\x00\x00\x18\x00\x38\x00\x1b\x00\x1c\x00\x1d\x00\x19\x00\x00\x00\x1e\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x20\x00\x00\x00\x21\x00\x22\x00\x00\x00\x1a\x00\x04\x00\x23\x00\x24\x00\x25\x00\x1b\x00\x1c\x00\x1d\x00\x00\x00\x17\x00\x1e\x00\x18\x00\x1f\x00\x00\x00\x35\x00\x20\x00\x19\x00\x21\x00\x22\x00\x00\x00\x00\x00\x04\x00\x23\x00\x24\x00\x25\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x17\x00\x00\x00\x18\x00\x00\x00\x1b\x00\x1c\x00\x1d\x00\x19\x00\x00\x00\x1e\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x20\x00\x00\x00\x21\x00\x22\x00\x00\x00\x1a\x00\x04\x00\x23\x00\x24\x00\x25\x00\x1b\x00\x1c\x00\x1d\x00\x00\x00\x32\x00\x1e\x00\x18\x00\x1f\x00\x00\x00\x00\x00\x20\x00\x19\x00\x21\x00\x22\x00\x00\x00\x00\x00\x04\x00\x23\x00\x24\x00\x25\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x17\x00\x00\x00\x18\x00\x00\x00\x1b\x00\x1c\x00\x1d\x00\x19\x00\x00\x00\x1e\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x20\x00\x00\x00\x21\x00\x22\x00\x00\x00\x1a\x00\x04\x00\x23\x00\x24\x00\x25\x00\x1b\x00\x1c\x00\x1d\x00\x00\x00\x32\x00\x1e\x00\x18\x00\x1f\x00\x00\x00\x00\x00\x20\x00\x19\x00\x21\x00\x22\x00\x00\x00\x00\x00\x04\x00\x23\x00\x24\x00\x25\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x17\x00\x00\x00\x18\x00\x00\x00\x1b\x00\x1c\x00\x1d\x00\x19\x00\x32\x00\x1e\x00\x18\x00\x1f\x00\x00\x00\x00\x00\x20\x00\x00\x00\x21\x00\x22\x00\x00\x00\x1a\x00\x04\x00\x23\x00\x24\x00\x25\x00\x1b\x00\x1c\x00\x1d\x00\x1a\x00\x32\x00\x1e\x00\x18\x00\x1f\x00\x1b\x00\x1c\x00\x20\x00\x00\x00\x21\x00\x22\x00\x00\x00\x00\x00\x04\x00\x23\x00\x24\x00\x25\x00\x21\x00\x22\x00\x00\x00\x00\x00\x04\x00\x23\x00\x24\x00\x25\x00\x1b\x00\x1c\x00\x9b\x00\x00\x00\x9c\x00\xbb\x00\x00\x00\x9d\x00\x00\x00\x9b\x00\x00\x00\x9c\x00\x21\x00\x22\x00\x9d\x00\x00\x00\x04\x00\x23\x00\x24\x00\x25\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x91\x00\x92\x00\x93\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x9e\x00\xc8\x00\x96\x00\x97\x00\x04\x00\x23\x00\x24\x00\x9e\x00\x00\x00\x00\x00\x00\x00\x04\x00\x23\x00\x24\x00\x4f\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x50\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x51\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x52\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x53\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x54\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x55\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x56\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x57\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x58\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x5b\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x05\x00\x06\x00\x07\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x59\x00\x11\x00\x12\x00\x13\x00\x14\x00\x5a\x00\x11\x00\x12\x00\x13\x00\x14\x00\x5c\x00\x12\x00\x13\x00\x14\x00\x5d\x00\x12\x00\x13\x00\x14\x00\x5e\x00\x12\x00\x13\x00\x14\x00\x30\x00\x12\x00\x13\x00\x14\x00\x00\x00\x00\x00\x3c\x00\x14\x00\x91\x00\x92\x00\x93\x00\x00\x00\x91\x00\x92\x00\x93\x00\x00\x00\x91\x00\x92\x00\x93\x00\x00\x00\x94\x00\x95\x00\x96\x00\x97\x00\x94\x00\x95\x00\x96\x00\x97\x00\xb7\x00\x95\x00\x96\x00\x97\x00\xb8\x00\xd7\x00\x98\x00\xc9\x00\x00\x00\x00\x00\x98\x00\x99\x00\x91\x00\x92\x00\x93\x00\x00\x00\x00\x00\x00\x00\x91\x00\x92\x00\x93\x00\x00\x00\x00\x00\x00\x00\xb7\x00\x95\x00\x96\x00\x97\x00\xb8\x00\xd8\x00\xb7\x00\x95\x00\x96\x00\x97\x00\xb8\x00\xb9\x00\x91\x00\x92\x00\x93\x00\x00\x00\x00\x00\x91\x00\x92\x00\x93\x00\x00\x00\x91\x00\x92\x00\x93\x00\xbb\x00\x95\x00\x96\x00\x97\x00\xbc\x00\xdb\x00\x95\x00\x96\x00\x97\x00\xc7\x00\x95\x00\x96\x00\x97\x00\xaa\x00\x92\x00\x93\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xab\x00\x00\x00\x00\x00\x00\x00\xac\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
+
+happyReduceArr = array (2, 120) [
+ (2 , happyReduce_2),
+ (3 , happyReduce_3),
+ (4 , happyReduce_4),
+ (5 , happyReduce_5),
+ (6 , happyReduce_6),
+ (7 , happyReduce_7),
+ (8 , happyReduce_8),
+ (9 , happyReduce_9),
+ (10 , happyReduce_10),
+ (11 , happyReduce_11),
+ (12 , happyReduce_12),
+ (13 , happyReduce_13),
+ (14 , happyReduce_14),
+ (15 , happyReduce_15),
+ (16 , happyReduce_16),
+ (17 , happyReduce_17),
+ (18 , happyReduce_18),
+ (19 , happyReduce_19),
+ (20 , happyReduce_20),
+ (21 , happyReduce_21),
+ (22 , happyReduce_22),
+ (23 , happyReduce_23),
+ (24 , happyReduce_24),
+ (25 , happyReduce_25),
+ (26 , happyReduce_26),
+ (27 , happyReduce_27),
+ (28 , happyReduce_28),
+ (29 , happyReduce_29),
+ (30 , happyReduce_30),
+ (31 , happyReduce_31),
+ (32 , happyReduce_32),
+ (33 , happyReduce_33),
+ (34 , happyReduce_34),
+ (35 , happyReduce_35),
+ (36 , happyReduce_36),
+ (37 , happyReduce_37),
+ (38 , happyReduce_38),
+ (39 , happyReduce_39),
+ (40 , happyReduce_40),
+ (41 , happyReduce_41),
+ (42 , happyReduce_42),
+ (43 , happyReduce_43),
+ (44 , happyReduce_44),
+ (45 , happyReduce_45),
+ (46 , happyReduce_46),
+ (47 , happyReduce_47),
+ (48 , happyReduce_48),
+ (49 , happyReduce_49),
+ (50 , happyReduce_50),
+ (51 , happyReduce_51),
+ (52 , happyReduce_52),
+ (53 , happyReduce_53),
+ (54 , happyReduce_54),
+ (55 , happyReduce_55),
+ (56 , happyReduce_56),
+ (57 , happyReduce_57),
+ (58 , happyReduce_58),
+ (59 , happyReduce_59),
+ (60 , happyReduce_60),
+ (61 , happyReduce_61),
+ (62 , happyReduce_62),
+ (63 , happyReduce_63),
+ (64 , happyReduce_64),
+ (65 , happyReduce_65),
+ (66 , happyReduce_66),
+ (67 , happyReduce_67),
+ (68 , happyReduce_68),
+ (69 , happyReduce_69),
+ (70 , happyReduce_70),
+ (71 , happyReduce_71),
+ (72 , happyReduce_72),
+ (73 , happyReduce_73),
+ (74 , happyReduce_74),
+ (75 , happyReduce_75),
+ (76 , happyReduce_76),
+ (77 , happyReduce_77),
+ (78 , happyReduce_78),
+ (79 , happyReduce_79),
+ (80 , happyReduce_80),
+ (81 , happyReduce_81),
+ (82 , happyReduce_82),
+ (83 , happyReduce_83),
+ (84 , happyReduce_84),
+ (85 , happyReduce_85),
+ (86 , happyReduce_86),
+ (87 , happyReduce_87),
+ (88 , happyReduce_88),
+ (89 , happyReduce_89),
+ (90 , happyReduce_90),
+ (91 , happyReduce_91),
+ (92 , happyReduce_92),
+ (93 , happyReduce_93),
+ (94 , happyReduce_94),
+ (95 , happyReduce_95),
+ (96 , happyReduce_96),
+ (97 , happyReduce_97),
+ (98 , happyReduce_98),
+ (99 , happyReduce_99),
+ (100 , happyReduce_100),
+ (101 , happyReduce_101),
+ (102 , happyReduce_102),
+ (103 , happyReduce_103),
+ (104 , happyReduce_104),
+ (105 , happyReduce_105),
+ (106 , happyReduce_106),
+ (107 , happyReduce_107),
+ (108 , happyReduce_108),
+ (109 , happyReduce_109),
+ (110 , happyReduce_110),
+ (111 , happyReduce_111),
+ (112 , happyReduce_112),
+ (113 , happyReduce_113),
+ (114 , happyReduce_114),
+ (115 , happyReduce_115),
+ (116 , happyReduce_116),
+ (117 , happyReduce_117),
+ (118 , happyReduce_118),
+ (119 , happyReduce_119),
+ (120 , happyReduce_120)
+ ]
+
+happy_n_terms = 55 :: Int
+happy_n_nonterms = 47 :: Int
+
+happyReduce_2 = happySpecReduce_1 0# happyReduction_2
+happyReduction_2 happy_x_1
+ = case happyOutTok happy_x_1 of { (PT _ (TV happy_var_1)) ->
+ happyIn5
+ (Ident happy_var_1
+ )}
+
+happyReduce_3 = happySpecReduce_1 1# happyReduction_3
+happyReduction_3 happy_x_1
+ = case happyOutTok happy_x_1 of { (PT _ (TL happy_var_1)) ->
+ happyIn6
+ (happy_var_1
+ )}
+
+happyReduce_4 = happySpecReduce_1 2# happyReduction_4
+happyReduction_4 happy_x_1
+ = case happyOutTok happy_x_1 of { (PT _ (TI happy_var_1)) ->
+ happyIn7
+ ((read happy_var_1) :: Integer
+ )}
+
+happyReduce_5 = happySpecReduce_1 3# happyReduction_5
+happyReduction_5 happy_x_1
+ = case happyOutTok happy_x_1 of { (PT _ (TD happy_var_1)) ->
+ happyIn8
+ ((read happy_var_1) :: Double
+ )}
+
+happyReduce_6 = happySpecReduce_2 4# happyReduction_6
+happyReduction_6 happy_x_2
+ happy_x_1
+ = case happyOut11 happy_x_1 of { happy_var_1 ->
+ case happyOut13 happy_x_2 of { happy_var_2 ->
+ happyIn9
+ (Module (reverse happy_var_1) (reverse happy_var_2)
+ )}}
+
+happyReduce_7 = happySpecReduce_2 5# happyReduction_7
+happyReduction_7 happy_x_2
+ happy_x_1
+ = case happyOut5 happy_x_2 of { happy_var_2 ->
+ happyIn10
+ (Import happy_var_2
+ )}
+
+happyReduce_8 = happySpecReduce_0 6# happyReduction_8
+happyReduction_8 = happyIn11
+ ([]
+ )
+
+happyReduce_9 = happySpecReduce_3 6# happyReduction_9
+happyReduction_9 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut11 happy_x_1 of { happy_var_1 ->
+ case happyOut10 happy_x_2 of { happy_var_2 ->
+ happyIn11
+ (flip (:) happy_var_1 happy_var_2
+ )}}
+
+happyReduce_10 = happyReduce 8# 7# happyReduction_10
+happyReduction_10 (happy_x_8 `HappyStk`
+ happy_x_7 `HappyStk`
+ happy_x_6 `HappyStk`
+ happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut5 happy_x_2 of { happy_var_2 ->
+ case happyOut26 happy_x_4 of { happy_var_4 ->
+ case happyOut15 happy_x_7 of { happy_var_7 ->
+ happyIn12
+ (DataDecl happy_var_2 happy_var_4 happy_var_7
+ ) `HappyStk` happyRest}}}
+
+happyReduce_11 = happySpecReduce_3 7# happyReduction_11
+happyReduction_11 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ case happyOut26 happy_x_3 of { happy_var_3 ->
+ happyIn12
+ (TypeDecl happy_var_1 happy_var_3
+ )}}
+
+happyReduce_12 = happyReduce 5# 7# happyReduction_12
+happyReduction_12 (happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ case happyOut23 happy_x_2 of { happy_var_2 ->
+ case happyOut16 happy_x_3 of { happy_var_3 ->
+ case happyOut26 happy_x_5 of { happy_var_5 ->
+ happyIn12
+ (ValueDecl happy_var_1 (reverse happy_var_2) happy_var_3 happy_var_5
+ ) `HappyStk` happyRest}}}}
+
+happyReduce_13 = happySpecReduce_3 7# happyReduction_13
+happyReduction_13 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut5 happy_x_2 of { happy_var_2 ->
+ case happyOut5 happy_x_3 of { happy_var_3 ->
+ happyIn12
+ (DeriveDecl happy_var_2 happy_var_3
+ )}}
+
+happyReduce_14 = happySpecReduce_0 8# happyReduction_14
+happyReduction_14 = happyIn13
+ ([]
+ )
+
+happyReduce_15 = happySpecReduce_3 8# happyReduction_15
+happyReduction_15 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut13 happy_x_1 of { happy_var_1 ->
+ case happyOut12 happy_x_2 of { happy_var_2 ->
+ happyIn13
+ (flip (:) happy_var_1 happy_var_2
+ )}}
+
+happyReduce_16 = happySpecReduce_3 9# happyReduction_16
+happyReduction_16 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ case happyOut26 happy_x_3 of { happy_var_3 ->
+ happyIn14
+ (ConsDecl happy_var_1 happy_var_3
+ )}}
+
+happyReduce_17 = happySpecReduce_0 10# happyReduction_17
+happyReduction_17 = happyIn15
+ ([]
+ )
+
+happyReduce_18 = happySpecReduce_1 10# happyReduction_18
+happyReduction_18 happy_x_1
+ = case happyOut14 happy_x_1 of { happy_var_1 ->
+ happyIn15
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_19 = happySpecReduce_3 10# happyReduction_19
+happyReduction_19 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut14 happy_x_1 of { happy_var_1 ->
+ case happyOut15 happy_x_3 of { happy_var_3 ->
+ happyIn15
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_20 = happySpecReduce_2 11# happyReduction_20
+happyReduction_20 happy_x_2
+ happy_x_1
+ = case happyOut28 happy_x_2 of { happy_var_2 ->
+ happyIn16
+ (GuardExp happy_var_2
+ )}
+
+happyReduce_21 = happySpecReduce_0 11# happyReduction_21
+happyReduction_21 = happyIn16
+ (GuardNo
+ )
+
+happyReduce_22 = happySpecReduce_3 12# happyReduction_22
+happyReduction_22 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut18 happy_x_1 of { happy_var_1 ->
+ case happyOut17 happy_x_3 of { happy_var_3 ->
+ happyIn17
+ (POr happy_var_1 happy_var_3
+ )}}
+
+happyReduce_23 = happySpecReduce_1 12# happyReduction_23
+happyReduction_23 happy_x_1
+ = case happyOut18 happy_x_1 of { happy_var_1 ->
+ happyIn17
+ (happy_var_1
+ )}
+
+happyReduce_24 = happySpecReduce_3 13# happyReduction_24
+happyReduction_24 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut19 happy_x_1 of { happy_var_1 ->
+ case happyOut18 happy_x_3 of { happy_var_3 ->
+ happyIn18
+ (PListCons happy_var_1 happy_var_3
+ )}}
+
+happyReduce_25 = happySpecReduce_1 13# happyReduction_25
+happyReduction_25 happy_x_1
+ = case happyOut19 happy_x_1 of { happy_var_1 ->
+ happyIn18
+ (happy_var_1
+ )}
+
+happyReduce_26 = happySpecReduce_3 14# happyReduction_26
+happyReduction_26 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ case happyOut20 happy_x_2 of { happy_var_2 ->
+ case happyOut23 happy_x_3 of { happy_var_3 ->
+ happyIn19
+ (PConsTop happy_var_1 happy_var_2 (reverse happy_var_3)
+ )}}}
+
+happyReduce_27 = happySpecReduce_1 14# happyReduction_27
+happyReduction_27 happy_x_1
+ = case happyOut20 happy_x_1 of { happy_var_1 ->
+ happyIn19
+ (happy_var_1
+ )}
+
+happyReduce_28 = happyReduce 4# 15# happyReduction_28
+happyReduction_28 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut25 happy_x_3 of { happy_var_3 ->
+ happyIn20
+ (PRec happy_var_3
+ ) `HappyStk` happyRest}
+
+happyReduce_29 = happySpecReduce_2 15# happyReduction_29
+happyReduction_29 happy_x_2
+ happy_x_1
+ = happyIn20
+ (PEmptyList
+ )
+
+happyReduce_30 = happySpecReduce_3 15# happyReduction_30
+happyReduction_30 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut22 happy_x_2 of { happy_var_2 ->
+ happyIn20
+ (PList happy_var_2
+ )}
+
+happyReduce_31 = happyReduce 5# 15# happyReduction_31
+happyReduction_31 (happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut21 happy_x_2 of { happy_var_2 ->
+ case happyOut22 happy_x_4 of { happy_var_4 ->
+ happyIn20
+ (PTuple happy_var_2 happy_var_4
+ ) `HappyStk` happyRest}}
+
+happyReduce_32 = happySpecReduce_1 15# happyReduction_32
+happyReduction_32 happy_x_1
+ = case happyOut6 happy_x_1 of { happy_var_1 ->
+ happyIn20
+ (PStr happy_var_1
+ )}
+
+happyReduce_33 = happySpecReduce_1 15# happyReduction_33
+happyReduction_33 happy_x_1
+ = case happyOut7 happy_x_1 of { happy_var_1 ->
+ happyIn20
+ (PInt happy_var_1
+ )}
+
+happyReduce_34 = happySpecReduce_1 15# happyReduction_34
+happyReduction_34 happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ happyIn20
+ (PVar happy_var_1
+ )}
+
+happyReduce_35 = happySpecReduce_1 15# happyReduction_35
+happyReduction_35 happy_x_1
+ = happyIn20
+ (PWild
+ )
+
+happyReduce_36 = happySpecReduce_3 15# happyReduction_36
+happyReduction_36 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut17 happy_x_2 of { happy_var_2 ->
+ happyIn20
+ (happy_var_2
+ )}
+
+happyReduce_37 = happySpecReduce_1 16# happyReduction_37
+happyReduction_37 happy_x_1
+ = case happyOut17 happy_x_1 of { happy_var_1 ->
+ happyIn21
+ (CommaPattern happy_var_1
+ )}
+
+happyReduce_38 = happySpecReduce_1 17# happyReduction_38
+happyReduction_38 happy_x_1
+ = case happyOut21 happy_x_1 of { happy_var_1 ->
+ happyIn22
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_39 = happySpecReduce_3 17# happyReduction_39
+happyReduction_39 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut21 happy_x_1 of { happy_var_1 ->
+ case happyOut22 happy_x_3 of { happy_var_3 ->
+ happyIn22
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_40 = happySpecReduce_0 18# happyReduction_40
+happyReduction_40 = happyIn23
+ ([]
+ )
+
+happyReduce_41 = happySpecReduce_2 18# happyReduction_41
+happyReduction_41 happy_x_2
+ happy_x_1
+ = case happyOut23 happy_x_1 of { happy_var_1 ->
+ case happyOut20 happy_x_2 of { happy_var_2 ->
+ happyIn23
+ (flip (:) happy_var_1 happy_var_2
+ )}}
+
+happyReduce_42 = happySpecReduce_3 19# happyReduction_42
+happyReduction_42 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ case happyOut17 happy_x_3 of { happy_var_3 ->
+ happyIn24
+ (FieldPattern happy_var_1 happy_var_3
+ )}}
+
+happyReduce_43 = happySpecReduce_0 20# happyReduction_43
+happyReduction_43 = happyIn25
+ ([]
+ )
+
+happyReduce_44 = happySpecReduce_1 20# happyReduction_44
+happyReduction_44 happy_x_1
+ = case happyOut24 happy_x_1 of { happy_var_1 ->
+ happyIn25
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_45 = happySpecReduce_3 20# happyReduction_45
+happyReduction_45 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut24 happy_x_1 of { happy_var_1 ->
+ case happyOut25 happy_x_3 of { happy_var_3 ->
+ happyIn25
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_46 = happyReduce 7# 21# happyReduction_46
+happyReduction_46 (happy_x_7 `HappyStk`
+ happy_x_6 `HappyStk`
+ happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut27 happy_x_2 of { happy_var_2 ->
+ case happyOut26 happy_x_4 of { happy_var_4 ->
+ case happyOut26 happy_x_7 of { happy_var_7 ->
+ happyIn26
+ (EPi happy_var_2 happy_var_4 happy_var_7
+ ) `HappyStk` happyRest}}}
+
+happyReduce_47 = happySpecReduce_3 21# happyReduction_47
+happyReduction_47 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut28 happy_x_1 of { happy_var_1 ->
+ case happyOut26 happy_x_3 of { happy_var_3 ->
+ happyIn26
+ (EPiNoVar happy_var_1 happy_var_3
+ )}}
+
+happyReduce_48 = happySpecReduce_1 21# happyReduction_48
+happyReduction_48 happy_x_1
+ = case happyOut28 happy_x_1 of { happy_var_1 ->
+ happyIn26
+ (happy_var_1
+ )}
+
+happyReduce_49 = happySpecReduce_1 22# happyReduction_49
+happyReduction_49 happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ happyIn27
+ (VVar happy_var_1
+ )}
+
+happyReduce_50 = happySpecReduce_1 22# happyReduction_50
+happyReduction_50 happy_x_1
+ = happyIn27
+ (VWild
+ )
+
+happyReduce_51 = happyReduce 4# 23# happyReduction_51
+happyReduction_51 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut27 happy_x_2 of { happy_var_2 ->
+ case happyOut28 happy_x_4 of { happy_var_4 ->
+ happyIn28
+ (EAbs happy_var_2 happy_var_4
+ ) `HappyStk` happyRest}}
+
+happyReduce_52 = happyReduce 6# 23# happyReduction_52
+happyReduction_52 (happy_x_6 `HappyStk`
+ happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut30 happy_x_3 of { happy_var_3 ->
+ case happyOut28 happy_x_6 of { happy_var_6 ->
+ happyIn28
+ (ELet happy_var_3 happy_var_6
+ ) `HappyStk` happyRest}}
+
+happyReduce_53 = happyReduce 6# 23# happyReduction_53
+happyReduction_53 (happy_x_6 `HappyStk`
+ happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut26 happy_x_2 of { happy_var_2 ->
+ case happyOut32 happy_x_5 of { happy_var_5 ->
+ happyIn28
+ (ECase happy_var_2 happy_var_5
+ ) `HappyStk` happyRest}}
+
+happyReduce_54 = happyReduce 6# 23# happyReduction_54
+happyReduction_54 (happy_x_6 `HappyStk`
+ happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut26 happy_x_2 of { happy_var_2 ->
+ case happyOut26 happy_x_4 of { happy_var_4 ->
+ case happyOut28 happy_x_6 of { happy_var_6 ->
+ happyIn28
+ (EIf happy_var_2 happy_var_4 happy_var_6
+ ) `HappyStk` happyRest}}}
+
+happyReduce_55 = happyReduce 5# 23# happyReduction_55
+happyReduction_55 (happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut34 happy_x_3 of { happy_var_3 ->
+ case happyOut26 happy_x_4 of { happy_var_4 ->
+ happyIn28
+ (EDo (reverse happy_var_3) happy_var_4
+ ) `HappyStk` happyRest}}
+
+happyReduce_56 = happySpecReduce_1 23# happyReduction_56
+happyReduction_56 happy_x_1
+ = case happyOut50 happy_x_1 of { happy_var_1 ->
+ happyIn28
+ (happy_var_1
+ )}
+
+happyReduce_57 = happySpecReduce_3 24# happyReduction_57
+happyReduction_57 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ case happyOut26 happy_x_3 of { happy_var_3 ->
+ happyIn29
+ (LetDef happy_var_1 happy_var_3
+ )}}
+
+happyReduce_58 = happySpecReduce_0 25# happyReduction_58
+happyReduction_58 = happyIn30
+ ([]
+ )
+
+happyReduce_59 = happySpecReduce_1 25# happyReduction_59
+happyReduction_59 happy_x_1
+ = case happyOut29 happy_x_1 of { happy_var_1 ->
+ happyIn30
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_60 = happySpecReduce_3 25# happyReduction_60
+happyReduction_60 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut29 happy_x_1 of { happy_var_1 ->
+ case happyOut30 happy_x_3 of { happy_var_3 ->
+ happyIn30
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_61 = happyReduce 4# 26# happyReduction_61
+happyReduction_61 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut17 happy_x_1 of { happy_var_1 ->
+ case happyOut16 happy_x_2 of { happy_var_2 ->
+ case happyOut26 happy_x_4 of { happy_var_4 ->
+ happyIn31
+ (Case happy_var_1 happy_var_2 happy_var_4
+ ) `HappyStk` happyRest}}}
+
+happyReduce_62 = happySpecReduce_0 27# happyReduction_62
+happyReduction_62 = happyIn32
+ ([]
+ )
+
+happyReduce_63 = happySpecReduce_1 27# happyReduction_63
+happyReduction_63 happy_x_1
+ = case happyOut31 happy_x_1 of { happy_var_1 ->
+ happyIn32
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_64 = happySpecReduce_3 27# happyReduction_64
+happyReduction_64 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut31 happy_x_1 of { happy_var_1 ->
+ case happyOut32 happy_x_3 of { happy_var_3 ->
+ happyIn32
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_65 = happySpecReduce_3 28# happyReduction_65
+happyReduction_65 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut27 happy_x_1 of { happy_var_1 ->
+ case happyOut26 happy_x_3 of { happy_var_3 ->
+ happyIn33
+ (BindVar happy_var_1 happy_var_3
+ )}}
+
+happyReduce_66 = happySpecReduce_1 28# happyReduction_66
+happyReduction_66 happy_x_1
+ = case happyOut26 happy_x_1 of { happy_var_1 ->
+ happyIn33
+ (BindNoVar happy_var_1
+ )}
+
+happyReduce_67 = happySpecReduce_0 29# happyReduction_67
+happyReduction_67 = happyIn34
+ ([]
+ )
+
+happyReduce_68 = happySpecReduce_3 29# happyReduction_68
+happyReduction_68 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut34 happy_x_1 of { happy_var_1 ->
+ case happyOut33 happy_x_2 of { happy_var_2 ->
+ happyIn34
+ (flip (:) happy_var_1 happy_var_2
+ )}}
+
+happyReduce_69 = happySpecReduce_3 30# happyReduction_69
+happyReduction_69 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut35 happy_x_1 of { happy_var_1 ->
+ case happyOut36 happy_x_3 of { happy_var_3 ->
+ happyIn35
+ (EBind happy_var_1 happy_var_3
+ )}}
+
+happyReduce_70 = happySpecReduce_3 30# happyReduction_70
+happyReduction_70 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut35 happy_x_1 of { happy_var_1 ->
+ case happyOut36 happy_x_3 of { happy_var_3 ->
+ happyIn35
+ (EBindC happy_var_1 happy_var_3
+ )}}
+
+happyReduce_71 = happySpecReduce_1 30# happyReduction_71
+happyReduction_71 happy_x_1
+ = case happyOut36 happy_x_1 of { happy_var_1 ->
+ happyIn35
+ (happy_var_1
+ )}
+
+happyReduce_72 = happySpecReduce_3 31# happyReduction_72
+happyReduction_72 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut37 happy_x_1 of { happy_var_1 ->
+ case happyOut36 happy_x_3 of { happy_var_3 ->
+ happyIn36
+ (EOr happy_var_1 happy_var_3
+ )}}
+
+happyReduce_73 = happySpecReduce_1 31# happyReduction_73
+happyReduction_73 happy_x_1
+ = case happyOut37 happy_x_1 of { happy_var_1 ->
+ happyIn36
+ (happy_var_1
+ )}
+
+happyReduce_74 = happySpecReduce_3 32# happyReduction_74
+happyReduction_74 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut38 happy_x_1 of { happy_var_1 ->
+ case happyOut37 happy_x_3 of { happy_var_3 ->
+ happyIn37
+ (EAnd happy_var_1 happy_var_3
+ )}}
+
+happyReduce_75 = happySpecReduce_1 32# happyReduction_75
+happyReduction_75 happy_x_1
+ = case happyOut38 happy_x_1 of { happy_var_1 ->
+ happyIn37
+ (happy_var_1
+ )}
+
+happyReduce_76 = happySpecReduce_3 33# happyReduction_76
+happyReduction_76 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut39 happy_x_1 of { happy_var_1 ->
+ case happyOut39 happy_x_3 of { happy_var_3 ->
+ happyIn38
+ (EEq happy_var_1 happy_var_3
+ )}}
+
+happyReduce_77 = happySpecReduce_3 33# happyReduction_77
+happyReduction_77 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut39 happy_x_1 of { happy_var_1 ->
+ case happyOut39 happy_x_3 of { happy_var_3 ->
+ happyIn38
+ (ENe happy_var_1 happy_var_3
+ )}}
+
+happyReduce_78 = happySpecReduce_3 33# happyReduction_78
+happyReduction_78 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut39 happy_x_1 of { happy_var_1 ->
+ case happyOut39 happy_x_3 of { happy_var_3 ->
+ happyIn38
+ (ELt happy_var_1 happy_var_3
+ )}}
+
+happyReduce_79 = happySpecReduce_3 33# happyReduction_79
+happyReduction_79 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut39 happy_x_1 of { happy_var_1 ->
+ case happyOut39 happy_x_3 of { happy_var_3 ->
+ happyIn38
+ (ELe happy_var_1 happy_var_3
+ )}}
+
+happyReduce_80 = happySpecReduce_3 33# happyReduction_80
+happyReduction_80 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut39 happy_x_1 of { happy_var_1 ->
+ case happyOut39 happy_x_3 of { happy_var_3 ->
+ happyIn38
+ (EGt happy_var_1 happy_var_3
+ )}}
+
+happyReduce_81 = happySpecReduce_3 33# happyReduction_81
+happyReduction_81 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut39 happy_x_1 of { happy_var_1 ->
+ case happyOut39 happy_x_3 of { happy_var_3 ->
+ happyIn38
+ (EGe happy_var_1 happy_var_3
+ )}}
+
+happyReduce_82 = happySpecReduce_1 33# happyReduction_82
+happyReduction_82 happy_x_1
+ = case happyOut39 happy_x_1 of { happy_var_1 ->
+ happyIn38
+ (happy_var_1
+ )}
+
+happyReduce_83 = happySpecReduce_3 34# happyReduction_83
+happyReduction_83 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut40 happy_x_1 of { happy_var_1 ->
+ case happyOut39 happy_x_3 of { happy_var_3 ->
+ happyIn39
+ (EListCons happy_var_1 happy_var_3
+ )}}
+
+happyReduce_84 = happySpecReduce_1 34# happyReduction_84
+happyReduction_84 happy_x_1
+ = case happyOut40 happy_x_1 of { happy_var_1 ->
+ happyIn39
+ (happy_var_1
+ )}
+
+happyReduce_85 = happySpecReduce_3 35# happyReduction_85
+happyReduction_85 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut40 happy_x_1 of { happy_var_1 ->
+ case happyOut41 happy_x_3 of { happy_var_3 ->
+ happyIn40
+ (EAdd happy_var_1 happy_var_3
+ )}}
+
+happyReduce_86 = happySpecReduce_3 35# happyReduction_86
+happyReduction_86 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut40 happy_x_1 of { happy_var_1 ->
+ case happyOut41 happy_x_3 of { happy_var_3 ->
+ happyIn40
+ (ESub happy_var_1 happy_var_3
+ )}}
+
+happyReduce_87 = happySpecReduce_1 35# happyReduction_87
+happyReduction_87 happy_x_1
+ = case happyOut41 happy_x_1 of { happy_var_1 ->
+ happyIn40
+ (happy_var_1
+ )}
+
+happyReduce_88 = happySpecReduce_3 36# happyReduction_88
+happyReduction_88 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut41 happy_x_1 of { happy_var_1 ->
+ case happyOut42 happy_x_3 of { happy_var_3 ->
+ happyIn41
+ (EMul happy_var_1 happy_var_3
+ )}}
+
+happyReduce_89 = happySpecReduce_3 36# happyReduction_89
+happyReduction_89 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut41 happy_x_1 of { happy_var_1 ->
+ case happyOut42 happy_x_3 of { happy_var_3 ->
+ happyIn41
+ (EDiv happy_var_1 happy_var_3
+ )}}
+
+happyReduce_90 = happySpecReduce_3 36# happyReduction_90
+happyReduction_90 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut41 happy_x_1 of { happy_var_1 ->
+ case happyOut42 happy_x_3 of { happy_var_3 ->
+ happyIn41
+ (EMod happy_var_1 happy_var_3
+ )}}
+
+happyReduce_91 = happySpecReduce_1 36# happyReduction_91
+happyReduction_91 happy_x_1
+ = case happyOut42 happy_x_1 of { happy_var_1 ->
+ happyIn41
+ (happy_var_1
+ )}
+
+happyReduce_92 = happySpecReduce_2 37# happyReduction_92
+happyReduction_92 happy_x_2
+ happy_x_1
+ = case happyOut42 happy_x_2 of { happy_var_2 ->
+ happyIn42
+ (ENeg happy_var_2
+ )}
+
+happyReduce_93 = happySpecReduce_1 37# happyReduction_93
+happyReduction_93 happy_x_1
+ = case happyOut43 happy_x_1 of { happy_var_1 ->
+ happyIn42
+ (happy_var_1
+ )}
+
+happyReduce_94 = happySpecReduce_2 38# happyReduction_94
+happyReduction_94 happy_x_2
+ happy_x_1
+ = case happyOut43 happy_x_1 of { happy_var_1 ->
+ case happyOut44 happy_x_2 of { happy_var_2 ->
+ happyIn43
+ (EApp happy_var_1 happy_var_2
+ )}}
+
+happyReduce_95 = happySpecReduce_1 38# happyReduction_95
+happyReduction_95 happy_x_1
+ = case happyOut44 happy_x_1 of { happy_var_1 ->
+ happyIn43
+ (happy_var_1
+ )}
+
+happyReduce_96 = happySpecReduce_3 39# happyReduction_96
+happyReduction_96 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut44 happy_x_1 of { happy_var_1 ->
+ case happyOut5 happy_x_3 of { happy_var_3 ->
+ happyIn44
+ (EProj happy_var_1 happy_var_3
+ )}}
+
+happyReduce_97 = happySpecReduce_1 39# happyReduction_97
+happyReduction_97 happy_x_1
+ = case happyOut45 happy_x_1 of { happy_var_1 ->
+ happyIn44
+ (happy_var_1
+ )}
+
+happyReduce_98 = happyReduce 4# 40# happyReduction_98
+happyReduction_98 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut47 happy_x_3 of { happy_var_3 ->
+ happyIn45
+ (ERecType happy_var_3
+ ) `HappyStk` happyRest}
+
+happyReduce_99 = happyReduce 4# 40# happyReduction_99
+happyReduction_99 (happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut49 happy_x_3 of { happy_var_3 ->
+ happyIn45
+ (ERec happy_var_3
+ ) `HappyStk` happyRest}
+
+happyReduce_100 = happySpecReduce_2 40# happyReduction_100
+happyReduction_100 happy_x_2
+ happy_x_1
+ = happyIn45
+ (EEmptyList
+ )
+
+happyReduce_101 = happySpecReduce_3 40# happyReduction_101
+happyReduction_101 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut51 happy_x_2 of { happy_var_2 ->
+ happyIn45
+ (EList happy_var_2
+ )}
+
+happyReduce_102 = happyReduce 5# 40# happyReduction_102
+happyReduction_102 (happy_x_5 `HappyStk`
+ happy_x_4 `HappyStk`
+ happy_x_3 `HappyStk`
+ happy_x_2 `HappyStk`
+ happy_x_1 `HappyStk`
+ happyRest)
+ = case happyOut26 happy_x_2 of { happy_var_2 ->
+ case happyOut51 happy_x_4 of { happy_var_4 ->
+ happyIn45
+ (ETuple happy_var_2 happy_var_4
+ ) `HappyStk` happyRest}}
+
+happyReduce_103 = happySpecReduce_1 40# happyReduction_103
+happyReduction_103 happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ happyIn45
+ (EVar happy_var_1
+ )}
+
+happyReduce_104 = happySpecReduce_1 40# happyReduction_104
+happyReduction_104 happy_x_1
+ = happyIn45
+ (EType
+ )
+
+happyReduce_105 = happySpecReduce_1 40# happyReduction_105
+happyReduction_105 happy_x_1
+ = case happyOut6 happy_x_1 of { happy_var_1 ->
+ happyIn45
+ (EStr happy_var_1
+ )}
+
+happyReduce_106 = happySpecReduce_1 40# happyReduction_106
+happyReduction_106 happy_x_1
+ = case happyOut7 happy_x_1 of { happy_var_1 ->
+ happyIn45
+ (EInteger happy_var_1
+ )}
+
+happyReduce_107 = happySpecReduce_1 40# happyReduction_107
+happyReduction_107 happy_x_1
+ = case happyOut8 happy_x_1 of { happy_var_1 ->
+ happyIn45
+ (EDouble happy_var_1
+ )}
+
+happyReduce_108 = happySpecReduce_1 40# happyReduction_108
+happyReduction_108 happy_x_1
+ = happyIn45
+ (EMeta
+ )
+
+happyReduce_109 = happySpecReduce_3 40# happyReduction_109
+happyReduction_109 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut26 happy_x_2 of { happy_var_2 ->
+ happyIn45
+ (happy_var_2
+ )}
+
+happyReduce_110 = happySpecReduce_3 41# happyReduction_110
+happyReduction_110 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ case happyOut26 happy_x_3 of { happy_var_3 ->
+ happyIn46
+ (FieldType happy_var_1 happy_var_3
+ )}}
+
+happyReduce_111 = happySpecReduce_0 42# happyReduction_111
+happyReduction_111 = happyIn47
+ ([]
+ )
+
+happyReduce_112 = happySpecReduce_1 42# happyReduction_112
+happyReduction_112 happy_x_1
+ = case happyOut46 happy_x_1 of { happy_var_1 ->
+ happyIn47
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_113 = happySpecReduce_3 42# happyReduction_113
+happyReduction_113 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut46 happy_x_1 of { happy_var_1 ->
+ case happyOut47 happy_x_3 of { happy_var_3 ->
+ happyIn47
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_114 = happySpecReduce_3 43# happyReduction_114
+happyReduction_114 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut5 happy_x_1 of { happy_var_1 ->
+ case happyOut26 happy_x_3 of { happy_var_3 ->
+ happyIn48
+ (FieldValue happy_var_1 happy_var_3
+ )}}
+
+happyReduce_115 = happySpecReduce_0 44# happyReduction_115
+happyReduction_115 = happyIn49
+ ([]
+ )
+
+happyReduce_116 = happySpecReduce_1 44# happyReduction_116
+happyReduction_116 happy_x_1
+ = case happyOut48 happy_x_1 of { happy_var_1 ->
+ happyIn49
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_117 = happySpecReduce_3 44# happyReduction_117
+happyReduction_117 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut48 happy_x_1 of { happy_var_1 ->
+ case happyOut49 happy_x_3 of { happy_var_3 ->
+ happyIn49
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyReduce_118 = happySpecReduce_1 45# happyReduction_118
+happyReduction_118 happy_x_1
+ = case happyOut35 happy_x_1 of { happy_var_1 ->
+ happyIn50
+ (happy_var_1
+ )}
+
+happyReduce_119 = happySpecReduce_1 46# happyReduction_119
+happyReduction_119 happy_x_1
+ = case happyOut26 happy_x_1 of { happy_var_1 ->
+ happyIn51
+ ((:[]) happy_var_1
+ )}
+
+happyReduce_120 = happySpecReduce_3 46# happyReduction_120
+happyReduction_120 happy_x_3
+ happy_x_2
+ happy_x_1
+ = case happyOut26 happy_x_1 of { happy_var_1 ->
+ case happyOut51 happy_x_3 of { happy_var_3 ->
+ happyIn51
+ ((:) happy_var_1 happy_var_3
+ )}}
+
+happyNewToken action sts stk [] =
+ happyDoAction 54# (error "reading EOF!") action sts stk []
+
+happyNewToken action sts stk (tk:tks) =
+ let cont i = happyDoAction i tk action sts stk tks in
+ case tk of {
+ PT _ (TS ";") -> cont 1#;
+ PT _ (TS ":") -> cont 2#;
+ PT _ (TS "{") -> cont 3#;
+ PT _ (TS "}") -> cont 4#;
+ PT _ (TS "=") -> cont 5#;
+ PT _ (TS "|") -> cont 6#;
+ PT _ (TS "||") -> cont 7#;
+ PT _ (TS "::") -> cont 8#;
+ PT _ (TS "(") -> cont 9#;
+ PT _ (TS ")") -> cont 10#;
+ PT _ (TS "[") -> cont 11#;
+ PT _ (TS "]") -> cont 12#;
+ PT _ (TS ",") -> cont 13#;
+ PT _ (TS "_") -> cont 14#;
+ PT _ (TS "->") -> cont 15#;
+ PT _ (TS "\\") -> cont 16#;
+ PT _ (TS "<-") -> cont 17#;
+ PT _ (TS ">>=") -> cont 18#;
+ PT _ (TS ">>") -> cont 19#;
+ PT _ (TS "&&") -> cont 20#;
+ PT _ (TS "==") -> cont 21#;
+ PT _ (TS "/=") -> cont 22#;
+ PT _ (TS "<") -> cont 23#;
+ PT _ (TS "<=") -> cont 24#;
+ PT _ (TS ">") -> cont 25#;
+ PT _ (TS ">=") -> cont 26#;
+ PT _ (TS "+") -> cont 27#;
+ PT _ (TS "-") -> cont 28#;
+ PT _ (TS "*") -> cont 29#;
+ PT _ (TS "/") -> cont 30#;
+ PT _ (TS "%") -> cont 31#;
+ PT _ (TS ".") -> cont 32#;
+ PT _ (TS "?") -> cont 33#;
+ PT _ (TS "Type") -> cont 34#;
+ PT _ (TS "case") -> cont 35#;
+ PT _ (TS "data") -> cont 36#;
+ PT _ (TS "derive") -> cont 37#;
+ PT _ (TS "do") -> cont 38#;
+ PT _ (TS "else") -> cont 39#;
+ PT _ (TS "if") -> cont 40#;
+ PT _ (TS "import") -> cont 41#;
+ PT _ (TS "in") -> cont 42#;
+ PT _ (TS "let") -> cont 43#;
+ PT _ (TS "of") -> cont 44#;
+ PT _ (TS "rec") -> cont 45#;
+ PT _ (TS "sig") -> cont 46#;
+ PT _ (TS "then") -> cont 47#;
+ PT _ (TS "where") -> cont 48#;
+ PT _ (TV happy_dollar_dollar) -> cont 49#;
+ PT _ (TL happy_dollar_dollar) -> cont 50#;
+ PT _ (TI happy_dollar_dollar) -> cont 51#;
+ PT _ (TD happy_dollar_dollar) -> cont 52#;
+ _ -> cont 53#;
+ _ -> happyError' (tk:tks)
+ }
+
+happyError_ tk tks = happyError' (tk:tks)
+
+happyThen :: () => Err a -> (a -> Err b) -> Err b
+happyThen = (thenM)
+happyReturn :: () => a -> Err a
+happyReturn = (returnM)
+happyThen1 m k tks = (thenM) m (\a -> k a tks)
+happyReturn1 :: () => a -> b -> Err a
+happyReturn1 = \a tks -> (returnM) a
+happyError' :: () => [Token] -> Err a
+happyError' = happyError
+
+pModule tks = happySomeParser where
+ happySomeParser = happyThen (happyParse 0# tks) (\x -> happyReturn (happyOut9 x))
+
+pExp tks = happySomeParser where
+ happySomeParser = happyThen (happyParse 1# tks) (\x -> happyReturn (happyOut26 x))
+
+happySeq = happyDontSeq
+
+returnM :: a -> Err a
+returnM = return
+
+thenM :: Err a -> (a -> Err b) -> Err b
+thenM = (>>=)
+
+happyError :: [Token] -> Err a
+happyError ts =
+ Bad $ "syntax error at " ++ tokenPos ts ++ if null ts then [] else (" before " ++ unwords (map prToken (take 4 ts)))
+
+myLexer = tokens
+{-# LINE 1 "GenericTemplate.hs" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "" #-}
+{-# LINE 1 "GenericTemplate.hs" #-}
+-- $Id$
+
+{-# LINE 28 "GenericTemplate.hs" #-}
+
+
+data Happy_IntList = HappyCons Int# Happy_IntList
+
+
+
+
+
+{-# LINE 49 "GenericTemplate.hs" #-}
+
+{-# LINE 59 "GenericTemplate.hs" #-}
+
+{-# LINE 68 "GenericTemplate.hs" #-}
+
+infixr 9 `HappyStk`
+data HappyStk a = HappyStk a (HappyStk a)
+
+-----------------------------------------------------------------------------
+-- starting the parse
+
+happyParse start_state = happyNewToken start_state notHappyAtAll notHappyAtAll
+
+-----------------------------------------------------------------------------
+-- Accepting the parse
+
+-- If the current token is 0#, it means we've just accepted a partial
+-- parse (a %partial parser). We must ignore the saved token on the top of
+-- the stack in this case.
+happyAccept 0# tk st sts (_ `HappyStk` ans `HappyStk` _) =
+ happyReturn1 ans
+happyAccept j tk st sts (HappyStk ans _) =
+ (happyTcHack j (happyTcHack st)) (happyReturn1 ans)
+
+-----------------------------------------------------------------------------
+-- Arrays only: do the next action
+
+
+
+happyDoAction i tk st
+ = {- nothing -}
+
+
+ case action of
+ 0# -> {- nothing -}
+ happyFail i tk st
+ -1# -> {- nothing -}
+ happyAccept i tk st
+ n | (n <# (0# :: Int#)) -> {- nothing -}
+
+ (happyReduceArr ! rule) i tk st
+ where rule = (I# ((negateInt# ((n +# (1# :: Int#))))))
+ n -> {- nothing -}
+
+
+ happyShift new_state i tk st
+ where new_state = (n -# (1# :: Int#))
+ where off = indexShortOffAddr happyActOffsets st
+ off_i = (off +# i)
+ check = if (off_i >=# (0# :: Int#))
+ then (indexShortOffAddr happyCheck off_i ==# i)
+ else False
+ action | check = indexShortOffAddr happyTable off_i
+ | otherwise = indexShortOffAddr happyDefActions st
+
+{-# LINE 127 "GenericTemplate.hs" #-}
+
+
+indexShortOffAddr (HappyA# arr) off =
+#if __GLASGOW_HASKELL__ > 500
+ narrow16Int# i
+#elif __GLASGOW_HASKELL__ == 500
+ intToInt16# i
+#else
+ (i `iShiftL#` 16#) `iShiftRA#` 16#
+#endif
+ where
+#if __GLASGOW_HASKELL__ >= 503
+ i = word2Int# ((high `uncheckedShiftL#` 8#) `or#` low)
+#else
+ i = word2Int# ((high `shiftL#` 8#) `or#` low)
+#endif
+ high = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
+ low = int2Word# (ord# (indexCharOffAddr# arr off'))
+ off' = off *# 2#
+
+
+
+
+
+data HappyAddr = HappyA# Addr#
+
+
+
+
+-----------------------------------------------------------------------------
+-- HappyState data type (not arrays)
+
+{-# LINE 170 "GenericTemplate.hs" #-}
+
+-----------------------------------------------------------------------------
+-- Shifting a token
+
+happyShift new_state 0# tk st sts stk@(x `HappyStk` _) =
+ let i = (case unsafeCoerce# x of { (I# (i)) -> i }) in
+-- trace "shifting the error token" $
+ happyDoAction i tk new_state (HappyCons (st) (sts)) (stk)
+
+happyShift new_state i tk st sts stk =
+ happyNewToken new_state (HappyCons (st) (sts)) ((happyInTok (tk))`HappyStk`stk)
+
+-- happyReduce is specialised for the common cases.
+
+happySpecReduce_0 i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happySpecReduce_0 nt fn j tk st@((action)) sts stk
+ = happyGoto nt j tk st (HappyCons (st) (sts)) (fn `HappyStk` stk)
+
+happySpecReduce_1 i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happySpecReduce_1 nt fn j tk _ sts@((HappyCons (st@(action)) (_))) (v1`HappyStk`stk')
+ = let r = fn v1 in
+ happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))
+
+happySpecReduce_2 i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happySpecReduce_2 nt fn j tk _ (HappyCons (_) (sts@((HappyCons (st@(action)) (_))))) (v1`HappyStk`v2`HappyStk`stk')
+ = let r = fn v1 v2 in
+ happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))
+
+happySpecReduce_3 i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happySpecReduce_3 nt fn j tk _ (HappyCons (_) ((HappyCons (_) (sts@((HappyCons (st@(action)) (_))))))) (v1`HappyStk`v2`HappyStk`v3`HappyStk`stk')
+ = let r = fn v1 v2 v3 in
+ happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))
+
+happyReduce k i fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happyReduce k nt fn j tk st sts stk
+ = case happyDrop (k -# (1# :: Int#)) sts of
+ sts1@((HappyCons (st1@(action)) (_))) ->
+ let r = fn stk in -- it doesn't hurt to always seq here...
+ happyDoSeq r (happyGoto nt j tk st1 sts1 r)
+
+happyMonadReduce k nt fn 0# tk st sts stk
+ = happyFail 0# tk st sts stk
+happyMonadReduce k nt fn j tk st sts stk =
+ happyThen1 (fn stk) (\r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk))
+ where sts1@((HappyCons (st1@(action)) (_))) = happyDrop k (HappyCons (st) (sts))
+ drop_stk = happyDropStk k stk
+
+happyDrop 0# l = l
+happyDrop n (HappyCons (_) (t)) = happyDrop (n -# (1# :: Int#)) t
+
+happyDropStk 0# l = l
+happyDropStk n (x `HappyStk` xs) = happyDropStk (n -# (1#::Int#)) xs
+
+-----------------------------------------------------------------------------
+-- Moving to a new state after a reduction
+
+
+happyGoto nt j tk st =
+ {- nothing -}
+ happyDoAction j tk new_state
+ where off = indexShortOffAddr happyGotoOffsets st
+ off_i = (off +# nt)
+ new_state = indexShortOffAddr happyTable off_i
+
+
+
+
+-----------------------------------------------------------------------------
+-- Error recovery (0# is the error token)
+
+-- parse error if we are in recovery and we fail again
+happyFail 0# tk old_st _ stk =
+-- trace "failing" $
+ happyError_ tk
+
+{- We don't need state discarding for our restricted implementation of
+ "error". In fact, it can cause some bogus parses, so I've disabled it
+ for now --SDM
+
+-- discard a state
+happyFail 0# tk old_st (HappyCons ((action)) (sts))
+ (saved_tok `HappyStk` _ `HappyStk` stk) =
+-- trace ("discarding state, depth " ++ show (length stk)) $
+ happyDoAction 0# tk action sts ((saved_tok`HappyStk`stk))
+-}
+
+-- Enter error recovery: generate an error token,
+-- save the old token and carry on.
+happyFail i tk (action) sts stk =
+-- trace "entering error recovery" $
+ happyDoAction 0# tk action sts ( (unsafeCoerce# (I# (i))) `HappyStk` stk)
+
+-- Internal happy errors:
+
+notHappyAtAll = error "Internal Happy error\n"
+
+-----------------------------------------------------------------------------
+-- Hack to get the typechecker to accept our action functions
+
+
+happyTcHack :: Int# -> a -> a
+happyTcHack x y = y
+{-# INLINE happyTcHack #-}
+
+
+-----------------------------------------------------------------------------
+-- Seq-ing. If the --strict flag is given, then Happy emits
+-- happySeq = happyDoSeq
+-- otherwise it emits
+-- happySeq = happyDontSeq
+
+happyDoSeq, happyDontSeq :: a -> b -> b
+happyDoSeq a b = a `seq` b
+happyDontSeq a b = b
+
+-----------------------------------------------------------------------------
+-- Don't inline any functions from the template. GHC has a nasty habit
+-- of deciding to inline happyGoto everywhere, which increases the size of
+-- the generated parser quite a bit.
+
+
+{-# NOINLINE happyDoAction #-}
+{-# NOINLINE happyTable #-}
+{-# NOINLINE happyCheck #-}
+{-# NOINLINE happyActOffsets #-}
+{-# NOINLINE happyGotoOffsets #-}
+{-# NOINLINE happyDefActions #-}
+
+{-# NOINLINE happyShift #-}
+{-# NOINLINE happySpecReduce_0 #-}
+{-# NOINLINE happySpecReduce_1 #-}
+{-# NOINLINE happySpecReduce_2 #-}
+{-# NOINLINE happySpecReduce_3 #-}
+{-# NOINLINE happyReduce #-}
+{-# NOINLINE happyMonadReduce #-}
+{-# NOINLINE happyGoto #-}
+{-# NOINLINE happyFail #-}
+
+-- end of Happy Template.
diff --git a/src-2.9/Transfer/Syntax/Par.y b/src-2.9/Transfer/Syntax/Par.y
new file mode 100644
index 000000000..13c7800a8
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Par.y
@@ -0,0 +1,340 @@
+-- This Happy file was machine-generated by the BNF converter
+{
+{-# OPTIONS -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
+module Transfer.Syntax.Par where
+import Transfer.Syntax.Abs
+import Transfer.Syntax.Lex
+import Transfer.ErrM
+}
+
+%name pModule Module
+%name pExp Exp
+
+-- no lexer declaration
+%monad { Err } { thenM } { returnM }
+%tokentype { Token }
+
+%token
+ ';' { PT _ (TS ";") }
+ ':' { PT _ (TS ":") }
+ '{' { PT _ (TS "{") }
+ '}' { PT _ (TS "}") }
+ '=' { PT _ (TS "=") }
+ '|' { PT _ (TS "|") }
+ '||' { PT _ (TS "||") }
+ '::' { PT _ (TS "::") }
+ '(' { PT _ (TS "(") }
+ ')' { PT _ (TS ")") }
+ '[' { PT _ (TS "[") }
+ ']' { PT _ (TS "]") }
+ ',' { PT _ (TS ",") }
+ '_' { PT _ (TS "_") }
+ '->' { PT _ (TS "->") }
+ '\\' { PT _ (TS "\\") }
+ '<-' { PT _ (TS "<-") }
+ '>>=' { PT _ (TS ">>=") }
+ '>>' { PT _ (TS ">>") }
+ '&&' { PT _ (TS "&&") }
+ '==' { PT _ (TS "==") }
+ '/=' { PT _ (TS "/=") }
+ '<' { PT _ (TS "<") }
+ '<=' { PT _ (TS "<=") }
+ '>' { PT _ (TS ">") }
+ '>=' { PT _ (TS ">=") }
+ '+' { PT _ (TS "+") }
+ '-' { PT _ (TS "-") }
+ '*' { PT _ (TS "*") }
+ '/' { PT _ (TS "/") }
+ '%' { PT _ (TS "%") }
+ '.' { PT _ (TS ".") }
+ '?' { PT _ (TS "?") }
+ 'Type' { PT _ (TS "Type") }
+ 'case' { PT _ (TS "case") }
+ 'data' { PT _ (TS "data") }
+ 'derive' { PT _ (TS "derive") }
+ 'do' { PT _ (TS "do") }
+ 'else' { PT _ (TS "else") }
+ 'if' { PT _ (TS "if") }
+ 'import' { PT _ (TS "import") }
+ 'in' { PT _ (TS "in") }
+ 'let' { PT _ (TS "let") }
+ 'of' { PT _ (TS "of") }
+ 'rec' { PT _ (TS "rec") }
+ 'sig' { PT _ (TS "sig") }
+ 'then' { PT _ (TS "then") }
+ 'where' { PT _ (TS "where") }
+
+L_ident { PT _ (TV $$) }
+L_quoted { PT _ (TL $$) }
+L_integ { PT _ (TI $$) }
+L_doubl { PT _ (TD $$) }
+L_err { _ }
+
+
+%%
+
+Ident :: { Ident } : L_ident { Ident $1 }
+String :: { String } : L_quoted { $1 }
+Integer :: { Integer } : L_integ { (read $1) :: Integer }
+Double :: { Double } : L_doubl { (read $1) :: Double }
+
+Module :: { Module }
+Module : ListImport ListDecl { Module (reverse $1) (reverse $2) }
+
+
+Import :: { Import }
+Import : 'import' Ident { Import $2 }
+
+
+ListImport :: { [Import] }
+ListImport : {- empty -} { [] }
+ | ListImport Import ';' { flip (:) $1 $2 }
+
+
+Decl :: { Decl }
+Decl : 'data' Ident ':' Exp 'where' '{' ListConsDecl '}' { DataDecl $2 $4 $7 }
+ | Ident ':' Exp { TypeDecl $1 $3 }
+ | Ident ListPattern Guard '=' Exp { ValueDecl $1 (reverse $2) $3 $5 }
+ | 'derive' Ident Ident { DeriveDecl $2 $3 }
+
+
+ListDecl :: { [Decl] }
+ListDecl : {- empty -} { [] }
+ | ListDecl Decl ';' { flip (:) $1 $2 }
+
+
+ConsDecl :: { ConsDecl }
+ConsDecl : Ident ':' Exp { ConsDecl $1 $3 }
+
+
+ListConsDecl :: { [ConsDecl] }
+ListConsDecl : {- empty -} { [] }
+ | ConsDecl { (:[]) $1 }
+ | ConsDecl ';' ListConsDecl { (:) $1 $3 }
+
+
+Guard :: { Guard }
+Guard : '|' Exp1 { GuardExp $2 }
+ | {- empty -} { GuardNo }
+
+
+Pattern :: { Pattern }
+Pattern : Pattern1 '||' Pattern { POr $1 $3 }
+ | Pattern1 { $1 }
+
+
+Pattern1 :: { Pattern }
+Pattern1 : Pattern2 '::' Pattern1 { PListCons $1 $3 }
+ | Pattern2 { $1 }
+
+
+Pattern2 :: { Pattern }
+Pattern2 : Ident Pattern3 ListPattern { PConsTop $1 $2 (reverse $3) }
+ | Pattern3 { $1 }
+
+
+Pattern3 :: { Pattern }
+Pattern3 : 'rec' '{' ListFieldPattern '}' { PRec $3 }
+ | '[' ']' { PEmptyList }
+ | '[' ListCommaPattern ']' { PList $2 }
+ | '(' CommaPattern ',' ListCommaPattern ')' { PTuple $2 $4 }
+ | String { PStr $1 }
+ | Integer { PInt $1 }
+ | Ident { PVar $1 }
+ | '_' { PWild }
+ | '(' Pattern ')' { $2 }
+
+
+CommaPattern :: { CommaPattern }
+CommaPattern : Pattern { CommaPattern $1 }
+
+
+ListCommaPattern :: { [CommaPattern] }
+ListCommaPattern : CommaPattern { (:[]) $1 }
+ | CommaPattern ',' ListCommaPattern { (:) $1 $3 }
+
+
+ListPattern :: { [Pattern] }
+ListPattern : {- empty -} { [] }
+ | ListPattern Pattern3 { flip (:) $1 $2 }
+
+
+FieldPattern :: { FieldPattern }
+FieldPattern : Ident '=' Pattern { FieldPattern $1 $3 }
+
+
+ListFieldPattern :: { [FieldPattern] }
+ListFieldPattern : {- empty -} { [] }
+ | FieldPattern { (:[]) $1 }
+ | FieldPattern ';' ListFieldPattern { (:) $1 $3 }
+
+
+Exp :: { Exp }
+Exp : '(' VarOrWild ':' Exp ')' '->' Exp { EPi $2 $4 $7 }
+ | Exp1 '->' Exp { EPiNoVar $1 $3 }
+ | Exp1 { $1 }
+
+
+VarOrWild :: { VarOrWild }
+VarOrWild : Ident { VVar $1 }
+ | '_' { VWild }
+
+
+Exp1 :: { Exp }
+Exp1 : '\\' VarOrWild '->' Exp1 { EAbs $2 $4 }
+ | 'let' '{' ListLetDef '}' 'in' Exp1 { ELet $3 $6 }
+ | 'case' Exp 'of' '{' ListCase '}' { ECase $2 $5 }
+ | 'if' Exp 'then' Exp 'else' Exp1 { EIf $2 $4 $6 }
+ | 'do' '{' ListBind Exp '}' { EDo (reverse $3) $4 }
+ | Exp2 { $1 }
+
+
+LetDef :: { LetDef }
+LetDef : Ident '=' Exp { LetDef $1 $3 }
+
+
+ListLetDef :: { [LetDef] }
+ListLetDef : {- empty -} { [] }
+ | LetDef { (:[]) $1 }
+ | LetDef ';' ListLetDef { (:) $1 $3 }
+
+
+Case :: { Case }
+Case : Pattern Guard '->' Exp { Case $1 $2 $4 }
+
+
+ListCase :: { [Case] }
+ListCase : {- empty -} { [] }
+ | Case { (:[]) $1 }
+ | Case ';' ListCase { (:) $1 $3 }
+
+
+Bind :: { Bind }
+Bind : VarOrWild '<-' Exp { BindVar $1 $3 }
+ | Exp { BindNoVar $1 }
+
+
+ListBind :: { [Bind] }
+ListBind : {- empty -} { [] }
+ | ListBind Bind ';' { flip (:) $1 $2 }
+
+
+Exp3 :: { Exp }
+Exp3 : Exp3 '>>=' Exp4 { EBind $1 $3 }
+ | Exp3 '>>' Exp4 { EBindC $1 $3 }
+ | Exp4 { $1 }
+
+
+Exp4 :: { Exp }
+Exp4 : Exp5 '||' Exp4 { EOr $1 $3 }
+ | Exp5 { $1 }
+
+
+Exp5 :: { Exp }
+Exp5 : Exp6 '&&' Exp5 { EAnd $1 $3 }
+ | Exp6 { $1 }
+
+
+Exp6 :: { Exp }
+Exp6 : Exp7 '==' Exp7 { EEq $1 $3 }
+ | Exp7 '/=' Exp7 { ENe $1 $3 }
+ | Exp7 '<' Exp7 { ELt $1 $3 }
+ | Exp7 '<=' Exp7 { ELe $1 $3 }
+ | Exp7 '>' Exp7 { EGt $1 $3 }
+ | Exp7 '>=' Exp7 { EGe $1 $3 }
+ | Exp7 { $1 }
+
+
+Exp7 :: { Exp }
+Exp7 : Exp8 '::' Exp7 { EListCons $1 $3 }
+ | Exp8 { $1 }
+
+
+Exp8 :: { Exp }
+Exp8 : Exp8 '+' Exp9 { EAdd $1 $3 }
+ | Exp8 '-' Exp9 { ESub $1 $3 }
+ | Exp9 { $1 }
+
+
+Exp9 :: { Exp }
+Exp9 : Exp9 '*' Exp10 { EMul $1 $3 }
+ | Exp9 '/' Exp10 { EDiv $1 $3 }
+ | Exp9 '%' Exp10 { EMod $1 $3 }
+ | Exp10 { $1 }
+
+
+Exp10 :: { Exp }
+Exp10 : '-' Exp10 { ENeg $2 }
+ | Exp11 { $1 }
+
+
+Exp11 :: { Exp }
+Exp11 : Exp11 Exp12 { EApp $1 $2 }
+ | Exp12 { $1 }
+
+
+Exp12 :: { Exp }
+Exp12 : Exp12 '.' Ident { EProj $1 $3 }
+ | Exp13 { $1 }
+
+
+Exp13 :: { Exp }
+Exp13 : 'sig' '{' ListFieldType '}' { ERecType $3 }
+ | 'rec' '{' ListFieldValue '}' { ERec $3 }
+ | '[' ']' { EEmptyList }
+ | '[' ListExp ']' { EList $2 }
+ | '(' Exp ',' ListExp ')' { ETuple $2 $4 }
+ | Ident { EVar $1 }
+ | 'Type' { EType }
+ | String { EStr $1 }
+ | Integer { EInteger $1 }
+ | Double { EDouble $1 }
+ | '?' { EMeta }
+ | '(' Exp ')' { $2 }
+
+
+FieldType :: { FieldType }
+FieldType : Ident ':' Exp { FieldType $1 $3 }
+
+
+ListFieldType :: { [FieldType] }
+ListFieldType : {- empty -} { [] }
+ | FieldType { (:[]) $1 }
+ | FieldType ';' ListFieldType { (:) $1 $3 }
+
+
+FieldValue :: { FieldValue }
+FieldValue : Ident '=' Exp { FieldValue $1 $3 }
+
+
+ListFieldValue :: { [FieldValue] }
+ListFieldValue : {- empty -} { [] }
+ | FieldValue { (:[]) $1 }
+ | FieldValue ';' ListFieldValue { (:) $1 $3 }
+
+
+Exp2 :: { Exp }
+Exp2 : Exp3 { $1 }
+
+
+ListExp :: { [Exp] }
+ListExp : Exp { (:[]) $1 }
+ | Exp ',' ListExp { (:) $1 $3 }
+
+
+
+{
+
+returnM :: a -> Err a
+returnM = return
+
+thenM :: Err a -> (a -> Err b) -> Err b
+thenM = (>>=)
+
+happyError :: [Token] -> Err a
+happyError ts =
+ Bad $ "syntax error at " ++ tokenPos ts ++ if null ts then [] else (" before " ++ unwords (map prToken (take 4 ts)))
+
+myLexer = tokens
+}
+
diff --git a/src-2.9/Transfer/Syntax/Print.hs b/src-2.9/Transfer/Syntax/Print.hs
new file mode 100644
index 000000000..50164477d
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Print.hs
@@ -0,0 +1,206 @@
+{-# OPTIONS_GHC -fglasgow-exts #-}
+module Transfer.Syntax.Print where
+
+-- pretty-printer generated by the BNF converter
+
+import Transfer.Syntax.Abs
+import Data.Char
+import Data.List (intersperse)
+
+-- the top-level printing method
+printTree :: Print a => a -> String
+printTree = render . prt 0
+
+type Doc = [ShowS] -> [ShowS]
+
+doc :: ShowS -> Doc
+doc = (:)
+
+render :: Doc -> String
+render d = rend 0 (map ($ "") $ d []) "" where
+ rend i ss = case ss of
+ "[" :ts -> showChar '[' . rend i ts
+ "(" :ts -> showChar '(' . rend i ts
+ "{" :ts -> showChar '{' . new (i+1) . rend (i+1) ts
+ "}" : ";":ts -> new (i-1) . space "}" . showChar ';' . new (i-1) . rend (i-1) ts
+ "}" :ts -> new (i-1) . showChar '}' . new (i-1) . rend (i-1) ts
+ ";" :ts -> showChar ';' . new i . rend i ts
+ t : "," :ts -> showString t . space "," . rend i ts
+ t : ")" :ts -> showString t . showChar ')' . rend i ts
+ t : "]" :ts -> showString t . showChar ']' . rend i ts
+ t :ts -> space t . rend i ts
+ _ -> id
+ new i = showChar '\n' . replicateS (2*i) (showChar ' ') . dropWhile isSpace
+ space t = showString t . (\s -> if null s then "" else (' ':s))
+
+parenth :: Doc -> Doc
+parenth ss = doc (showChar '(') . ss . doc (showChar ')')
+
+concatS :: [ShowS] -> ShowS
+concatS = foldr (.) id
+
+concatD :: [Doc] -> Doc
+concatD = foldr (.) id
+
+unwordsD :: [Doc] -> Doc
+unwordsD = concatD . intersperse (doc (showChar ' '))
+
+replicateS :: Int -> ShowS -> ShowS
+replicateS n f = concatS (replicate n f)
+
+-- the printer class does the job
+class Print a where
+ prt :: Int -> a -> Doc
+
+instance Print Char where
+ prt _ s = doc (showChar '\'' . mkEsc '\'' s . showChar '\'')
+
+instance Print String where
+ prt _ s = doc (showChar '"' . concatS (map (mkEsc '"') s) . showChar '"')
+
+mkEsc :: Char -> Char -> ShowS
+mkEsc q s = case s of
+ _ | s == q -> showChar '\\' . showChar s
+ '\\'-> showString "\\\\"
+ '\n' -> showString "\\n"
+ '\t' -> showString "\\t"
+ _ -> showChar s
+
+prPrec :: Int -> Int -> Doc -> Doc
+prPrec i j = if j prPrec _i 0 (concatD [prt 0 imports , prt 0 decls])
+ Import i -> prPrec _i 0 (concatD [doc (showString "import") , prt 0 i])
+ DataDecl i exp consdecls -> prPrec _i 0 (concatD [doc (showString "data") , prt 0 i , doc (showString ":") , prt 0 exp , doc (showString "where") , doc (showString "{") , prt 0 consdecls , doc (showString "}")])
+ TypeDecl i exp -> prPrec _i 0 (concatD [prt 0 i , doc (showString ":") , prt 0 exp])
+ ValueDecl i patterns guard exp -> prPrec _i 0 (concatD [prt 0 i , prt 0 patterns , prt 0 guard , doc (showString "=") , prt 0 exp])
+ DeriveDecl i0 i1 -> prPrec _i 0 (concatD [doc (showString "derive") , prt 0 i0 , prt 0 i1])
+ ConsDecl i exp -> prPrec _i 0 (concatD [prt 0 i , doc (showString ":") , prt 0 exp])
+ GuardExp exp -> prPrec _i 0 (concatD [doc (showString "|") , prt 1 exp])
+ GuardNo -> prPrec _i 0 (concatD [])
+ POr pattern0 pattern1 -> prPrec _i 0 (concatD [prt 1 pattern0 , doc (showString "||") , prt 0 pattern1])
+ PListCons pattern0 pattern1 -> prPrec _i 1 (concatD [prt 2 pattern0 , doc (showString "::") , prt 1 pattern1])
+ PConsTop i pattern patterns -> prPrec _i 2 (concatD [prt 0 i , prt 3 pattern , prt 0 patterns])
+ PCons i patterns -> prPrec _i 3 (concatD [doc (showString "(") , prt 0 i , prt 0 patterns , doc (showString ")")])
+ PRec fieldpatterns -> prPrec _i 3 (concatD [doc (showString "rec") , doc (showString "{") , prt 0 fieldpatterns , doc (showString "}")])
+ PEmptyList -> prPrec _i 3 (concatD [doc (showString "[") , doc (showString "]")])
+ PList commapatterns -> prPrec _i 3 (concatD [doc (showString "[") , prt 0 commapatterns , doc (showString "]")])
+ PTuple commapattern commapatterns -> prPrec _i 3 (concatD [doc (showString "(") , prt 0 commapattern , doc (showString ",") , prt 0 commapatterns , doc (showString ")")])
+ PStr str -> prPrec _i 3 (concatD [prt 0 str])
+ PInt n -> prPrec _i 3 (concatD [prt 0 n])
+ PVar i -> prPrec _i 3 (concatD [prt 0 i])
+ PWild -> prPrec _i 3 (concatD [doc (showString "_")])
+ CommaPattern pattern -> prPrec _i 0 (concatD [prt 0 pattern])
+ FieldPattern i pattern -> prPrec _i 0 (concatD [prt 0 i , doc (showString "=") , prt 0 pattern])
+ EPi varorwild exp0 exp1 -> prPrec _i 0 (concatD [doc (showString "(") , prt 0 varorwild , doc (showString ":") , prt 0 exp0 , doc (showString ")") , doc (showString "->") , prt 0 exp1])
+ EPiNoVar exp0 exp1 -> prPrec _i 0 (concatD [prt 1 exp0 , doc (showString "->") , prt 0 exp1])
+ EAbs varorwild exp -> prPrec _i 1 (concatD [doc (showString "\\") , prt 0 varorwild , doc (showString "->") , prt 1 exp])
+ ELet letdefs exp -> prPrec _i 1 (concatD [doc (showString "let") , doc (showString "{") , prt 0 letdefs , doc (showString "}") , doc (showString "in") , prt 1 exp])
+ ECase exp cases -> prPrec _i 1 (concatD [doc (showString "case") , prt 0 exp , doc (showString "of") , doc (showString "{") , prt 0 cases , doc (showString "}")])
+ EIf exp0 exp1 exp2 -> prPrec _i 1 (concatD [doc (showString "if") , prt 0 exp0 , doc (showString "then") , prt 0 exp1 , doc (showString "else") , prt 1 exp2])
+ EDo binds exp -> prPrec _i 1 (concatD [doc (showString "do") , doc (showString "{") , prt 0 binds , prt 0 exp , doc (showString "}")])
+ EBind exp0 exp1 -> prPrec _i 3 (concatD [prt 3 exp0 , doc (showString ">>=") , prt 4 exp1])
+ EBindC exp0 exp1 -> prPrec _i 3 (concatD [prt 3 exp0 , doc (showString ">>") , prt 4 exp1])
+ EOr exp0 exp1 -> prPrec _i 4 (concatD [prt 5 exp0 , doc (showString "||") , prt 4 exp1])
+ EAnd exp0 exp1 -> prPrec _i 5 (concatD [prt 6 exp0 , doc (showString "&&") , prt 5 exp1])
+ EEq exp0 exp1 -> prPrec _i 6 (concatD [prt 7 exp0 , doc (showString "==") , prt 7 exp1])
+ ENe exp0 exp1 -> prPrec _i 6 (concatD [prt 7 exp0 , doc (showString "/=") , prt 7 exp1])
+ ELt exp0 exp1 -> prPrec _i 6 (concatD [prt 7 exp0 , doc (showString "<") , prt 7 exp1])
+ ELe exp0 exp1 -> prPrec _i 6 (concatD [prt 7 exp0 , doc (showString "<=") , prt 7 exp1])
+ EGt exp0 exp1 -> prPrec _i 6 (concatD [prt 7 exp0 , doc (showString ">") , prt 7 exp1])
+ EGe exp0 exp1 -> prPrec _i 6 (concatD [prt 7 exp0 , doc (showString ">=") , prt 7 exp1])
+ EListCons exp0 exp1 -> prPrec _i 7 (concatD [prt 8 exp0 , doc (showString "::") , prt 7 exp1])
+ EAdd exp0 exp1 -> prPrec _i 8 (concatD [prt 8 exp0 , doc (showString "+") , prt 9 exp1])
+ ESub exp0 exp1 -> prPrec _i 8 (concatD [prt 8 exp0 , doc (showString "-") , prt 9 exp1])
+ EMul exp0 exp1 -> prPrec _i 9 (concatD [prt 9 exp0 , doc (showString "*") , prt 10 exp1])
+ EDiv exp0 exp1 -> prPrec _i 9 (concatD [prt 9 exp0 , doc (showString "/") , prt 10 exp1])
+ EMod exp0 exp1 -> prPrec _i 9 (concatD [prt 9 exp0 , doc (showString "%") , prt 10 exp1])
+ ENeg exp -> prPrec _i 10 (concatD [doc (showString "-") , prt 10 exp])
+ EApp exp0 exp1 -> prPrec _i 11 (concatD [prt 11 exp0 , prt 12 exp1])
+ EProj exp i -> prPrec _i 12 (concatD [prt 12 exp , doc (showString ".") , prt 0 i])
+ ERecType fieldtypes -> prPrec _i 13 (concatD [doc (showString "sig") , doc (showString "{") , prt 0 fieldtypes , doc (showString "}")])
+ ERec fieldvalues -> prPrec _i 13 (concatD [doc (showString "rec") , doc (showString "{") , prt 0 fieldvalues , doc (showString "}")])
+ EEmptyList -> prPrec _i 13 (concatD [doc (showString "[") , doc (showString "]")])
+ EList exps -> prPrec _i 13 (concatD [doc (showString "[") , prt 0 exps , doc (showString "]")])
+ ETuple exp exps -> prPrec _i 13 (concatD [doc (showString "(") , prt 0 exp , doc (showString ",") , prt 0 exps , doc (showString ")")])
+ EVar i -> prPrec _i 13 (concatD [prt 0 i])
+ EType -> prPrec _i 13 (concatD [doc (showString "Type")])
+ EStr str -> prPrec _i 13 (concatD [prt 0 str])
+ EInteger n -> prPrec _i 13 (concatD [prt 0 n])
+ EDouble d -> prPrec _i 13 (concatD [prt 0 d])
+ EMeta -> prPrec _i 13 (concatD [doc (showString "?")])
+ VVar i -> prPrec _i 0 (concatD [prt 0 i])
+ VWild -> prPrec _i 0 (concatD [doc (showString "_")])
+ LetDef i exp -> prPrec _i 0 (concatD [prt 0 i , doc (showString "=") , prt 0 exp])
+ Case pattern guard exp -> prPrec _i 0 (concatD [prt 0 pattern , prt 0 guard , doc (showString "->") , prt 0 exp])
+ BindVar varorwild exp -> prPrec _i 0 (concatD [prt 0 varorwild , doc (showString "<-") , prt 0 exp])
+ BindNoVar exp -> prPrec _i 0 (concatD [prt 0 exp])
+ FieldType i exp -> prPrec _i 0 (concatD [prt 0 i , doc (showString ":") , prt 0 exp])
+ FieldValue i exp -> prPrec _i 0 (concatD [prt 0 i , doc (showString "=") , prt 0 exp])
+ Ident str -> prPrec _i 0 (doc (showString str))
+
+instance Print [Import] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [Decl] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [ConsDecl] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [CommaPattern] where
+ prt _ es = case es of
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+instance Print [Pattern] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ x:xs -> (concatD [prt 3 x , prt 0 xs])
+instance Print [FieldPattern] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [LetDef] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [Case] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [Bind] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [FieldType] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [FieldValue] where
+ prt _ es = case es of
+ [] -> (concatD [])
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
+instance Print [Exp] where
+ prt _ es = case es of
+ [x] -> (concatD [prt 0 x])
+ x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
diff --git a/src-2.9/Transfer/Syntax/ResolveLayout.hs b/src-2.9/Transfer/Syntax/ResolveLayout.hs
new file mode 100644
index 000000000..9d7ab607a
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/ResolveLayout.hs
@@ -0,0 +1,29 @@
+module Main where
+
+import System.Environment (getArgs)
+
+import Transfer.Syntax.Lex
+import Transfer.Syntax.Layout
+
+prTokens :: [Token] -> String
+prTokens = prTokens_ 1 1
+ where
+ prTokens_ _ _ [] = ""
+ prTokens_ l c (t@(PT (Pn _ l' c') _):ts) =
+ replicate (l'-l) '\n'
+ ++ replicate (if l' == l then c'-c else c'-1) ' '
+ ++ s ++ prTokens_ l' (c'+length s) ts
+ where s = prToken t
+-- prTokens_ l c (Err p:ts) =
+
+layout :: String -> String
+layout s = prTokens ts'
+-- ++ "\n" ++ show ts'
+ where ts = tokens s
+ ts' = resolveLayout True ts
+
+main :: IO ()
+main = do args <- getArgs
+ case args of
+ [] -> getContents >>= putStrLn . layout
+ fs -> mapM_ (\f -> readFile f >>= putStrLn . layout) fs
diff --git a/src-2.9/Transfer/Syntax/Skel.hs b/src-2.9/Transfer/Syntax/Skel.hs
new file mode 100644
index 000000000..b2376478b
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Skel.hs
@@ -0,0 +1,200 @@
+module Transfer.Syntax.Skel where
+
+-- Haskell module generated by the BNF converter
+
+import Transfer.Syntax.Abs
+import Transfer.ErrM
+type Result = Err String
+
+failure :: Show a => a -> Result
+failure x = Bad $ "Undefined case: " ++ show x
+
+transTree :: Tree c -> Result
+transTree t = case t of
+ Module imports decls -> failure t
+ Import i -> failure t
+ DataDecl i exp consdecls -> failure t
+ TypeDecl i exp -> failure t
+ ValueDecl i patterns guard exp -> failure t
+ DeriveDecl i0 i1 -> failure t
+ ConsDecl i exp -> failure t
+ GuardExp exp -> failure t
+ GuardNo -> failure t
+ POr pattern0 pattern1 -> failure t
+ PListCons pattern0 pattern1 -> failure t
+ PConsTop i pattern patterns -> failure t
+ PCons i patterns -> failure t
+ PRec fieldpatterns -> failure t
+ PEmptyList -> failure t
+ PList commapatterns -> failure t
+ PTuple commapattern commapatterns -> failure t
+ PStr str -> failure t
+ PInt n -> failure t
+ PVar i -> failure t
+ PWild -> failure t
+ CommaPattern pattern -> failure t
+ FieldPattern i pattern -> failure t
+ EPi varorwild exp0 exp1 -> failure t
+ EPiNoVar exp0 exp1 -> failure t
+ EAbs varorwild exp -> failure t
+ ELet letdefs exp -> failure t
+ ECase exp cases -> failure t
+ EIf exp0 exp1 exp2 -> failure t
+ EDo binds exp -> failure t
+ EBind exp0 exp1 -> failure t
+ EBindC exp0 exp1 -> failure t
+ EOr exp0 exp1 -> failure t
+ EAnd exp0 exp1 -> failure t
+ EEq exp0 exp1 -> failure t
+ ENe exp0 exp1 -> failure t
+ ELt exp0 exp1 -> failure t
+ ELe exp0 exp1 -> failure t
+ EGt exp0 exp1 -> failure t
+ EGe exp0 exp1 -> failure t
+ EListCons exp0 exp1 -> failure t
+ EAdd exp0 exp1 -> failure t
+ ESub exp0 exp1 -> failure t
+ EMul exp0 exp1 -> failure t
+ EDiv exp0 exp1 -> failure t
+ EMod exp0 exp1 -> failure t
+ ENeg exp -> failure t
+ EApp exp0 exp1 -> failure t
+ EProj exp i -> failure t
+ ERecType fieldtypes -> failure t
+ ERec fieldvalues -> failure t
+ EEmptyList -> failure t
+ EList exps -> failure t
+ ETuple exp exps -> failure t
+ EVar i -> failure t
+ EType -> failure t
+ EStr str -> failure t
+ EInteger n -> failure t
+ EDouble d -> failure t
+ EMeta -> failure t
+ VVar i -> failure t
+ VWild -> failure t
+ LetDef i exp -> failure t
+ Case pattern guard exp -> failure t
+ BindVar varorwild exp -> failure t
+ BindNoVar exp -> failure t
+ FieldType i exp -> failure t
+ FieldValue i exp -> failure t
+ Ident str -> failure t
+
+transModule :: Module -> Result
+transModule t = case t of
+ Module imports decls -> failure t
+
+transImport :: Import -> Result
+transImport t = case t of
+ Import i -> failure t
+
+transDecl :: Decl -> Result
+transDecl t = case t of
+ DataDecl i exp consdecls -> failure t
+ TypeDecl i exp -> failure t
+ ValueDecl i patterns guard exp -> failure t
+ DeriveDecl i0 i1 -> failure t
+
+transConsDecl :: ConsDecl -> Result
+transConsDecl t = case t of
+ ConsDecl i exp -> failure t
+
+transGuard :: Guard -> Result
+transGuard t = case t of
+ GuardExp exp -> failure t
+ GuardNo -> failure t
+
+transPattern :: Pattern -> Result
+transPattern t = case t of
+ POr pattern0 pattern1 -> failure t
+ PListCons pattern0 pattern1 -> failure t
+ PConsTop i pattern patterns -> failure t
+ PCons i patterns -> failure t
+ PRec fieldpatterns -> failure t
+ PEmptyList -> failure t
+ PList commapatterns -> failure t
+ PTuple commapattern commapatterns -> failure t
+ PStr str -> failure t
+ PInt n -> failure t
+ PVar i -> failure t
+ PWild -> failure t
+
+transCommaPattern :: CommaPattern -> Result
+transCommaPattern t = case t of
+ CommaPattern pattern -> failure t
+
+transFieldPattern :: FieldPattern -> Result
+transFieldPattern t = case t of
+ FieldPattern i pattern -> failure t
+
+transExp :: Exp -> Result
+transExp t = case t of
+ EPi varorwild exp0 exp1 -> failure t
+ EPiNoVar exp0 exp1 -> failure t
+ EAbs varorwild exp -> failure t
+ ELet letdefs exp -> failure t
+ ECase exp cases -> failure t
+ EIf exp0 exp1 exp2 -> failure t
+ EDo binds exp -> failure t
+ EBind exp0 exp1 -> failure t
+ EBindC exp0 exp1 -> failure t
+ EOr exp0 exp1 -> failure t
+ EAnd exp0 exp1 -> failure t
+ EEq exp0 exp1 -> failure t
+ ENe exp0 exp1 -> failure t
+ ELt exp0 exp1 -> failure t
+ ELe exp0 exp1 -> failure t
+ EGt exp0 exp1 -> failure t
+ EGe exp0 exp1 -> failure t
+ EListCons exp0 exp1 -> failure t
+ EAdd exp0 exp1 -> failure t
+ ESub exp0 exp1 -> failure t
+ EMul exp0 exp1 -> failure t
+ EDiv exp0 exp1 -> failure t
+ EMod exp0 exp1 -> failure t
+ ENeg exp -> failure t
+ EApp exp0 exp1 -> failure t
+ EProj exp i -> failure t
+ ERecType fieldtypes -> failure t
+ ERec fieldvalues -> failure t
+ EEmptyList -> failure t
+ EList exps -> failure t
+ ETuple exp exps -> failure t
+ EVar i -> failure t
+ EType -> failure t
+ EStr str -> failure t
+ EInteger n -> failure t
+ EDouble d -> failure t
+ EMeta -> failure t
+
+transVarOrWild :: VarOrWild -> Result
+transVarOrWild t = case t of
+ VVar i -> failure t
+ VWild -> failure t
+
+transLetDef :: LetDef -> Result
+transLetDef t = case t of
+ LetDef i exp -> failure t
+
+transCase :: Case -> Result
+transCase t = case t of
+ Case pattern guard exp -> failure t
+
+transBind :: Bind -> Result
+transBind t = case t of
+ BindVar varorwild exp -> failure t
+ BindNoVar exp -> failure t
+
+transFieldType :: FieldType -> Result
+transFieldType t = case t of
+ FieldType i exp -> failure t
+
+transFieldValue :: FieldValue -> Result
+transFieldValue t = case t of
+ FieldValue i exp -> failure t
+
+transIdent :: Ident -> Result
+transIdent t = case t of
+ Ident str -> failure t
+
diff --git a/src-2.9/Transfer/Syntax/Syntax.cf b/src-2.9/Transfer/Syntax/Syntax.cf
new file mode 100644
index 000000000..7429e34f9
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Syntax.cf
@@ -0,0 +1,147 @@
+entrypoints Module, Exp ;
+
+layout "let", "where", "of","rec", "sig", "do" ;
+layout stop "in" ;
+layout toplevel ;
+
+comment "--" ;
+comment "{-" "-}" ;
+
+Module. Module ::= [Import] [Decl] ;
+
+Import. Import ::= "import" Ident ;
+-- FIXME: this is terminator to ensure that the pretty printer
+-- produces a semicolon after the last import. This could cause
+-- problems in a program which only does imports and uses layout syntax.
+terminator Import ";" ;
+
+DataDecl. Decl ::= "data" Ident ":" Exp "where" "{" [ConsDecl] "}" ;
+TypeDecl. Decl ::= Ident ":" Exp ;
+ValueDecl. Decl ::= Ident [Pattern] Guard "=" Exp ;
+DeriveDecl. Decl ::= "derive" Ident Ident ;
+terminator Decl ";" ;
+
+ConsDecl. ConsDecl ::= Ident ":" Exp ;
+separator ConsDecl ";" ;
+
+GuardExp. Guard ::= "|" Exp1 ;
+GuardNo. Guard ::= ;
+
+-- Disjunctive patterns.
+POr. Pattern ::= Pattern1 "||" Pattern ;
+
+-- List constructor patterns
+PListCons. Pattern1 ::= Pattern2 "::" Pattern1 ;
+
+-- Hack: constructor applied to at least one pattern
+-- this is to separate it from variable patterns
+PConsTop. Pattern2 ::= Ident Pattern3 [Pattern] ;
+
+-- Real constructor pattern
+internal PCons. Pattern3 ::= "(" Ident [Pattern] ")" ;
+
+-- Record patterns
+PRec. Pattern3 ::= "rec" "{" [FieldPattern] "}";
+
+-- List patterns
+PEmptyList. Pattern3 ::= "[" "]" ;
+PList. Pattern3 ::= "[" [CommaPattern] "]" ;
+
+-- Tuple patterns
+PTuple. Pattern3 ::= "(" CommaPattern "," [CommaPattern] ")" ;
+
+-- hack to allow a different [Pattern] from the one defined
+-- for constructor patterns
+CommaPattern. CommaPattern ::= Pattern ;
+separator nonempty CommaPattern "," ;
+
+-- String literal patterns
+PStr. Pattern3 ::= String ;
+-- Integer literal patterns
+PInt. Pattern3 ::= Integer ;
+-- Variable patterns
+PVar. Pattern3 ::= Ident ;
+-- Wild card patterns
+PWild. Pattern3 ::= "_" ;
+
+coercions Pattern 3 ;
+
+[]. [Pattern] ::= ;
+(:). [Pattern] ::= Pattern3 [Pattern] ;
+
+FieldPattern. FieldPattern ::= Ident "=" Pattern ;
+separator FieldPattern ";" ;
+
+-- Function types have precedence < 1 to keep the
+-- "->" from conflicting with the "->" after guards
+EPi. Exp ::= "(" VarOrWild ":" Exp ")" "->" Exp ;
+EPiNoVar. Exp ::= Exp1 "->" Exp ;
+VVar. VarOrWild ::= Ident ;
+VWild. VarOrWild ::= "_" ;
+
+EAbs. Exp1 ::= "\\" VarOrWild "->" Exp1 ;
+ELet. Exp1 ::= "let" "{" [LetDef] "}" "in" Exp1 ;
+LetDef. LetDef ::= Ident "=" Exp ;
+separator LetDef ";" ;
+ECase. Exp1 ::= "case" Exp "of" "{" [Case] "}" ;
+Case. Case ::= Pattern Guard "->" Exp ;
+separator Case ";" ;
+EIf. Exp1 ::= "if" Exp "then" Exp "else" Exp1 ;
+EDo. Exp1 ::= "do" "{" [Bind] Exp "}" ;
+BindVar. Bind ::= VarOrWild "<-" Exp ;
+BindNoVar. Bind ::= Exp ;
+terminator Bind ";" ;
+
+EBind. Exp3 ::= Exp3 ">>=" Exp4 ;
+EBindC. Exp3 ::= Exp3 ">>" Exp4 ;
+
+EOr. Exp4 ::= Exp5 "||" Exp4 ;
+
+EAnd. Exp5 ::= Exp6 "&&" Exp5 ;
+
+EEq. Exp6 ::= Exp7 "==" Exp7 ;
+ENe. Exp6 ::= Exp7 "/=" Exp7 ;
+ELt. Exp6 ::= Exp7 "<" Exp7 ;
+ELe. Exp6 ::= Exp7 "<=" Exp7 ;
+EGt. Exp6 ::= Exp7 ">" Exp7 ;
+EGe. Exp6 ::= Exp7 ">=" Exp7 ;
+
+EListCons. Exp7 ::= Exp8 "::" Exp7 ;
+
+EAdd. Exp8 ::= Exp8 "+" Exp9 ;
+ESub. Exp8 ::= Exp8 "-" Exp9 ;
+
+EMul. Exp9 ::= Exp9 "*" Exp10 ;
+EDiv. Exp9 ::= Exp9 "/" Exp10 ;
+EMod. Exp9 ::= Exp9 "%" Exp10 ;
+
+ENeg. Exp10 ::= "-" Exp10 ;
+
+EApp. Exp11 ::= Exp11 Exp12 ;
+
+EProj. Exp12 ::= Exp12 "." Ident ;
+
+ERecType. Exp13 ::= "sig" "{" [FieldType] "}" ;
+FieldType. FieldType ::= Ident ":" Exp ;
+separator FieldType ";" ;
+
+ERec. Exp13 ::= "rec" "{" [FieldValue] "}" ;
+FieldValue.FieldValue ::= Ident "=" Exp ;
+separator FieldValue ";" ;
+
+EEmptyList.Exp13 ::= "[" "]" ;
+EList. Exp13 ::= "[" [Exp] "]" ;
+
+-- n-tuple, where n>=2
+ETuple. Exp13 ::= "(" Exp "," [Exp] ")" ;
+
+EVar. Exp13 ::= Ident ;
+EType. Exp13 ::= "Type" ;
+EStr. Exp13 ::= String ;
+EInteger. Exp13 ::= Integer ;
+EDouble. Exp13 ::= Double ;
+EMeta. Exp13 ::= "?" ;
+
+coercions Exp 13 ;
+
+separator nonempty Exp "," ;
diff --git a/src-2.9/Transfer/Syntax/Test.hs b/src-2.9/Transfer/Syntax/Test.hs
new file mode 100644
index 000000000..3f5fab7ad
--- /dev/null
+++ b/src-2.9/Transfer/Syntax/Test.hs
@@ -0,0 +1,58 @@
+-- automatically generated by BNF Converter
+module Main where
+
+
+import IO ( stdin, hGetContents )
+import System ( getArgs, getProgName )
+
+import Transfer.Syntax.Lex
+import Transfer.Syntax.Par
+import Transfer.Syntax.Skel
+import Transfer.Syntax.Print
+import Transfer.Syntax.Abs
+import Transfer.Syntax.Layout
+
+
+
+import Transfer.ErrM
+
+type ParseFun a = [Token] -> Err a
+
+myLLexer = resolveLayout True . myLexer
+
+type Verbosity = Int
+
+putStrV :: Verbosity -> String -> IO ()
+putStrV v s = if v > 1 then putStrLn s else return ()
+
+runFile :: (Print a, Show a) => Verbosity -> ParseFun a -> FilePath -> IO ()
+runFile v p f = putStrLn f >> readFile f >>= run v p
+
+run :: (Print a, Show a) => Verbosity -> ParseFun a -> String -> IO ()
+run v p s = let ts = myLLexer s in case p ts of
+ Bad s -> do putStrLn "\nParse Failed...\n"
+ putStrV v "Tokens:"
+ putStrV v $ show ts
+ putStrLn s
+ Ok tree -> do putStrLn "\nParse Successful!"
+ showTree v tree
+
+
+
+showTree :: (Show a, Print a) => Int -> a -> IO ()
+showTree v tree
+ = do
+ putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
+ putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
+
+main :: IO ()
+main = do args <- getArgs
+ case args of
+ [] -> hGetContents stdin >>= run 2 pModule
+ "-s":fs -> mapM_ (runFile 0 pModule) fs
+ fs -> mapM_ (runFile 2 pModule) fs
+
+
+
+
+
diff --git a/src-2.9/Transfer/SyntaxToCore.hs b/src-2.9/Transfer/SyntaxToCore.hs
new file mode 100644
index 000000000..32796eb50
--- /dev/null
+++ b/src-2.9/Transfer/SyntaxToCore.hs
@@ -0,0 +1,766 @@
+-- | Translate to the core language
+module Transfer.SyntaxToCore where
+
+import Transfer.Syntax.Abs
+import Transfer.Syntax.Print
+
+import Control.Monad.State
+import Data.List
+import Data.Maybe
+import qualified Data.Set as Set
+import Data.Set (Set)
+import qualified Data.Map as Map
+import Data.Map (Map)
+import Data.Monoid
+
+import Debug.Trace
+
+type C a = State CState a
+
+data CState = CState {
+ nextVar :: Integer,
+ nextMeta :: Integer
+ }
+
+
+
+declsToCore :: [Decl] -> [Decl]
+declsToCore m = evalState (declsToCore_ m) newState
+
+declsToCore_ :: [Decl] -> C [Decl]
+declsToCore_ = deriveDecls
+ >>> desugar
+ >>> compilePattDecls
+ >>> numberMetas
+ >>> replaceCons
+ >>> expandOrPatts
+ >>> optimize
+
+optimize :: [Decl] -> C [Decl]
+optimize = uniqueVars
+ >>> removeUselessMatch
+ >>> betaReduce
+
+newState :: CState
+newState = CState {
+ nextVar = 0,
+ nextMeta = 0
+ }
+
+
+--
+-- * Make all variable names unique
+--
+
+uniqueVars :: [Decl] -> C [Decl]
+uniqueVars = mapM (f Map.empty)
+ where
+ f :: Map Ident Ident -> Tree a -> C (Tree a)
+ f ss t = case t of
+ ELet ds _ ->
+ do
+ let vs = Set.toList (letDefBinds ds)
+ vs' <- freshIdents (length vs)
+ let ss' = addToSubstEnv (zip vs vs') ss
+ composOpM (f ss') t
+ LetDef i e ->
+ case Map.lookup i ss of
+ Nothing -> fail $ "let var " ++ printTree i ++ " not renamed"
+ Just i' -> liftM (LetDef i') (f ss e)
+ Case p _ _ ->
+ do
+ let vs = Set.toList (binds p)
+ vs' <- freshIdents (length vs)
+ let ss' = addToSubstEnv (zip vs vs') ss
+ composOpM (f ss') t
+ EAbs (VVar i) e ->
+ do
+ i' <- freshIdent
+ let ss' = addToSubstEnv [(i,i')] ss
+ liftM (EAbs (VVar i')) (f ss' e)
+ EPi (VVar i) e1 e2 ->
+ do
+ i' <- freshIdent
+ let ss' = addToSubstEnv [(i,i')] ss
+ liftM2 (EPi (VVar i')) (f ss e1) (f ss' e2)
+ EVar i -> return $ case Map.lookup i ss of
+ Nothing -> t -- constructor
+ Just i' -> EVar i'
+ PVar i -> return $ case Map.lookup i ss of
+ Nothing -> t -- constructor
+ Just i' -> PVar i'
+ _ -> composOpM (f ss) t
+ where addToSubstEnv bs m = foldr (\ (k,v) -> Map.insert k v) m bs
+
+--
+-- * Number meta variables
+--
+
+numberMetas :: [Decl] -> C [Decl]
+numberMetas = mapM f
+ where
+ f :: Tree a -> C (Tree a)
+ f t = case t of
+ EMeta -> do
+ st <- get
+ put (st { nextMeta = nextMeta st + 1})
+ return $ EVar $ Ident $ "?" ++ show (nextMeta st) -- FIXME: hack
+ _ -> composOpM f t
+
+
+--
+-- * Pattern equations
+--
+
+compilePattDecls :: [Decl] -> C [Decl]
+compilePattDecls [] = return []
+compilePattDecls (d@(ValueDecl x _ _ _):ds) =
+ do
+ let (xs,rest) = span (isValueDecl x) ds
+ d <- mergeDecls (d:xs)
+ rs <- compilePattDecls rest
+ return (d:rs)
+compilePattDecls (d:ds) = liftM (d:) (compilePattDecls ds)
+
+-- | Checks if a declaration is a value declaration
+-- of the given identifier.
+isValueDecl :: Ident -> Decl -> Bool
+isValueDecl x (ValueDecl y _ _ _) = x == y
+isValueDecl _ _ = False
+
+-- | Take a non-empty list of pattern equations with guards
+-- for the same function, and produce a single declaration.
+mergeDecls :: [Decl] -> C Decl
+mergeDecls ds@(ValueDecl x p _ _:_)
+ = do let cs = [ (ps,g,rhs) | ValueDecl _ ps g rhs <- ds ]
+ (pss,_,_) = unzip3 cs
+ n = length p
+ when (not (all ((== n) . length) pss))
+ $ fail $ "Pattern count mismatch for " ++ printTree x
+ vs <- freshIdents n
+ let cases = map (\ (ps,g,rhs) -> Case (mkPTuple ps) g rhs) cs
+ c = ECase (mkETuple (map EVar vs)) cases
+ f = foldr (EAbs . VVar) c vs
+ return $ ValueDecl x [] GuardNo f
+
+--
+-- * Derived function definitions
+--
+
+deriveDecls :: [Decl] -> C [Decl]
+deriveDecls ds = liftM concat (mapM der ds)
+ where
+ ts = dataTypes ds
+ der (DeriveDecl (Ident f) t) =
+ case lookup f derivators of
+ Just d -> d t k cs
+ _ -> fail $ "Don't know how to derive " ++ f
+ where (k,cs) = getDataType ts t
+ der d = return [d]
+
+type Derivator = Ident -> Exp -> [(Ident,Exp)] -> C [Decl]
+
+derivators :: [(String, Derivator)]
+derivators = [
+ ("Compos", deriveCompos),
+ ("Show", deriveShow),
+ ("Eq", deriveEq),
+ ("Ord", deriveOrd)
+ ]
+
+--
+-- * Deriving instances of Compos
+--
+
+deriveCompos :: Derivator
+deriveCompos t@(Ident ts) k cs =
+ do
+ co <- deriveComposOp t k cs
+ cf <- deriveComposFold t k cs
+ let [c] = argumentTypes k -- FIXME: what if there is not exactly one argument to t?
+ d = Ident ("compos_"++ts)
+ dt = apply (var "Compos") [c, EVar t]
+ r = ERec [FieldValue (Ident "composOp") co,
+ FieldValue (Ident "composFold") cf]
+ return [TypeDecl d dt, ValueDecl d [] GuardNo r]
+
+deriveComposOp :: Ident -> Exp -> [(Ident,Exp)] -> C Exp
+deriveComposOp t k cs =
+ do
+ f <- freshIdent
+ x <- freshIdent
+ let e = EVar
+ pv = VVar
+ infixr 3 \->
+ (\->) = EAbs
+ mkCase ci ct =
+ do
+ vars <- freshIdents (arity ct)
+ -- FIXME: the type argument to f is wrong if the constructor
+ -- has a dependent type
+ -- FIXME: make a special case for lists?
+ let rec v at = case at of
+ EApp (EVar t') c | t' == t -> apply (e f) [c, e v]
+ _ -> e v
+ calls = zipWith rec vars (argumentTypes ct)
+ return $ Case (PCons ci (map PVar vars)) gtrue (apply (e ci) calls)
+ cases <- mapM (uncurry mkCase) cs
+ let cases' = cases ++ [Case PWild gtrue (e x)]
+ fb <- abstract (arity k) $ const $ pv f \-> pv x \-> ECase (e x) cases'
+ return fb
+
+deriveComposFold :: Ident -> Exp -> [(Ident,Exp)] -> C Exp
+deriveComposFold t k cs =
+ do
+ f <- freshIdent
+ x <- freshIdent
+ b <- freshIdent
+ r <- freshIdent
+ let e = EVar
+ pv = VVar
+ infixr 3 \->
+ (\->) = EAbs
+ mkCase ci ct =
+ do
+ vars <- freshIdents (arity ct)
+ -- FIXME: the type argument to f is wrong if the constructor
+ -- has a dependent type
+ -- FIXME: make a special case for lists?
+ let rec v at = case at of
+ EApp (EVar t') c | t' == t -> apply (e f) [c, e v]
+ _ -> e v
+ calls = zipWith rec vars (argumentTypes ct)
+ z = EProj (e r) (Ident "mzero")
+ p = EProj (e r) (Ident "mplus")
+ joinCalls [] = z
+ joinCalls cs = foldr1 (\x y -> apply p [x,y]) cs
+ return $ Case (PCons ci (map PVar vars)) gtrue (joinCalls calls)
+ cases <- mapM (uncurry mkCase) cs
+ let cases' = cases ++ [Case PWild gtrue (e x)]
+ fb <- abstract (arity k) $ const $ pv f \-> pv x \-> ECase (e x) cases'
+ return $ VWild \-> pv r \-> fb
+
+--
+-- * Deriving instances of Show
+--
+
+deriveShow :: Derivator
+deriveShow t k cs = fail $ "derive Show not implemented"
+
+--
+-- * Deriving instances of Eq
+--
+
+-- FIXME: how do we require Eq instances for all
+-- constructor arguments?
+
+deriveEq :: Derivator
+deriveEq t@(Ident tn) k cs =
+ do
+ dt <- abstractType ats (EApp (var "Eq") . apply (EVar t))
+ f <- mkEq
+ r <- abstract (arity k) (\_ -> ERec [FieldValue (Ident "eq") f])
+ return [TypeDecl d dt, ValueDecl d [] GuardNo r]
+ where
+ ats = argumentTypes k
+ d = Ident ("eq_"++tn)
+ mkEq = do
+ x <- freshIdent
+ y <- freshIdent
+ cases <- mapM (uncurry mkEqCase) cs
+ let fc = Case PWild gtrue false
+ abstract 2 (\es -> ECase (mkETuple es) (cases++[fc]))
+ mkEqCase c ct =
+ do
+ let n = arity ct
+ ts = argumentTypes ct
+ vs1 <- freshIdents n
+ vs2 <- freshIdents n
+ let pr = mkPTuple [PCons c (map PVar vs1), PCons c (map PVar vs2)]
+ eqs = concat $ zipWith3 child_eq ts vs1 vs2
+ rhs [] = true
+ rhs xs = foldr1 EAnd xs
+ return $ Case pr gtrue (rhs eqs)
+ -- FIXME: hack: this returns a list to skip testing type arguments.
+ child_eq EType _ _ = []
+ child_eq t x y = [apply (var "eq") [t,eq_dict t, EVar x, EVar y]]
+ -- FIXME: this is a hack to at least support Tree types
+ eq_dict (EApp (EVar t') _)
+ | t' == t = apply (EVar d) (replicate (arity k) EMeta)
+ eq_dict (EVar (Ident x))
+ | x `elem` ["String","Integer","Double"] = var ("eq_"++x)
+ eq_dict _ = EMeta
+
+--
+-- * Deriving instances of Ord
+--
+
+deriveOrd :: Derivator
+deriveOrd t k cs = fail $ "derive Ord not implemented"
+
+--
+-- * Constructor patterns and applications.
+--
+
+type DataConsInfo = Map Ident Int
+
+consArities :: [Decl] -> DataConsInfo
+consArities ds = Map.fromList [ (c, arity t) | DataDecl _ _ cs <- ds,
+ ConsDecl c t <- cs ]
+
+-- | Get the arity of a function type.
+arity :: Exp -> Int
+arity = length . argumentTypes
+
+-- | Get the argument type of a function type. Note that
+-- the returned types may contains free variables
+-- which should be bound to the values of earlier arguments.
+argumentTypes :: Exp -> [Exp]
+argumentTypes e = case e of
+ EPi _ t e' -> t : argumentTypes e'
+ EPiNoVar t e' -> t : argumentTypes e'
+ _ -> []
+
+-- | Fix up constructor patterns and applications.
+replaceCons :: [Decl] -> C [Decl]
+replaceCons ds = mapM (f cs) ds
+ where
+ cs = consArities ds
+ f :: DataConsInfo -> Tree a -> C (Tree a)
+ f cs x = case x of
+ -- get rid of the PConsTop hack
+ PConsTop id p1 ps -> f cs (PCons id (p1:ps))
+ -- replace patterns C where C is a constructor with (C)
+ PVar id | isCons id -> return $ PCons id []
+ -- don't eta-expand overshadowed constructors
+ EAbs (VVar id) e | isCons id ->
+ liftM (EAbs (VVar id)) (f (Map.delete id cs) e)
+ EPi (VVar id) t e | isCons id ->
+ liftM2 (EPi (VVar id)) (f cs t) (f (Map.delete id cs) e)
+ -- eta-expand constructors. betaReduce will remove any beta
+ -- redexes produced here.
+ EVar id | isCons id -> do
+ let Just n = Map.lookup id cs
+ abstract n (apply x)
+ _ -> composOpM (f cs) x
+ where isCons = (`Map.member` cs)
+
+--
+-- * Do simple beta reductions.
+--
+
+betaReduce :: [Decl] -> C [Decl]
+betaReduce = return . map f
+ where
+ f :: Tree a -> Tree a
+ f t = case t of
+ EApp e1 e2 ->
+ case (f e1, f e2) of
+ (EAbs (VVar x) b, e) | countFreeOccur x b == 1 -> f (subst x e b)
+ (e1',e2') -> EApp e1' e2'
+ _ -> composOp f t
+
+--
+-- * Remove useless pattern matching and variable binding.
+--
+
+removeUselessMatch :: [Decl] -> C [Decl]
+removeUselessMatch = return . map f
+ where
+ f :: Tree a -> Tree a
+ f x = case x of
+ EAbs (VVar x) b ->
+ case f b of
+ -- replace \x -> case x of { y | True -> e } with \y -> e,
+ -- if x is not free in e
+ ECase (EVar x') [Case (PVar y) g e]
+ | x' == x && isTrueGuard g && not (x `isFreeIn` e)
+ -> f (EAbs (VVar y) e)
+ -- replace unused variable in lambda with wild card
+ e | not (x `isFreeIn` e) -> f (EAbs VWild e)
+ e -> EAbs (VVar x) e
+ -- replace unused variable in pi with wild card
+ EPi (VVar x) t e ->
+ let e' = f e
+ v = if not (x `isFreeIn` e') then VWild else VVar x
+ in EPi v (f t) e'
+ -- replace unused variables in case patterns with wild cards
+ Case p (GuardExp g) e ->
+ let g' = f g
+ e' = f e
+ used = freeVars g' `Set.union` freeVars e'
+ p' = f (removeUnusedVarPatts used p)
+ in Case p' (GuardExp g') e'
+ -- for value declarations without patterns, compilePattDecls
+ -- generates pattern matching on the empty record, remove these
+ ECase (ERec []) [Case (PRec []) g e] | isTrueGuard g -> f e
+ -- if the pattern matching is on a single field of a record expression
+ -- with only one field, there is no need to wrap it in a record
+ ECase (ERec [FieldValue x e]) cs | all (isSingleFieldPattern x) (casePatterns cs)
+ -> f (ECase e [ Case p g r | Case (PRec [FieldPattern _ p]) g r <- cs ])
+ -- for all fields in record matching where all patterns for the field just
+ -- bind variables, substitute in the field value (if it is a variable)
+ -- in the guards and right hand sides.
+ ECase (ERec fs) cs | all isPRec (casePatterns cs) ->
+ let h (FieldValue f v@(EVar _):fs) xs
+ | all (onlyBindsFieldToVariable f) (casePatterns xs)
+ = h fs (map (inlineField f v) xs)
+ h (f:fs) xs = let (fs',xs') = h fs xs in (f:fs',xs')
+ h [] xs = ([],xs)
+ inlineField f v (Case (PRec fps) (GuardExp g) e) =
+ let p' = PRec [fp | fp@(FieldPattern f' _) <- fps, f' /= f]
+ ss = zip (fieldPatternVars f fps) (repeat v)
+ in Case p' (GuardExp (substs ss g)) (substs ss e)
+ (fs',cs') = h fs cs
+ x' = ECase (ERec fs') cs'
+ in if length fs' < length fs then f x' else composOp f x'
+ -- Remove wild card patterns in record patterns
+ PRec fps -> PRec (map f (fps \\ wildcards))
+ where wildcards = [fp | fp@(FieldPattern _ PWild) <- fps]
+ _ -> composOp f x
+
+isTrueGuard :: Guard -> Bool
+isTrueGuard (GuardExp (EVar (Ident "True"))) = True
+isTrueGuard GuardNo = True
+isTrueGuard _ = False
+
+removeUnusedVarPatts :: Set Ident -> Tree a -> Tree a
+removeUnusedVarPatts keep x = case x of
+ PVar id | not (id `Set.member` keep) -> PWild
+ _ -> composOp (removeUnusedVarPatts keep) x
+
+isSingleFieldPattern :: Ident -> Pattern -> Bool
+isSingleFieldPattern x p = case p of
+ PRec [FieldPattern y _] -> x == y
+ _ -> False
+
+casePatterns :: [Case] -> [Pattern]
+casePatterns cs = [p | Case p _ _ <- cs]
+
+isPRec :: Pattern -> Bool
+isPRec (PRec _) = True
+isPRec _ = False
+
+-- | Checks if given pattern is a record pattern, and matches the field
+-- with just a variable, with a wild card, or not at all.
+onlyBindsFieldToVariable :: Ident -> Pattern -> Bool
+onlyBindsFieldToVariable f (PRec fps) =
+ all isVar [p | FieldPattern f' p <- fps, f == f']
+ where isVar (PVar _) = True
+ isVar PWild = True
+ isVar _ = False
+onlyBindsFieldToVariable _ _ = False
+
+fieldPatternVars :: Ident -> [FieldPattern] -> [Ident]
+fieldPatternVars f fps = [p | FieldPattern f' (PVar p) <- fps, f == f']
+
+--
+-- * Expand disjunctive patterns.
+--
+
+expandOrPatts :: [Decl] -> C [Decl]
+expandOrPatts = return . map f
+ where
+ f :: Tree a -> Tree a
+ f x = case x of
+ ECase e cs -> ECase (f e) (concatMap (expandCase . f) cs)
+ _ -> composOp f x
+
+expandCase :: Case -> [Case]
+expandCase (Case p g e) = [ Case p' g e | p' <- expandPatt p ]
+
+expandPatt :: Pattern -> [Pattern]
+expandPatt p = case p of
+ POr p1 p2 -> expandPatt p1 ++ expandPatt p2
+ PCons i ps -> map (PCons i) $ expandPatts ps
+ PRec fps -> let (fs,ps) = unzip $ fromPRec fps
+ fpss = map (zip fs) (expandPatts ps)
+ in map (PRec . toPRec) fpss
+ _ -> [p]
+
+expandPatts :: [Pattern] -> [[Pattern]]
+expandPatts [] = [[]]
+expandPatts (p:ps) = [ p':ps' | p' <- expandPatt p, ps' <- expandPatts ps]
+
+--
+-- * Remove simple syntactic sugar.
+--
+
+desugar :: [Decl] -> C [Decl]
+desugar = return . map f
+ where
+ f :: Tree a -> Tree a
+ f x = case x of
+ PListCons p1 p2 -> pListCons <| p1 <| p2
+ PEmptyList -> pList []
+ PList xs -> pList [f p | CommaPattern p <- xs]
+ PTuple x xs -> mkPTuple [f p | CommaPattern p <- (x:xs)]
+ GuardNo -> gtrue
+ EIf exp0 exp1 exp2 -> ifBool <| exp0 <| exp1 <| exp2
+ EDo bs e -> mkDo (map f bs) (f e)
+ BindNoVar exp0 -> BindVar VWild <| exp0
+ EPiNoVar exp0 exp1 -> EPi VWild <| exp0 <| exp1
+ EBind exp0 exp1 -> appBind <| exp0 <| exp1
+ EBindC exp0 exp1 -> appBindC <| exp0 <| exp1
+ EOr exp0 exp1 -> orBool <| exp0 <| exp1
+ EAnd exp0 exp1 -> andBool <| exp0 <| exp1
+ EEq exp0 exp1 -> overlBin "eq" <| exp0 <| exp1
+ ENe exp0 exp1 -> overlBin "ne" <| exp0 <| exp1
+ ELt exp0 exp1 -> overlBin "lt" <| exp0 <| exp1
+ ELe exp0 exp1 -> overlBin "le" <| exp0 <| exp1
+ EGt exp0 exp1 -> overlBin "gt" <| exp0 <| exp1
+ EGe exp0 exp1 -> overlBin "ge" <| exp0 <| exp1
+ EListCons exp0 exp1 -> appCons <| exp0 <| exp1
+ EAdd exp0 exp1 -> overlBin "plus" <| exp0 <| exp1
+ ESub exp0 exp1 -> overlBin "minus" <| exp0 <| exp1
+ EMul exp0 exp1 -> overlBin "times" <| exp0 <| exp1
+ EDiv exp0 exp1 -> overlBin "div" <| exp0 <| exp1
+ EMod exp0 exp1 -> overlBin "mod" <| exp0 <| exp1
+ ENeg exp0 -> overlUn "neg" <| exp0
+ EEmptyList -> mkList []
+ EList exps -> mkList (map f exps)
+ ETuple exp1 exps -> mkETuple (map f (exp1:exps))
+ _ -> composOp f x
+ where g <| x = g (f x)
+
+--
+-- * List patterns
+--
+
+pListCons :: Pattern -> Pattern -> Pattern
+pListCons p1 p2 = PCons (Ident "Cons") [PWild,p1,p2]
+
+pList :: [Pattern] -> Pattern
+pList = foldr pListCons (PCons (Ident "Nil") [PWild])
+
+--
+-- * Use an overloaded function.
+--
+
+overlUn :: String -> Exp -> Exp
+overlUn f e1 = apply (EVar (Ident f)) [EMeta,EVar (Ident "num_Integer"),e1] -- FIXME: hack, should be ?
+
+overlBin :: String -> Exp -> Exp -> Exp
+overlBin f e1 e2 = apply (EVar (Ident f)) [EMeta,EVar (Ident "num_Integer"),e1,e2] -- FIXME: hack, should be ?
+
+--
+-- * Monad
+--
+
+mkDo :: [Bind] -> Exp -> Exp
+mkDo bs e = foldr (\ (BindVar v r) x -> appBind r (EAbs v x)) e bs
+
+appBind :: Exp -> Exp -> Exp
+appBind e1 e2 = apply (EVar (Ident "bind")) [EMeta,EMeta,EMeta,EMeta,e1,e2]
+
+appBindC :: Exp -> Exp -> Exp
+appBindC e1 e2 = appBind e1 (EAbs VWild e2)
+
+--
+-- * List
+--
+
+mkList :: [Exp] -> Exp
+mkList = foldr appCons (EApp (EVar (Ident "Nil")) EMeta)
+
+appCons :: Exp -> Exp -> Exp
+appCons e1 e2 = apply (EVar (Ident "Cons")) [EMeta,e1,e2]
+
+
+--
+-- * Booleans
+--
+
+andBool :: Exp -> Exp -> Exp
+andBool e1 e2 = ifBool e1 e2 false
+
+orBool :: Exp -> Exp -> Exp
+orBool e1 e2 = ifBool e1 true e2
+
+ifBool :: Exp -> Exp -> Exp -> Exp
+ifBool c t e = ECase c [Case (PCons (Ident "True") []) gtrue t,
+ Case (PCons (Ident "False") []) gtrue e]
+
+
+--
+-- * Substitution
+--
+
+subst :: Ident -> Exp -> Exp -> Exp
+subst x e = substs [(x,e)]
+
+
+
+-- | Simultaneuous substitution
+substs :: [(Ident, Exp)] -> Exp -> Exp
+substs ss = f (Map.fromList ss)
+ where
+ f :: Map Ident Exp -> Tree a -> Tree a
+ f ss t | Map.null ss = t
+ f ss t = case t of
+ EVar i -> Map.findWithDefault t i ss
+ _ -> composOp (f ss) t
+
+
+{-
+-- not needed now that variable names are unique
+-- FIXE: this function does not properly rename bound variables
+substs :: [(Ident, Exp)] -> Exp -> Exp
+substs ss = f (Map.fromList ss)
+ where
+ f :: Map Ident Exp -> Tree a -> Tree a
+ f ss t | Map.null ss = t
+ f ss t = case t of
+ ELet ds e3 ->
+ ELet [LetDef id (f ss' e2) | LetDef id e2 <- ds] (f ss' e3)
+ where ss' = ss `mapMinusSet` letDefBinds ds
+ Case p g e -> Case p (f ss' g) (f ss' e) where ss' = ss `mapMinusSet` binds p
+ EAbs (VVar id) e -> EAbs (VVar id) (f ss' e) where ss' = Map.delete id ss
+ EPi (VVar id) e1 e2 ->
+ EPi (VVar id) (f ss e1) (f ss' e2) where ss' = Map.delete id ss
+ EVar i -> Map.findWithDefault t i ss
+ _ -> composOp (f ss) t
+-}
+
+--
+-- * Abstract syntax utilities
+--
+
+var :: String -> Exp
+var s = EVar (Ident s)
+
+true :: Exp
+true = var "True"
+
+false :: Exp
+false = var "False"
+
+gtrue :: Guard
+gtrue = GuardExp true
+
+
+mkETuple :: [Exp] -> Exp
+mkETuple = ERec . zipWith (\i -> FieldValue (Ident ("p"++show i))) [1..]
+
+mkPTuple :: [Pattern] -> Pattern
+mkPTuple = PRec . zipWith (\i -> FieldPattern (Ident ("p"++show i))) [1..]
+
+-- | Apply an expression to a list of arguments.
+apply :: Exp -> [Exp] -> Exp
+apply = foldl EApp
+
+-- | Abstract a value over some arguments.
+abstract :: Int -- ^ number of arguments
+ -> ([Exp] -> Exp) -> C Exp
+abstract n f =
+ do
+ vs <- freshIdents n
+ return $ foldr EAbs (f (map EVar vs)) (map VVar vs)
+
+-- | Abstract a type over some arguments.
+abstractType :: [Exp] -- ^ argument types
+ -> ([Exp] -> Exp) -- ^ function from variable expressions
+ -- to the expression to return
+ -> C Exp
+abstractType ts f =
+ do
+ vs <- freshIdents (length ts)
+ let pi (v,t) e = EPi (VVar v) t e
+ return $ foldr pi (f (map EVar vs)) (zip vs ts)
+
+-- | Get an identifier which cannot occur in user-written
+-- code, and which has not been generated before.
+freshIdent :: C Ident
+freshIdent = do
+ st <- get
+ put (st { nextVar = nextVar st + 1 })
+ return (Ident ("x_"++show (nextVar st)))
+
+freshIdents :: Int -> C [Ident]
+freshIdents n = replicateM n freshIdent
+
+-- | Get the variables bound by a set of let definitions.
+letDefBinds :: [LetDef] -> Set Ident
+letDefBinds defs = Set.fromList [ id | LetDef id _ <- defs]
+
+letDefRhss :: [LetDef] -> [Exp]
+letDefRhss defs = [ exp | LetDef _ exp <- defs ]
+
+-- | Get the free variables in an expression.
+freeVars :: Exp -> Set Ident
+freeVars = f
+ where
+ f :: Tree a -> Set Ident
+ f t = case t of
+ ELet defs exp ->
+ Set.unions (f exp:map f (letDefRhss defs)) Set.\\ letDefBinds defs
+ ECase exp cases -> f exp `Set.union`
+ Set.unions [(f g `Set.union` f e) Set.\\ binds p
+ | Case p g e <- cases]
+ EAbs (VVar id) exp -> Set.delete id (f exp)
+ EPi (VVar id) exp1 exp2 -> f exp1 `Set.union` Set.delete id (f exp2)
+ EVar i -> Set.singleton i
+ _ -> composOpMonoid f t
+
+isFreeIn :: Ident -> Exp -> Bool
+isFreeIn x e = countFreeOccur x e > 0
+
+-- | Count the number of times a variable occurs free in an expression.
+countFreeOccur :: Ident -> Exp -> Int
+countFreeOccur x = f
+ where
+ f :: Tree a -> Int
+ f t = case t of
+ ELet defs _ | x `Set.member` letDefBinds defs -> 0
+ Case p _ _ | x `Set.member` binds p -> 0
+ EAbs (VVar id) _ | id == x -> 0
+ EPi (VVar id) exp1 _ | id == x -> f exp1
+ EVar id | id == x -> 1
+ _ -> composOpFold 0 (+) f t
+
+-- | Get the variables bound by a pattern.
+binds :: Pattern -> Set Ident
+binds = f
+ where
+ f :: Tree a -> Set Ident
+ f p = case p of
+ -- replaceCons removes non-variable PVars
+ PVar id -> Set.singleton id
+ _ -> composOpMonoid f p
+
+
+fromPRec :: [FieldPattern] -> [(Ident,Pattern)]
+fromPRec fps = [ (l,p) | FieldPattern l p <- fps ]
+
+toPRec :: [(Ident,Pattern)] -> [FieldPattern]
+toPRec = map (uncurry FieldPattern)
+
+--
+-- * Data types
+--
+
+type DataTypes = Map Ident (Exp,[(Ident,Exp)])
+
+-- | Get a map of data type names to the type of the type constructor
+-- and all data constructors with their types.
+dataTypes :: [Decl] -> Map Ident (Exp,[(Ident,Exp)])
+dataTypes ds = Map.fromList [ (i,(t,[(c,ct) | ConsDecl c ct <- cs])) | DataDecl i t cs <- ds]
+
+getDataType :: DataTypes -> Ident -> (Exp,[(Ident,Exp)])
+getDataType ts i =
+ case Map.lookup i ts of
+ Just t -> t
+ Nothing -> error $ "Data type " ++ printTree i ++ " not found."
+ ++ " Known types: " ++ show (Map.keysSet ts)
+
+--
+-- * Utilities
+--
+
+infixl 1 >>>
+
+(>>>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
+f >>> g = (g =<<) . f
+
+mapMinusSet :: Ord k => Map k a -> Set k -> Map k a
+mapMinusSet m s = m Map.\\ (Map.fromList [(x,()) | x <- Set.toList s])
diff --git a/src-2.9/config.guess b/src-2.9/config.guess
new file mode 100644
index 000000000..c085f4f51
--- /dev/null
+++ b/src-2.9/config.guess
@@ -0,0 +1,1497 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
+# Inc.
+
+timestamp='2006-05-13'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+
+# Originally written by Per Bothner .
+# Please send patches to . Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# This script attempts to guess a canonical system name similar to
+# config.sub. If it succeeds, it prints the system name on stdout, and
+# exits with 0. Otherwise, it exits with 1.
+#
+# The plan is that this can be called by configure scripts if you
+# don't specify an explicit build system type.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Operation modes:
+ -h, --help print this help, then exit
+ -t, --time-stamp print date of last modification, then exit
+ -v, --version print version number, then exit
+
+Report bugs and patches to ."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+ case $1 in
+ --time-stamp | --time* | -t )
+ echo "$timestamp" ; exit ;;
+ --version | -v )
+ echo "$version" ; exit ;;
+ --help | --h* | -h )
+ echo "$usage"; exit ;;
+ -- ) # Stop option processing
+ shift; break ;;
+ - ) # Use stdin as input.
+ break ;;
+ -* )
+ echo "$me: invalid option $1$help" >&2
+ exit 1 ;;
+ * )
+ break ;;
+ esac
+done
+
+if test $# != 0; then
+ echo "$me: too many arguments$help" >&2
+ exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,) echo "int x;" > $dummy.c ;
+ for c in cc gcc c89 c99 ; do
+ if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
+ CC_FOR_BUILD="$c"; break ;
+ fi ;
+ done ;
+ if test x"$CC_FOR_BUILD" = x ; then
+ CC_FOR_BUILD=no_compiler_found ;
+ fi
+ ;;
+ ,,*) CC_FOR_BUILD=$CC ;;
+ ,*,*) CC_FOR_BUILD=$HOST_CC ;;
+esac ; set_cc_for_build= ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+ PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+ *:NetBSD:*:*)
+ # NetBSD (nbsd) targets should (where applicable) match one or
+ # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
+ # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
+ # switched to ELF, *-*-netbsd* would select the old
+ # object file format. This provides both forward
+ # compatibility and a consistent mechanism for selecting the
+ # object file format.
+ #
+ # Note: NetBSD doesn't particularly care about the vendor
+ # portion of the name. We always set it to "unknown".
+ sysctl="sysctl -n hw.machine_arch"
+ UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
+ /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
+ case "${UNAME_MACHINE_ARCH}" in
+ armeb) machine=armeb-unknown ;;
+ arm*) machine=arm-unknown ;;
+ sh3el) machine=shl-unknown ;;
+ sh3eb) machine=sh-unknown ;;
+ *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+ esac
+ # The Operating System including object format, if it has switched
+ # to ELF recently, or will in the future.
+ case "${UNAME_MACHINE_ARCH}" in
+ arm*|i386|m68k|ns32k|sh3*|sparc|vax)
+ eval $set_cc_for_build
+ if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+ | grep __ELF__ >/dev/null
+ then
+ # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+ # Return netbsd for either. FIX?
+ os=netbsd
+ else
+ os=netbsdelf
+ fi
+ ;;
+ *)
+ os=netbsd
+ ;;
+ esac
+ # The OS release
+ # Debian GNU/NetBSD machines have a different userland, and
+ # thus, need a distinct triplet. However, they do not need
+ # kernel version information, so it can be replaced with a
+ # suitable tag, in the style of linux-gnu.
+ case "${UNAME_VERSION}" in
+ Debian*)
+ release='-gnu'
+ ;;
+ *)
+ release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+ ;;
+ esac
+ # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+ # contains redundant information, the shorter form:
+ # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+ echo "${machine}-${os}${release}"
+ exit ;;
+ *:OpenBSD:*:*)
+ UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+ echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ *:ekkoBSD:*:*)
+ echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+ exit ;;
+ *:SolidBSD:*:*)
+ echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+ exit ;;
+ macppc:MirBSD:*:*)
+ echo powerppc-unknown-mirbsd${UNAME_RELEASE}
+ exit ;;
+ *:MirBSD:*:*)
+ echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+ exit ;;
+ alpha:OSF1:*:*)
+ case $UNAME_RELEASE in
+ *4.0)
+ UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+ ;;
+ *5.*)
+ UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+ ;;
+ esac
+ # According to Compaq, /usr/sbin/psrinfo has been available on
+ # OSF/1 and Tru64 systems produced since 1995. I hope that
+ # covers most systems running today. This code pipes the CPU
+ # types through head -n 1, so we only detect the type of CPU 0.
+ ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+ case "$ALPHA_CPU_TYPE" in
+ "EV4 (21064)")
+ UNAME_MACHINE="alpha" ;;
+ "EV4.5 (21064)")
+ UNAME_MACHINE="alpha" ;;
+ "LCA4 (21066/21068)")
+ UNAME_MACHINE="alpha" ;;
+ "EV5 (21164)")
+ UNAME_MACHINE="alphaev5" ;;
+ "EV5.6 (21164A)")
+ UNAME_MACHINE="alphaev56" ;;
+ "EV5.6 (21164PC)")
+ UNAME_MACHINE="alphapca56" ;;
+ "EV5.7 (21164PC)")
+ UNAME_MACHINE="alphapca57" ;;
+ "EV6 (21264)")
+ UNAME_MACHINE="alphaev6" ;;
+ "EV6.7 (21264A)")
+ UNAME_MACHINE="alphaev67" ;;
+ "EV6.8CB (21264C)")
+ UNAME_MACHINE="alphaev68" ;;
+ "EV6.8AL (21264B)")
+ UNAME_MACHINE="alphaev68" ;;
+ "EV6.8CX (21264D)")
+ UNAME_MACHINE="alphaev68" ;;
+ "EV6.9A (21264/EV69A)")
+ UNAME_MACHINE="alphaev69" ;;
+ "EV7 (21364)")
+ UNAME_MACHINE="alphaev7" ;;
+ "EV7.9 (21364A)")
+ UNAME_MACHINE="alphaev79" ;;
+ esac
+ # A Pn.n version is a patched version.
+ # A Vn.n version is a released version.
+ # A Tn.n version is a released field test version.
+ # A Xn.n version is an unreleased experimental baselevel.
+ # 1.2 uses "1.2" for uname -r.
+ echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+ exit ;;
+ Alpha\ *:Windows_NT*:*)
+ # How do we know it's Interix rather than the generic POSIX subsystem?
+ # Should we change UNAME_MACHINE based on the output of uname instead
+ # of the specific Alpha model?
+ echo alpha-pc-interix
+ exit ;;
+ 21064:Windows_NT:50:3)
+ echo alpha-dec-winnt3.5
+ exit ;;
+ Amiga*:UNIX_System_V:4.0:*)
+ echo m68k-unknown-sysv4
+ exit ;;
+ *:[Aa]miga[Oo][Ss]:*:*)
+ echo ${UNAME_MACHINE}-unknown-amigaos
+ exit ;;
+ *:[Mm]orph[Oo][Ss]:*:*)
+ echo ${UNAME_MACHINE}-unknown-morphos
+ exit ;;
+ *:OS/390:*:*)
+ echo i370-ibm-openedition
+ exit ;;
+ *:z/VM:*:*)
+ echo s390-ibm-zvmoe
+ exit ;;
+ *:OS400:*:*)
+ echo powerpc-ibm-os400
+ exit ;;
+ arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+ echo arm-acorn-riscix${UNAME_RELEASE}
+ exit ;;
+ arm:riscos:*:*|arm:RISCOS:*:*)
+ echo arm-unknown-riscos
+ exit ;;
+ SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+ echo hppa1.1-hitachi-hiuxmpp
+ exit ;;
+ Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+ # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+ if test "`(/bin/universe) 2>/dev/null`" = att ; then
+ echo pyramid-pyramid-sysv3
+ else
+ echo pyramid-pyramid-bsd
+ fi
+ exit ;;
+ NILE*:*:*:dcosx)
+ echo pyramid-pyramid-svr4
+ exit ;;
+ DRS?6000:unix:4.0:6*)
+ echo sparc-icl-nx6
+ exit ;;
+ DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
+ case `/usr/bin/uname -p` in
+ sparc) echo sparc-icl-nx7; exit ;;
+ esac ;;
+ sun4H:SunOS:5.*:*)
+ echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+ echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ i86pc:SunOS:5.*:*)
+ echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ sun4*:SunOS:6*:*)
+ # According to config.sub, this is the proper way to canonicalize
+ # SunOS6. Hard to guess exactly what SunOS6 will be like, but
+ # it's likely to be more like Solaris than SunOS4.
+ echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ sun4*:SunOS:*:*)
+ case "`/usr/bin/arch -k`" in
+ Series*|S4*)
+ UNAME_RELEASE=`uname -v`
+ ;;
+ esac
+ # Japanese Language versions have a version number like `4.1.3-JL'.
+ echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+ exit ;;
+ sun3*:SunOS:*:*)
+ echo m68k-sun-sunos${UNAME_RELEASE}
+ exit ;;
+ sun*:*:4.2BSD:*)
+ UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+ test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+ case "`/bin/arch`" in
+ sun3)
+ echo m68k-sun-sunos${UNAME_RELEASE}
+ ;;
+ sun4)
+ echo sparc-sun-sunos${UNAME_RELEASE}
+ ;;
+ esac
+ exit ;;
+ aushp:SunOS:*:*)
+ echo sparc-auspex-sunos${UNAME_RELEASE}
+ exit ;;
+ # The situation for MiNT is a little confusing. The machine name
+ # can be virtually everything (everything which is not
+ # "atarist" or "atariste" at least should have a processor
+ # > m68000). The system name ranges from "MiNT" over "FreeMiNT"
+ # to the lowercase version "mint" (or "freemint"). Finally
+ # the system name "TOS" denotes a system which is actually not
+ # MiNT. But MiNT is downward compatible to TOS, so this should
+ # be no problem.
+ atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+ echo m68k-atari-mint${UNAME_RELEASE}
+ exit ;;
+ atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+ echo m68k-atari-mint${UNAME_RELEASE}
+ exit ;;
+ *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+ echo m68k-atari-mint${UNAME_RELEASE}
+ exit ;;
+ milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+ echo m68k-milan-mint${UNAME_RELEASE}
+ exit ;;
+ hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+ echo m68k-hades-mint${UNAME_RELEASE}
+ exit ;;
+ *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+ echo m68k-unknown-mint${UNAME_RELEASE}
+ exit ;;
+ m68k:machten:*:*)
+ echo m68k-apple-machten${UNAME_RELEASE}
+ exit ;;
+ powerpc:machten:*:*)
+ echo powerpc-apple-machten${UNAME_RELEASE}
+ exit ;;
+ RISC*:Mach:*:*)
+ echo mips-dec-mach_bsd4.3
+ exit ;;
+ RISC*:ULTRIX:*:*)
+ echo mips-dec-ultrix${UNAME_RELEASE}
+ exit ;;
+ VAX*:ULTRIX*:*:*)
+ echo vax-dec-ultrix${UNAME_RELEASE}
+ exit ;;
+ 2020:CLIX:*:* | 2430:CLIX:*:*)
+ echo clipper-intergraph-clix${UNAME_RELEASE}
+ exit ;;
+ mips:*:*:UMIPS | mips:*:*:RISCos)
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+#ifdef __cplusplus
+#include /* for printf() prototype */
+ int main (int argc, char *argv[]) {
+#else
+ int main (argc, argv) int argc; char *argv[]; {
+#endif
+ #if defined (host_mips) && defined (MIPSEB)
+ #if defined (SYSTYPE_SYSV)
+ printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+ #endif
+ #if defined (SYSTYPE_SVR4)
+ printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+ #endif
+ #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+ printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+ #endif
+ #endif
+ exit (-1);
+ }
+EOF
+ $CC_FOR_BUILD -o $dummy $dummy.c &&
+ dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+ SYSTEM_NAME=`$dummy $dummyarg` &&
+ { echo "$SYSTEM_NAME"; exit; }
+ echo mips-mips-riscos${UNAME_RELEASE}
+ exit ;;
+ Motorola:PowerMAX_OS:*:*)
+ echo powerpc-motorola-powermax
+ exit ;;
+ Motorola:*:4.3:PL8-*)
+ echo powerpc-harris-powermax
+ exit ;;
+ Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
+ echo powerpc-harris-powermax
+ exit ;;
+ Night_Hawk:Power_UNIX:*:*)
+ echo powerpc-harris-powerunix
+ exit ;;
+ m88k:CX/UX:7*:*)
+ echo m88k-harris-cxux7
+ exit ;;
+ m88k:*:4*:R4*)
+ echo m88k-motorola-sysv4
+ exit ;;
+ m88k:*:3*:R3*)
+ echo m88k-motorola-sysv3
+ exit ;;
+ AViiON:dgux:*:*)
+ # DG/UX returns AViiON for all architectures
+ UNAME_PROCESSOR=`/usr/bin/uname -p`
+ if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+ then
+ if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+ [ ${TARGET_BINARY_INTERFACE}x = x ]
+ then
+ echo m88k-dg-dgux${UNAME_RELEASE}
+ else
+ echo m88k-dg-dguxbcs${UNAME_RELEASE}
+ fi
+ else
+ echo i586-dg-dgux${UNAME_RELEASE}
+ fi
+ exit ;;
+ M88*:DolphinOS:*:*) # DolphinOS (SVR3)
+ echo m88k-dolphin-sysv3
+ exit ;;
+ M88*:*:R3*:*)
+ # Delta 88k system running SVR3
+ echo m88k-motorola-sysv3
+ exit ;;
+ XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+ echo m88k-tektronix-sysv3
+ exit ;;
+ Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+ echo m68k-tektronix-bsd
+ exit ;;
+ *:IRIX*:*:*)
+ echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+ exit ;;
+ ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+ echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
+ exit ;; # Note that: echo "'`uname -s`'" gives 'AIX '
+ i*86:AIX:*:*)
+ echo i386-ibm-aix
+ exit ;;
+ ia64:AIX:*:*)
+ if [ -x /usr/bin/oslevel ] ; then
+ IBM_REV=`/usr/bin/oslevel`
+ else
+ IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+ fi
+ echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+ exit ;;
+ *:AIX:2:3)
+ if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #include
+
+ main()
+ {
+ if (!__power_pc())
+ exit(1);
+ puts("powerpc-ibm-aix3.2.5");
+ exit(0);
+ }
+EOF
+ if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+ then
+ echo "$SYSTEM_NAME"
+ else
+ echo rs6000-ibm-aix3.2.5
+ fi
+ elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+ echo rs6000-ibm-aix3.2.4
+ else
+ echo rs6000-ibm-aix3.2
+ fi
+ exit ;;
+ *:AIX:*:[45])
+ IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
+ if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+ IBM_ARCH=rs6000
+ else
+ IBM_ARCH=powerpc
+ fi
+ if [ -x /usr/bin/oslevel ] ; then
+ IBM_REV=`/usr/bin/oslevel`
+ else
+ IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+ fi
+ echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+ exit ;;
+ *:AIX:*:*)
+ echo rs6000-ibm-aix
+ exit ;;
+ ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+ echo romp-ibm-bsd4.4
+ exit ;;
+ ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and
+ echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
+ exit ;; # report: romp-ibm BSD 4.3
+ *:BOSX:*:*)
+ echo rs6000-bull-bosx
+ exit ;;
+ DPX/2?00:B.O.S.:*:*)
+ echo m68k-bull-sysv3
+ exit ;;
+ 9000/[34]??:4.3bsd:1.*:*)
+ echo m68k-hp-bsd
+ exit ;;
+ hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+ echo m68k-hp-bsd4.4
+ exit ;;
+ 9000/[34678]??:HP-UX:*:*)
+ HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+ case "${UNAME_MACHINE}" in
+ 9000/31? ) HP_ARCH=m68000 ;;
+ 9000/[34]?? ) HP_ARCH=m68k ;;
+ 9000/[678][0-9][0-9])
+ if [ -x /usr/bin/getconf ]; then
+ sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+ sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+ case "${sc_cpu_version}" in
+ 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+ 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+ 532) # CPU_PA_RISC2_0
+ case "${sc_kernel_bits}" in
+ 32) HP_ARCH="hppa2.0n" ;;
+ 64) HP_ARCH="hppa2.0w" ;;
+ '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
+ esac ;;
+ esac
+ fi
+ if [ "${HP_ARCH}" = "" ]; then
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+
+ #define _HPUX_SOURCE
+ #include
+ #include
+
+ int main ()
+ {
+ #if defined(_SC_KERNEL_BITS)
+ long bits = sysconf(_SC_KERNEL_BITS);
+ #endif
+ long cpu = sysconf (_SC_CPU_VERSION);
+
+ switch (cpu)
+ {
+ case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+ case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+ case CPU_PA_RISC2_0:
+ #if defined(_SC_KERNEL_BITS)
+ switch (bits)
+ {
+ case 64: puts ("hppa2.0w"); break;
+ case 32: puts ("hppa2.0n"); break;
+ default: puts ("hppa2.0"); break;
+ } break;
+ #else /* !defined(_SC_KERNEL_BITS) */
+ puts ("hppa2.0"); break;
+ #endif
+ default: puts ("hppa1.0"); break;
+ }
+ exit (0);
+ }
+EOF
+ (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+ test -z "$HP_ARCH" && HP_ARCH=hppa
+ fi ;;
+ esac
+ if [ ${HP_ARCH} = "hppa2.0w" ]
+ then
+ eval $set_cc_for_build
+
+ # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+ # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler
+ # generating 64-bit code. GNU and HP use different nomenclature:
+ #
+ # $ CC_FOR_BUILD=cc ./config.guess
+ # => hppa2.0w-hp-hpux11.23
+ # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+ # => hppa64-hp-hpux11.23
+
+ if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+ grep __LP64__ >/dev/null
+ then
+ HP_ARCH="hppa2.0w"
+ else
+ HP_ARCH="hppa64"
+ fi
+ fi
+ echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+ exit ;;
+ ia64:HP-UX:*:*)
+ HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+ echo ia64-hp-hpux${HPUX_REV}
+ exit ;;
+ 3050*:HI-UX:*:*)
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #include
+ int
+ main ()
+ {
+ long cpu = sysconf (_SC_CPU_VERSION);
+ /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+ true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
+ results, however. */
+ if (CPU_IS_PA_RISC (cpu))
+ {
+ switch (cpu)
+ {
+ case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+ case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+ case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+ default: puts ("hppa-hitachi-hiuxwe2"); break;
+ }
+ }
+ else if (CPU_IS_HP_MC68K (cpu))
+ puts ("m68k-hitachi-hiuxwe2");
+ else puts ("unknown-hitachi-hiuxwe2");
+ exit (0);
+ }
+EOF
+ $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+ { echo "$SYSTEM_NAME"; exit; }
+ echo unknown-hitachi-hiuxwe2
+ exit ;;
+ 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+ echo hppa1.1-hp-bsd
+ exit ;;
+ 9000/8??:4.3bsd:*:*)
+ echo hppa1.0-hp-bsd
+ exit ;;
+ *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
+ echo hppa1.0-hp-mpeix
+ exit ;;
+ hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+ echo hppa1.1-hp-osf
+ exit ;;
+ hp8??:OSF1:*:*)
+ echo hppa1.0-hp-osf
+ exit ;;
+ i*86:OSF1:*:*)
+ if [ -x /usr/sbin/sysversion ] ; then
+ echo ${UNAME_MACHINE}-unknown-osf1mk
+ else
+ echo ${UNAME_MACHINE}-unknown-osf1
+ fi
+ exit ;;
+ parisc*:Lites*:*:*)
+ echo hppa1.1-hp-lites
+ exit ;;
+ C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+ echo c1-convex-bsd
+ exit ;;
+ C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+ if getsysinfo -f scalar_acc
+ then echo c32-convex-bsd
+ else echo c2-convex-bsd
+ fi
+ exit ;;
+ C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+ echo c34-convex-bsd
+ exit ;;
+ C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+ echo c38-convex-bsd
+ exit ;;
+ C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+ echo c4-convex-bsd
+ exit ;;
+ CRAY*Y-MP:*:*:*)
+ echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ CRAY*[A-Z]90:*:*:*)
+ echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
+ -e 's/\.[^.]*$/.X/'
+ exit ;;
+ CRAY*TS:*:*:*)
+ echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ CRAY*T3E:*:*:*)
+ echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ CRAY*SV1:*:*:*)
+ echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ *:UNICOS/mp:*:*)
+ echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+ FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+ FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+ FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+ echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+ exit ;;
+ 5000:UNIX_System_V:4.*:*)
+ FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+ FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+ echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+ exit ;;
+ i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+ echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+ exit ;;
+ sparc*:BSD/OS:*:*)
+ echo sparc-unknown-bsdi${UNAME_RELEASE}
+ exit ;;
+ *:BSD/OS:*:*)
+ echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+ exit ;;
+ *:FreeBSD:*:*)
+ case ${UNAME_MACHINE} in
+ pc98)
+ echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+ amd64)
+ echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+ *)
+ echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+ esac
+ exit ;;
+ i*:CYGWIN*:*)
+ echo ${UNAME_MACHINE}-pc-cygwin
+ exit ;;
+ i*:MINGW*:*)
+ echo ${UNAME_MACHINE}-pc-mingw32
+ exit ;;
+ i*:windows32*:*)
+ # uname -m includes "-pc" on this system.
+ echo ${UNAME_MACHINE}-mingw32
+ exit ;;
+ i*:PW*:*)
+ echo ${UNAME_MACHINE}-pc-pw32
+ exit ;;
+ x86:Interix*:[345]*)
+ echo i586-pc-interix${UNAME_RELEASE}
+ exit ;;
+ EM64T:Interix*:[345]*)
+ echo x86_64-unknown-interix${UNAME_RELEASE}
+ exit ;;
+ [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
+ echo i${UNAME_MACHINE}-pc-mks
+ exit ;;
+ i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+ # How do we know it's Interix rather than the generic POSIX subsystem?
+ # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+ # UNAME_MACHINE based on the output of uname instead of i386?
+ echo i586-pc-interix
+ exit ;;
+ i*:UWIN*:*)
+ echo ${UNAME_MACHINE}-pc-uwin
+ exit ;;
+ amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+ echo x86_64-unknown-cygwin
+ exit ;;
+ p*:CYGWIN*:*)
+ echo powerpcle-unknown-cygwin
+ exit ;;
+ prep*:SunOS:5.*:*)
+ echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ *:GNU:*:*)
+ # the GNU system
+ echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+ exit ;;
+ *:GNU/*:*:*)
+ # other systems with GNU libc and userland
+ echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
+ exit ;;
+ i*86:Minix:*:*)
+ echo ${UNAME_MACHINE}-pc-minix
+ exit ;;
+ arm*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ exit ;;
+ cris:Linux:*:*)
+ echo cris-axis-linux-gnu
+ exit ;;
+ crisv32:Linux:*:*)
+ echo crisv32-axis-linux-gnu
+ exit ;;
+ frv:Linux:*:*)
+ echo frv-unknown-linux-gnu
+ exit ;;
+ ia64:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ exit ;;
+ m32r*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ exit ;;
+ m68*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ exit ;;
+ mips:Linux:*:*)
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #undef CPU
+ #undef mips
+ #undef mipsel
+ #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+ CPU=mipsel
+ #else
+ #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+ CPU=mips
+ #else
+ CPU=
+ #endif
+ #endif
+EOF
+ eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+ /^CPU/{
+ s: ::g
+ p
+ }'`"
+ test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+ ;;
+ mips64:Linux:*:*)
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #undef CPU
+ #undef mips64
+ #undef mips64el
+ #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+ CPU=mips64el
+ #else
+ #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+ CPU=mips64
+ #else
+ CPU=
+ #endif
+ #endif
+EOF
+ eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+ /^CPU/{
+ s: ::g
+ p
+ }'`"
+ test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+ ;;
+ or32:Linux:*:*)
+ echo or32-unknown-linux-gnu
+ exit ;;
+ ppc:Linux:*:*)
+ echo powerpc-unknown-linux-gnu
+ exit ;;
+ ppc64:Linux:*:*)
+ echo powerpc64-unknown-linux-gnu
+ exit ;;
+ alpha:Linux:*:*)
+ case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+ EV5) UNAME_MACHINE=alphaev5 ;;
+ EV56) UNAME_MACHINE=alphaev56 ;;
+ PCA56) UNAME_MACHINE=alphapca56 ;;
+ PCA57) UNAME_MACHINE=alphapca56 ;;
+ EV6) UNAME_MACHINE=alphaev6 ;;
+ EV67) UNAME_MACHINE=alphaev67 ;;
+ EV68*) UNAME_MACHINE=alphaev68 ;;
+ esac
+ objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
+ if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
+ echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
+ exit ;;
+ parisc:Linux:*:* | hppa:Linux:*:*)
+ # Look for CPU level
+ case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+ PA7*) echo hppa1.1-unknown-linux-gnu ;;
+ PA8*) echo hppa2.0-unknown-linux-gnu ;;
+ *) echo hppa-unknown-linux-gnu ;;
+ esac
+ exit ;;
+ parisc64:Linux:*:* | hppa64:Linux:*:*)
+ echo hppa64-unknown-linux-gnu
+ exit ;;
+ s390:Linux:*:* | s390x:Linux:*:*)
+ echo ${UNAME_MACHINE}-ibm-linux
+ exit ;;
+ sh64*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ exit ;;
+ sh*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ exit ;;
+ sparc:Linux:*:* | sparc64:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ exit ;;
+ vax:Linux:*:*)
+ echo ${UNAME_MACHINE}-dec-linux-gnu
+ exit ;;
+ x86_64:Linux:*:*)
+ echo x86_64-unknown-linux-gnu
+ exit ;;
+ i*86:Linux:*:*)
+ # The BFD linker knows what the default object file format is, so
+ # first see if it will tell us. cd to the root directory to prevent
+ # problems with other programs or directories called `ld' in the path.
+ # Set LC_ALL=C to ensure ld outputs messages in English.
+ ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
+ | sed -ne '/supported targets:/!d
+ s/[ ][ ]*/ /g
+ s/.*supported targets: *//
+ s/ .*//
+ p'`
+ case "$ld_supported_targets" in
+ elf32-i386)
+ TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
+ ;;
+ a.out-i386-linux)
+ echo "${UNAME_MACHINE}-pc-linux-gnuaout"
+ exit ;;
+ coff-i386)
+ echo "${UNAME_MACHINE}-pc-linux-gnucoff"
+ exit ;;
+ "")
+ # Either a pre-BFD a.out linker (linux-gnuoldld) or
+ # one that does not give us useful --help.
+ echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
+ exit ;;
+ esac
+ # Determine whether the default compiler is a.out or elf
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #include
+ #ifdef __ELF__
+ # ifdef __GLIBC__
+ # if __GLIBC__ >= 2
+ LIBC=gnu
+ # else
+ LIBC=gnulibc1
+ # endif
+ # else
+ LIBC=gnulibc1
+ # endif
+ #else
+ #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+ LIBC=gnu
+ #else
+ LIBC=gnuaout
+ #endif
+ #endif
+ #ifdef __dietlibc__
+ LIBC=dietlibc
+ #endif
+EOF
+ eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+ /^LIBC/{
+ s: ::g
+ p
+ }'`"
+ test x"${LIBC}" != x && {
+ echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
+ exit
+ }
+ test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
+ ;;
+ i*86:DYNIX/ptx:4*:*)
+ # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
+ # earlier versions are messed up and put the nodename in both
+ # sysname and nodename.
+ echo i386-sequent-sysv4
+ exit ;;
+ i*86:UNIX_SV:4.2MP:2.*)
+ # Unixware is an offshoot of SVR4, but it has its own version
+ # number series starting with 2...
+ # I am not positive that other SVR4 systems won't match this,
+ # I just have to hope. -- rms.
+ # Use sysv4.2uw... so that sysv4* matches it.
+ echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+ exit ;;
+ i*86:OS/2:*:*)
+ # If we were able to find `uname', then EMX Unix compatibility
+ # is probably installed.
+ echo ${UNAME_MACHINE}-pc-os2-emx
+ exit ;;
+ i*86:XTS-300:*:STOP)
+ echo ${UNAME_MACHINE}-unknown-stop
+ exit ;;
+ i*86:atheos:*:*)
+ echo ${UNAME_MACHINE}-unknown-atheos
+ exit ;;
+ i*86:syllable:*:*)
+ echo ${UNAME_MACHINE}-pc-syllable
+ exit ;;
+ i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
+ echo i386-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ i*86:*DOS:*:*)
+ echo ${UNAME_MACHINE}-pc-msdosdjgpp
+ exit ;;
+ i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
+ UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+ if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+ echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+ else
+ echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+ fi
+ exit ;;
+ i*86:*:5:[678]*)
+ # UnixWare 7.x, OpenUNIX and OpenServer 6.
+ case `/bin/uname -X | grep "^Machine"` in
+ *486*) UNAME_MACHINE=i486 ;;
+ *Pentium) UNAME_MACHINE=i586 ;;
+ *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
+ esac
+ echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
+ exit ;;
+ i*86:*:3.2:*)
+ if test -f /usr/options/cb.name; then
+ UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then
+ UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
+ (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
+ (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
+ && UNAME_MACHINE=i586
+ (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
+ && UNAME_MACHINE=i686
+ (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
+ && UNAME_MACHINE=i686
+ echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+ else
+ echo ${UNAME_MACHINE}-pc-sysv32
+ fi
+ exit ;;
+ pc:*:*:*)
+ # Left here for compatibility:
+ # uname -m prints for DJGPP always 'pc', but it prints nothing about
+ # the processor, so we play safe by assuming i386.
+ echo i386-pc-msdosdjgpp
+ exit ;;
+ Intel:Mach:3*:*)
+ echo i386-pc-mach3
+ exit ;;
+ paragon:*:*:*)
+ echo i860-intel-osf1
+ exit ;;
+ i860:*:4.*:*) # i860-SVR4
+ if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+ echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+ else # Add other i860-SVR4 vendors below as they are discovered.
+ echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
+ fi
+ exit ;;
+ mini*:CTIX:SYS*5:*)
+ # "miniframe"
+ echo m68010-convergent-sysv
+ exit ;;
+ mc68k:UNIX:SYSTEM5:3.51m)
+ echo m68k-convergent-sysv
+ exit ;;
+ M680?0:D-NIX:5.3:*)
+ echo m68k-diab-dnix
+ exit ;;
+ M68*:*:R3V[5678]*:*)
+ test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
+ 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
+ OS_REL=''
+ test -r /etc/.relid \
+ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+ /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+ && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+ /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+ 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+ /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+ && { echo i486-ncr-sysv4; exit; } ;;
+ m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+ echo m68k-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ mc68030:UNIX_System_V:4.*:*)
+ echo m68k-atari-sysv4
+ exit ;;
+ TSUNAMI:LynxOS:2.*:*)
+ echo sparc-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ rs6000:LynxOS:2.*:*)
+ echo rs6000-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
+ echo powerpc-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ SM[BE]S:UNIX_SV:*:*)
+ echo mips-dde-sysv${UNAME_RELEASE}
+ exit ;;
+ RM*:ReliantUNIX-*:*:*)
+ echo mips-sni-sysv4
+ exit ;;
+ RM*:SINIX-*:*:*)
+ echo mips-sni-sysv4
+ exit ;;
+ *:SINIX-*:*:*)
+ if uname -p 2>/dev/null >/dev/null ; then
+ UNAME_MACHINE=`(uname -p) 2>/dev/null`
+ echo ${UNAME_MACHINE}-sni-sysv4
+ else
+ echo ns32k-sni-sysv
+ fi
+ exit ;;
+ PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+ # says
+ echo i586-unisys-sysv4
+ exit ;;
+ *:UNIX_System_V:4*:FTX*)
+ # From Gerald Hewes .
+ # How about differentiating between stratus architectures? -djm
+ echo hppa1.1-stratus-sysv4
+ exit ;;
+ *:*:*:FTX*)
+ # From seanf@swdc.stratus.com.
+ echo i860-stratus-sysv4
+ exit ;;
+ i*86:VOS:*:*)
+ # From Paul.Green@stratus.com.
+ echo ${UNAME_MACHINE}-stratus-vos
+ exit ;;
+ *:VOS:*:*)
+ # From Paul.Green@stratus.com.
+ echo hppa1.1-stratus-vos
+ exit ;;
+ mc68*:A/UX:*:*)
+ echo m68k-apple-aux${UNAME_RELEASE}
+ exit ;;
+ news*:NEWS-OS:6*:*)
+ echo mips-sony-newsos6
+ exit ;;
+ R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+ if [ -d /usr/nec ]; then
+ echo mips-nec-sysv${UNAME_RELEASE}
+ else
+ echo mips-unknown-sysv${UNAME_RELEASE}
+ fi
+ exit ;;
+ BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
+ echo powerpc-be-beos
+ exit ;;
+ BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
+ echo powerpc-apple-beos
+ exit ;;
+ BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
+ echo i586-pc-beos
+ exit ;;
+ SX-4:SUPER-UX:*:*)
+ echo sx4-nec-superux${UNAME_RELEASE}
+ exit ;;
+ SX-5:SUPER-UX:*:*)
+ echo sx5-nec-superux${UNAME_RELEASE}
+ exit ;;
+ SX-6:SUPER-UX:*:*)
+ echo sx6-nec-superux${UNAME_RELEASE}
+ exit ;;
+ Power*:Rhapsody:*:*)
+ echo powerpc-apple-rhapsody${UNAME_RELEASE}
+ exit ;;
+ *:Rhapsody:*:*)
+ echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+ exit ;;
+ *:Darwin:*:*)
+ UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+ case $UNAME_PROCESSOR in
+ unknown) UNAME_PROCESSOR=powerpc ;;
+ esac
+ echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+ exit ;;
+ *:procnto*:*:* | *:QNX:[0123456789]*:*)
+ UNAME_PROCESSOR=`uname -p`
+ if test "$UNAME_PROCESSOR" = "x86"; then
+ UNAME_PROCESSOR=i386
+ UNAME_MACHINE=pc
+ fi
+ echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
+ exit ;;
+ *:QNX:*:4*)
+ echo i386-pc-qnx
+ exit ;;
+ NSE-?:NONSTOP_KERNEL:*:*)
+ echo nse-tandem-nsk${UNAME_RELEASE}
+ exit ;;
+ NSR-?:NONSTOP_KERNEL:*:*)
+ echo nsr-tandem-nsk${UNAME_RELEASE}
+ exit ;;
+ *:NonStop-UX:*:*)
+ echo mips-compaq-nonstopux
+ exit ;;
+ BS2000:POSIX*:*:*)
+ echo bs2000-siemens-sysv
+ exit ;;
+ DS/*:UNIX_System_V:*:*)
+ echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+ exit ;;
+ *:Plan9:*:*)
+ # "uname -m" is not consistent, so use $cputype instead. 386
+ # is converted to i386 for consistency with other x86
+ # operating systems.
+ if test "$cputype" = "386"; then
+ UNAME_MACHINE=i386
+ else
+ UNAME_MACHINE="$cputype"
+ fi
+ echo ${UNAME_MACHINE}-unknown-plan9
+ exit ;;
+ *:TOPS-10:*:*)
+ echo pdp10-unknown-tops10
+ exit ;;
+ *:TENEX:*:*)
+ echo pdp10-unknown-tenex
+ exit ;;
+ KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+ echo pdp10-dec-tops20
+ exit ;;
+ XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+ echo pdp10-xkl-tops20
+ exit ;;
+ *:TOPS-20:*:*)
+ echo pdp10-unknown-tops20
+ exit ;;
+ *:ITS:*:*)
+ echo pdp10-unknown-its
+ exit ;;
+ SEI:*:*:SEIUX)
+ echo mips-sei-seiux${UNAME_RELEASE}
+ exit ;;
+ *:DragonFly:*:*)
+ echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+ exit ;;
+ *:*VMS:*:*)
+ UNAME_MACHINE=`(uname -p) 2>/dev/null`
+ case "${UNAME_MACHINE}" in
+ A*) echo alpha-dec-vms ; exit ;;
+ I*) echo ia64-dec-vms ; exit ;;
+ V*) echo vax-dec-vms ; exit ;;
+ esac ;;
+ *:XENIX:*:SysV)
+ echo i386-pc-xenix
+ exit ;;
+ i*86:skyos:*:*)
+ echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+ exit ;;
+ i*86:rdos:*:*)
+ echo ${UNAME_MACHINE}-pc-rdos
+ exit ;;
+esac
+
+#echo '(No uname command or uname output not recognized.)' 1>&2
+#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
+
+eval $set_cc_for_build
+cat >$dummy.c <
+# include
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+ /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
+ I don't know.... */
+ printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include
+ printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+ "4"
+#else
+ ""
+#endif
+ ); exit (0);
+#endif
+#endif
+
+#if defined (__arm) && defined (__acorn) && defined (__unix)
+ printf ("arm-acorn-riscix\n"); exit (0);
+#endif
+
+#if defined (hp300) && !defined (hpux)
+ printf ("m68k-hp-bsd\n"); exit (0);
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+ int version;
+ version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+ if (version < 4)
+ printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+ else
+ printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
+ exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+ printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+ printf ("ns32k-encore-mach\n"); exit (0);
+#else
+ printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+ printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+ printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+ printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+ struct utsname un;
+
+ uname(&un);
+
+ if (strncmp(un.version, "V2", 2) == 0) {
+ printf ("i386-sequent-ptx2\n"); exit (0);
+ }
+ if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+ printf ("i386-sequent-ptx1\n"); exit (0);
+ }
+ printf ("i386-sequent-ptx\n"); exit (0);
+
+#endif
+
+#if defined (vax)
+# if !defined (ultrix)
+# include
+# if defined (BSD)
+# if BSD == 43
+ printf ("vax-dec-bsd4.3\n"); exit (0);
+# else
+# if BSD == 199006
+ printf ("vax-dec-bsd4.3reno\n"); exit (0);
+# else
+ printf ("vax-dec-bsd\n"); exit (0);
+# endif
+# endif
+# else
+ printf ("vax-dec-bsd\n"); exit (0);
+# endif
+# else
+ printf ("vax-dec-ultrix\n"); exit (0);
+# endif
+#endif
+
+#if defined (alliant) && defined (i860)
+ printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+ exit (1);
+}
+EOF
+
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
+ { echo "$SYSTEM_NAME"; exit; }
+
+# Apollos put the system type in the environment.
+
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
+
+# Convex versions that predate uname can use getsysinfo(1)
+
+if [ -x /usr/convex/getsysinfo ]
+then
+ case `getsysinfo -f cpu_type` in
+ c1*)
+ echo c1-convex-bsd
+ exit ;;
+ c2*)
+ if getsysinfo -f scalar_acc
+ then echo c32-convex-bsd
+ else echo c2-convex-bsd
+ fi
+ exit ;;
+ c34*)
+ echo c34-convex-bsd
+ exit ;;
+ c38*)
+ echo c38-convex-bsd
+ exit ;;
+ c4*)
+ echo c4-convex-bsd
+ exit ;;
+ esac
+fi
+
+cat >&2 < in order to provide the needed
+information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo = `(hostinfo) 2>/dev/null`
+/bin/universe = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/src-2.9/config.mk.in b/src-2.9/config.mk.in
new file mode 100644
index 000000000..e8a8ab567
--- /dev/null
+++ b/src-2.9/config.mk.in
@@ -0,0 +1,37 @@
+# GF configuration file. configure will produce config.mk from this file
+# @configure_input@
+
+PACKAGE_VERSION = @PACKAGE_VERSION@
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+libdir = @libdir@
+datadir = @datadir@
+
+host = @host@
+build = @build@
+
+GHCFLAGS = @GHCFLAGS@
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+
+EXEEXT = @EXEEXT@
+
+INSTALL = @INSTALL@
+TAR = @TAR@
+
+GHC = "@GHC@"
+GHCI = "@GHCI@"
+
+READLINE = @READLINE@
+
+INTERRUPT = @INTERRUPT@
+
+ATK = @ATK@
+
+ENABLE_JAVA = @ENABLE_JAVA@
+
+JAVAC = "@JAVAC@"
+JAR = "@JAR@"
+
diff --git a/src-2.9/config.sub b/src-2.9/config.sub
new file mode 100644
index 000000000..4d936e239
--- /dev/null
+++ b/src-2.9/config.sub
@@ -0,0 +1,1608 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
+# Inc.
+
+timestamp='2006-05-13'
+
+# This file is (in principle) common to ALL GNU software.
+# The presence of a machine in this file suggests that SOME GNU software
+# can handle that machine. It does not imply ALL GNU software can.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+
+# Please send patches to . Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support. The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+ $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+ -h, --help print this help, then exit
+ -t, --time-stamp print date of last modification, then exit
+ -v, --version print version number, then exit
+
+Report bugs and patches to ."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+ case $1 in
+ --time-stamp | --time* | -t )
+ echo "$timestamp" ; exit ;;
+ --version | -v )
+ echo "$version" ; exit ;;
+ --help | --h* | -h )
+ echo "$usage"; exit ;;
+ -- ) # Stop option processing
+ shift; break ;;
+ - ) # Use stdin as input.
+ break ;;
+ -* )
+ echo "$me: invalid option $1$help"
+ exit 1 ;;
+
+ *local*)
+ # First pass through any local machine types.
+ echo $1
+ exit ;;
+
+ * )
+ break ;;
+ esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+ exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+ exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+ nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
+ uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
+ storm-chaos* | os2-emx* | rtmk-nova*)
+ os=-$maybe_os
+ basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+ ;;
+ *)
+ basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+ if [ $basic_machine != $1 ]
+ then os=`echo $1 | sed 's/.*-/-/'`
+ else os=; fi
+ ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work. We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+ -sun*os*)
+ # Prevent following clause from handling this invalid input.
+ ;;
+ -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+ -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+ -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+ -apple | -axis | -knuth | -cray)
+ os=
+ basic_machine=$1
+ ;;
+ -sim | -cisco | -oki | -wec | -winbond)
+ os=
+ basic_machine=$1
+ ;;
+ -scout)
+ ;;
+ -wrs)
+ os=-vxworks
+ basic_machine=$1
+ ;;
+ -chorusos*)
+ os=-chorusos
+ basic_machine=$1
+ ;;
+ -chorusrdb)
+ os=-chorusrdb
+ basic_machine=$1
+ ;;
+ -hiux*)
+ os=-hiuxwe2
+ ;;
+ -sco6)
+ os=-sco5v6
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco5)
+ os=-sco3.2v5
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco4)
+ os=-sco3.2v4
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco3.2.[4-9]*)
+ os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco3.2v[4-9]*)
+ # Don't forget version if it is 3.2v4 or newer.
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco5v6*)
+ # Don't forget version if it is 3.2v4 or newer.
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco*)
+ os=-sco3.2v2
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -udk*)
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -isc)
+ os=-isc2.2
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -clix*)
+ basic_machine=clipper-intergraph
+ ;;
+ -isc*)
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -lynx*)
+ os=-lynxos
+ ;;
+ -ptx*)
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+ ;;
+ -windowsnt*)
+ os=`echo $os | sed -e 's/windowsnt/winnt/'`
+ ;;
+ -psos*)
+ os=-psos
+ ;;
+ -mint | -mint[0-9]*)
+ basic_machine=m68k-atari
+ os=-mint
+ ;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+ # Recognize the basic CPU types without company name.
+ # Some are omitted here because they have special meanings below.
+ 1750a | 580 \
+ | a29k \
+ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+ | am33_2.0 \
+ | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
+ | bfin \
+ | c4x | clipper \
+ | d10v | d30v | dlx | dsp16xx \
+ | fr30 | frv \
+ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+ | i370 | i860 | i960 | ia64 \
+ | ip2k | iq2000 \
+ | m32c | m32r | m32rle | m68000 | m68k | m88k \
+ | maxq | mb | microblaze | mcore \
+ | mips | mipsbe | mipseb | mipsel | mipsle \
+ | mips16 \
+ | mips64 | mips64el \
+ | mips64vr | mips64vrel \
+ | mips64orion | mips64orionel \
+ | mips64vr4100 | mips64vr4100el \
+ | mips64vr4300 | mips64vr4300el \
+ | mips64vr5000 | mips64vr5000el \
+ | mips64vr5900 | mips64vr5900el \
+ | mipsisa32 | mipsisa32el \
+ | mipsisa32r2 | mipsisa32r2el \
+ | mipsisa64 | mipsisa64el \
+ | mipsisa64r2 | mipsisa64r2el \
+ | mipsisa64sb1 | mipsisa64sb1el \
+ | mipsisa64sr71k | mipsisa64sr71kel \
+ | mipstx39 | mipstx39el \
+ | mn10200 | mn10300 \
+ | mt \
+ | msp430 \
+ | nios | nios2 \
+ | ns16k | ns32k \
+ | or32 \
+ | pdp10 | pdp11 | pj | pjl \
+ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
+ | pyramid \
+ | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+ | sh64 | sh64le \
+ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+ | spu | strongarm \
+ | tahoe | thumb | tic4x | tic80 | tron \
+ | v850 | v850e \
+ | we32k \
+ | x86 | xscale | xscalee[bl] | xstormy16 | xtensa \
+ | z8k)
+ basic_machine=$basic_machine-unknown
+ ;;
+ m6811 | m68hc11 | m6812 | m68hc12)
+ # Motorola 68HC11/12.
+ basic_machine=$basic_machine-unknown
+ os=-none
+ ;;
+ m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+ ;;
+ ms1)
+ basic_machine=mt-unknown
+ ;;
+
+ # We use `pc' rather than `unknown'
+ # because (1) that's what they normally are, and
+ # (2) the word "unknown" tends to confuse beginning users.
+ i*86 | x86_64)
+ basic_machine=$basic_machine-pc
+ ;;
+ # Object if more than one company name word.
+ *-*-*)
+ echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+ exit 1
+ ;;
+ # Recognize the basic CPU types with company name.
+ 580-* \
+ | a29k-* \
+ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
+ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \
+ | avr-* \
+ | bfin-* | bs2000-* \
+ | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
+ | clipper-* | craynv-* | cydra-* \
+ | d10v-* | d30v-* | dlx-* \
+ | elxsi-* \
+ | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \
+ | h8300-* | h8500-* \
+ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+ | i*86-* | i860-* | i960-* | ia64-* \
+ | ip2k-* | iq2000-* \
+ | m32c-* | m32r-* | m32rle-* \
+ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+ | m88110-* | m88k-* | maxq-* | mcore-* \
+ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+ | mips16-* \
+ | mips64-* | mips64el-* \
+ | mips64vr-* | mips64vrel-* \
+ | mips64orion-* | mips64orionel-* \
+ | mips64vr4100-* | mips64vr4100el-* \
+ | mips64vr4300-* | mips64vr4300el-* \
+ | mips64vr5000-* | mips64vr5000el-* \
+ | mips64vr5900-* | mips64vr5900el-* \
+ | mipsisa32-* | mipsisa32el-* \
+ | mipsisa32r2-* | mipsisa32r2el-* \
+ | mipsisa64-* | mipsisa64el-* \
+ | mipsisa64r2-* | mipsisa64r2el-* \
+ | mipsisa64sb1-* | mipsisa64sb1el-* \
+ | mipsisa64sr71k-* | mipsisa64sr71kel-* \
+ | mipstx39-* | mipstx39el-* \
+ | mmix-* \
+ | mt-* \
+ | msp430-* \
+ | nios-* | nios2-* \
+ | none-* | np1-* | ns16k-* | ns32k-* \
+ | orion-* \
+ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
+ | pyramid-* \
+ | romp-* | rs6000-* \
+ | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+ | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+ | sparclite-* \
+ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
+ | tahoe-* | thumb-* \
+ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+ | tron-* \
+ | v850-* | v850e-* | vax-* \
+ | we32k-* \
+ | x86-* | x86_64-* | xps100-* | xscale-* | xscalee[bl]-* \
+ | xstormy16-* | xtensa-* \
+ | ymp-* \
+ | z8k-*)
+ ;;
+ # Recognize the various machine names and aliases which stand
+ # for a CPU type and a company and sometimes even an OS.
+ 386bsd)
+ basic_machine=i386-unknown
+ os=-bsd
+ ;;
+ 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+ basic_machine=m68000-att
+ ;;
+ 3b*)
+ basic_machine=we32k-att
+ ;;
+ a29khif)
+ basic_machine=a29k-amd
+ os=-udi
+ ;;
+ abacus)
+ basic_machine=abacus-unknown
+ ;;
+ adobe68k)
+ basic_machine=m68010-adobe
+ os=-scout
+ ;;
+ alliant | fx80)
+ basic_machine=fx80-alliant
+ ;;
+ altos | altos3068)
+ basic_machine=m68k-altos
+ ;;
+ am29k)
+ basic_machine=a29k-none
+ os=-bsd
+ ;;
+ amd64)
+ basic_machine=x86_64-pc
+ ;;
+ amd64-*)
+ basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ amdahl)
+ basic_machine=580-amdahl
+ os=-sysv
+ ;;
+ amiga | amiga-*)
+ basic_machine=m68k-unknown
+ ;;
+ amigaos | amigados)
+ basic_machine=m68k-unknown
+ os=-amigaos
+ ;;
+ amigaunix | amix)
+ basic_machine=m68k-unknown
+ os=-sysv4
+ ;;
+ apollo68)
+ basic_machine=m68k-apollo
+ os=-sysv
+ ;;
+ apollo68bsd)
+ basic_machine=m68k-apollo
+ os=-bsd
+ ;;
+ aux)
+ basic_machine=m68k-apple
+ os=-aux
+ ;;
+ balance)
+ basic_machine=ns32k-sequent
+ os=-dynix
+ ;;
+ c90)
+ basic_machine=c90-cray
+ os=-unicos
+ ;;
+ convex-c1)
+ basic_machine=c1-convex
+ os=-bsd
+ ;;
+ convex-c2)
+ basic_machine=c2-convex
+ os=-bsd
+ ;;
+ convex-c32)
+ basic_machine=c32-convex
+ os=-bsd
+ ;;
+ convex-c34)
+ basic_machine=c34-convex
+ os=-bsd
+ ;;
+ convex-c38)
+ basic_machine=c38-convex
+ os=-bsd
+ ;;
+ cray | j90)
+ basic_machine=j90-cray
+ os=-unicos
+ ;;
+ craynv)
+ basic_machine=craynv-cray
+ os=-unicosmp
+ ;;
+ cr16c)
+ basic_machine=cr16c-unknown
+ os=-elf
+ ;;
+ crds | unos)
+ basic_machine=m68k-crds
+ ;;
+ crisv32 | crisv32-* | etraxfs*)
+ basic_machine=crisv32-axis
+ ;;
+ cris | cris-* | etrax*)
+ basic_machine=cris-axis
+ ;;
+ crx)
+ basic_machine=crx-unknown
+ os=-elf
+ ;;
+ da30 | da30-*)
+ basic_machine=m68k-da30
+ ;;
+ decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+ basic_machine=mips-dec
+ ;;
+ decsystem10* | dec10*)
+ basic_machine=pdp10-dec
+ os=-tops10
+ ;;
+ decsystem20* | dec20*)
+ basic_machine=pdp10-dec
+ os=-tops20
+ ;;
+ delta | 3300 | motorola-3300 | motorola-delta \
+ | 3300-motorola | delta-motorola)
+ basic_machine=m68k-motorola
+ ;;
+ delta88)
+ basic_machine=m88k-motorola
+ os=-sysv3
+ ;;
+ djgpp)
+ basic_machine=i586-pc
+ os=-msdosdjgpp
+ ;;
+ dpx20 | dpx20-*)
+ basic_machine=rs6000-bull
+ os=-bosx
+ ;;
+ dpx2* | dpx2*-bull)
+ basic_machine=m68k-bull
+ os=-sysv3
+ ;;
+ ebmon29k)
+ basic_machine=a29k-amd
+ os=-ebmon
+ ;;
+ elxsi)
+ basic_machine=elxsi-elxsi
+ os=-bsd
+ ;;
+ encore | umax | mmax)
+ basic_machine=ns32k-encore
+ ;;
+ es1800 | OSE68k | ose68k | ose | OSE)
+ basic_machine=m68k-ericsson
+ os=-ose
+ ;;
+ fx2800)
+ basic_machine=i860-alliant
+ ;;
+ genix)
+ basic_machine=ns32k-ns
+ ;;
+ gmicro)
+ basic_machine=tron-gmicro
+ os=-sysv
+ ;;
+ go32)
+ basic_machine=i386-pc
+ os=-go32
+ ;;
+ h3050r* | hiux*)
+ basic_machine=hppa1.1-hitachi
+ os=-hiuxwe2
+ ;;
+ h8300hms)
+ basic_machine=h8300-hitachi
+ os=-hms
+ ;;
+ h8300xray)
+ basic_machine=h8300-hitachi
+ os=-xray
+ ;;
+ h8500hms)
+ basic_machine=h8500-hitachi
+ os=-hms
+ ;;
+ harris)
+ basic_machine=m88k-harris
+ os=-sysv3
+ ;;
+ hp300-*)
+ basic_machine=m68k-hp
+ ;;
+ hp300bsd)
+ basic_machine=m68k-hp
+ os=-bsd
+ ;;
+ hp300hpux)
+ basic_machine=m68k-hp
+ os=-hpux
+ ;;
+ hp3k9[0-9][0-9] | hp9[0-9][0-9])
+ basic_machine=hppa1.0-hp
+ ;;
+ hp9k2[0-9][0-9] | hp9k31[0-9])
+ basic_machine=m68000-hp
+ ;;
+ hp9k3[2-9][0-9])
+ basic_machine=m68k-hp
+ ;;
+ hp9k6[0-9][0-9] | hp6[0-9][0-9])
+ basic_machine=hppa1.0-hp
+ ;;
+ hp9k7[0-79][0-9] | hp7[0-79][0-9])
+ basic_machine=hppa1.1-hp
+ ;;
+ hp9k78[0-9] | hp78[0-9])
+ # FIXME: really hppa2.0-hp
+ basic_machine=hppa1.1-hp
+ ;;
+ hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+ # FIXME: really hppa2.0-hp
+ basic_machine=hppa1.1-hp
+ ;;
+ hp9k8[0-9][13679] | hp8[0-9][13679])
+ basic_machine=hppa1.1-hp
+ ;;
+ hp9k8[0-9][0-9] | hp8[0-9][0-9])
+ basic_machine=hppa1.0-hp
+ ;;
+ hppa-next)
+ os=-nextstep3
+ ;;
+ hppaosf)
+ basic_machine=hppa1.1-hp
+ os=-osf
+ ;;
+ hppro)
+ basic_machine=hppa1.1-hp
+ os=-proelf
+ ;;
+ i370-ibm* | ibm*)
+ basic_machine=i370-ibm
+ ;;
+# I'm not sure what "Sysv32" means. Should this be sysv3.2?
+ i*86v32)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-sysv32
+ ;;
+ i*86v4*)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-sysv4
+ ;;
+ i*86v)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-sysv
+ ;;
+ i*86sol2)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-solaris2
+ ;;
+ i386mach)
+ basic_machine=i386-mach
+ os=-mach
+ ;;
+ i386-vsta | vsta)
+ basic_machine=i386-unknown
+ os=-vsta
+ ;;
+ iris | iris4d)
+ basic_machine=mips-sgi
+ case $os in
+ -irix*)
+ ;;
+ *)
+ os=-irix4
+ ;;
+ esac
+ ;;
+ isi68 | isi)
+ basic_machine=m68k-isi
+ os=-sysv
+ ;;
+ m88k-omron*)
+ basic_machine=m88k-omron
+ ;;
+ magnum | m3230)
+ basic_machine=mips-mips
+ os=-sysv
+ ;;
+ merlin)
+ basic_machine=ns32k-utek
+ os=-sysv
+ ;;
+ mingw32)
+ basic_machine=i386-pc
+ os=-mingw32
+ ;;
+ miniframe)
+ basic_machine=m68000-convergent
+ ;;
+ *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+ basic_machine=m68k-atari
+ os=-mint
+ ;;
+ mips3*-*)
+ basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+ ;;
+ mips3*)
+ basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+ ;;
+ monitor)
+ basic_machine=m68k-rom68k
+ os=-coff
+ ;;
+ morphos)
+ basic_machine=powerpc-unknown
+ os=-morphos
+ ;;
+ msdos)
+ basic_machine=i386-pc
+ os=-msdos
+ ;;
+ ms1-*)
+ basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+ ;;
+ mvs)
+ basic_machine=i370-ibm
+ os=-mvs
+ ;;
+ ncr3000)
+ basic_machine=i486-ncr
+ os=-sysv4
+ ;;
+ netbsd386)
+ basic_machine=i386-unknown
+ os=-netbsd
+ ;;
+ netwinder)
+ basic_machine=armv4l-rebel
+ os=-linux
+ ;;
+ news | news700 | news800 | news900)
+ basic_machine=m68k-sony
+ os=-newsos
+ ;;
+ news1000)
+ basic_machine=m68030-sony
+ os=-newsos
+ ;;
+ news-3600 | risc-news)
+ basic_machine=mips-sony
+ os=-newsos
+ ;;
+ necv70)
+ basic_machine=v70-nec
+ os=-sysv
+ ;;
+ next | m*-next )
+ basic_machine=m68k-next
+ case $os in
+ -nextstep* )
+ ;;
+ -ns2*)
+ os=-nextstep2
+ ;;
+ *)
+ os=-nextstep3
+ ;;
+ esac
+ ;;
+ nh3000)
+ basic_machine=m68k-harris
+ os=-cxux
+ ;;
+ nh[45]000)
+ basic_machine=m88k-harris
+ os=-cxux
+ ;;
+ nindy960)
+ basic_machine=i960-intel
+ os=-nindy
+ ;;
+ mon960)
+ basic_machine=i960-intel
+ os=-mon960
+ ;;
+ nonstopux)
+ basic_machine=mips-compaq
+ os=-nonstopux
+ ;;
+ np1)
+ basic_machine=np1-gould
+ ;;
+ nsr-tandem)
+ basic_machine=nsr-tandem
+ ;;
+ op50n-* | op60c-*)
+ basic_machine=hppa1.1-oki
+ os=-proelf
+ ;;
+ openrisc | openrisc-*)
+ basic_machine=or32-unknown
+ ;;
+ os400)
+ basic_machine=powerpc-ibm
+ os=-os400
+ ;;
+ OSE68000 | ose68000)
+ basic_machine=m68000-ericsson
+ os=-ose
+ ;;
+ os68k)
+ basic_machine=m68k-none
+ os=-os68k
+ ;;
+ pa-hitachi)
+ basic_machine=hppa1.1-hitachi
+ os=-hiuxwe2
+ ;;
+ paragon)
+ basic_machine=i860-intel
+ os=-osf
+ ;;
+ pbd)
+ basic_machine=sparc-tti
+ ;;
+ pbb)
+ basic_machine=m68k-tti
+ ;;
+ pc532 | pc532-*)
+ basic_machine=ns32k-pc532
+ ;;
+ pc98)
+ basic_machine=i386-pc
+ ;;
+ pc98-*)
+ basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pentium | p5 | k5 | k6 | nexgen | viac3)
+ basic_machine=i586-pc
+ ;;
+ pentiumpro | p6 | 6x86 | athlon | athlon_*)
+ basic_machine=i686-pc
+ ;;
+ pentiumii | pentium2 | pentiumiii | pentium3)
+ basic_machine=i686-pc
+ ;;
+ pentium4)
+ basic_machine=i786-pc
+ ;;
+ pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+ basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pentiumpro-* | p6-* | 6x86-* | athlon-*)
+ basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+ basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pentium4-*)
+ basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pn)
+ basic_machine=pn-gould
+ ;;
+ power) basic_machine=power-ibm
+ ;;
+ ppc) basic_machine=powerpc-unknown
+ ;;
+ ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ppcle | powerpclittle | ppc-le | powerpc-little)
+ basic_machine=powerpcle-unknown
+ ;;
+ ppcle-* | powerpclittle-*)
+ basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ppc64) basic_machine=powerpc64-unknown
+ ;;
+ ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+ basic_machine=powerpc64le-unknown
+ ;;
+ ppc64le-* | powerpc64little-*)
+ basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ps2)
+ basic_machine=i386-ibm
+ ;;
+ pw32)
+ basic_machine=i586-unknown
+ os=-pw32
+ ;;
+ rdos)
+ basic_machine=i386-pc
+ os=-rdos
+ ;;
+ rom68k)
+ basic_machine=m68k-rom68k
+ os=-coff
+ ;;
+ rm[46]00)
+ basic_machine=mips-siemens
+ ;;
+ rtpc | rtpc-*)
+ basic_machine=romp-ibm
+ ;;
+ s390 | s390-*)
+ basic_machine=s390-ibm
+ ;;
+ s390x | s390x-*)
+ basic_machine=s390x-ibm
+ ;;
+ sa29200)
+ basic_machine=a29k-amd
+ os=-udi
+ ;;
+ sb1)
+ basic_machine=mipsisa64sb1-unknown
+ ;;
+ sb1el)
+ basic_machine=mipsisa64sb1el-unknown
+ ;;
+ sei)
+ basic_machine=mips-sei
+ os=-seiux
+ ;;
+ sequent)
+ basic_machine=i386-sequent
+ ;;
+ sh)
+ basic_machine=sh-hitachi
+ os=-hms
+ ;;
+ sh64)
+ basic_machine=sh64-unknown
+ ;;
+ sparclite-wrs | simso-wrs)
+ basic_machine=sparclite-wrs
+ os=-vxworks
+ ;;
+ sps7)
+ basic_machine=m68k-bull
+ os=-sysv2
+ ;;
+ spur)
+ basic_machine=spur-unknown
+ ;;
+ st2000)
+ basic_machine=m68k-tandem
+ ;;
+ stratus)
+ basic_machine=i860-stratus
+ os=-sysv4
+ ;;
+ sun2)
+ basic_machine=m68000-sun
+ ;;
+ sun2os3)
+ basic_machine=m68000-sun
+ os=-sunos3
+ ;;
+ sun2os4)
+ basic_machine=m68000-sun
+ os=-sunos4
+ ;;
+ sun3os3)
+ basic_machine=m68k-sun
+ os=-sunos3
+ ;;
+ sun3os4)
+ basic_machine=m68k-sun
+ os=-sunos4
+ ;;
+ sun4os3)
+ basic_machine=sparc-sun
+ os=-sunos3
+ ;;
+ sun4os4)
+ basic_machine=sparc-sun
+ os=-sunos4
+ ;;
+ sun4sol2)
+ basic_machine=sparc-sun
+ os=-solaris2
+ ;;
+ sun3 | sun3-*)
+ basic_machine=m68k-sun
+ ;;
+ sun4)
+ basic_machine=sparc-sun
+ ;;
+ sun386 | sun386i | roadrunner)
+ basic_machine=i386-sun
+ ;;
+ sv1)
+ basic_machine=sv1-cray
+ os=-unicos
+ ;;
+ symmetry)
+ basic_machine=i386-sequent
+ os=-dynix
+ ;;
+ t3e)
+ basic_machine=alphaev5-cray
+ os=-unicos
+ ;;
+ t90)
+ basic_machine=t90-cray
+ os=-unicos
+ ;;
+ tic54x | c54x*)
+ basic_machine=tic54x-unknown
+ os=-coff
+ ;;
+ tic55x | c55x*)
+ basic_machine=tic55x-unknown
+ os=-coff
+ ;;
+ tic6x | c6x*)
+ basic_machine=tic6x-unknown
+ os=-coff
+ ;;
+ tx39)
+ basic_machine=mipstx39-unknown
+ ;;
+ tx39el)
+ basic_machine=mipstx39el-unknown
+ ;;
+ toad1)
+ basic_machine=pdp10-xkl
+ os=-tops20
+ ;;
+ tower | tower-32)
+ basic_machine=m68k-ncr
+ ;;
+ tpf)
+ basic_machine=s390x-ibm
+ os=-tpf
+ ;;
+ udi29k)
+ basic_machine=a29k-amd
+ os=-udi
+ ;;
+ ultra3)
+ basic_machine=a29k-nyu
+ os=-sym1
+ ;;
+ v810 | necv810)
+ basic_machine=v810-nec
+ os=-none
+ ;;
+ vaxv)
+ basic_machine=vax-dec
+ os=-sysv
+ ;;
+ vms)
+ basic_machine=vax-dec
+ os=-vms
+ ;;
+ vpp*|vx|vx-*)
+ basic_machine=f301-fujitsu
+ ;;
+ vxworks960)
+ basic_machine=i960-wrs
+ os=-vxworks
+ ;;
+ vxworks68)
+ basic_machine=m68k-wrs
+ os=-vxworks
+ ;;
+ vxworks29k)
+ basic_machine=a29k-wrs
+ os=-vxworks
+ ;;
+ w65*)
+ basic_machine=w65-wdc
+ os=-none
+ ;;
+ w89k-*)
+ basic_machine=hppa1.1-winbond
+ os=-proelf
+ ;;
+ xbox)
+ basic_machine=i686-pc
+ os=-mingw32
+ ;;
+ xps | xps100)
+ basic_machine=xps100-honeywell
+ ;;
+ ymp)
+ basic_machine=ymp-cray
+ os=-unicos
+ ;;
+ z8k-*-coff)
+ basic_machine=z8k-unknown
+ os=-sim
+ ;;
+ none)
+ basic_machine=none-none
+ os=-none
+ ;;
+
+# Here we handle the default manufacturer of certain CPU types. It is in
+# some cases the only manufacturer, in others, it is the most popular.
+ w89k)
+ basic_machine=hppa1.1-winbond
+ ;;
+ op50n)
+ basic_machine=hppa1.1-oki
+ ;;
+ op60c)
+ basic_machine=hppa1.1-oki
+ ;;
+ romp)
+ basic_machine=romp-ibm
+ ;;
+ mmix)
+ basic_machine=mmix-knuth
+ ;;
+ rs6000)
+ basic_machine=rs6000-ibm
+ ;;
+ vax)
+ basic_machine=vax-dec
+ ;;
+ pdp10)
+ # there are many clones, so DEC is not a safe bet
+ basic_machine=pdp10-unknown
+ ;;
+ pdp11)
+ basic_machine=pdp11-dec
+ ;;
+ we32k)
+ basic_machine=we32k-att
+ ;;
+ sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele)
+ basic_machine=sh-unknown
+ ;;
+ sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+ basic_machine=sparc-sun
+ ;;
+ cydra)
+ basic_machine=cydra-cydrome
+ ;;
+ orion)
+ basic_machine=orion-highlevel
+ ;;
+ orion105)
+ basic_machine=clipper-highlevel
+ ;;
+ mac | mpw | mac-mpw)
+ basic_machine=m68k-apple
+ ;;
+ pmac | pmac-mpw)
+ basic_machine=powerpc-apple
+ ;;
+ *-unknown)
+ # Make sure to match an already-canonicalized machine name.
+ ;;
+ *)
+ echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+ exit 1
+ ;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+ *-digital*)
+ basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+ ;;
+ *-commodore*)
+ basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+ ;;
+ *)
+ ;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+ # First match some system type aliases
+ # that might get confused with valid system types.
+ # -solaris* is a basic system type, with this one exception.
+ -solaris1 | -solaris1.*)
+ os=`echo $os | sed -e 's|solaris1|sunos4|'`
+ ;;
+ -solaris)
+ os=-solaris2
+ ;;
+ -svr4*)
+ os=-sysv4
+ ;;
+ -unixware*)
+ os=-sysv4.2uw
+ ;;
+ -gnu/linux*)
+ os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+ ;;
+ # First accept the basic system types.
+ # The portable systems comes first.
+ # Each alternative MUST END IN A *, to match a version number.
+ # -sysv* is not here because it comes later, after sysvr4.
+ -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+ | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
+ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+ | -aos* \
+ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+ | -openbsd* | -solidbsd* \
+ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+ | -chorusos* | -chorusrdb* \
+ | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+ | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
+ | -uxpv* | -beos* | -mpeix* | -udk* \
+ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
+ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+ | -skyos* | -haiku* | -rdos*)
+ # Remember, each alternative MUST END IN *, to match a version number.
+ ;;
+ -qnx*)
+ case $basic_machine in
+ x86-* | i*86-*)
+ ;;
+ *)
+ os=-nto$os
+ ;;
+ esac
+ ;;
+ -nto-qnx*)
+ ;;
+ -nto*)
+ os=`echo $os | sed -e 's|nto|nto-qnx|'`
+ ;;
+ -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+ | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+ ;;
+ -mac*)
+ os=`echo $os | sed -e 's|mac|macos|'`
+ ;;
+ -linux-dietlibc)
+ os=-linux-dietlibc
+ ;;
+ -linux*)
+ os=`echo $os | sed -e 's|linux|linux-gnu|'`
+ ;;
+ -sunos5*)
+ os=`echo $os | sed -e 's|sunos5|solaris2|'`
+ ;;
+ -sunos6*)
+ os=`echo $os | sed -e 's|sunos6|solaris3|'`
+ ;;
+ -opened*)
+ os=-openedition
+ ;;
+ -os400*)
+ os=-os400
+ ;;
+ -wince*)
+ os=-wince
+ ;;
+ -osfrose*)
+ os=-osfrose
+ ;;
+ -osf*)
+ os=-osf
+ ;;
+ -utek*)
+ os=-bsd
+ ;;
+ -dynix*)
+ os=-bsd
+ ;;
+ -acis*)
+ os=-aos
+ ;;
+ -atheos*)
+ os=-atheos
+ ;;
+ -syllable*)
+ os=-syllable
+ ;;
+ -386bsd)
+ os=-bsd
+ ;;
+ -ctix* | -uts*)
+ os=-sysv
+ ;;
+ -nova*)
+ os=-rtmk-nova
+ ;;
+ -ns2 )
+ os=-nextstep2
+ ;;
+ -nsk*)
+ os=-nsk
+ ;;
+ # Preserve the version number of sinix5.
+ -sinix5.*)
+ os=`echo $os | sed -e 's|sinix|sysv|'`
+ ;;
+ -sinix*)
+ os=-sysv4
+ ;;
+ -tpf*)
+ os=-tpf
+ ;;
+ -triton*)
+ os=-sysv3
+ ;;
+ -oss*)
+ os=-sysv3
+ ;;
+ -svr4)
+ os=-sysv4
+ ;;
+ -svr3)
+ os=-sysv3
+ ;;
+ -sysvr4)
+ os=-sysv4
+ ;;
+ # This must come after -sysvr4.
+ -sysv*)
+ ;;
+ -ose*)
+ os=-ose
+ ;;
+ -es1800*)
+ os=-ose
+ ;;
+ -xenix)
+ os=-xenix
+ ;;
+ -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+ os=-mint
+ ;;
+ -aros*)
+ os=-aros
+ ;;
+ -kaos*)
+ os=-kaos
+ ;;
+ -zvmoe)
+ os=-zvmoe
+ ;;
+ -none)
+ ;;
+ *)
+ # Get rid of the `-' at the beginning of $os.
+ os=`echo $os | sed 's/[^-]*-//'`
+ echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+ exit 1
+ ;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system. Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+ spu-*)
+ os=-elf
+ ;;
+ *-acorn)
+ os=-riscix1.2
+ ;;
+ arm*-rebel)
+ os=-linux
+ ;;
+ arm*-semi)
+ os=-aout
+ ;;
+ c4x-* | tic4x-*)
+ os=-coff
+ ;;
+ # This must come before the *-dec entry.
+ pdp10-*)
+ os=-tops20
+ ;;
+ pdp11-*)
+ os=-none
+ ;;
+ *-dec | vax-*)
+ os=-ultrix4.2
+ ;;
+ m68*-apollo)
+ os=-domain
+ ;;
+ i386-sun)
+ os=-sunos4.0.2
+ ;;
+ m68000-sun)
+ os=-sunos3
+ # This also exists in the configure program, but was not the
+ # default.
+ # os=-sunos4
+ ;;
+ m68*-cisco)
+ os=-aout
+ ;;
+ mips*-cisco)
+ os=-elf
+ ;;
+ mips*-*)
+ os=-elf
+ ;;
+ or32-*)
+ os=-coff
+ ;;
+ *-tti) # must be before sparc entry or we get the wrong os.
+ os=-sysv3
+ ;;
+ sparc-* | *-sun)
+ os=-sunos4.1.1
+ ;;
+ *-be)
+ os=-beos
+ ;;
+ *-haiku)
+ os=-haiku
+ ;;
+ *-ibm)
+ os=-aix
+ ;;
+ *-knuth)
+ os=-mmixware
+ ;;
+ *-wec)
+ os=-proelf
+ ;;
+ *-winbond)
+ os=-proelf
+ ;;
+ *-oki)
+ os=-proelf
+ ;;
+ *-hp)
+ os=-hpux
+ ;;
+ *-hitachi)
+ os=-hiux
+ ;;
+ i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+ os=-sysv
+ ;;
+ *-cbm)
+ os=-amigaos
+ ;;
+ *-dg)
+ os=-dgux
+ ;;
+ *-dolphin)
+ os=-sysv3
+ ;;
+ m68k-ccur)
+ os=-rtu
+ ;;
+ m88k-omron*)
+ os=-luna
+ ;;
+ *-next )
+ os=-nextstep
+ ;;
+ *-sequent)
+ os=-ptx
+ ;;
+ *-crds)
+ os=-unos
+ ;;
+ *-ns)
+ os=-genix
+ ;;
+ i370-*)
+ os=-mvs
+ ;;
+ *-next)
+ os=-nextstep3
+ ;;
+ *-gould)
+ os=-sysv
+ ;;
+ *-highlevel)
+ os=-bsd
+ ;;
+ *-encore)
+ os=-bsd
+ ;;
+ *-sgi)
+ os=-irix
+ ;;
+ *-siemens)
+ os=-sysv4
+ ;;
+ *-masscomp)
+ os=-rtu
+ ;;
+ f30[01]-fujitsu | f700-fujitsu)
+ os=-uxpv
+ ;;
+ *-rom68k)
+ os=-coff
+ ;;
+ *-*bug)
+ os=-coff
+ ;;
+ *-apple)
+ os=-macos
+ ;;
+ *-atari*)
+ os=-mint
+ ;;
+ *)
+ os=-none
+ ;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer. We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+ *-unknown)
+ case $os in
+ -riscix*)
+ vendor=acorn
+ ;;
+ -sunos*)
+ vendor=sun
+ ;;
+ -aix*)
+ vendor=ibm
+ ;;
+ -beos*)
+ vendor=be
+ ;;
+ -hpux*)
+ vendor=hp
+ ;;
+ -mpeix*)
+ vendor=hp
+ ;;
+ -hiux*)
+ vendor=hitachi
+ ;;
+ -unos*)
+ vendor=crds
+ ;;
+ -dgux*)
+ vendor=dg
+ ;;
+ -luna*)
+ vendor=omron
+ ;;
+ -genix*)
+ vendor=ns
+ ;;
+ -mvs* | -opened*)
+ vendor=ibm
+ ;;
+ -os400*)
+ vendor=ibm
+ ;;
+ -ptx*)
+ vendor=sequent
+ ;;
+ -tpf*)
+ vendor=ibm
+ ;;
+ -vxsim* | -vxworks* | -windiss*)
+ vendor=wrs
+ ;;
+ -aux*)
+ vendor=apple
+ ;;
+ -hms*)
+ vendor=hitachi
+ ;;
+ -mpw* | -macos*)
+ vendor=apple
+ ;;
+ -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+ vendor=atari
+ ;;
+ -vos*)
+ vendor=stratus
+ ;;
+ esac
+ basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+ ;;
+esac
+
+echo $basic_machine$os
+exit
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/src-2.9/configure.ac b/src-2.9/configure.ac
new file mode 100644
index 000000000..de153c796
--- /dev/null
+++ b/src-2.9/configure.ac
@@ -0,0 +1,229 @@
+dnl Run autoconf to generate configure from this file
+
+AC_INIT([GF],[2.9],[aarne@cs.chalmers.se],[GF])
+
+AC_PREREQ(2.53)
+
+AC_REVISION($Revision: 1.26 $)
+
+AC_CONFIG_FILES([config.mk gfc jgf gfeditor])
+
+AC_CANONICAL_HOST
+
+dnl ***********************************************
+dnl Executable suffix
+dnl ***********************************************
+
+
+AC_MSG_CHECKING([executable suffix])
+case $host_os in
+ cygwin)
+ EXEEXT='.exe';;
+ *)
+ EXEEXT='';;
+esac
+AC_MSG_RESULT(['$EXEEXT'])
+AC_SUBST(EXEEXT)
+
+dnl ***********************************************
+dnl GHC
+dnl ***********************************************
+
+AC_ARG_WITH(ghc,
+ AC_HELP_STRING([--with-ghc=],
+ [Use a different command instead of
+ 'ghc' for the Haskell compiler.]),
+ [AC_CHECK_FILE("$withval",GHC="$withval",[AC_PATH_PROG(GHC,"$withval")])],
+ [AC_PATH_PROG(GHC,ghc)])
+
+GHCI=$(dirname $GHC)/ghci
+
+GHC_VERSION=`$GHC --version | sed -e 's/.*version //'`
+AC_MSG_CHECKING([GHC version])
+AC_MSG_RESULT($GHC_VERSION)
+
+
+AC_SUBST(GHC)
+AC_SUBST(GHCI)
+
+dnl ***********************************************
+dnl readline
+dnl ***********************************************
+
+AC_ARG_WITH(readline,
+ AC_HELP_STRING([--with-readline=],
+ [Select which readline implementation to use.
+ Available alternatives are: 'readline' (GNU readline),
+ 'no' (don't use readline)
+ (default = readline)]),
+ [if test "$withval" = "yes"; then
+ READLINE="readline"
+ else
+ READLINE="$withval"
+ fi],
+ [if test "$host_os" = "cygwin"; then
+ AC_MSG_WARN([There are problems with readline for Windows,
+ for example, pipe characters do not work.
+ Disabling readline support.
+ Use --with-readline to override.])
+ READLINE="no"
+ else
+ READLINE="readline"
+ fi])
+
+case $READLINE in
+ readline)
+ ;;
+ no)
+ ;;
+ *)
+ AC_MSG_ERROR([Bad value for --with-readline: $READLINE])
+ ;;
+esac
+
+AC_SUBST(READLINE)
+
+dnl ***********************************************
+dnl command interruption
+dnl ***********************************************
+
+AC_ARG_WITH(interrupt,
+ AC_HELP_STRING([--with-interrupt=],
+ [Choose whether to enable interruption of commands
+ with SIGINT (Ctrl-C)
+ Available alternatives are: 'yes', 'no'
+ (default = yes)]),
+ [INTERRUPT="$withval"],
+ [if test "$host_os" = "cygwin"; then
+ AC_MSG_WARN([Command interruption does not work under
+ Cygwin, because of missing signal handler support.
+ Disabling command interruption support.
+ Use --with-interrupt to override.])
+ INTERRUPT="no"
+ else
+ INTERRUPT="yes"
+ fi])
+
+case $INTERRUPT in
+ yes)
+ ;;
+ no)
+ ;;
+ *)
+ AC_MSG_ERROR([Bad value for --with-interrupt: $INTERRUPT])
+ ;;
+esac
+
+AC_SUBST(INTERRUPT)
+
+dnl ***********************************************
+dnl ATK speech recognition
+dnl ***********************************************
+
+AC_ARG_WITH(atk,
+ AC_HELP_STRING([--with-atk=