fix bug with ^ and $
This commit is contained in:
parent
c1885c8038
commit
edfd0b791b
66
regex.tal
66
regex.tal
|
@ -115,25 +115,22 @@
|
||||||
( str* should be a null-terminated string. )
|
( str* should be a null-terminated string. )
|
||||||
( )
|
( )
|
||||||
( returns true if the string, and false otherwise. )
|
( returns true if the string, and false otherwise. )
|
||||||
@match ( str* regex* -> bool^ )
|
@rx-match ( str* regex* -> bool^ )
|
||||||
#01 ;match-multiline STA
|
#01 ;match-multiline STA
|
||||||
#00 ;search-mode STA
|
#00 ;search-mode STA
|
||||||
;reset-stack JSR2
|
;reset-stack JSR2
|
||||||
;loop JMP2
|
;loop JMP2
|
||||||
|
|
||||||
|
@rx-search-multiline ( str* regex* -> bool^ )
|
||||||
|
#01 ;match-multiline STA
|
||||||
|
#01 ;search-mode STA
|
||||||
|
,rx-search/main JMP
|
||||||
|
|
||||||
@rx-search ( str* regex* -> bool^ )
|
@rx-search ( str* regex* -> bool^ )
|
||||||
#00 ;match-multiline STA
|
#00 ;match-multiline STA
|
||||||
#01 ;search-mode STA
|
#01 ;search-mode STA
|
||||||
;_search JMP2
|
&main STH2 ( s* [r*] )
|
||||||
|
DUP2 ;string-start STA2 ( s* [r*] )
|
||||||
( @search-multiline ( str* regex* -> bool^ )
|
|
||||||
#01 ;match-multiline STA
|
|
||||||
#01 ;search-mode STA
|
|
||||||
;_search JMP2 )
|
|
||||||
|
|
||||||
@_search ( str* regex* -> bool^ )
|
|
||||||
STH2 ( s* [r*] )
|
|
||||||
DUP2 ;string-start STA2 ( s* [r*] )
|
|
||||||
&loop LDAk #00 EQU ,&eof JCN ( s* [r*] )
|
&loop LDAk #00 EQU ,&eof JCN ( s* [r*] )
|
||||||
;reset-stack JSR2 ( s* [r*] )
|
;reset-stack JSR2 ( s* [r*] )
|
||||||
DUP2 ;search-start STA2 ( s* [r*] )
|
DUP2 ;search-start STA2 ( s* [r*] )
|
||||||
|
@ -340,13 +337,13 @@
|
||||||
@compile-region-loop
|
@compile-region-loop
|
||||||
;read JSR2
|
;read JSR2
|
||||||
DUP #00 EQU ;c-done JCN2
|
DUP #00 EQU ;c-done JCN2
|
||||||
DUP LIT '| EQU ;c-or JCN2
|
DUP LIT '| EQU ;c-or JCN2
|
||||||
DUP LIT '. EQU ;c-dot JCN2
|
DUP LIT '. EQU ;c-dot JCN2
|
||||||
DUP LIT '^ EQU ;c-caret JCN2
|
DUP LIT '^ EQU ;c-caret JCN2
|
||||||
DUP LIT '$ EQU ;c-dollar JCN2
|
DUP LIT '$ EQU ;c-dollar JCN2
|
||||||
DUP LIT '( EQU ;c-lpar JCN2
|
DUP LIT '( EQU ;c-lpar JCN2
|
||||||
DUP LIT ') EQU ;c-rpar JCN2
|
DUP LIT ') EQU ;c-rpar JCN2
|
||||||
DUP LIT '\ EQU ;c-esc JCN2
|
DUP LIT '\ EQU ;c-esc JCN2
|
||||||
DUP LIT '* EQU ;c-star JCN2
|
DUP LIT '* EQU ;c-star JCN2
|
||||||
DUP LIT '+ EQU ;c-plus JCN2
|
DUP LIT '+ EQU ;c-plus JCN2
|
||||||
DUP LIT '? EQU ;c-qmark JCN2
|
DUP LIT '? EQU ;c-qmark JCN2
|
||||||
|
@ -430,7 +427,7 @@
|
||||||
( allocates a caret-node and continues. )
|
( allocates a caret-node and continues. )
|
||||||
@c-caret ( c^ -> r2* )
|
@c-caret ( c^ -> r2* )
|
||||||
POP
|
POP
|
||||||
#06 ;alloc3 JMP2
|
#06 ;alloc3 JSR2
|
||||||
DUP2 ;c-peek-and-finalize JMP2
|
DUP2 ;c-peek-and-finalize JMP2
|
||||||
|
|
||||||
( called when we read "$" )
|
( called when we read "$" )
|
||||||
|
@ -438,7 +435,7 @@
|
||||||
( allocates a dollar-node and continues. )
|
( allocates a dollar-node and continues. )
|
||||||
@c-dollar ( c^ -> r2* )
|
@c-dollar ( c^ -> r2* )
|
||||||
POP
|
POP
|
||||||
#07 ;alloc3 JMP2
|
#07 ;alloc3 JSR2
|
||||||
DUP2 ;c-peek-and-finalize JMP2
|
DUP2 ;c-peek-and-finalize JMP2
|
||||||
|
|
||||||
( called when we read "\" )
|
( called when we read "\" )
|
||||||
|
@ -494,6 +491,10 @@
|
||||||
|
|
||||||
( ALLOCATING REGEX NDOES )
|
( ALLOCATING REGEX NDOES )
|
||||||
|
|
||||||
|
@rx-node-sizes
|
||||||
|
( 00 01 02 03 04 05 06 07 08 09 )
|
||||||
|
[ 00 03 03 04 ] [ 05 05 03 03 ] [ 05 05 ]
|
||||||
|
|
||||||
@alloc3 ( mode^ -> r* )
|
@alloc3 ( mode^ -> r* )
|
||||||
#0000 ROT ( 00 00 mode^ )
|
#0000 ROT ( 00 00 mode^ )
|
||||||
#03 ;alloc JSR2 ( 00 00 mode^ addr* )
|
#03 ;alloc JSR2 ( 00 00 mode^ addr* )
|
||||||
|
@ -588,7 +589,7 @@
|
||||||
;set-next JSR2 SWP2 ( x0 r1 )
|
;set-next JSR2 SWP2 ( x0 r1 )
|
||||||
;push4 JSR2
|
;push4 JSR2
|
||||||
JMP2r
|
JMP2r
|
||||||
&is-zero POP2 POP2 ;push4 JSR2 JMP2r
|
&is-zero POP2 POP2 ;push4 JMP2
|
||||||
|
|
||||||
( load the given address: )
|
( load the given address: )
|
||||||
( )
|
( )
|
||||||
|
@ -596,7 +597,7 @@
|
||||||
( 2. otherwise, call set-next on it )
|
( 2. otherwise, call set-next on it )
|
||||||
@set-next-addr ( target* addr* -> )
|
@set-next-addr ( target* addr* -> )
|
||||||
LDA2k #0000 EQU2 ( target addr addr=0? ) ,&is-zero JCN
|
LDA2k #0000 EQU2 ( target addr addr=0? ) ,&is-zero JCN
|
||||||
LDA2 ;set-next JSR2 JMP2r
|
LDA2 ;set-next JMP2
|
||||||
&is-zero STA2 JMP2r
|
&is-zero STA2 JMP2r
|
||||||
|
|
||||||
( set regex.next to target )
|
( set regex.next to target )
|
||||||
|
@ -610,17 +611,16 @@
|
||||||
( back up we only bother taking the left branch. otherwise )
|
( back up we only bother taking the left branch. otherwise )
|
||||||
( you can end up double-appending things. )
|
( you can end up double-appending things. )
|
||||||
@set-next ( target* regex* -> )
|
@set-next ( target* regex* -> )
|
||||||
LDAk #01 LTH ,&unknown JCN
|
LDAk #01 LTH ,&unknown JCN
|
||||||
LDAk #07 GTH ,&unknown JCN
|
LDAk #09 GTH ,&unknown JCN
|
||||||
LDAk #05 NEQ ,&!5 JCN #0003 ADD2 ,&continue JMP
|
LDAk #00 SWP ;rx-node-sizes ADD2
|
||||||
&!5 LDAk #03 NEQ ,&!3 JCN #0002 ADD2 ,&continue JMP
|
LDA #00 SWP ADD2 #0002 SUB2
|
||||||
&!3 INC2
|
;set-next-addr JMP2
|
||||||
&continue ;set-next-addr JSR2 JMP2r
|
|
||||||
&unknown LDAk ;unknown-node-type ;error!! JSR2
|
&unknown LDAk ;unknown-node-type ;error!! JSR2
|
||||||
|
|
||||||
@set-next-or-addr ( target* addr* -> )
|
@set-next-or-addr ( target* addr* -> )
|
||||||
LDA2k #0000 EQU2 ( target addr addr=0? ) ,&is-zero JCN
|
LDA2k #0000 EQU2 ( target addr addr=0? ) ,&is-zero JCN
|
||||||
LDA2 ;set-next-or JSR2 JMP2r
|
LDA2 ;set-next-or JMP2
|
||||||
&is-zero STA2 JMP2r
|
&is-zero STA2 JMP2r
|
||||||
|
|
||||||
( this is used when first building or-nodes )
|
( this is used when first building or-nodes )
|
||||||
|
@ -630,7 +630,7 @@
|
||||||
@set-next-or ( target* regex* -> )
|
@set-next-or ( target* regex* -> )
|
||||||
LDAk #04 NEQ ,&!4 JCN
|
LDAk #04 NEQ ,&!4 JCN
|
||||||
OVR2 OVR2 INC2 ;set-next-addr JSR2
|
OVR2 OVR2 INC2 ;set-next-addr JSR2
|
||||||
#0003 ADD2 ;set-next-or-addr JSR2 JMP2r
|
#0003 ADD2 ;set-next-or-addr JMP2
|
||||||
&!4 ;set-next JMP2
|
&!4 ;set-next JMP2
|
||||||
|
|
||||||
( STACK OPERATIONS )
|
( STACK OPERATIONS )
|
||||||
|
@ -663,16 +663,6 @@
|
||||||
STH2r STH2r ( restore str and regex )
|
STH2r STH2r ( restore str and regex )
|
||||||
JMP2r
|
JMP2r
|
||||||
|
|
||||||
(
|
|
||||||
( -> size^ )
|
|
||||||
@frame-size
|
|
||||||
#00 STH ;stack-pos LDA2
|
|
||||||
&loop
|
|
||||||
#0004 SUB2 LDA2k #ffff EQU2 ,&done JCN
|
|
||||||
INCr ,&loop JMP
|
|
||||||
&done
|
|
||||||
STHr JMP2r )
|
|
||||||
|
|
||||||
( reset stack pointers )
|
( reset stack pointers )
|
||||||
@reset-stack ( -> )
|
@reset-stack ( -> )
|
||||||
;stack-bot ;stack-pos STA2 JMP2r ( pos <- 0 )
|
;stack-bot ;stack-pos STA2 JMP2r ( pos <- 0 )
|
||||||
|
|
|
@ -52,7 +52,8 @@
|
||||||
#00 ;ptr LDA2 STA ( null terminate string )
|
#00 ;ptr LDA2 STA ( null terminate string )
|
||||||
;ptr LDA2 ;buffer EQU2 STH ( stash is-empty? )
|
;ptr LDA2 ;buffer EQU2 STH ( stash is-empty? )
|
||||||
;buffer ;ptr STA2 ( reset ptr )
|
;buffer ;ptr STA2 ( reset ptr )
|
||||||
;buffer ;regex LDA2 ;match JSR2 ( match regex )
|
( ;buffer ;regex LDA2 ;rx-match JSR2 ( match regex ) )
|
||||||
|
;buffer ;regex LDA2 ;rx-search JSR2 ( search regex )
|
||||||
;emit-byte JSR2 nl ( print result )
|
;emit-byte JSR2 nl ( print result )
|
||||||
STHr ,&was-empty JCN
|
STHr ,&was-empty JCN
|
||||||
;s-prompt ;println JSR2
|
;s-prompt ;println JSR2
|
||||||
|
@ -96,13 +97,13 @@
|
||||||
@emit-arena ( -> )
|
@emit-arena ( -> )
|
||||||
;arena-bot
|
;arena-bot
|
||||||
&loop
|
&loop
|
||||||
DUP2 ;arena-pos LDA2 LTH2 ,&ok JCN POP2 JMP2r
|
DUP2 ;arena-pos LDA2 LTH2 ,&ok JCN POP2 JMP2r
|
||||||
&ok
|
&ok
|
||||||
DUP2 ;emit-short JSR2
|
DUP2 ;emit-short JSR2
|
||||||
LIT ': emit! space
|
LIT ': emit! space
|
||||||
LDAk #01 NEQ ,&!1 JCN #03 ;emit-n JSR2 ,&loop JMP
|
LDAk #01 LTH ,&uu JCN
|
||||||
&!1 LDAk #02 NEQ ,&!2 JCN #03 ;emit-n JSR2 ,&loop JMP
|
LDAk #09 GTH ,&uu JCN
|
||||||
&!2 LDAk #03 NEQ ,&!3 JCN #04 ;emit-n JSR2 ,&loop JMP
|
LDAk #00 SWP ;rx-node-sizes ADD2
|
||||||
&!3 LDAk #04 NEQ ,&!4 JCN #05 ;emit-n JSR2 ,&loop JMP
|
LDA ;emit-n JSR2 ,&loop JMP
|
||||||
&!4 LDAk #05 NEQ ,&!5 JCN #05 ;emit-n JSR2 ,&loop JMP
|
&uu
|
||||||
&!5 ;unknown-node-type ;error!! JSR2
|
;unknown-node-type ;error!! JSR2
|
||||||
|
|
Loading…
Reference in New Issue