]> gitweb.factorcode.org Git - factor.git/commitdiff
parser: new parsing word parse-array-def
authorBjörn Lindqvist <bjourne@gmail.com>
Sat, 3 Dec 2016 11:56:47 +0000 (12:56 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Sat, 3 Dec 2016 11:56:47 +0000 (12:56 +0100)
The idea behind this word is that in many cases parsing to an array is
much more convenient than parsing to a quotation.

core/parser/parser-docs.factor
core/parser/parser-tests.factor
core/parser/parser.factor

index f2e348e41400ec5b55c42557ef154c9ee9dde76b..32d6c8c04f9e473935d3cc327b9407f8c5b1658a 100644 (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." } ;
 
index 8f0d78b0239780fcb79921f8e723e683b61a023d..ad9052af42d155361a865886f4641df5c88c7750 100644 (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
index 9369bbc17eb10420344671b8084542cd0311b62b..2e7540c0c677ea898353b6fc019cb1e1f36eaeb5 100644 (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 )