2010-02-23 05:57:13 -05:00
|
|
|
! Copyright (C) 2008, 2010 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
|
2010-03-05 16:30:10 -05:00
|
|
|
combinators arrays make vocabs.parser classes parser ;
|
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 ;
|
2010-03-05 16:30:10 -05:00
|
|
|
ERROR: invalid-effect-variable ;
|
|
|
|
ERROR: effect-variable-can't-have-type ;
|
|
|
|
ERROR: stack-effect-omits-dashes ;
|
|
|
|
|
|
|
|
SYMBOL: effect-var
|
|
|
|
|
|
|
|
: parse-var ( first? var name -- var )
|
|
|
|
nip
|
|
|
|
[ ":" ?tail [ effect-variable-can't-have-type ] when ] curry
|
|
|
|
[ invalid-effect-variable ] if ;
|
|
|
|
|
|
|
|
: parse-effect-token ( first? var end -- var more? )
|
|
|
|
scan [ nip ] [ = ] 2bi [ drop nip f ] [
|
|
|
|
dup { f "(" "((" "--" } member? [ bad-effect ] [
|
|
|
|
dup { ")" "))" } member? [ stack-effect-omits-dashes ] [
|
|
|
|
".." ?head [ parse-var t ] [
|
|
|
|
[ drop ] 2dip
|
|
|
|
":" ?tail [
|
|
|
|
scan {
|
|
|
|
{ [ dup "(" = ] [ drop ")" parse-effect ] }
|
|
|
|
{ [ dup f = ] [ ")" unexpected-eof ] }
|
|
|
|
[ parse-word dup class? [ bad-effect ] unless ]
|
|
|
|
} cond 2array
|
|
|
|
] when , t
|
|
|
|
] if
|
|
|
|
] if
|
2008-06-25 04:25:08 -04:00
|
|
|
] if
|
|
|
|
] if ;
|
2008-07-18 20:22:59 -04:00
|
|
|
|
2010-03-05 16:30:10 -05:00
|
|
|
: parse-effect-tokens ( end -- var tokens )
|
|
|
|
[
|
|
|
|
[ t f ] dip [ parse-effect-token [ f ] 2dip ] curry [ ] while nip
|
|
|
|
] { } make ;
|
2009-08-12 00:09:02 -04:00
|
|
|
|
2008-07-18 20:22:59 -04:00
|
|
|
: parse-effect ( end -- effect )
|
2010-03-05 16:30:10 -05:00
|
|
|
[ "--" parse-effect-tokens ] dip parse-effect-tokens
|
|
|
|
<variable-effect> ;
|
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 )
|
2009-10-28 16:29:01 -04:00
|
|
|
[ ")" parse-effect ] dip 2array append! ;
|
2010-02-23 05:57:13 -05:00
|
|
|
|
|
|
|
: (:) ( -- word def effect )
|
|
|
|
CREATE-WORD
|
|
|
|
complete-effect
|
|
|
|
parse-definition swap ;
|