### main.pkg
### John Reppy (http://www.cs.uchicago.edu/~jhr)
### Aaron Turon (adrassi@gmail.com)
### All rights reserved.
# Compiled by:
#
src/app/future-lex/src/lexgen.lib# Driver for lexgen
### In our morale must lie our strength:
### So, that we may behold at length
### Routed Apollo's
### Battalions melt away like fog,
### Keep well the Hermetic Decalogue,
### Which runs as follows:-
### Thou shalt not do as the dean pleases,
### Thou shalt not write thy doctor's thesis
### On education,
### Thou shalt not worship projects nor
### Shalt thou or thine bow down before
### Administration.
### Thou shalt not answer questionnaires
### Or quizzes upon World-Affairs,
### Nor with compliance
### Take any test. Thou shalt not sit
### With statisticians nor commit
### A social science.
### Thou shalt not be on friendly terms
### With guys in advertising firms,
### Nor speak with such
### As read the Bible for its prose,
### Nor, above all, make love to those
### Who wash too much.
### Thou shalt not live within thy means
### Nor on plain water and raw greens.
### If thou must choose
### Between the chances, choose the odd;
### Read The New Yorker, trust in God;
###
### And take short views.
###
###
###
### Excerpt from "Under Which Lyre: A reactionary Tract for the Times", by W. H. Auden
stipulate
package fil = file__premicrothread; # file__premicrothread is from
src/lib/std/src/posix/file--premicrothread.pkg package re= regular_expression; # regular_expression is from
src/app/future-lex/src/regular-expression.pkg package lex= lex_fn; # lex_fn is from
src/app/future-lex/src/lex-fn.pkg package lo= lex_output_spec; # lex_output_spec is from
src/app/future-lex/src/backends/lex-output-spec.pkgherein
package main { # XXX BUGGO FIXME 'main' is a terrible package name in Mythryl.
#
fun debug s = { print s; print "\n";};
# Command-line parameters
Options =
OPT {
fname: Ref( String ),
lex_compat: Ref( Bool ),
dump: Ref( Bool ),
dot: Ref( Bool ),
match: Ref( Bool ),
be_test: Ref( Bool )
};
# Count the total number of DFA states
fun state_count (lo::SPEC { dfa, ... } )
=
list::length dfa;
fun ml_flex (OPT { fname, lex_compat, dot, dump, match, be_test } )
=
{
if (string::length_in_bytes *fname == 0)
#
print "No input file specified (usage: lexgen [options] file)\n";
winix__premicrothread::process::exit 1;
fi;
if (*lex_compat == FALSE)
#
print "--mythryl-lex-mode switch must be specified\n";
winix__premicrothread::process::exit 1;
fi;
debug "[lexgen: parsing]";
in_spec' = mllex_input::parse_file *fname;
in_spec = if *be_test lex_spec::empty_actions in_spec';
else in_spec'; fi;
debug "[lexgen: DFA gen]";
out_spec = lex::gen in_spec;
(debug (cat [" ", int::to_string (state_count out_spec),
" states in full DFA"]));
if *dump
debug "[lexgen: DFA dump]";
dump_output::output (out_spec, *fname);
fi;
if *dot
debug "[lexgen: DOT gen]";
dot_output::output (out_spec, *fname);
fi;
debug "[lexgen: SML gen]";
smlfun_output::output (out_spec, *fname);
if *match
debug "-- Interactive matching (blank line to quit) --";
match::output (out_spec, *fname);
fi;
winix__premicrothread::process::success;
}
except
ex = { fil::write (fil::stderr, cat [
"uncaught exception ", exceptions::exception_name ex,
" [", exceptions::exception_message ex, "]\n"
]);
apply (\\ s = fil::write (fil::stderr, cat [ " raised at ", s, "\n" ]))
(lib7::exception_history ex);
winix__premicrothread::process::exit_x 1;
};
fun process_args (OPT { fname, lex_compat, dot, dump, match, be_test } ) arg
=
case arg
#
"--dot" => dot := TRUE;
"--dump" => dump := TRUE;
#
"--match" => match := TRUE;
"--testbe" => be_test := TRUE;
#
"--mythryl-lex-mode" => lex_compat := TRUE;
#
file => if (string::length_in_bytes *fname > 0)
#
print "Only one input file may be specified\n";
winix__premicrothread::process::exit_x 1;
else
fname := file;
fi;
esac;
fun main (_, args)
=
{ opt = OPT { fname => REF "", lex_compat => REF FALSE,
dot => REF FALSE, dump => REF FALSE,
match => REF FALSE, be_test => REF FALSE
};
list::apply (process_args opt) args;
ml_flex opt;
};
};
end;