factor/library/syntax/parse-stream.factor

49 lines
1.5 KiB
Factor
Raw Normal View History

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
USING: kernel lists namespaces sequences io ;
2004-07-30 16:22:20 -04:00
: file-vocabs ( -- )
2004-07-30 02:44:12 -04:00
"file-in" get "in" set
"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-05-05 16:03:24 -04:00
[
>r file set f ( initial parse tree ) r>
[ (parse) ] read-lines reverse
file off
line-number off
] with-parser ;
2004-07-18 22:14:36 -04:00
2004-08-20 19:27:48 -04:00
: parse-stream ( name stream -- quot )
2005-05-05 16:51:38 -04:00
[ file-vocabs (parse-stream) ] with-scope ;
2004-07-18 22:14:36 -04:00
2004-08-20 19:27:48 -04:00
: parse-file ( file -- quot )
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 )
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.
2005-05-18 16:26:22 -04:00
"resource:" over append 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 ;