tools.completion: moving "complete-?" words.

db4
John Benediktsson 2012-09-25 09:10:44 -07:00
parent d5998a712f
commit a5b91e181a
4 changed files with 56 additions and 62 deletions

View File

@ -4,15 +4,29 @@ tools.test ;
IN: tools.completion
[ f ] [ "abc" "def" fuzzy ] unit-test
[ V{ 4 5 6 } ] [ "set-nth" "nth" fuzzy ] unit-test
{ f } [ "abc" "def" fuzzy ] unit-test
{ V{ 4 5 6 } } [ "set-nth" "nth" fuzzy ] unit-test
[ V{ V{ 0 } V{ 4 5 6 } } ] [ V{ 0 4 5 6 } runs ] unit-test
{ V{ V{ 0 } V{ 4 5 6 } } } [ V{ 0 4 5 6 } runs ] unit-test
[ { "nth" "?nth" "set-nth" } ] [
{ { "nth" "?nth" "set-nth" } } [
"nth" { "set-nth" "nth" "?nth" } dup zip completions keys
] unit-test
[ { "a" "b" "c" "d" "e" "f" "g" } ] [
{ { "a" "b" "c" "d" "e" "f" "g" } } [
"" { "a" "b" "c" "d" "e" "f" "g" } dup zip completions keys
] unit-test
{ f } [ { "USE:" "A" "B" "C" } complete-vocab? ] unit-test
{ f } [ { "USE:" "A" "B" } complete-vocab? ] unit-test
{ f } [ { "USE:" "A" "" } complete-vocab? ] unit-test
{ t } [ { "USE:" "A" } complete-vocab? ] unit-test
{ t } [ { "USE:" "" } complete-vocab? ] unit-test
{ f } [ { "USE:" } complete-vocab? ] unit-test
{ t } [ { "UNUSE:" "A" } complete-vocab? ] unit-test
{ t } [ { "QUALIFIED:" "A" } complete-vocab? ] unit-test
{ t } [ { "QUALIFIED-WITH:" "A" } complete-vocab? ] unit-test
{ t } [ { "USING:" "A" "B" "C" } complete-vocab? ] unit-test
{ f } [ { "USING:" "A" "B" "C" ";" } complete-vocab? ] unit-test
{ t } [ { "X" ";" "USING:" "A" "B" "C" } complete-vocab? ] unit-test

View File

@ -1,10 +1,11 @@
! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs colors.constants combinators fry
io io.directories kernel locals make math math.order namespaces
sequences sorting strings unicode.case unicode.categories
unicode.data vectors vocabs vocabs.hierarchy words ;
USING: accessors arrays assocs colors.constants combinators
combinators.short-circuit fry io io.directories kernel locals
make math math.order namespaces sequences sorting splitting
strings unicode.case unicode.categories unicode.data vectors
vocabs vocabs.hierarchy words ;
IN: tools.completion
@ -100,3 +101,34 @@ PRIVATE>
: paths-matching ( str path -- seq )
directory-files dup zip completions ;
<PRIVATE
: (complete-single-vocab?) ( str -- ? )
{ "IN:" "USE:" "UNUSE:" "QUALIFIED:" "QUALIFIED-WITH:" }
member? ; inline
: complete-single-vocab? ( tokens -- ? )
dup last empty? [
harvest ?last (complete-single-vocab?)
] [
harvest dup length 1 >
[ 2 tail* ?first (complete-single-vocab?) ] [ drop f ] if
] if ;
: chop-; ( seq -- seq' )
{ ";" } split1-last [ ] [ ] ?if ;
: complete-vocab-list? ( tokens -- ? )
chop-; 1 short head* "USING:" swap member? ;
PRIVATE>
: complete-vocab? ( tokens -- ? )
{ [ complete-single-vocab? ] [ complete-vocab-list? ] } 1|| ;
: complete-CHAR:? ( tokens -- ? )
2 short tail* "CHAR:" swap member? ;
: complete-COLOR:? ( tokens -- ? )
2 short tail* "COLOR:" swap member? ;

View File

@ -1,28 +0,0 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test ui.tools.listener.completion ;
IN: ui.tools.listener.completion.tests
[ f ] [ { "USE:" "A" "B" "C" } complete-vocab? ] unit-test
[ f ] [ { "USE:" "A" "B" } complete-vocab? ] unit-test
[ f ] [ { "USE:" "A" "" } complete-vocab? ] unit-test
[ t ] [ { "USE:" "A" } complete-vocab? ] unit-test
[ t ] [ { "USE:" "" } complete-vocab? ] unit-test
[ f ] [ { "USE:" } complete-vocab? ] unit-test
[ t ] [ { "UNUSE:" "A" } complete-vocab? ] unit-test
[ t ] [ { "QUALIFIED:" "A" } complete-vocab? ] unit-test
[ t ] [ { "QUALIFIED-WITH:" "A" } complete-vocab? ] unit-test
[ t ] [ { "USING:" "A" "B" "C" } complete-vocab-list? ] unit-test
[ f ] [ { "USING:" "A" "B" "C" ";" } complete-vocab-list? ] unit-test
[ t ] [ { "X" ";" "USING:" "A" "B" "C" } complete-vocab-list? ] unit-test

View File

@ -81,37 +81,13 @@ M: vocab-completion row-color
M: color-completion row-color
drop named-color ;
: (complete-vocab?) ( str -- ? )
{ "IN:" "USE:" "UNUSE:" "QUALIFIED:" "QUALIFIED-WITH:" }
member? ; inline
: complete-vocab? ( tokens -- ? )
dup last empty? [
harvest ?last (complete-vocab?)
] [
harvest dup length 1 >
[ 2 tail* ?first (complete-vocab?) ] [ drop f ] if
] if ;
: chop-; ( seq -- seq' )
{ ";" } split1-last [ ] [ ] ?if ;
: complete-vocab-list? ( tokens -- ? )
chop-; 1 short head* "USING:" swap member? ;
: complete-CHAR:? ( tokens -- ? )
2 short tail* "CHAR:" swap member? ;
: complete-COLOR:? ( tokens -- ? )
2 short tail* "COLOR:" swap member? ;
: up-to-caret ( caret document -- string )
[ { 0 0 } ] 2dip doc-range ;
: completion-mode ( interactor -- symbol )
[ manifest>> ] [ editor-caret ] [ model>> ] tri up-to-caret " \r\n" split
{
{ [ dup { [ complete-vocab? ] [ complete-vocab-list? ] } 1|| ] [ 2drop vocab-completion ] }
{ [ dup complete-vocab? ] [ 2drop vocab-completion ] }
{ [ dup complete-CHAR:? ] [ 2drop char-completion ] }
{ [ dup complete-COLOR:? ] [ 2drop color-completion ] }
[ drop <word-completion> ]