]> gitweb.factorcode.org Git - factor.git/blob - core/effects/parser/parser.factor
over push -> suffix!, over push-all -> append!
[factor.git] / core / effects / parser / parser.factor
1 ! Copyright (C) 2008, 2009 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 ;
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 search class? ] [ search ] }
18                     { [ dup f = ] [ ")" unexpected-eof ] }
19                     [ bad-effect ]
20                 } cond 2array
21             ] when
22         ] if
23     ] if ;
24
25 : parse-effect-tokens ( end -- tokens )
26     [ parse-effect-token dup ] curry [ ] produce nip ;
27
28 ERROR: stack-effect-omits-dashes effect ;
29
30 : parse-effect ( end -- effect )
31     parse-effect-tokens { "--" } split1 dup
32     [ <effect> ] [ drop stack-effect-omits-dashes ] if ;
33
34 : complete-effect ( -- effect )
35     "(" expect ")" parse-effect ;
36
37 : parse-call( ( accum word -- accum )
38     [ ")" parse-effect ] dip 2array append! ;