37 lines
1005 B
Factor
37 lines
1005 B
Factor
|
|
USING: kernel namespaces words math sequences arrays hashtables
|
|
inspector vars ;
|
|
|
|
IN: parser
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
: word-restarts ( string -- restarts )
|
|
words-named natural-sort
|
|
[ [ "Use the word " swap summary append ] keep 2array ] map
|
|
{ "Define this word as a symbol" 0 } add
|
|
{ "Defer this word in the 'scratchpad' vocabulary" f } add ;
|
|
|
|
: no-word-option ( obj -- word )
|
|
{ { [ dup f = ] [ drop in get create ] }
|
|
{ [ dup 0 = ] [ drop in get create dup define-symbol ] }
|
|
{ [ t ] [ nip dup word-vocabulary use+ ] }
|
|
} cond ;
|
|
|
|
VAR: new-symbol-action ! ( str -- word )
|
|
|
|
[ dup no-word no-word-option ] new-symbol-action set-global
|
|
|
|
! For lisp:
|
|
!
|
|
! [ in get create dup define-symbol ] >new-symbol-action
|
|
|
|
: search ( str -- word )
|
|
{ { [ dup use get hash-stack ]
|
|
[ use get hash-stack ] }
|
|
{ [ dup words-named empty? ]
|
|
[ new-symbol-action> call ] }
|
|
{ [ dup words-named length 0 > ]
|
|
[ dup no-word no-word-option ] }
|
|
} cond ;
|