! Copyright (C) 2005, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays definitions generic assocs kernel math namespaces
-prettyprint sequences strings vectors words quotations summary
-io.styles io combinators sorting splitting math.parser effects
-continuations debugger io.files io.streams.string vocabs
-io.encodings.utf8 source-files classes hashtables
-compiler.errors compiler.units accessors sets lexer ;
+sequences strings vectors words quotations io.styles io
+combinators sorting splitting math.parser effects continuations
+io.files io.streams.string vocabs io.encodings.utf8 source-files
+classes hashtables compiler.errors compiler.units accessors sets
+lexer ;
IN: parser
: location ( -- loc )
: note. ( str -- )
parser-notes? [
- file get [ file. ] when*
+ file get [ path>> write ] when*
lexer get line>> number>string write ": " write
"Note: " write dup print
] when drop ;
ERROR: no-current-vocab ;
-M: no-current-vocab summary ( obj -- )
- drop "Not in a vocabulary; IN: form required" ;
-
: current-vocab ( -- str )
in get [ no-current-vocab ] unless* ;
: word-restarts ( possibilities -- restarts )
natural-sort [
- [ "Use the word " swap summary append ] keep
+ [
+ "Use the " swap vocabulary>> " vocabulary" 3append
+ ] keep
] { } map>assoc ;
TUPLE: no-word-error name ;
-M: no-word-error summary
- drop "Word not found in current vocabulary search path" ;
-
: no-word ( name -- newword )
dup no-word-error boa
swap words-named [ forward-reference? not ] filter
ERROR: staging-violation word ;
-M: staging-violation summary
- drop
- "A parsing word cannot be used in the same file it is defined in." ;
-
: execute-parsing ( word -- )
dup changed-definitions get key? [ staging-violation ] when
execute ;
ERROR: bad-number ;
-M: bad-number summary
- drop "Bad number literal" ;
-
: parse-base ( parsed base -- parsed )
scan swap base> [ bad-number ] unless* parsed ;
"quiet" get [
drop
] [
- "Loading " write <pathname> . flush
+ "Loading " write print flush
] if ;
: filter-moved ( assoc1 assoc2 -- seq )
: ?run-file ( path -- )
dup exists? [ run-file ] [ drop ] if ;
-
-: eval ( str -- )
- [ string-lines parse-fresh ] with-compilation-unit call ;
-
-: eval>string ( str -- output )
- [
- parser-notes off
- [ [ eval ] keep ] try drop
- ] with-string-writer ;