provide an action to accept current input
Is it possible to provide an action to send the current buffer into the server regardless of whether it is syntax correct or not?
For example, currently in the utop 3;; Enter the phrase will be sent to the toplevel, 3 Enter will result in a new line Is it possible to send a phrase only "3" ?
I tried the [accept] action, but it seems not to work, thanks!
Yes, that's possible. But I need to change a little bit the way actions are handled.
This makes sense to me, since I have changed the parser of toplevel, maybe other people benefit from this flexible design as well.
I'll have a look
Would mind explain a bit how utop works? Will it parse the string? I changed my parser to double semicolon, then utop accepts it happily, but it still gives me an paser error
let a = {:exp| 3 |};; Error: Syntax error
utop does not use Toploop.parse_toplevel_phrase. It has its own UTop.parse_toplevel_phrase which works a bit differently. So if you want to use your own parser you need to use this one. The main difference is the way it reports errors, because utop wants to highlight the location itself.
For accepting current input the only problem is that it is currently not possible to define utop specific actions. I'd like to change how lambda-term handles editing actions so that it is possible to do so. But in the meantime a quick-workaround is to define a new action (for instance accept2 or terminate-and-accept ) in lambda-term and overload it to accepting the current input in utop.
I may have some time to have a look at it this week end but if you want to have a look, here is what need to be done:
- add a new constructor to
LTerm_read_line.action - update
doc_of_actionand theactionslist - make this new action behave the same way as
AcceptinLTerm_read_line, there are two places to update:engine#send_actionandterm#exec - maybe provide a default binding for it, like Meta-Enter
- in
UTop_mainupdateread_phrase#execto change the behavior of this new action: add the phrase as it to the history, then addUTop.phrase_terminatorand parse it
Thanks for your help! I got a roughly working version by mutating UTop.parse_toplevel_phrase. utop is an invaluable piece of software for ocaml programmers, it would be great that some internals are documented so that more people could contribute. Thanks again
Yep, you are right. I intend to do so, I'll put some documentation on the wiki.