! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays combinators effects kernel lexer make namespaces parser sequences splitting words ; IN: effects.parser DEFER: parse-effect ERROR: bad-effect ; ERROR: invalid-row-variable ; ERROR: row-variable-can't-have-type ; ERROR: stack-effect-omits-dashes ; SYMBOL: effect-var : parse-effect-token ( first? var end -- var more? ) scan-token { { [ end-token? ] [ drop nip f ] } { [ effect-opener? ] [ bad-effect ] } { [ effect-closer? ] [ stack-effect-omits-dashes ] } { [ row-variable? ] [ parse-effect-var t ] } [ [ drop ] 2dip parse-effect-value , t ] } cond ; : parse-effect-tokens ( end -- var tokens ) [ [ t f ] dip [ parse-effect-token [ f ] 2dip ] curry [ ] while nip ] { } make ; : parse-effect ( end -- effect ) [ "--" parse-effect-tokens ] dip parse-effect-tokens ; : scan-effect ( -- effect ) "(" expect ")" parse-effect ; : parse-call( ( accum word -- accum ) [ ")" parse-effect ] dip 2array append! ; SYMBOL: in-definition ERROR: can't-nest-definitions word ; : check-in-definition ( -- ) in-definition get [ word can't-nest-definitions ] when ; : with-definition ( quot -- ) [ check-in-definition t in-definition ] dip with-variable ; inline : (:) ( -- word def effect ) [ scan-new-word scan-effect parse-definition swap ] with-definition ;