From b642f4e31e4cb24ab66611d7f741c7ff7334def3 Mon Sep 17 00:00:00 2001 From: olus2000 Date: Sat, 13 Jan 2024 10:38:39 +0100 Subject: [PATCH] sequences.parser: rename and redefine `next` Change the word `next` to advance the parser and *then* return the element. Rename the old behavior of `next` to `consume`. --- basis/compression/run-length/run-length.factor | 16 ++++++++-------- extra/html/parser/parser.factor | 2 +- extra/lint/vocabs/vocabs.factor | 4 ++-- {basis => extra}/sequences/parser/authors.txt | 0 .../sequences/parser/parser-tests.factor | 0 {basis => extra}/sequences/parser/parser.factor | 5 ++++- 6 files changed, 15 insertions(+), 12 deletions(-) rename {basis => extra}/sequences/parser/authors.txt (100%) rename {basis => extra}/sequences/parser/parser-tests.factor (100%) rename {basis => extra}/sequences/parser/parser.factor (98%) diff --git a/basis/compression/run-length/run-length.factor b/basis/compression/run-length/run-length.factor index 22650af9b0..1e1a6609a9 100644 --- a/basis/compression/run-length/run-length.factor +++ b/basis/compression/run-length/run-length.factor @@ -19,8 +19,8 @@ IN: compression.run-length f :> done?! [ ! i j [ number>string ] bi@ " " glue . - sp next dup 0 = [ - sp next dup 0x03 0xff between? [ + sp consume dup 0 = [ + sp consume dup 0x03 0xff between? [ nip [ sp ] dip dup odd? [ 1 + take-n but-last ] [ take-n ] if [ j matrix i swap nth copy ] [ length j + j! ] bi @@ -28,11 +28,11 @@ IN: compression.run-length nip { { 0 [ i 1 + i! 0 j! ] } { 1 [ t done?! ] } - { 2 [ sp next j + j! sp next i + i! ] } + { 2 [ sp consume j + j! sp consume i + i! ] } } case ] if ] [ - [ sp next 8hi-lo 2array concat ] [ head ] bi + [ sp consume 8hi-lo 2array concat ] [ head ] bi [ j matrix i swap nth copy ] [ length j + j! ] bi ] if @@ -51,8 +51,8 @@ IN: compression.run-length f :> done?! [ ! i j [ number>string ] bi@ " " glue . - sp next dup 0 = [ - sp next dup 0x03 0xff between? [ + sp consume dup 0 = [ + sp consume dup 0x03 0xff between? [ nip [ sp ] dip dup odd? [ 1 + take-n but-last ] [ take-n ] if [ j matrix i swap nth copy ] [ length j + j! ] bi @@ -60,11 +60,11 @@ IN: compression.run-length nip { { 0 [ i 1 + i! 0 j! ] } { 1 [ t done?! ] } - { 2 [ sp next j + j! sp next i + i! ] } + { 2 [ sp consume j + j! sp consume i + i! ] } } case ] if ] [ - sp next [ j matrix i swap nth copy ] [ length j + j! ] bi + sp consume [ j matrix i swap nth copy ] [ length j + j! ] bi ] if ! j stride >= [ i 1 + i! 0 j! ] when diff --git a/extra/html/parser/parser.factor b/extra/html/parser/parser.factor index b9c09e41ac..ac47cc929b 100644 --- a/extra/html/parser/parser.factor +++ b/extra/html/parser/parser.factor @@ -46,7 +46,7 @@ SYMBOL: tagstack CHAR: \" (read-quote) ; : read-quote ( sequence-parser -- string ) - dup next CHAR: ' = + dup consume CHAR: ' = [ read-single-quote ] [ read-double-quote ] if ; : read-key ( sequence-parser -- string ) diff --git a/extra/lint/vocabs/vocabs.factor b/extra/lint/vocabs/vocabs.factor index ab1d4dffb7..1bc7ca9537 100644 --- a/extra/lint/vocabs/vocabs.factor +++ b/extra/lint/vocabs/vocabs.factor @@ -167,14 +167,14 @@ DEFER: next-token ! Words for finding the words used in a program ! and stripping out import statements : skip-imports ( sequence-parser -- sequence-parser string/? ) - dup next { + dup consume { { "USING:" [ ";" skip-after* f ] } { "USE:" [ advance f ] } [ ] } case ; : take-imports ( sequence-parser -- vector ) - dup next { + dup consume { { "USING:" [ ";" take-until-object ] } { "USE:" [ 1 take-n ] } [ 2drop f ] diff --git a/basis/sequences/parser/authors.txt b/extra/sequences/parser/authors.txt similarity index 100% rename from basis/sequences/parser/authors.txt rename to extra/sequences/parser/authors.txt diff --git a/basis/sequences/parser/parser-tests.factor b/extra/sequences/parser/parser-tests.factor similarity index 100% rename from basis/sequences/parser/parser-tests.factor rename to extra/sequences/parser/parser-tests.factor diff --git a/basis/sequences/parser/parser.factor b/extra/sequences/parser/parser.factor similarity index 98% rename from basis/sequences/parser/parser.factor rename to extra/sequences/parser/parser.factor index cee5fb4898..f2a0ddd45a 100644 --- a/basis/sequences/parser/parser.factor +++ b/extra/sequences/parser/parser.factor @@ -31,9 +31,12 @@ TUPLE: sequence-parser sequence n ; : advance ( sequence-parser -- sequence-parser ) [ 1 + ] change-n ; inline -: next ( sequence-parser -- char/f ) +: consume ( sequence-parser -- char/f ) [ current ] [ advance drop ] bi ; inline +: next ( sequence-parser -- char/f ) + [ advance drop ] [ current ] bi ; inline + :: skip-until ( ... sequence-parser quot: ( ... obj -- ... ? ) -- ... ) sequence-parser current [ sequence-parser quot call -- 2.34.1