]> gitweb.factorcode.org Git - factor.git/commitdiff
parser: added helper word use-first-word? to simplify no-word
authorBjörn Lindqvist <bjourne@gmail.com>
Mon, 8 Jun 2015 04:57:23 +0000 (06:57 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Tue, 9 Jun 2015 11:02:03 +0000 (13:02 +0200)
core/parser/parser-docs.factor
core/parser/parser-tests.factor
core/parser/parser.factor

index b7366f154d0f4dfe8b525e829122943e4b90f3b6..a4820f53cd91d95693fc27910c227c861dde3645 100644 (file)
@@ -284,6 +284,10 @@ HELP: auto-use?
 { $var-description "If set to a true value, the behavior of the parser when encountering an unknown word name is changed. If only one loaded vocabulary has a word with this name, instead of throwing an error, the parser adds the vocabulary to the search path and prints a parse note. Off by default." }
 { $notes "This feature is intended to help during development. To generate a " { $link POSTPONE: USING: } " form automatically, enable " { $link auto-use? } ", load the source file, and copy and paste the " { $link POSTPONE: USING: } " form printed by the parser back into the file, then disable " { $link auto-use? } ". See " { $link "word-search-errors" } "." } ;
 
+HELP: use-first-word?
+{ $values { "words" sequence } { "?" boolean } }
+{ $description "Checks if the first word can be used automatically without first throwing a restartable " { $link no-word-error } } ;
+
 HELP: scan-object
 { $values { "object" object } }
 { $description "Parses a literal representation of an object." }
index d561d909e4a6016be84ad7bc8961553e012137ed..a8412da1b35e47d9c311823fab206e56d97765d9 100644 (file)
@@ -641,3 +641,9 @@ EXCLUDE: qualified.tests.bar => x ;
 
 [ "GENERIC: 33 ( -- )" <string-reader> "generic identifier test" parse-stream ]
 [ error>> lexer-error? ] must-fail-with
+
+{ t } [
+    t auto-use? [
+        { private? } use-first-word?
+    ] with-variable
+] unit-test
index eb2c3323204c3c55f235831497192f843e77b61d..5793cbf4dfe7027dee5820bfee4d4c13ae3ce7c0 100644 (file)
@@ -36,17 +36,17 @@ SYMBOL: auto-use?
 
 : private? ( word -- ? ) vocabulary>> ".private" tail? ;
 
+: use-first-word? ( words -- ? )
+    [ length 1 = ] [ ?first dup [ private? not ] [ ] ?if ] bi and
+    auto-use? get and ;
+
 ! True branch is a singleton public word with no name conflicts
 ! False branch, singleton private words need confirmation regardless
 ! of name conflicts
 : no-word ( name -- newword )
     dup words-named ignore-forwards
-    dup [ length 1 = ]
-    [ [ f ] [ first private? not ] if-empty ] bi and
-    auto-use? get and
-    [ nip first no-word-restarted ]
-    [ <no-word-error> throw-restarts no-word-restarted ]
-    if ;
+    dup use-first-word? [ nip first ] [ <no-word-error> throw-restarts ] if
+    no-word-restarted ;
 
 : parse-word ( string -- word )
     dup search [ ] [ no-word ] ?if ;