HOOK: normalize-directory io-backend ( str -- newstr )
-M: object normalize-directory ;
-
HOOK: normalize-pathname io-backend ( str -- newstr )
-M: object normalize-pathname ;
+M: object normalize-directory normalize-pathname ;
: set-io-backend ( io-backend -- )
io-backend set-global init-io init-stdio ;
IN: io.files.tests
-USING: tools.test io.files io threads kernel continuations io.encodings.ascii
-io.files.unique sequences strings accessors ;
+USING: tools.test io.files io threads kernel continuations
+io.encodings.ascii io.files.unique sequences strings accessors
+io.encodings.utf8 ;
[ ] [ "blahblah" temp-file dup exists? [ delete-directory ] [ drop ] if ] unit-test
[ ] [ "blahblah" temp-file make-directory ] unit-test
"delete-tree-test" temp-file delete-tree
] unit-test
+[ { { "kernel" t } } ] [
+ "core" resource-path [
+ "." directory [ first "kernel" = ] subset
+ ] with-directory
+] unit-test
+
[ ] [
"copy-tree-test/a/b/c" temp-file make-directories
] unit-test
[ t ] [ cwd "misc" resource-path [ ] with-directory cwd = ] unit-test
+[ t ] [
+ temp-directory [ "hi41" "test41" utf8 set-file-contents ] with-directory
+ temp-directory "test41" append-path utf8 file-contents "hi41" =
+] unit-test
+
+[ t ] [
+ temp-directory [ "test41" file-info size>> ] with-directory 4 =
+] unit-test
+
[ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test
[ ] [ "append-test" temp-file ascii <file-appender> dispose ] unit-test
HOOK: (file-appender) io-backend ( path -- stream )
: <file-reader> ( path encoding -- stream )
- swap (file-reader) swap <decoder> ;
+ swap normalize-pathname (file-reader) swap <decoder> ;
: <file-writer> ( path encoding -- stream )
- swap (file-writer) swap <encoder> ;
+ swap normalize-pathname (file-writer) swap <encoder> ;
: <file-appender> ( path encoding -- stream )
- swap (file-appender) swap <encoder> ;
+ swap normalize-pathname (file-appender) swap <encoder> ;
: file-lines ( path encoding -- seq )
<file-reader> lines ;
: temp-file ( name -- path ) temp-directory prepend-path ;
+M: object normalize-pathname ( path -- path' )
+ current-directory get prepend-path ;
+
! Pathname presentations
TUPLE: pathname string ;
\ file-info construct-boa ;
M: unix-io file-info ( path -- info )
- stat* stat>file-info ;
+ normalize-pathname stat* stat>file-info ;
M: unix-io link-info ( path -- info )
- lstat* stat>file-info ;
+ normalize-pathname lstat* stat>file-info ;
IN: io.unix.launcher.tests
USING: io.files tools.test io.launcher arrays io namespaces
continuations math io.encodings.binary io.encodings.ascii
-accessors kernel sequences ;
+accessors kernel sequences io.encodings.utf8 ;
[ ] [
[ "launcher-test-1" temp-file delete-file ] ignore-errors
+replace-environment+ >>environment-mode
ascii <process-stream> lines
] unit-test
+
+[ "hi\n" ] [
+ temp-directory [
+ [ "aloha" delete-file ] ignore-errors
+ <process>
+ { "echo" "hi" } >>command
+ "aloha" >>stdout
+ try-process
+ ] with-directory
+ temp-directory "aloha" append-path
+ utf8 file-contents
+] unit-test
2nip reset-fd ;
: redirect-file ( obj mode fd -- )
- >r file-mode open dup io-error r> redirect-fd ;
+ >r >r normalize-pathname r> file-mode
+ open dup io-error r> redirect-fd ;
: redirect-closed ( obj mode fd -- )
>r >r drop "/dev/null" r> r> redirect-file ;
: spawn-process ( process -- * )
[
- current-directory get cd
setup-priority
setup-redirection
+ current-directory get cd
dup pass-environment? [
dup get-environment set-os-envs
] when
] if ;
M: windows-nt-io file-info ( path -- info )
- get-file-information-stat ;
+ normalize-pathname get-file-information-stat ;
+
+M: windows-nt-io link-info ( path -- info )
+ file-info ;
! Clean up resources (open handle) if add-completion fails
: open-file ( path access-mode create-mode flags -- handle )
[
- >r >r >r normalize-pathname r>
+ >r >r
share-mode security-attributes-inherit r> r> CreateFile-flags f CreateFile
dup invalid-handle? dup close-later
dup add-completion
USING: kernel sequences strings namespaces math assocs shuffle
vectors arrays combinators.lib math.parser match
unicode.categories sequences.lib compiler.units parser
- words quotations effects memoize accessors combinators.cleave ;
+ words quotations effects memoize accessors
+ combinators.cleave locals ;
IN: peg
TUPLE: parse-result remaining ast ;
parse-result construct-boa ;
SYMBOL: compiled-parsers
+SYMBOL: packrat
+SYMBOL: failed
GENERIC: (compile) ( parser -- quot )
+:: run-packrat-parser ( input quot c -- result )
+ input slice? [ input slice-from ] [ 0 ] if
+ quot c [ drop H{ } clone ] cache
+ [
+ drop input quot call
+ ] cache ; inline
+
+: run-parser ( input quot -- result )
+ #! If a packrat cache is available, use memoization for
+ #! packrat parsing, otherwise do a standard peg call.
+ packrat get [ run-packrat-parser ] [ call ] if* ; inline
+
: compiled-parser ( parser -- word )
#! Look to see if the given parser has been compiled.
#! If not, compile it to a temporary word, cache it,
dup compiled-parsers get at [
nip
] [
- dup (compile) define-temp
+ dup (compile) [ run-parser ] curry define-temp
[ swap compiled-parsers get set-at ] keep
] if* ;
-MEMO: compile ( parser -- word )
+: compile ( parser -- word )
H{ } clone compiled-parsers [
[ compiled-parser ] with-compilation-unit
] with-variable ;
USING: arrays ui.gadgets
ui.gadgets.viewports ui.gadgets.frames ui.gadgets.grids
ui.gadgets.theme ui.gadgets.sliders ui.gestures kernel math
-namespaces sequences models combinators math.vectors ;
+namespaces sequences models combinators math.vectors
+tuples ;
IN: ui.gadgets.scrollers
TUPLE: scroller viewport x y follows ;
: find-scroller ( gadget -- scroller/f )
- [ scroller? ] find-parent ;
+ [ [ scroller? ] is? ] find-parent ;
: scroll-up-page scroller-y -1 swap slide-by-page ;
ui.gadgets ui.gadgets.editors ui.gadgets.labelled
ui.gadgets.panes ui.gadgets.buttons ui.gadgets.scrollers
ui.gadgets.tracks ui.gestures ui.operations vocabs words
-prettyprint listener debugger threads boxes concurrency.flags ;
+prettyprint listener debugger threads boxes concurrency.flags
+math arrays ;
IN: ui.tools.listener
TUPLE: listener-gadget input output stack ;
: <listener-input> ( listener -- gadget )
listener-gadget-output <pane-stream> <interactor> ;
+TUPLE: input-scroller ;
+
+: <input-scroller> ( interactor -- scroller )
+ <scroller>
+ input-scroller construct-empty
+ [ set-gadget-delegate ] keep ;
+
+M: input-scroller pref-dim*
+ drop { 0 100 } ;
+
: listener-input, ( -- )
g <listener-input> g-> set-listener-gadget-input
- <scroller> "Input" <labelled-gadget> f track, ;
+ <input-scroller> "Input" <labelled-gadget> f track, ;
: welcome. ( -- )
"If this is your first time with Factor, please read the " print