]> gitweb.factorcode.org Git - factor.git/commitdiff
Rename use+ to add-use, move search to vocabs.parser, EXCLUDE: bombs out if word...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 14 May 2009 03:15:48 +0000 (22:15 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 14 May 2009 03:15:48 +0000 (22:15 -0500)
19 files changed:
basis/interpolate/interpolate.factor
basis/io/sockets/sockets.factor
basis/io/sockets/unix/unix.factor
basis/listener/listener-tests.factor
basis/opengl/gl/extensions/extensions.factor
basis/peg/ebnf/ebnf.factor
basis/see/see-docs.factor
basis/tools/test/test.factor
basis/ui/pixel-formats/pixel-formats-docs.factor
basis/ui/tools/operations/operations.factor
core/parser/parser-docs.factor
core/parser/parser-tests.factor
core/parser/parser.factor
core/syntax/syntax.factor
core/vocabs/parser/parser-docs.factor
core/vocabs/parser/parser.factor
core/words/words-docs.factor
extra/fuel/eval/eval.factor
extra/sandbox/syntax/syntax.factor

index 1de65fa91f8febc1f5002002cb8867f2dda5fd1a..ea965aac5b48e1922c9b946c325bf27326507c3c 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: io kernel macros make multiline namespaces parser
+USING: io kernel macros make multiline namespaces vocabs.parser
 present sequences strings splitting fry accessors ;
 IN: interpolate
 
index a0beb1f421b3ac20602737ef597a49b859cd7c52..0671247ade17d003b263baabbd6d979f9be868fb 100644 (file)
@@ -12,7 +12,7 @@ IN: io.sockets
 << {
     { [ os windows? ] [ "windows.winsock" ] }
     { [ os unix? ] [ "unix" ] }
-} cond use+ >>
+} cond add-use >>
 
 ! Addressing
 GENERIC: protocol-family ( addrspec -- af )
index 799dfa78d53be343e6224a08b653cf1458e37226..68c7d5c196e39f426d64a4e6a22f1bcdb6f53a29 100644 (file)
@@ -7,7 +7,7 @@ io.backend io.ports io.pathnames io.files.private
 io.encodings.utf8 math.parser continuations libc combinators
 system accessors destructors unix locals init ;
 
-EXCLUDE: io => read write close ;
+EXCLUDE: io => read write ;
 EXCLUDE: io.sockets => accept ;
 
 IN: io.sockets.unix
index 7ed082234a0542847dc07a0a6a1b34c2071fd3c3..9ae5250416b7788e2b5ed3bfec5bc02dcb4d3158 100644 (file)
@@ -15,7 +15,7 @@ SYNTAX: hello "Hi" print ;
 ] with-file-vocabs
 
 [
-    "debugger" use+
+    "debugger" add-use
 
     [ [ \ + 1 2 3 4 ] ]
     [
index ccd3f5fad74e2ed9806fe53f5b349fe91a3efd47..8878e1904a9062cea1588105a2120ecbabc7f480 100644 (file)
@@ -9,7 +9,7 @@ ERROR: unknown-gl-platform ;
     { [ os macosx? ]  [ "opengl.gl.macosx" ] }
     { [ os unix? ] [ "opengl.gl.unix" ] }
     [ unknown-gl-platform ]
-} cond use+ >>
+} cond add-use >>
 
 SYMBOL: +gl-function-number-counter+
 SYMBOL: +gl-function-pointers+
index b50ba685b8c06582583cb370ca972ac4660859a8..fafb8461471e851c43b91664b8797d3e9581fb2e 100644 (file)
@@ -5,7 +5,7 @@ sequences quotations vectors namespaces make math assocs
 continuations peg peg.parsers unicode.categories multiline\r
 splitting accessors effects sequences.deep peg.search\r
 combinators.short-circuit lexer io.streams.string stack-checker\r
-io combinators parser summary ;\r
+io combinators parser vocabs.parser summary ;\r
 IN: peg.ebnf\r
 \r
 : rule ( name word -- parser )\r
index b2e99843c7ca230e641f456a2e745699382d01a7..2423950d8631b358eaedde7eeee163e775f936a9 100644 (file)
@@ -25,7 +25,7 @@ HELP: see-methods
 { $contract "Prettyprints the methods defined on a generic word or class." } ;
 
 HELP: definer
-{ $values { "defspec" "a definition specifier" } { "start" word } { "end" "a word or " { $link f } } }
+{ $values { "defspec" "a definition specifier" } { "start" word } { "end" { $maybe word } } }
 { $contract "Outputs the parsing words which delimit the definition." }
 { $examples
     { $example "USING: definitions prettyprint ;"
index 3dc7b8740b171b1da5c60b78f47ef5c796333923..7b07311ded119dc7923ef76212d7ef1339540132 100644 (file)
@@ -2,11 +2,11 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs combinators compiler.units
 continuations debugger effects fry generalizations io io.files
-io.styles kernel lexer locals macros math.parser namespaces
-parser prettyprint quotations sequences source-files splitting
+io.styles kernel lexer locals macros math.parser namespaces parser
+vocabs.parser prettyprint quotations sequences source-files splitting
 stack-checker summary unicode.case vectors vocabs vocabs.loader
-vocabs.files words tools.errors source-files.errors
-io.streams.string make compiler.errors ;
+vocabs.files words tools.errors source-files.errors io.streams.string
+make compiler.errors ;
 IN: tools.test
 
 TUPLE: test-failure < source-file-error continuation ;
index 003b205c3daf2664995f9fad79db3217cfee02d2..53e44ec18ee2c670da153d744f5755b2d1afce9e 100644 (file)
@@ -6,7 +6,7 @@ IN: ui.pixel-formats
 <<
     "ui.gadgets.worlds" create-vocab drop
     "world" "ui.gadgets.worlds" create drop
-    "ui.gadgets.worlds" (use+)
+    "ui.gadgets.worlds" (add-use)
 >>
 
 ARTICLE: "ui.pixel-formats-attributes" "Pixel format attributes"
index 650d751ee29d741fb323d2324011f50a0cb8cd57..49bb74d18c9e3c92e255fbb3e9733bb1cf2d3fdf 100644 (file)
@@ -137,7 +137,7 @@ M: word com-stack-effect 1quotation com-stack-effect ;
     { +listener+ t }
 } define-operation
 
-: com-use-vocab ( vocab -- ) vocab-name use+ ;
+: com-use-vocab ( vocab -- ) vocab-name add-use ;
 
 [ vocab-spec? ] \ com-use-vocab H{
     { +secondary+ t }
index 98f41ae39aac72ab8f5441e425b0a7b2f469f7f5..d6c69f08c2f60b8c83f4800dbb41d8762b8f12a7 100644 (file)
@@ -119,45 +119,7 @@ HELP: parser-notes?
 HELP: bad-number
 { $error-description "Indicates the parser encountered an invalid numeric literal." } ;
 
-HELP: use
-{ $var-description "A variable holding the current vocabulary search path as a sequence of assocs." } ;
-
-{ use in use+ (use+) set-use set-in POSTPONE: USING: POSTPONE: USE: with-file-vocabs with-interactive-vocabs } related-words
-
-HELP: in
-{ $var-description "A variable holding the name of the current vocabulary for new definitions." } ;
-
-HELP: current-vocab
-{ $values { "str" "a vocabulary" } }
-{ $description "Returns the vocabulary stored in the " { $link in } " symbol. Throws an error if the current vocabulary is " { $link f } "." } ;
-
-HELP: (use+)
-{ $values { "vocab" "an assoc mapping strings to words" } }
-{ $description "Adds an assoc at the front of the search path." }
-$parsing-note ;
-
-HELP: use+
-{ $values { "vocab" string } }
-{ $description "Adds a new vocabulary at the front of the search path after loading it if necessary. Subsequent word lookups by the parser will search this vocabulary first." }
-$parsing-note
-{ $errors "Throws an error if the vocabulary does not exist." } ;
-
-HELP: set-use
-{ $values { "seq" "a sequence of strings" } }
-{ $description "Sets the vocabulary search path. Later vocabularies take precedence." }
-{ $errors "Throws an error if one of the vocabularies does not exist." }
-$parsing-note ;
-
-HELP: add-use
-{ $values { "seq" "a sequence of strings" } }
-{ $description "Adds multiple vocabularies to the search path, with later vocabularies taking precedence." }
-{ $errors "Throws an error if one of the vocabularies does not exist." }
-$parsing-note ;
-
-HELP: set-in
-{ $values { "name" string } }
-{ $description "Sets the current vocabulary where new words will be defined, creating the vocabulary first if it does not exist." }
-$parsing-note ;
+{ use in add-use (add-use) set-use set-in POSTPONE: USING: POSTPONE: USE: with-file-vocabs with-interactive-vocabs } related-words
 
 HELP: create-in
 { $values { "str" "a word name" } { "word" "a new word" } }
@@ -178,11 +140,6 @@ HELP: no-word
 { $values { "name" string } { "newword" word } }
 { $description "Throws a " { $link no-word-error } "." } ;
 
-HELP: search
-{ $values { "str" string } { "word/f" "a word or " { $link f } } }
-{ $description "Searches for a word by name in the current vocabulary search path. If no such word could be found, outputs " { $link f } "." }
-$parsing-note ;
-
 HELP: scan-word
 { $values { "word/number/f" "a word, number or " { $link f } } }
 { $description "Reads the next token from parser input. If the token is a valid number literal, it is converted to a number, otherwise the dictionary is searched for a word named by the token. Outputs " { $link f } " if the end of the input has been reached." }
index e944ecc6f29ed0a1963a03117b7388dc5f69231b..4474ed45c4a4c1939977c12bbbcb54a8507da88e 100644 (file)
@@ -4,7 +4,7 @@ sequences strings io.files io.pathnames definitions
 continuations sorting classes.tuple compiler.units debugger
 vocabs vocabs.loader accessors eval combinators lexer
 vocabs.parser words.symbol multiline source-files.errors
-tools.crossref ;
+tools.crossref grouping ;
 IN: parser.tests
 
 [
@@ -583,3 +583,41 @@ EXCLUDE: qualified.tests.bar => x ;
 
 [ t ] [ "is-not-deferred" "parser.tests" lookup >boolean ] unit-test
 [ t ] [ "is-not-deferred" "parser.tests" lookup deferred? ] unit-test
+
+! Forward-reference resolution case iterated using list in the wrong direction
+[ [ ] ] [
+    "IN: parser.tests.forward-ref-1 DEFER: x DEFER: y"
+    <string-reader> "forward-ref-1" parse-stream
+] unit-test
+
+[ [ ] ] [
+    "IN: parser.tests.forward-ref-2 DEFER: x DEFER: y"
+    <string-reader> "forward-ref-2" parse-stream
+] unit-test
+
+[ [ ] ] [
+    "IN: parser.tests.forward-ref-3 USING: parser.tests.forward-ref-1 parser.tests.forward-ref-2 ; : z ( -- ) x y ;"
+    <string-reader> "forward-ref-3" parse-stream
+] unit-test
+
+[ t ] [
+    "z" "parser.tests.forward-ref-3" lookup def>> [ vocabulary>> ] map all-equal?
+] unit-test
+
+[ [ ] ] [
+    "USING: parser.tests.forward-ref-1 parser.tests.forward-ref-2 ; IN: parser.tests.forward-ref-3 : x ( -- ) ; : z ( -- ) x y ;"
+    <string-reader> "forward-ref-3" parse-stream
+] unit-test
+
+[ f ] [
+    "z" "parser.tests.forward-ref-3" lookup def>> [ vocabulary>> ] map all-equal?
+] unit-test
+
+[ [ ] ] [
+    "IN: parser.tests.forward-ref-3 USING: parser.tests.forward-ref-1 parser.tests.forward-ref-2 ; : z ( -- ) x y ;"
+    <string-reader> "forward-ref-3" parse-stream
+] unit-test
+
+[ t ] [
+    "z" "parser.tests.forward-ref-3" lookup def>> [ vocabulary>> ] map all-equal?
+] unit-test
\ No newline at end of file
index 01e0b18887d3ef7d5a2cf4b1cb0b87988bbd58c0..d802fd72fa5656e5e7ae14a29a98acb4d1be618d 100644 (file)
@@ -55,7 +55,7 @@ SYMBOL: auto-use?
 : no-word-restarted ( restart-value -- word )
     dup word? [
         dup vocabulary>>
-        [ (use+) ]
+        [ (add-use) ]
         [ amended-use get dup [ push ] [ 2drop ] if ]
         [ "Added \"" "\" vocabulary to search path" surround note. ]
         tri
@@ -68,19 +68,6 @@ SYMBOL: auto-use?
     [ <no-word-error> throw-restarts no-word-restarted ]
     if ;
 
-: check-forward ( str word -- word/f )
-    dup forward-reference? [
-        drop
-        use get
-        [ at ] with map sift
-        [ forward-reference? not ] find nip
-    ] [
-        nip
-    ] if ;
-
-: search ( str -- word/f )
-    dup use get assoc-stack check-forward ;
-
 : scan-word ( -- word/number/f )
     scan dup [
         dup search [ ] [
index 7d710717aaa93b4939c9af1d0a773b900a0ece18..8d52a2c786bd7967e43f2872d961ee819ecc0562 100644 (file)
@@ -49,9 +49,9 @@ IN: bootstrap.syntax
         POSTPONE: PRIVATE> in get ".private" append set-in
     ] define-core-syntax
 
-    "USE:" [ scan use+ ] define-core-syntax
+    "USE:" [ scan add-use ] define-core-syntax
 
-    "USING:" [ ";" parse-tokens add-use ] define-core-syntax
+    "USING:" [ ";" parse-tokens [ add-use ] each ] define-core-syntax
 
     "QUALIFIED:" [ scan dup add-qualified ] define-core-syntax
 
index 71862402cdefaac3b58da02987ab8155582f6660..d61c9987251c5b527a823b32bdfa8a7858d4831c 100644 (file)
@@ -1,4 +1,4 @@
-USING: help.markup help.syntax parser ;
+USING: help.markup help.syntax parser strings words ;
 IN: vocabs.parser
 
 ARTICLE: "vocabulary-search-shadow" "Shadowing word names"
@@ -78,3 +78,40 @@ $nl
 { $see-also "words" } ;
 
 ABOUT: "vocabulary-search"
+
+HELP: use
+{ $var-description "A variable holding the current vocabulary search path as a sequence of assocs." } ;
+
+HELP: in
+{ $var-description "A variable holding the name of the current vocabulary for new definitions." } ;
+
+HELP: current-vocab
+{ $values { "str" "a vocabulary" } }
+{ $description "Returns the vocabulary stored in the " { $link in } " symbol. Throws an error if the current vocabulary is " { $link f } "." } ;
+
+HELP: (add-use)
+{ $values { "vocab" "an assoc mapping strings to words" } }
+{ $description "Adds an assoc at the front of the search path." }
+$parsing-note ;
+
+HELP: add-use
+{ $values { "vocab" string } }
+{ $description "Adds a new vocabulary at the front of the search path after loading it if necessary. Subsequent word lookups by the parser will search this vocabulary first." }
+$parsing-note
+{ $errors "Throws an error if the vocabulary does not exist." } ;
+
+HELP: set-use
+{ $values { "seq" "a sequence of strings" } }
+{ $description "Sets the vocabulary search path. Later vocabularies take precedence." }
+{ $errors "Throws an error if one of the vocabularies does not exist." }
+$parsing-note ;
+
+HELP: set-in
+{ $values { "name" string } }
+{ $description "Sets the current vocabulary where new words will be defined, creating the vocabulary first if it does not exist." }
+$parsing-note ;
+
+HELP: search
+{ $values { "str" string } { "word/f" { $maybe word } } }
+{ $description "Searches for a word by name in the current vocabulary search path. If no such word could be found, outputs " { $link f } "." }
+$parsing-note ;
index e8783c0dbe1655fcadf5d7a141659fbd8ee0a87b..d5978270dcd87db407f1f896a588ab3a55c1b4a4 100644 (file)
@@ -2,7 +2,7 @@
 ! Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: assocs hashtables kernel namespaces sequences
-sets strings vocabs sorting accessors arrays ;
+sets strings vocabs sorting accessors arrays compiler.units ;
 IN: vocabs.parser
 
 ERROR: no-word-error name ;
@@ -19,13 +19,11 @@ ERROR: no-word-error name ;
 SYMBOL: use
 SYMBOL: in
 
-: (use+) ( vocab -- )
+: (add-use) ( vocab -- )
     vocab-words use get push ;
 
-: use+ ( vocab -- )
-    load-vocab (use+) ;
-
-: add-use ( seq -- ) [ use+ ] each ;
+: add-use ( vocab -- )
+    load-vocab (add-use) ;
 
 : set-use ( seq -- )
     [ vocab-words ] V{ } map-as sift use set ;
@@ -35,15 +33,17 @@ SYMBOL: in
     [ swap [ prepend ] dip ] curry assoc-map
     use get push ;
 
-: partial-vocab ( words vocab -- assoc )
-    load-vocab vocab-words
+: words-named-in ( words assoc -- assoc' )
     [ dupd at [ no-word-error ] unless* ] curry { } map>assoc ;
 
+: partial-vocab-including ( words vocab -- assoc )
+    load-vocab vocab-words words-named-in ;
+
 : add-words-from ( words vocab -- )
-    partial-vocab use get push ;
+    partial-vocab-including use get push ;
 
 : partial-vocab-excluding ( words vocab -- assoc )
-    load-vocab [ vocab-words keys swap diff ] keep partial-vocab ;
+    load-vocab vocab-words [ nip ] [ words-named-in ] 2bi assoc-diff ;
 
 : add-words-excluding ( words vocab -- )
     partial-vocab-excluding use get push ;
@@ -56,4 +56,17 @@ SYMBOL: in
     dup string? [ "Vocabulary name must be a string" throw ] unless ;
 
 : set-in ( name -- )
-    check-vocab-string dup in set create-vocab (use+) ;
\ No newline at end of file
+    check-vocab-string dup in set create-vocab (add-use) ;
+
+: check-forward ( str word -- word/f )
+    dup forward-reference? [
+        drop
+        use get
+        [ at ] with map sift
+        [ forward-reference? not ] find-last nip
+    ] [
+        nip
+    ] if ;
+
+: search ( str -- word/f )
+    dup use get assoc-stack check-forward ;
\ No newline at end of file
index 3725086f70d7d8dc52a3c0847e0dda7a12f9c64c..a04b95bcfd6fe0c83de2b1a7e3bb2436868f6719 100644 (file)
@@ -237,7 +237,7 @@ HELP: set-word
 { $description "Sets the recently defined word." } ;
 
 HELP: lookup
-{ $values { "name" string } { "vocab" string } { "word" "a word or " { $link f } } }
+{ $values { "name" string } { "vocab" string } { "word" { $maybe word } } }
 { $description "Looks up a word in the dictionary. If the vocabulary or the word is not defined, outputs " { $link f } "." } ;
 
 HELP: reveal
index 3f7ce863c7023dee38a455ff0be2486c078d9b4c..9f0b6fc0a3c092d1fb3d013bfb74d6077c5a980c 100644 (file)
@@ -60,7 +60,7 @@ t fuel-eval-res-flag set-global
     [ print-error ] recover ;
 
 : (fuel-eval-usings) ( usings -- )
-    [ [ use+ ] curry [ drop ] recover ] each
+    [ [ add-use ] curry [ drop ] recover ] each
     fuel-forget-error fuel-forget-output ;
 
 : (fuel-eval-in) ( in -- )
index 2ff5f070c7b9b0889f3292207bd48c2b735adb21..f04b05acd8347c6715af8bfc07e06b1b237bb665 100644 (file)
@@ -9,7 +9,7 @@ IN: sandbox.syntax
 ERROR: sandbox-error vocab ;
 
 : sandbox-use+ ( alias -- )
-    dup whitelist get at [ use+ ] [ sandbox-error ] ?if ;
+    dup whitelist get at [ add-use ] [ sandbox-error ] ?if ;
 
 PRIVATE>