2005-08-19 21:46:12 -04:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: parser
|
2005-11-12 00:54:28 -05:00
|
|
|
USING: errors io kernel lists math namespaces sequences words ;
|
2005-08-19 21:46:12 -04:00
|
|
|
|
|
|
|
: file-vocabs ( -- )
|
|
|
|
"scratchpad" "in" set
|
|
|
|
[ "syntax" "scratchpad" ] "use" set ;
|
|
|
|
|
2005-09-14 00:37:50 -04:00
|
|
|
: parse-lines ( lines -- quot )
|
2005-08-19 21:46:12 -04:00
|
|
|
[
|
2005-09-14 00:37:50 -04:00
|
|
|
dup length [ ]
|
2005-09-16 22:47:28 -04:00
|
|
|
[ 1+ line-number set (parse) ] 2reduce
|
2005-08-19 21:46:12 -04:00
|
|
|
reverse
|
|
|
|
] with-parser ;
|
|
|
|
|
2005-09-14 00:37:50 -04:00
|
|
|
: parse-stream ( stream name -- quot )
|
|
|
|
[ file set file-vocabs lines parse-lines ] with-scope ;
|
2005-08-19 21:46:12 -04:00
|
|
|
|
2005-12-11 15:37:16 -05:00
|
|
|
: parsing-file ( file -- ) "Loading " write print ;
|
2005-12-11 14:27:36 -05:00
|
|
|
|
2005-08-19 21:46:12 -04:00
|
|
|
: parse-file ( file -- quot )
|
2005-12-11 15:14:41 -05:00
|
|
|
dup parsing-file
|
2005-09-14 00:37:50 -04:00
|
|
|
[ <file-reader> ] keep parse-stream ;
|
2005-08-19 21:46:12 -04:00
|
|
|
|
|
|
|
: run-file ( file -- )
|
|
|
|
parse-file call ;
|
|
|
|
|
|
|
|
: parse-resource ( path -- quot )
|
|
|
|
#! Resources are loaded from the resource-path variable, or
|
|
|
|
#! the current directory if it is not set. Words defined in
|
|
|
|
#! resources have a definition source path starting with
|
|
|
|
#! resource:. This allows words that operate on source
|
|
|
|
#! files, like "jedit", to use a different resource path
|
|
|
|
#! at run time than was used at parse time.
|
2005-12-11 15:14:41 -05:00
|
|
|
dup parsing-file
|
2005-09-14 00:37:50 -04:00
|
|
|
[ <resource-stream> "resource:" ] keep append parse-stream ;
|
2005-08-19 21:46:12 -04:00
|
|
|
|
|
|
|
: run-resource ( file -- )
|
|
|
|
parse-resource call ;
|
2005-08-31 21:06:13 -04:00
|
|
|
|
|
|
|
: word-file ( word -- file )
|
2005-09-14 00:37:50 -04:00
|
|
|
"file" word-prop dup
|
|
|
|
[ "resource:/" ?head [ resource-path ] when ] when ;
|
2005-08-31 21:06:13 -04:00
|
|
|
|
|
|
|
: reload ( word -- )
|
|
|
|
#! Reload the source file the word originated from.
|
|
|
|
word-file run-file ;
|