Merge branch 'master' of git://factorcode.org/git/factor
commit
a5c4463e34
|
@ -2,7 +2,7 @@ USING: locals math sequences tools.test hashtables words kernel
|
||||||
namespaces arrays strings prettyprint io.streams.string parser
|
namespaces arrays strings prettyprint io.streams.string parser
|
||||||
accessors generic eval combinators combinators.short-circuit
|
accessors generic eval combinators combinators.short-circuit
|
||||||
combinators.short-circuit.smart math.order math.functions
|
combinators.short-circuit.smart math.order math.functions
|
||||||
definitions compiler.units fry ;
|
definitions compiler.units fry lexer ;
|
||||||
IN: locals.tests
|
IN: locals.tests
|
||||||
|
|
||||||
:: foo ( a b -- a a ) a a ;
|
:: foo ( a b -- a a ) a a ;
|
||||||
|
@ -412,6 +412,12 @@ M:: integer lambda-method-forget-test ( a -- b ) ;
|
||||||
[ t ] [ 3 funny-macro-test ] unit-test
|
[ t ] [ 3 funny-macro-test ] unit-test
|
||||||
[ f ] [ 2 funny-macro-test ] unit-test
|
[ f ] [ 2 funny-macro-test ] unit-test
|
||||||
|
|
||||||
|
! Some odd parser corner cases
|
||||||
|
[ "USE: locals [let" eval ] [ error>> unexpected-eof? ] must-fail-with
|
||||||
|
[ "USE: locals [let |" eval ] [ error>> unexpected-eof? ] must-fail-with
|
||||||
|
[ "USE: locals [let | a" eval ] [ error>> unexpected-eof? ] must-fail-with
|
||||||
|
[ "USE: locals [|" eval ] [ error>> unexpected-eof? ] must-fail-with
|
||||||
|
|
||||||
! :: wlet-&&-test ( a -- ? )
|
! :: wlet-&&-test ( a -- ? )
|
||||||
! [wlet | is-integer? [ a integer? ]
|
! [wlet | is-integer? [ a integer? ]
|
||||||
! is-even? [ a even? ]
|
! is-even? [ a even? ]
|
||||||
|
|
|
@ -290,21 +290,15 @@ SYMBOL: in-lambda?
|
||||||
|
|
||||||
: parse-binding ( -- pair/f )
|
: parse-binding ( -- pair/f )
|
||||||
scan {
|
scan {
|
||||||
|
{ [ dup not ] [ unexpected-eof ] }
|
||||||
{ [ dup "|" = ] [ drop f ] }
|
{ [ dup "|" = ] [ drop f ] }
|
||||||
{ [ dup "!" = ] [ drop lexer get next-line parse-binding ] }
|
{ [ dup "!" = ] [ drop POSTPONE: ! parse-binding ] }
|
||||||
{ [ t ]
|
[ scan-object 2array ]
|
||||||
[
|
|
||||||
scan {
|
|
||||||
{ "[" [ \ ] parse-until >quotation ] }
|
|
||||||
{ "[|" [ parse-lambda ] }
|
|
||||||
} case 2array
|
|
||||||
]
|
|
||||||
}
|
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
: (parse-bindings) ( -- )
|
: (parse-bindings) ( -- )
|
||||||
parse-binding [
|
parse-binding [
|
||||||
first2 >r make-local r> 2array ,
|
first2 [ make-local ] dip 2array ,
|
||||||
(parse-bindings)
|
(parse-bindings)
|
||||||
] when* ;
|
] when* ;
|
||||||
|
|
||||||
|
@ -357,7 +351,7 @@ M: wlet local-rewrite*
|
||||||
in>> [ dup pair? [ first ] when ] map make-locals dup push-locals ;
|
in>> [ dup pair? [ first ] when ] map make-locals dup push-locals ;
|
||||||
|
|
||||||
: parse-locals-definition ( word -- word quot )
|
: parse-locals-definition ( word -- word quot )
|
||||||
scan "(" assert= parse-locals \ ; (parse-lambda) <lambda>
|
"(" expect parse-locals \ ; (parse-lambda) <lambda>
|
||||||
2dup "lambda" set-word-prop
|
2dup "lambda" set-word-prop
|
||||||
lambda-rewrite first ;
|
lambda-rewrite first ;
|
||||||
|
|
||||||
|
@ -375,15 +369,15 @@ PRIVATE>
|
||||||
: [| parse-lambda parsed-lambda ; parsing
|
: [| parse-lambda parsed-lambda ; parsing
|
||||||
|
|
||||||
: [let
|
: [let
|
||||||
scan "|" assert= parse-bindings
|
"|" expect parse-bindings
|
||||||
\ ] (parse-lambda) <let> parsed-lambda ; parsing
|
\ ] (parse-lambda) <let> parsed-lambda ; parsing
|
||||||
|
|
||||||
: [let*
|
: [let*
|
||||||
scan "|" assert= parse-bindings*
|
"|" expect parse-bindings*
|
||||||
\ ] (parse-lambda) <let*> parsed-lambda ; parsing
|
\ ] (parse-lambda) <let*> parsed-lambda ; parsing
|
||||||
|
|
||||||
: [wlet
|
: [wlet
|
||||||
scan "|" assert= parse-wbindings
|
"|" expect parse-wbindings
|
||||||
\ ] (parse-lambda) <wlet> parsed-lambda ; parsing
|
\ ] (parse-lambda) <wlet> parsed-lambda ; parsing
|
||||||
|
|
||||||
: :: (::) define ; parsing
|
: :: (::) define ; parsing
|
||||||
|
|
|
@ -17,15 +17,13 @@ IN: qualified
|
||||||
#! Syntax: QUALIFIED-WITH: vocab prefix
|
#! Syntax: QUALIFIED-WITH: vocab prefix
|
||||||
scan scan define-qualified ; parsing
|
scan scan define-qualified ; parsing
|
||||||
|
|
||||||
: expect=> ( -- ) scan "=>" assert= ;
|
|
||||||
|
|
||||||
: partial-vocab ( words vocab -- assoc )
|
: partial-vocab ( words vocab -- assoc )
|
||||||
'[ dup _ lookup [ no-word-error ] unless* ]
|
'[ dup _ lookup [ no-word-error ] unless* ]
|
||||||
{ } map>assoc ;
|
{ } map>assoc ;
|
||||||
|
|
||||||
: FROM:
|
: FROM:
|
||||||
#! Syntax: FROM: vocab => words... ;
|
#! Syntax: FROM: vocab => words... ;
|
||||||
scan dup load-vocab drop expect=>
|
scan dup load-vocab drop "=>" expect
|
||||||
";" parse-tokens swap partial-vocab use get push ; parsing
|
";" parse-tokens swap partial-vocab use get push ; parsing
|
||||||
|
|
||||||
: partial-vocab-excluding ( words vocab -- assoc )
|
: partial-vocab-excluding ( words vocab -- assoc )
|
||||||
|
@ -33,13 +31,13 @@ IN: qualified
|
||||||
|
|
||||||
: EXCLUDE:
|
: EXCLUDE:
|
||||||
#! Syntax: EXCLUDE: vocab => words ... ;
|
#! Syntax: EXCLUDE: vocab => words ... ;
|
||||||
scan expect=>
|
scan "=>" expect
|
||||||
";" parse-tokens swap partial-vocab-excluding use get push ; parsing
|
";" parse-tokens swap partial-vocab-excluding use get push ; parsing
|
||||||
|
|
||||||
: RENAME:
|
: RENAME:
|
||||||
#! Syntax: RENAME: word vocab => newname
|
#! Syntax: RENAME: word vocab => newname
|
||||||
scan scan dup load-vocab drop
|
scan scan dup load-vocab drop
|
||||||
dupd lookup [ ] [ no-word-error ] ?if
|
dupd lookup [ ] [ no-word-error ] ?if
|
||||||
expect=>
|
"=>" expect
|
||||||
scan associate use get push ; parsing
|
scan associate use get push ; parsing
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,12 @@ PREDICATE: unexpected-eof < unexpected
|
||||||
|
|
||||||
: unexpected-eof ( word -- * ) f unexpected ;
|
: unexpected-eof ( word -- * ) f unexpected ;
|
||||||
|
|
||||||
|
: expect ( token -- )
|
||||||
|
scan
|
||||||
|
[ 2dup = [ 2drop ] [ unexpected ] if ]
|
||||||
|
[ unexpected-eof ]
|
||||||
|
if* ;
|
||||||
|
|
||||||
: (parse-tokens) ( accum end -- accum )
|
: (parse-tokens) ( accum end -- accum )
|
||||||
scan 2dup = [
|
scan 2dup = [
|
||||||
2drop
|
2drop
|
||||||
|
|
Loading…
Reference in New Issue