2006-05-24 04:29:25 -04:00
|
|
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
IN: parser
|
|
|
|
USING: arrays errors generic hashtables kernel math namespaces
|
|
|
|
sequences strings vectors words ;
|
|
|
|
|
|
|
|
SYMBOL: use
|
|
|
|
SYMBOL: in
|
|
|
|
|
|
|
|
SYMBOL: file
|
|
|
|
SYMBOL: line-number
|
|
|
|
|
|
|
|
SYMBOL: line-text
|
|
|
|
SYMBOL: column
|
|
|
|
|
2006-08-01 17:35:00 -04:00
|
|
|
TUPLE: check-vocab name ;
|
2006-05-24 04:29:25 -04:00
|
|
|
: check-vocab ( name -- vocab )
|
2006-06-05 23:26:44 -04:00
|
|
|
dup vocab [ ] [
|
2006-08-01 17:35:00 -04:00
|
|
|
<check-vocab>
|
|
|
|
{ { "Continue" f } } condition
|
2006-06-05 23:26:44 -04:00
|
|
|
] ?if ;
|
2006-05-24 04:29:25 -04:00
|
|
|
|
2006-08-01 17:35:00 -04:00
|
|
|
: use+ ( string -- ) check-vocab [ use get push ] when* ;
|
2006-05-24 04:29:25 -04:00
|
|
|
|
|
|
|
: add-use ( seq -- ) [ use+ ] each ;
|
|
|
|
|
2006-08-01 17:35:00 -04:00
|
|
|
: set-use ( seq -- )
|
|
|
|
[ check-vocab ] map [ ] subset >vector use set ;
|
2006-05-24 04:29:25 -04:00
|
|
|
|
|
|
|
: set-in ( name -- ) dup ensure-vocab dup in set use+ ;
|
|
|
|
|
|
|
|
: parsing? ( word -- ? )
|
|
|
|
dup word? [ "parsing" word-prop ] [ drop f ] if ;
|
|
|
|
|
2006-08-02 03:49:13 -04:00
|
|
|
: location ( -- loc ) file get line-number get 2array ;
|
|
|
|
|
2006-05-24 04:29:25 -04:00
|
|
|
: save-location ( word -- )
|
2006-08-02 03:49:13 -04:00
|
|
|
dup set-word location "loc" set-word-prop ;
|
2006-05-24 04:29:25 -04:00
|
|
|
|
|
|
|
: create-in in get create dup save-location ;
|
|
|
|
|
|
|
|
: create-constructor ( class -- word )
|
|
|
|
word-name in get constructor-word dup save-location ;
|
|
|
|
|
|
|
|
TUPLE: parse-error file line col text ;
|
|
|
|
|
|
|
|
C: parse-error ( error -- error )
|
|
|
|
file get over set-parse-error-file
|
|
|
|
line-number get over set-parse-error-line
|
|
|
|
column get over set-parse-error-col
|
|
|
|
line-text get over set-parse-error-text
|
|
|
|
[ set-delegate ] keep ;
|
2006-08-15 03:01:24 -04:00
|
|
|
|
|
|
|
TUPLE: effect in out declarations terminated? ;
|
|
|
|
|
|
|
|
C: effect
|
|
|
|
[
|
|
|
|
over { "*" } sequence=
|
|
|
|
[ nip t swap set-effect-terminated? ]
|
|
|
|
[ set-effect-out ] if
|
|
|
|
] keep
|
|
|
|
[ set-effect-in ] keep
|
|
|
|
H{ } clone over set-effect-declarations ;
|
|
|
|
|
|
|
|
: effect-height ( effect -- n )
|
|
|
|
dup effect-out length swap effect-in length - ;
|
|
|
|
|
|
|
|
: effect<= ( eff1 eff2 -- ? )
|
|
|
|
2dup [ effect-terminated? ] 2apply = >r
|
|
|
|
2dup [ effect-in length ] 2apply <= >r
|
|
|
|
[ effect-height ] 2apply number= r> and r> and ;
|