factor/library/syntax/parse-stream.factor

37 lines
1.1 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 ( -- )
2005-07-31 23:38:33 -04:00
"scratchpad" "in" set
[ "syntax" "scratchpad" ] "use" set ;
2004-07-18 19:52:01 -04:00
2005-07-31 23:38:33 -04:00
: (parse-stream) ( stream -- quot )
[ f swap [ (parse) ] read-lines reverse ] with-parser ;
2004-07-18 22:14:36 -04:00
2004-08-20 19:27:48 -04:00
: parse-stream ( name stream -- quot )
2005-07-31 23:38:33 -04:00
[
swap file set file-vocabs
(parse-stream)
file off line-number off
] 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 -- )
2004-08-20 19:27:48 -04:00
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-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 ;