M: protocol group-words protocol-words ;
SYNTAX: SLOT-PROTOCOL:
- CREATE-WORD ";" parse-tokens
- [ [ reader-word ] [ writer-word ] bi 2array ] map concat
- define-protocol ;
\ No newline at end of file
+ CREATE-WORD ";"
+ [ [ reader-word ] [ writer-word ] bi 2array ]
+ map-tokens concat define-protocol ;
: make-locals ( seq -- words assoc )
[ [ make-local ] map ] H{ } make-assoc ;
+: parse-local-defs ( -- words assoc )
+ [ "|" [ make-local ] map-tokens ] H{ } make-assoc ;
+
: make-local-word ( name def -- word )
[ <local-word> [ dup name>> set ] [ ] [ ] tri ] dip
"local-word-def" set-word-prop ;
[ \ ] parse-until >quotation ] ((parse-lambda)) ;
: parse-lambda ( -- lambda )
- "|" parse-tokens make-locals
+ parse-local-defs
(parse-lambda) <lambda>
?rewrite-closures ;
: parse-multi-def ( locals -- multi-def )
- ")" parse-tokens swap [ [ make-local ] map ] bind <multi-def> ;
+ [ ")" [ make-local ] map-tokens ] bind <multi-def> ;
: parse-def ( name/paren locals -- def )
over "(" = [ nip parse-multi-def ] [ [ make-local ] bind <def> ] if ;
[ define-match-var ] each ;
SYNTAX: MATCH-VARS: ! vars ...
- ";" parse-tokens define-match-vars ;
+ ";" [ define-match-var ] each-token ;
: match-var? ( symbol -- bool )
dup word? [ "match-var" word-prop ] [ drop f ] if ;
M: pointer c-direct-array-constructor drop void* c-direct-array-constructor ;
SYNTAX: SPECIALIZED-ARRAYS:
- ";" parse-tokens [ parse-c-type define-array-vocab use-vocab ] each ;
+ ";" [ parse-c-type define-array-vocab use-vocab ] each-token ;
SYNTAX: SPECIALIZED-ARRAY:
scan-c-type define-array-vocab use-vocab ;
generate-vocab ;
SYNTAX: SPECIALIZED-VECTORS:
- ";" parse-tokens [
+ ";" [
parse-c-type
[ define-array-vocab use-vocab ]
[ define-vector-vocab use-vocab ] bi
- ] each ;
+ ] each-token ;
SYNTAX: SPECIALIZED-VECTOR:
scan-c-type
[ unexpected-eof ]
if* ;
-: (parse-tokens) ( accum end -- accum )
- scan 2dup = [
- 2drop
- ] [
- [ pick push (parse-tokens) ] [ unexpected-eof ] if*
- ] if ;
+: (each-token) ( end quot -- pred quot )
+ [ [ [ scan dup ] ] dip [ = not ] curry [ [ f ] if* ] curry compose ] dip ; inline
+
+: each-token ( end quot -- )
+ (each-token) while drop ; inline
+
+: map-tokens ( end quot -- seq )
+ (each-token) produce nip ; inline
: parse-tokens ( end -- seq )
- 100 <vector> swap (parse-tokens) >array ;
+ [ ] map-tokens ;
TUPLE: lexer-error line column line-text error ;
"UNUSE:" [ scan unuse-vocab ] define-core-syntax
- "USING:" [ ";" parse-tokens [ use-vocab ] each ] define-core-syntax
+ "USING:" [ ";" [ use-vocab ] each-token ] define-core-syntax
"QUALIFIED:" [ scan dup add-qualified ] define-core-syntax
] define-core-syntax
"SYMBOLS:" [
- ";" parse-tokens
- [ create-in dup reset-generic define-symbol ] each
+ ";" [ create-in dup reset-generic define-symbol ] each-token
] define-core-syntax
"SINGLETONS:" [
- ";" parse-tokens
- [ create-class-in define-singleton-class ] each
+ ";" [ create-class-in define-singleton-class ] each-token
] define-core-syntax
"DEFER:" [
string>value value>hand-name ;
SYNTAX: HAND{
- "}" parse-tokens [ card> ] { } map-as suffix! ;
+ "}" [ card> ] map-tokens suffix! ;
IN: slots.syntax
SYNTAX: slots{
- "}" parse-tokens
- [ reader-word 1quotation ] map
- '[ [ _ cleave ] output>array ] append! ;
\ No newline at end of file
+ "}" [ reader-word 1quotation ] map-tokens
+ '[ [ _ cleave ] output>array ] append! ;
[ define-var ] each ;
SYNTAX: VARS: ! vars ...
- ";" parse-tokens define-vars ;
+ ";" [ define-var ] each-token ;