2005-03-21 20:53:26 -05:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-07-18 19:52:01 -04:00
|
|
|
IN: parser
|
2005-04-25 19:54:21 -04:00
|
|
|
USING: kernel lists namespaces sequences streams strings ;
|
2004-07-21 19:26:41 -04:00
|
|
|
|
2004-07-30 16:22:20 -04:00
|
|
|
: file-vocabs ( -- )
|
2004-07-30 02:44:12 -04:00
|
|
|
"file-in" get "in" set
|
2004-08-08 17:20:54 -04:00
|
|
|
"file-use" get "use" set ;
|
2004-07-18 19:52:01 -04:00
|
|
|
|
2004-08-20 19:27:48 -04:00
|
|
|
: (parse-stream) ( name stream -- quot )
|
2004-07-30 16:22:20 -04:00
|
|
|
#! Uses the current namespace for temporary variables.
|
2005-02-24 20:52:17 -05:00
|
|
|
>r file set f ( initial parse tree ) r>
|
2004-10-12 01:11:35 -04:00
|
|
|
[ (parse) ] read-lines reverse
|
2005-02-24 20:52:17 -05:00
|
|
|
file off
|
|
|
|
line-number off ;
|
2004-07-18 22:14:36 -04:00
|
|
|
|
2004-08-20 19:27:48 -04:00
|
|
|
: parse-stream ( name stream -- quot )
|
2005-03-25 21:43:06 -05:00
|
|
|
[
|
|
|
|
file-vocabs
|
|
|
|
[ (parse-stream) ] with-parser
|
|
|
|
] with-scope ;
|
2004-07-18 22:14:36 -04:00
|
|
|
|
2004-08-20 19:27:48 -04:00
|
|
|
: parse-file ( file -- quot )
|
2005-01-29 00:07:56 -05:00
|
|
|
dup <file-reader> parse-stream ;
|
2004-07-30 02:44:12 -04:00
|
|
|
|
2004-07-30 16:22:20 -04:00
|
|
|
: run-file ( file -- )
|
|
|
|
#! Run a file. The file is read with the default IN:/USE:
|
|
|
|
#! for files.
|
2004-08-20 19:27:48 -04:00
|
|
|
parse-file call ;
|
|
|
|
|
|
|
|
: (parse-file) ( file -- quot )
|
2005-01-29 00:07:56 -05:00
|
|
|
dup <file-reader> (parse-stream) ;
|
2004-08-20 19:27:48 -04:00
|
|
|
|
|
|
|
: (run-file) ( file -- )
|
|
|
|
#! Run a file. The file is read with the same IN:/USE: as
|
|
|
|
#! the current interactive interpreter.
|
|
|
|
(parse-file) call ;
|
2004-07-30 16:22:20 -04:00
|
|
|
|
2004-08-20 19:27:48 -04:00
|
|
|
: 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.
|
2004-08-22 21:56:06 -04:00
|
|
|
"resource:" over cat2 swap <resource-stream> parse-stream ;
|
2004-08-20 19:27:48 -04:00
|
|
|
|
2004-07-30 02:44:12 -04:00
|
|
|
: run-resource ( file -- )
|
2004-08-20 19:27:48 -04:00
|
|
|
parse-resource call ;
|