parser: new parsing word parse-array-def

The idea behind this word is that in many cases parsing to an array is
much more convenient than parsing to a quotation.
char-rename
Björn Lindqvist 2016-12-03 12:56:47 +01:00
parent 4d5b83c3f5
commit 1c53e43768
3 changed files with 16 additions and 3 deletions

View File

@ -1,5 +1,5 @@
USING: compiler.units definitions help.markup help.syntax kernel
lexer math namespaces quotations sequences source-files strings
USING: arrays compiler.units definitions help.markup help.syntax
kernel lexer math namespaces quotations sequences source-files strings
vectors vocabs vocabs.parser words words.symbol ;
IN: parser
@ -49,7 +49,7 @@ ARTICLE: "defining-words" "Defining words"
{ $subsections parse-definition }
"The " { $link POSTPONE: ; } " word is just a delimiter; an unpaired occurrence throws a parse error:"
{ $see POSTPONE: ; }
"There are additional parsing words whose syntax is delimited by " { $link POSTPONE: ; } ", and they are all implemented by calling " { $link parse-definition } "." ;
"There are additional parsing words whose syntax is delimited by " { $link POSTPONE: ; } ", and they are all implemented by calling " { $link parse-definition } " or " { $link parse-array-def } "." ;
ARTICLE: "parsing-tokens" "Parsing raw tokens"
"So far we have seen how to read individual tokens, or read a sequence of parsed objects until a delimiter. It is also possible to read raw tokens from the input and perform custom processing."
@ -231,6 +231,11 @@ HELP: parse-definition
{ $examples "This word is used to implement " { $link POSTPONE: : } "." }
$parsing-note ;
HELP: parse-array-def
{ $values { "array" "a new " { $link array } } }
{ $description "Like " { $link parse-definition } ", except the parsed sequence it outputted as an array." }
$parsing-note ;
HELP: bootstrap-syntax
{ $var-description "Only set during bootstrap. Stores a copy of the " { $link vocab-words-assoc } " of the host's syntax vocabulary; this allows the host's parsing words to be used during bootstrap source parsing, not the target's." } ;

View File

@ -645,3 +645,8 @@ EXCLUDE: qualified.tests.bar => x ;
{ private? } use-first-word?
] with-variable
] unit-test
! parse-array-def
{ { 10 20 30 } } [
{ "10 20 30 ;" } <lexer> [ parse-array-def ] with-lexer
] unit-test

View File

@ -147,6 +147,9 @@ M: f parse-quotation \ ] parse-until >quotation ;
: parse-definition ( -- quot )
\ ; parse-until >quotation ;
: parse-array-def ( -- array )
\ ; parse-until >array ;
ERROR: bad-number ;
: scan-base ( base -- n )