1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: lexer sets sequences kernel splitting effects
4 combinators arrays vocabs.parser classes parser ;
11 : parse-effect-token ( end -- token/f )
12 scan [ nip ] [ = ] 2bi [ drop f ] [
13 dup { f "(" "((" } member? [ bad-effect ] [
16 { [ dup "(" = ] [ drop ")" parse-effect ] }
17 { [ dup f = ] [ ")" unexpected-eof ] }
18 [ parse-word dup class? [ bad-effect ] unless ]
24 : parse-effect-tokens ( end -- tokens )
25 [ parse-effect-token dup ] curry [ ] produce nip ;
27 ERROR: stack-effect-omits-dashes tokens ;
29 : parse-effect ( end -- effect )
30 parse-effect-tokens { "--" } split1 dup
31 [ <effect> ] [ drop stack-effect-omits-dashes ] if ;
33 : complete-effect ( -- effect )
34 "(" expect ")" parse-effect ;
36 : parse-call( ( accum word -- accum )
37 [ ")" parse-effect ] dip 2array append! ;
39 : (:) ( -- word def effect )
42 parse-definition swap ;