]> gitweb.factorcode.org Git - factor.git/blob - core/effects/parser/parser.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / core / effects / parser / parser.factor
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 ;
5 IN: effects.parser
6
7 DEFER: parse-effect
8
9 ERROR: bad-effect ;
10
11 : parse-effect-token ( end -- token/f )
12     scan [ nip ] [ = ] 2bi [ drop f ] [
13         dup { f "(" "((" } member? [ bad-effect ] [
14             ":" ?tail [
15                 scan {
16                     { [ dup "(" = ] [ drop ")" parse-effect ] }
17                     { [ dup f = ] [ ")" unexpected-eof ] }
18                     [ parse-word dup class? [ bad-effect ] unless ]
19                 } cond 2array
20             ] when
21         ] if
22     ] if ;
23
24 : parse-effect-tokens ( end -- tokens )
25     [ parse-effect-token dup ] curry [ ] produce nip ;
26
27 ERROR: stack-effect-omits-dashes tokens ;
28
29 : parse-effect ( end -- effect )
30     parse-effect-tokens { "--" } split1 dup
31     [ <effect> ] [ drop stack-effect-omits-dashes ] if ;
32
33 : complete-effect ( -- effect )
34     "(" expect ")" parse-effect ;
35
36 : parse-call( ( accum word -- accum )
37     [ ")" parse-effect ] dip 2array append! ;
38
39 : (:) ( -- word def effect )
40     CREATE-WORD
41     complete-effect
42     parse-definition swap ;