factor/core/effects/parser/parser.factor

34 lines
990 B
Factor
Raw Normal View History

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
combinators arrays ;
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 [
scan {
{ "(" [ ")" parse-effect ] }
{ f [ ")" unexpected-eof ] }
2008-07-18 20:22:59 -04:00
} case 2array
] when
2008-06-25 04:25:08 -04:00
] if
] if ;
2008-07-18 20:22:59 -04:00
: parse-effect-tokens ( end -- tokens )
[ parse-effect-token dup ] curry [ ] produce nip ;
2008-07-18 20:22:59 -04:00
: parse-effect ( end -- effect )
parse-effect-tokens { "--" } split1 dup
[ <effect> ] [ "Stack effect declaration must contain --" throw ] 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 )
[ ")" parse-effect ] dip 2array over push-all ;