factor/core/effects/parser/parser.factor

39 lines
1.1 KiB
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 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 [
scan {
{ [ dup "(" = ] [ drop ")" parse-effect ] }
{ [ dup search class? ] [ search ] }
{ [ dup f = ] [ ")" unexpected-eof ] }
[ bad-effect ]
} 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 )
[ parse-effect-token dup ] curry [ ] produce nip ;
2008-07-18 20:22:59 -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
[ <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 )
[ ")" parse-effect ] dip 2array over push-all ;