]> gitweb.factorcode.org Git - factor.git/blob - core/effects/parser/parser.factor
Create basis vocab root
[factor.git] / core / effects / parser / parser.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: lexer sets sequences kernel splitting effects
4 combinators arrays 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 tuck = [ drop f ] [
13         dup { f "(" "((" } member? [ bad-effect ] [
14             ":" ?tail [
15                 scan-word {
16                     { \ ( [ ")" parse-effect ] }
17                     [ ]
18                 } case 2array
19             ] when
20         ] if
21     ] if ;
22
23 : parse-effect-tokens ( end -- tokens )
24     [ parse-effect-token dup ] curry [ ] [ drop ] produce ;
25
26 : parse-effect ( end -- effect )
27     parse-effect-tokens { "--" } split1 dup
28     [ <effect> ] [ "Stack effect declaration must contain --" throw ] if ;