2009-03-16 21:11:36 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2008-06-25 04:25:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-07-28 23:03:13 -04:00
|
|
|
USING: lexer sets sequences kernel splitting effects
|
2009-09-01 15:39:22 -04:00
|
|
|
combinators arrays vocabs.parser classes ;
|
2008-06-25 04:25:08 -04:00
|
|
|
IN: effects.parser
|
|
|
|
|
2008-07-18 20:22:59 -04:00
|
|
|
DEFER: parse-effect
|
|
|
|
|
|
|
|
ERROR: bad-effect ;
|
|
|
|
|
|
|
|
: parse-effect-token ( end -- token/f )
|
2009-01-23 19:20:47 -05:00
|
|
|
scan [ nip ] [ = ] 2bi [ drop f ] [
|
2008-07-18 20:22:59 -04:00
|
|
|
dup { f "(" "((" } member? [ bad-effect ] [
|
|
|
|
":" ?tail [
|
2009-03-21 04:17:35 -04:00
|
|
|
scan {
|
2009-09-01 15:39:22 -04:00
|
|
|
{ [ dup "(" = ] [ drop ")" parse-effect ] }
|
|
|
|
{ [ dup search class? ] [ search ] }
|
|
|
|
{ [ dup f = ] [ ")" unexpected-eof ] }
|
2009-04-01 00:18:52 -04:00
|
|
|
[ bad-effect ]
|
2009-09-01 15:39:22 -04:00
|
|
|
} cond 2array
|
2008-07-18 20:22:59 -04:00
|
|
|
] when
|
2008-06-25 04:25:08 -04:00
|
|
|
] if
|
|
|
|
] if ;
|
2008-07-18 20:22:59 -04:00
|
|
|
|
|
|
|
: parse-effect-tokens ( end -- tokens )
|
2009-02-28 16:31:34 -05:00
|
|
|
[ parse-effect-token dup ] curry [ ] produce nip ;
|
2008-07-18 20:22:59 -04:00
|
|
|
|
2009-08-12 00:09:02 -04:00
|
|
|
ERROR: stack-effect-omits-dashes effect ;
|
|
|
|
|
2008-07-18 20:22:59 -04:00
|
|
|
: parse-effect ( end -- effect )
|
|
|
|
parse-effect-tokens { "--" } split1 dup
|
2009-08-12 00:09:02 -04:00
|
|
|
[ <effect> ] [ drop stack-effect-omits-dashes ] if ;
|
2009-03-16 21:11:36 -04:00
|
|
|
|
2009-03-22 18:59:40 -04:00
|
|
|
: complete-effect ( -- effect )
|
|
|
|
"(" expect ")" parse-effect ;
|
|
|
|
|
2009-03-16 21:11:36 -04:00
|
|
|
: parse-call( ( accum word -- accum )
|
2009-04-01 00:18:52 -04:00
|
|
|
[ ")" parse-effect ] dip 2array over push-all ;
|