From a2be187ba0971fa185a451ccd6bc61aff6bbdbe0 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Wed, 17 Sep 2025 20:19:12 -0400 Subject: [PATCH] ^ to negate class --- grep.tal | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/grep.tal b/grep.tal index 00b070fa14262f1b7a1e48eeabdce3d520636cef..6046869d840f094f09dd7c987f511ceed5fcb98c 100644 --- a/grep.tal +++ b/grep.tal @@ -9,6 +9,7 @@ %kil { #010f DEO BRK } %p2brk { BRK } ( replace this with POP2r BRK when debugging ) + ( --- initialization --- ) |100 @@ -75,6 +76,7 @@ DEI ,unknopt/opt STR !unknopt + ( --- printing --- ) @usage/str "usage: 20 " 20 "| 20 @@ -89,9 +91,9 @@ #02 ;/str ( >> ) @die ( code str* -- ) &loop - LDAk DUP #19 DEO ( get and write char ) - STH INC2 STHr ( increment str* ) - #0a NEQ ?/loop ( loop if char != 0a ) + LDAk STHk #19 DEO ( get and write char ) + INC2 ( increment str* ) + STHr #0a NEQ ?/loop ( loop if char != 0a ) POP2 #0f DEO BRK ( exit with status XX ) @@ -125,9 +127,9 @@ ?{ ( we saw a match, print the line ) ;/line &loop - LDAk DUP #18 DEO ( get and write char ) - STH INC2 STHr ( increment str* ) - #0a NEQ ?/loop ( loop if char != 0a ) + LDAk STHk #18 DEO ( get and write char ) + INC2 ( increment str* ) + STHr #0a NEQ ?/loop ( loop if char != 0a ) POP2 } BRK @@ -140,9 +142,9 @@ SUB2 SWP2 ( start* end* ) #0a ROT ROT STA ( write a newline ) &only-loop - LDAk DUP #18 DEO - STH INC2 STHr - #0a NEQ ?/only-loop + LDAk STHk #18 DEO + INC2 + STHr #0a NEQ ?/only-loop POP2 } BRK @@ -155,18 +157,25 @@ SWP2 STA2 ( write new mask ) JMP2r -@lut/in-wildcard ( -- ) - /get-mask [ LIT2r =lut/end LIT2r =lut ] ( mask* `end* `addr* ) - &wc-loop - DUP2 STH2rk LDA2 AND2 ( calculate new mask ) +@lut/col-negate ( -- ) + /get-mask #ffff EOR2 + [ LIT2r =lut/end LIT2r =lut ] ( mask* `end* `addr* ) + &nc-loop + DUP2 STH2rk LDA2 EOR2 ( calculate new mask ) STH2rk STA2 ( save it ) INC2r INC2r ( inc. addr ) - NEQ2rk STHr ?/wc-loop ( loop ) + NEQ2rk STHr ?/nc-loop ( loop ) POP2r POP2r POP2 JMP2r @lut/in-class1 ( -- ) + ;/in-class2 ,/parser-jmp STR2 ( only do this once ) + LIT2 "^ 12 DEI NEQ ?{ ( negation op ) + [ LIT2 00 _/negate-class ] STR ( enable negation ) + p2brk } + ( >> ) +@lut/in-class2 ( -- ) ;/in-class ,/parser-jmp STR2 ( only do this once ) LIT2 "- 12 DEI NEQ ?{ ( leading dash ) /in-fixed @@ -175,6 +184,10 @@ @lut/in-class ( -- ) #12 DEIk LIT "] NEQ ?{ POP ( end of class ) + [ LIT &negate-class 01 ] ?{ + [ LIT2 01 _/negate-class ] STR + /col-negate + } ;/in-pattern ,/parser-jmp STR2 JMP2r } DEIk LIT "- NEQ ?{ POP ( range section ) @@ -223,7 +236,7 @@ ;/in-class1 ,/parser-jmp STR2 p2brk } ( don't shift mask ) - DEIk LIT "? NEQ ?{ POP !/in-wildcard } ( will allow anything ) + DEIk LIT "? NEQ ?{ POP !/col-negate } ( will allow anything ) POP !/in-fixed ( non-special ) @lut/in-bs ( -- )