2004-07-22 19:48:50 -04:00
|
|
|
! :folding=indent:collapseFolds=1:
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
! $Id$
|
|
|
|
!
|
|
|
|
! Copyright (C) 2003, 2004 Slava Pestov.
|
|
|
|
!
|
|
|
|
! Redistribution and use in source and binary forms, with or without
|
|
|
|
! modification, are permitted provided that the following conditions are met:
|
|
|
|
!
|
|
|
|
! 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
! this list of conditions and the following disclaimer.
|
|
|
|
!
|
|
|
|
! 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
! this list of conditions and the following disclaimer in the documentation
|
|
|
|
! and/or other materials provided with the distribution.
|
|
|
|
!
|
|
|
|
! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2004-08-16 19:29:07 -04:00
|
|
|
IN: words
|
2004-12-17 23:02:19 -05:00
|
|
|
USE: generic
|
2004-07-16 02:26:21 -04:00
|
|
|
USE: inspector
|
|
|
|
USE: lists
|
|
|
|
USE: kernel
|
|
|
|
USE: namespaces
|
2004-07-21 19:26:41 -04:00
|
|
|
USE: prettyprint
|
2004-07-16 02:26:21 -04:00
|
|
|
USE: stdio
|
|
|
|
USE: strings
|
|
|
|
USE: unparser
|
2004-12-17 23:02:19 -05:00
|
|
|
USE: math
|
2005-01-17 15:33:12 -05:00
|
|
|
USE: hashtables
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-01-17 15:33:12 -05:00
|
|
|
GENERIC: word-uses? ( of in -- ? )
|
|
|
|
M: word word-uses? 2drop f ;
|
|
|
|
M: compound word-uses? ( of in -- ? )
|
2004-07-16 02:26:21 -04:00
|
|
|
2dup = [
|
|
|
|
2drop f ! Don't say that a word uses itself
|
|
|
|
] [
|
2004-08-24 15:27:37 -04:00
|
|
|
word-parameter tree-contains?
|
2004-07-16 02:26:21 -04:00
|
|
|
] ifte ;
|
2005-01-17 15:33:12 -05:00
|
|
|
M: generic word-uses? ( of in -- ? )
|
|
|
|
"methods" word-property hash>alist tree-contains? ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
: usages-in-vocab ( of vocab -- usages )
|
|
|
|
#! Push a list of all usages of a word in a vocabulary.
|
|
|
|
words [
|
2004-10-01 22:25:19 -04:00
|
|
|
dup compound? [
|
2004-07-16 02:26:21 -04:00
|
|
|
dupd word-uses?
|
|
|
|
] [
|
2004-07-19 17:36:20 -04:00
|
|
|
drop f ! Ignore words without a definition
|
2004-07-16 02:26:21 -04:00
|
|
|
] ifte
|
|
|
|
] subset nip ;
|
|
|
|
|
|
|
|
: usages-in-vocab. ( of vocab -- )
|
|
|
|
#! List all usages of a word in a vocabulary.
|
|
|
|
tuck usages-in-vocab dup [
|
|
|
|
swap "IN: " write print [.]
|
|
|
|
] [
|
|
|
|
2drop
|
|
|
|
] ifte ;
|
|
|
|
|
|
|
|
: usages. ( word -- )
|
|
|
|
#! List all usages of a word in all vocabularies.
|
2005-01-01 17:20:48 -05:00
|
|
|
vocabs [ usages-in-vocab. ] each-with ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-07-19 17:36:20 -04:00
|
|
|
: vocab-apropos ( substring vocab -- list )
|
2004-07-16 02:26:21 -04:00
|
|
|
#! Push a list of all words in a vocabulary whose names
|
|
|
|
#! contain a string.
|
2004-07-23 01:38:36 -04:00
|
|
|
words [ word-name dupd str-contains? ] subset nip ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-07-19 17:36:20 -04:00
|
|
|
: vocab-apropos. ( substring vocab -- )
|
2004-07-16 02:26:21 -04:00
|
|
|
#! List all words in a vocabulary that contain a string.
|
2004-07-19 17:36:20 -04:00
|
|
|
tuck vocab-apropos dup [
|
2004-07-16 02:26:21 -04:00
|
|
|
"IN: " write swap print [.]
|
|
|
|
] [
|
|
|
|
2drop
|
|
|
|
] ifte ;
|
|
|
|
|
2004-11-24 21:45:30 -05:00
|
|
|
: vocab-completions ( substring vocab -- list )
|
|
|
|
#! Used by jEdit plugin. Like vocab-apropos, but only
|
|
|
|
#! matches at the start of a word name are considered.
|
2004-12-19 03:04:03 -05:00
|
|
|
words [ word-name over ?str-head nip ] subset nip ;
|
2004-11-24 21:45:30 -05:00
|
|
|
|
2004-07-19 17:36:20 -04:00
|
|
|
: apropos. ( substring -- )
|
2004-07-16 02:26:21 -04:00
|
|
|
#! List all words that contain a string.
|
2005-01-01 17:20:48 -05:00
|
|
|
vocabs [ vocab-apropos. ] each-with ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
: in. ( -- )
|
|
|
|
#! Print the vocabulary where new words are added in
|
|
|
|
#! interactive parsers.
|
|
|
|
"in" get print ;
|
|
|
|
|
|
|
|
: use. ( -- )
|
|
|
|
#! Print the vocabulary search path for interactive parsers.
|
|
|
|
"use" get . ;
|
2004-07-30 16:22:20 -04:00
|
|
|
|
|
|
|
: vocabs. ( -- )
|
|
|
|
vocabs . ;
|
|
|
|
|
|
|
|
: words. ( vocab -- )
|
|
|
|
words . ;
|