Mercurial > repo
view src/ploki/examples/ret.pk @ 8916:0234daffd946
<oerjan> addquote <int-e> I couldn\'t help thinking that maybe if one considers the ramifications in full detail it will turn out that overthinking is often not helpful and therefore, not something to be proud of.
author | HackBot |
---|---|
date | Sun, 14 Aug 2016 02:31:47 +0000 |
parents | ac0403686959 |
children |
line wrap: on
line source
#!../ploki REM regular expression tester NEXT main: FOR trymatch LEET txt \@ . 0 LEET pat \@ . 1 LEET ms txt ~ pat IF ms LET me \_ "matched at pos \Vms [\V(txt ] ms)\033[1m\V(txt [ ms ] (me - ms))\033[m\V(txt [ me ] 255)] IF @DEF-P \0 WUNT "\\0<\V@-0, \V@+0>: \V\0 FI IF @DEF-P \1 WUNT "\\1<\V@-1, \V@+1>: \V\1 FI IF @DEF-P \2 WUNT "\\2<\V@-2, \V@+2>: \V\2 FI ELSE WUNT "no match FI KTHX FOR main: IF \ARG < 2 WUNT "Usage: \V\ARG:0 PATTERN [FILE] END @NEG1 FI LET pat \ARG:1 IF \ARG > 2 LET fh @LAPERS \ARG:2 IF @NOT fh WUNT \AUSG \ARG:0_": "_\ARG:2_": "_\!_" END @NEG1 FI FOR buf LET s fh . 4096 IF s ; "" #! "appending [\V@TYPE OFs:\V@LENGTHs]\Vs to \Vtxt LET txt _= s NEXT buf FI #! "matching /\Vpat/ against \Vtxt trymatch #<txt pat#> ELSE "pattern: /\Vpat/ FOR line LET line @LEGS \EING IF line ; "" IF line [ -1 : " LET line line ] -1 FI trymatch #<line pat#> NEXT line FI FI