Proper error handling in console.

This commit is contained in:
C. Guy Yarvin 2015-03-19 11:53:05 -07:00
parent b5a4f6784a
commit 035230dd13
4 changed files with 31 additions and 97 deletions

View File

@ -523,8 +523,8 @@
++ he-dope :: sole user of ++dp
|= txt=tape ::
^- (each (unit dojo-command) hair) :: prefix/result
=+ vex=(dp-command:dp [1 1] txt)
?. =(+((lent txt)) q.p.vex) :: fully parsed
=+ vex=(dp-command:dp [0 0] txt) ::
?. =((lent txt) q.p.vex) :: fully parsed
[%| p.vex] :: syntax error
[%& ?~(q.vex ~ `p.u.q.vex)] :: prefix/complete
::
@ -603,11 +603,12 @@
=^ dat say (~(transceive cs say) cal)
?. ?& ?=(%del -.dat)
=(+(p.dat) (lent buf.say))
=(%| -:(he-dope (tufa buf.say)))
==
+>.$
=+ foy=(he-dope (tufa buf.say))
?: ?=(%& -.foy) +>.$
=^ lic say (~(transmit cs say) dat)
(he-rush %mor [%bel ~] [%det lic] ~)
(he-rush %mor [%det lic] [%err q.p.foy] ~)
::
++ he-plan :: execute command
|= mad=dojo-command
@ -620,13 +621,7 @@
^+ +>
=+ doy=(he-duke txt)
?- -.doy
%|
%- he-rush
:~ %mor
[%tan [%leaf "syntax error at {<p.doy>}"]~]
[%bel ~]
==
::
%| (he-rush [%err p.doy])
%&
=+ old=(weld "> " (tufa buf.say))
=^ cal say (~(transmit cs say) [%set ~])

View File

@ -343,6 +343,11 @@
.(+> (se-blit %bel ~))
(ta-hom %del pos.inp)
::
++ ta-err :: hear error
|= pos=@ud
=. pos (~(transpose cs say.inp) pos)
ta-bel(pos.inp (min pos (lent buf.say.inp)))
::
++ ta-fec :: apply effect
|= fec=console-effect
^+ +>
@ -351,6 +356,7 @@
%blk +>
%clr +>(+> (se-blit fec))
%det (ta-got +.fec)
%err (ta-err +.fec)
%mor |- ^+ +>.^$
?~ p.fec +>.^$
$(p.fec t.p.fec, +>.^$ ^$(fec i.p.fec))

View File

@ -12,80 +12,6 @@
++ cs :: shared-state engine
|_ console-share
++ abet +<
++ apex :: engine by rule
|* sef=_rule
|= act=console-action
^+ [[p=*(list console-effect) q=(rust ~ sef)] *console-share]
?- -.act
%det
=^ dut +<.apex
%+ remit +.act
|= buf=(list ,@c)
=+ txt=(tufa buf)
=((lent txt) q.p:(sef [0 0] txt))
[[?~(dut ~ [[%det u.dut] [%bel ~] ~]) ~] +<.apex]
::
%ret
=+ dod=(rust (tufa buf) sef)
?~ dod
[[[%bel ~]~ ~] +<.apex]
=^ cal +<.apex (transmit [%set ~])
:_ +<.apex
:_ dod
:~ [%det cal]
[%nex ~]
==
==
++ apse :: dialog engine
|* dog=(console-dialog)
|= act=(unit console-action)
=< abet |%
++ abet
?~ act (ajar ~)
?- -.u.act
%det
=^ dut +<.apse
%+ remit +.u.act
|= buf=(list ,@c)
!=(~ (dog `(tufa buf)))
:_ +<.apse
:_ dog
:_ q=[~ u=~]
^= p ^- (list console-effect)
?~(dut ~ [[%det u.dut] [%bel ~] ~])
::
%ret (ajar `(tufa buf))
==
++ ajar
|= unp=(unit console-input)
=+ god=(dog unp)
?: |(?=(~ god) ?=(~ u.god))
:_ +<.apse
:_ dog
:- p=`(list console-effect)`[%bel ~]~
q=[~ u=~]
=+ fex=`(list console-effect)`[%tan p.u.u.god]~
?- -.q.u.u.god
%&
:_ +<.apse
:_ dog
:- p=fex
q=?~(p.q.u.u.god ~ [~ u=p.q.u.u.god])
::
%|
=^ cal +<.apse (transmit [%set ~])
:_ +<.apse
:_ q.p.q.u.u.god
:_ q=[~ u=~]
^= p ^+ fex
:* [%det cal]
[%nex ~]
[%pro p.p.q.u.u.god]
fex
==
==
--
::
++ apply
|= ted=console-edit
^+ +>
@ -173,18 +99,6 @@
%set [%set buf]
==
::
++ transmit :: outgoing change
|= ted=console-edit
^- [console-change console-share]
[[[his.ven own.ven] (sham buf) ted] (commit ted)]
::
++ transceive :: receive and invert
|= console-change
^- [console-edit console-share]
=+ old=buf
=^ dat +>+<.$ (receive +<.$)
[(inverse(buf old) dat) +>+<.$]
::
++ receive :: naturalize event
|= console-change
^- [console-edit console-share]
@ -204,5 +118,23 @@
[~ +>+<.$]
=^ lic +>+<.$ (transmit (inverse(buf old) dat))
[`lic +>+<.$]
::
++ transmit :: outgoing change
|= ted=console-edit
^- [console-change console-share]
[[[his.ven own.ven] (sham buf) ted] (commit ted)]
::
++ transceive :: receive and invert
|= console-change
^- [console-edit console-share]
=+ old=buf
=^ dat +>+<.$ (receive +<.$)
[(inverse(buf old) dat) +>+<.$]
::
++ transpose :: adjust position
|= pos=@ud
=+ dat=(transmute [%mor leg] [%ins pos `@c`0])
?> ?=(%ins -.dat)
p.dat
--
--

View File

@ -63,6 +63,7 @@
[%blk p=@ud q=@c] :: blink/match char at
[%clr ~] :: clear screen
[%det console-change] :: edit command
[%err p=@ud] :: error point
[%mor p=(list console-effect)] :: multiple effects
[%nex ~] :: save, clear command
[%pro console-prompt] :: set prompt