uxn11/test/ispell.tal

86 lines
3.9 KiB
Tal
Raw Normal View History

2023-12-03 22:07:14 -05:00
( ispell.tal )
( )
( note that this is not a production spell-checker and is currently )
( kind of brittle in the same ways as `ispell -a` on raw input )
2023-12-03 16:59:39 -05:00
|10 @Console [
2023-12-03 22:13:43 -05:00
&vector $2 &stdin $1 &pad1 $4 &type $1
&stdout $1 &stderr $1 &proc-put $1 &pad2 $1 &param $2 &opts $1 &host-put $1
2023-12-03 16:59:39 -05:00
]
|0000
2023-12-03 22:07:14 -05:00
@ready $1 ( ; are we ready? or still reading ispell startup banner? )
@correct $1 ( ; was the last word spelled ok? )
2023-12-03 16:59:39 -05:00
|0100 ( -> BRK )
2023-12-03 22:07:14 -05:00
;on-console-read .Console/vector DEO2 ( ; set up console vector callback )
word-reset ( ; initialize word buffer )
#31 .Console/opts DEO ( ; child 1: write child.in, read child.out )
2023-12-03 16:59:39 -05:00
;ispell-cmd .Console/param DEO2 ( ; set up `ispell -a` to run )
2023-12-03 22:07:14 -05:00
#01 .Console/host-put DEO BRK ( ; run the command now and return )
2023-12-03 16:59:39 -05:00
@word-reset ( -> )
;word-buf ;word-pos STA2 ( ; reset word-pos pointer )
#00 ;word-buf STA JMP2r ( ; write zero into word buffer )
2023-12-03 22:07:14 -05:00
@word-append ( c^ -> BRK )
;word-pos LDA2 STA ( ; pos<-c )
;word-pos LDA2 INC2 ;word-pos STA2 ( ; pos<-pos+1 )
#00 ;word-pos LDA2 STA BRK ( ; pos<-00 )
2023-12-03 16:59:39 -05:00
@on-console-read
2023-12-03 22:07:14 -05:00
.Console/type DEI ( ; what kind of input is this? )
DUP #21 NEQ ?{ POP !on-ispell-input } ( ; input from ispell process )
DUP #01 NEQ ?{ POP !on-stdin } ( ; input from stdin, i.e. user )
POP BRK ( ; otherwise skip )
2023-12-03 16:59:39 -05:00
@on-stdin
2023-12-03 22:07:14 -05:00
.Console/stdin DEI #0a EQU ?check ( ; if newline, check spelling )
.Console/stdin DEI DUP !word-append ( ; if not newline, append to buffer )
2023-12-03 16:59:39 -05:00
@on-ispell-input ( -> BRK )
2023-12-03 22:07:14 -05:00
.ready LDZ ?{ !on-console-init } ( ; if not ready, parse ispell banner )
2023-12-03 22:13:43 -05:00
.Console/stdin DEI LIT "* EQU ( ; line starting with "*" means ok )
.Console/stdin DEI LIT "+ EQU ORA ( ; line starting with "+" means ok too )
2023-12-03 22:07:14 -05:00
.correct STZ ( ; store spelling result )
#20 print ( ; print a space )
LIT "0 .correct LDZ ADD println ( ; print 1 if ok, 0 otherwise )
#00 ;on-ispell-drain/done STA ( ; drain two lines )
2023-12-03 16:59:39 -05:00
;on-ispell-drain .Console/vector DEO2 ( ; ignore rest of line )
BRK
2023-12-03 22:07:14 -05:00
@on-console-init ( -- BRK )
2023-12-03 22:13:43 -05:00
.Console/stdin DEI #0a EQU ?{ BRK } ( ; skip ispell's one line banner )
2023-12-03 22:07:14 -05:00
#01 .ready STZ ( ; after newline we are ready )
LIT "> print BRK ( ; print simple prompt and return )
2023-12-03 16:59:39 -05:00
2023-12-03 22:07:14 -05:00
@on-ispell-drain ( -> BRK )
2023-12-03 16:59:39 -05:00
.Console/type DEI #21 EQU ?{ BRK } ( ; 0x21 signals input from child 1 )
2023-12-03 22:13:43 -05:00
.Console/stdin DEI #0a EQU ?{ BRK } ( ; skip ispell's outupt )
2023-12-03 22:07:14 -05:00
LIT &done $1 ?{ #01 ,&done STR BRK } ( ; only exit if second newline )
2023-12-03 16:59:39 -05:00
;on-console-read .Console/vector DEO2 ( ; drain finished, checker is ready )
2023-12-03 22:07:14 -05:00
word-reset LIT "> print BRK ( ; reset buffer, print prompt, return )
@check ( word* -> BRK )
.ready LDZ ?{ !check-not-ready }
;word-buf #01 .Console/opts DEO ( ; prepare buffer, act on child 1 )
&loop LDAk ?{ POP2 #0a send BRK } ( ; when we read \0 we are done )
LDAk DUP print send INC2 !&loop ( ; send byte to child 1 and loop )
@check-not-ready
#20 print LIT "? println ( ; print " ?\n" )
word-reset LIT "> print BRK ( ; reset the buffer, print prompt, return )
@send ( c^ -> )
.Console/proc-put DEO JMP2r ( ; send character to ispell process )
@print ( c^ -> )
.Console/stdout DEO JMP2r ( ; send character to stdout )
@println ( c^ -> )
print #0a .Console/stdout DEO JMP2r ( ; send character and newline to stdout )
@ispell-cmd "ispell 20 "-a 00 ( ; "ispell -a" )
@word-pos $2 ( ; position in word-buf )
@word-buf $100 ( ; buffer for input characters )