parser: added helper word use-first-word? to simplify no-word

db4
Björn Lindqvist 2015-06-08 06:57:23 +02:00
parent d68175f48f
commit 4d47b826bf
3 changed files with 16 additions and 6 deletions

View 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." }

View 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

View 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 ;