patch for review (refactor ghci command loops,
add multiline commands)
Claus Reinke
claus.reinke at talk21.com
Sat Sep 15 16:44:44 EDT 2007
i finally found a way to make my .ghci-file readable, by
implementing multiline commands for ghci!-)
patch and test attached. patch seems to make no difference
to existing tests (fast stage=2).
issues
- multiline commands in ghci and .ghci would be great
- they can only partially be implemented at user level
(in particular, the user level implementation won't
work in .ghci files, where it would be most useful)
- ghci has three separate command loops for file, readline,
and cmdqueue, treating the queue slightly differently
and spreading functionality over three pieces of code;
moreover, fileLoop/readLineLoop are in control, and
runCommands returns to them when it needs more input,
making it difficult to implement multiline commands;
solutions in this patch
- refactor ghci command loops into one (runCommands);
fileLoop/readLineLoop just feed single lines to
runCommands, as does the new queryQueue;
commands are read from the queue, or from the
current feeder, if the queue is empty; all sources of
commands are otherwise treated equally, in a single
location
- add multiline commands ':{\n ..lines.. \n:}\n', which has
become trivial after the refactoring, and works via stdin,
in .ghci, via readFile, and via :cmd/:def
the refactoring should be independently useful, as a cleanup
and to bring common functionality into a single source location.
multiline commands have been asked for both to improve
interactive sessions, and to make .ghci files readable (without
this patch, my own .ghci file was unmaintainable). the syntax
i've chosen is:
:{
let
{ x = True
; y = False
}
:}
that is, multiline commands are clearly separated by ':{',':}',
each on a line of its own, and add no other functionality. in
particular, we do not:
- enable anything but existing commands spread
over multiple lines (no layout, no data)
- read .ghci via stdin to make this work (that would
interfere with type-ahead and with piping into ghci)
- use '\' as line-continuations, as conventional, because
those may appear in existing commands at the end
(:info \\) or at the beginning (\x->x)
please review, and adopt for HEAD and STABLE.
(in addition to the patch and test, i also attach my .ghci,
so you can see this feature in action; if you recall the
original form of the :redir command, all squished into
a single line, you'll agree that this little feature makes
a great difference to maintainability of .ghci files;-)
btw, it seems that ghci tests are not protected from .ghci
files (shouldn't they be run with -ignore-dot-ghci?)!
my own test tests stdin and :cmd readFile, but not .ghci,
because i didn't know how to add a .ghci file for a single
test only (should there be a ghci option to specify the
.ghci-filename?).
enjoy!-)
claus
ps fileLoop/readLineLoop are no longer loops, but
i left the names unchanged to simplify reviewing
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghci-multiline-commands-testsuite.diff
Type: application/octet-stream
Size: 180 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/cvs-ghc/attachments/20070915/437ac2b3/ghci-multiline-commands-testsuite.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghci-multiline-commands.diff
Type: application/octet-stream
Size: 4611 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/cvs-ghc/attachments/20070915/437ac2b3/ghci-multiline-commands.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghci023.stdout
Type: application/octet-stream
Size: 420 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/cvs-ghc/attachments/20070915/437ac2b3/ghci023.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghci023.ghci
Type: application/octet-stream
Size: 78 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/cvs-ghc/attachments/20070915/437ac2b3/ghci023-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghci023.script
Type: application/octet-stream
Size: 252 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/cvs-ghc/attachments/20070915/437ac2b3/ghci023-0002.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .ghci
Type: application/octet-stream
Size: 3008 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/cvs-ghc/attachments/20070915/437ac2b3/ghci.obj
More information about the Cvs-ghc
mailing list