[MLton-user] signal handling an mllex based filter
Michael Norrish
Michael.Norrish at nicta.com.au
Mon Aug 3 22:47:37 PDT 2009
I have a filter that reads from stdin and writes to stdout. The input
is lexed with an mllex program that recognises the tokens and outputs
the necessary transformations.
In other words, the end of the program looks like
val lexer = filter.makeLexer (read_from_stream instream) state
val _ = lexer()
I want the user to be able to hit control-c to reset the state of the
lexer. In particular, if the lexer can get into different internal
states if it's in the middle of recognising a quotation literal
(something with delimiters).
It has MLlex code like
<START>{quote-begin} (YYBEGIN INQUOTE; continue());
...
<INQUOTE>{quote-end} (YYBEGIN START; continue());
<INQUOTE>...
In Moscow ML, I did some magic to get SIGINT recognised as an Interrupt
exception, and did
lexer() handle Interrupt => lexer()
In Poly/ML, I had to do a little different magic, but was again able to
get SIGINT recognised as an Interrupt exception. I thus had the same
code again.
In MLton, I'm confused.
I can handle SIGINT with MLton.Signal.setHandler, but it seems as if I
am going to have to explicitly set myself up with a master thread that
repeatedly creates slave threads to run lexer(). Then in the handler, I
can just switch to the master, leaving the interrupted slave to expire
through lack of attention.
Is this stylistically and pragmatically correct?
Thanks,
Michael
More information about the MLton-user
mailing list