diff --git a/core/lexer/lexer-docs.factor b/core/lexer/lexer-docs.factor index 363295adb4..01ed6828c2 100644 --- a/core/lexer/lexer-docs.factor +++ b/core/lexer/lexer-docs.factor @@ -57,14 +57,14 @@ HELP: parse-token { $values { "lexer" lexer } { "str/f" { $maybe string } } } { $description "Reads the next token from the lexer. Tokens are delimited by whitespace, with the exception that " { $snippet "\"" } " is treated like a single token even when not followed by whitespace." } ; -HELP: (scan-token) +HELP: ?scan-token { $values { "str/f" { $maybe string } } } { $description "Reads the next token from the lexer. Tokens are delimited by whitespace, with the exception that " { $snippet "\"" } " is treated like a single token even when not followed by whitespace. This word outputs " { $link f } " on end of input. To throw an error on end of input, use " { $link scan-token } " instead." } $parsing-note ; HELP: scan-token { $values { "str" string } } -{ $description "Reads the next token from the lexer. Tokens are delimited by whitespace, with the exception that " { $snippet "\"" } " is treated like a single token even when not followed by whitespace. This word throws " { $link unexpected-eof } " on end of input. To output " { $link f } " on end of input, use " { $link (scan-token) } " instead." } +{ $description "Reads the next token from the lexer. Tokens are delimited by whitespace, with the exception that " { $snippet "\"" } " is treated like a single token even when not followed by whitespace. This word throws " { $link unexpected-eof } " on end of input. To output " { $link f } " on end of input, use " { $link ?scan-token } " instead." } $parsing-note ; HELP: still-parsing? diff --git a/core/lexer/lexer.factor b/core/lexer/lexer.factor index c143eceab6..ffccd7694c 100644 --- a/core/lexer/lexer.factor +++ b/core/lexer/lexer.factor @@ -117,14 +117,14 @@ M: lexer skip-word [ (parse-token) ] [ dup next-line parse-token ] if ] [ drop f ] if ; -: (scan-token) ( -- str/f ) lexer get parse-token ; +: ?scan-token ( -- str/f ) lexer get parse-token ; PREDICATE: unexpected-eof < unexpected got>> not ; : throw-unexpected-eof ( word -- * ) f unexpected ; : scan-token ( -- str ) - (scan-token) [ "token" throw-unexpected-eof ] unless* ; + ?scan-token [ "token" throw-unexpected-eof ] unless* ; : expect ( token -- ) scan-token 2dup = [ 2drop ] [ unexpected ] if ; diff --git a/core/parser/parser-docs.factor b/core/parser/parser-docs.factor index 96a6ad642c..7df66997c9 100644 --- a/core/parser/parser-docs.factor +++ b/core/parser/parser-docs.factor @@ -18,8 +18,8 @@ ARTICLE: "reading-ahead" "Reading ahead" } "Parsing words that return " { $link f } " on end of file:" { $subsections - (scan-token) - (scan-datum) + ?scan-token + ?scan-datum } "A simple example is the " { $link POSTPONE: \ } " word:" { $see POSTPONE: \ } ; @@ -160,7 +160,7 @@ HELP: parse-datum { $values { "string" string } { "word/number" "a word or number" } } { $description "If " { $snippet "string" } " is a valid number literal, it is converted to a number, otherwise the current vocabulary search path is searched for a word named by the string." } { $errors "Throws an error if the token does not name a word, and does not parse as a number." } -{ $notes "This word is used to implement " { $link (scan-datum) } " and " { $link scan-datum } "." } ; +{ $notes "This word is used to implement " { $link ?scan-datum } " and " { $link scan-datum } "." } ; HELP: scan-word { $values { "word" "a word" } } @@ -176,25 +176,25 @@ HELP: scan-word-name { $errors "Throws an error if the scanned token is a number or upon finding end of file." } $parsing-note ; -HELP: (scan-datum) -{ $values { "word/number/f" "a word, a number, or " { $link f } } } +HELP: ?scan-datum +{ $values { "word/number/f" { $maybe word number } } } { $description "Reads the next token from parser input. If the token is found in the vocabulary search path, returns the word named by the token. If the token does not find a word, it is next converted to a number. If this conversion fails, too, this word returns " { $link f } "." } $parsing-note ; HELP: scan-datum -{ $values { "word/number" "a word or a number" } } +{ $values { "word/number" { $or word number } } } { $description "Reads the next token from parser input. If the token is found in the vocabulary search path, returns the word named be the token. If the token is not found in the vocabulary search path, it is converted to a number. If this conversion fails, an error is thrown." } { $errors "Throws an error if the token is not a number or end of file is reached." } $parsing-note ; HELP: scan-number -{ $values { "number" "a number" } } +{ $values { "number" number } } { $description "Reads the next token from parser input. If the token is a number literal, it is converted to a number. Otherwise, it throws an error." } { $errors "Throws an error if the token is not a number or end of file is reached." } $parsing-note ; HELP: parse-until-step -{ $values { "accum" vector } { "end" word } { "?" "a boolean" } } +{ $values { "accum" vector } { "end" word } { "?" boolean } } { $description "Parses a token. If the token is a number or an ordinary word, it is added to the accumulator. If it is a parsing word, calls the parsing word with the accumulator on the stack. Outputs " { $link f } " if " { $snippet "end" } " is encountered, " { $link t } " otherwise." } $parsing-note ; diff --git a/core/parser/parser.factor b/core/parser/parser.factor index bba9bfe543..9060fa1557 100644 --- a/core/parser/parser.factor +++ b/core/parser/parser.factor @@ -59,17 +59,17 @@ ERROR: number-expected ; dup string>number [ ] [ no-word ] ?if ] ?if ; -: (scan-datum) ( -- word/number/f ) - (scan-token) dup [ parse-datum ] when ; +: ?scan-datum ( -- word/number/f ) + ?scan-token dup [ parse-datum ] when ; : scan-datum ( -- word/number ) - (scan-datum) [ \ word throw-unexpected-eof ] unless* ; + ?scan-datum [ \ word throw-unexpected-eof ] unless* ; : scan-word ( -- word ) - (scan-token) parse-word ; + ?scan-token parse-word ; : scan-number ( -- number ) - (scan-token) parse-number ; + ?scan-token parse-number ; ERROR: invalid-word-name string ; @@ -105,7 +105,7 @@ ERROR: staging-violation word ; scan-object \ f or ; : parse-until-step ( accum end -- accum ? ) - (scan-datum) { + ?scan-datum { { [ 2dup eq? ] [ 2drop f ] } { [ dup not ] [ drop throw-unexpected-eof t ] } { [ dup delimiter? ] [ unexpected t ] }