]> gitweb.factorcode.org Git - factor.git/commitdiff
Shorthand syntax for arrays-of-arrays, arrays-of-quotations, and hashtables
authorJoe Groff <arcata@gmail.com>
Fri, 4 Jul 2008 04:13:10 +0000 (21:13 -0700)
committerJoe Groff <arcata@gmail.com>
Fri, 4 Jul 2008 04:13:10 +0000 (21:13 -0700)
extra/arrays/nested-syntax/authors.txt [new file with mode: 0644]
extra/arrays/nested-syntax/nested-syntax-docs.factor [new file with mode: 0644]
extra/arrays/nested-syntax/nested-syntax-tests.factor [new file with mode: 0644]
extra/arrays/nested-syntax/nested-syntax.factor [new file with mode: 0644]
extra/arrays/nested-syntax/summary.txt [new file with mode: 0644]
extra/arrays/nested-syntax/tags.txt [new file with mode: 0644]

diff --git a/extra/arrays/nested-syntax/authors.txt b/extra/arrays/nested-syntax/authors.txt
new file mode 100644 (file)
index 0000000..f13c9c1
--- /dev/null
@@ -0,0 +1 @@
+Joe Groff
diff --git a/extra/arrays/nested-syntax/nested-syntax-docs.factor b/extra/arrays/nested-syntax/nested-syntax-docs.factor
new file mode 100644 (file)
index 0000000..7933aa0
--- /dev/null
@@ -0,0 +1,29 @@
+USING: help.markup help.syntax ;
+IN: arrays.nested-syntax
+
+HELP: {{
+{ $syntax "{{ zim zang ;; zoop ;; zidilly zam ;; ... }}" }
+{ $description "Shorthand for a literal array of arrays. Subarrays are separated by the " { $link POSTPONE: ;; } " token." }
+{ $examples "The following blocks of code push an equivalent array onto the stack:" { $example "{{ 1 ;; 2 3 ;; 4 5 6 }}" } { $example "{ { 1 } { 2 3 } { 4 5 6 } }" } } ;
+
+HELP: H{{
+{ $syntax "H{{ zim zang ;; zoop zidilly ;; zam zung ;; ... }}" }
+{ $description "Shorthand for a literal hashtable. Key-value pairs are separated by the " { $link POSTPONE: ;; } " token." }
+{ $examples "The following blocks of code push an equivalent hash table onto the stack:" { $example "H{{ \"Monday\" 1 ;; \"Tuesday\" 2 ;; \"Wednesday\" 3 ;; \"Thursday\" 4 }}" } { $example "H{ { \"Monday\" 1 } { \"Tuesday\" 2 } { \"Wednesday\" 3 } { \"Thursday\" 4 } }" } } ;
+
+HELP: [[
+{ $syntax "[[ foo ;; bar bas ;; qux quux quuuux ;; ... ]]" }
+{ $description "Shorthand for a literal array of quotations. Each quotation is separated by the " { $link POSTPONE: ;; } " token." }
+{ $examples "The following blocks of code are equivalent:" { $example "[[ 1+ ;; 2 + ]] cleave" } { $example "{ [ 1+ ] [ 2 + ] } cleave" } } ;
+
+{ POSTPONE: {{ POSTPONE: H{{ POSTPONE: [[ } related-words
+
+HELP: ;;
+{ $description "Separator token used in the " { $link POSTPONE: {{ } ", " { $link POSTPONE: H{{ } ", and " { $link POSTPONE: [[ } " literal syntaxes." } ;
+
+HELP: }}
+{ $description "Delimiter token used to close the " { $link POSTPONE: {{ } " and " { $link POSTPONE: H{{ } " literal syntaxes." } ;
+
+HELP: ]]
+{ $description "Delimiter token used to close the " { $link POSTPONE: [[ } " literal syntax." } ;
+
diff --git a/extra/arrays/nested-syntax/nested-syntax-tests.factor b/extra/arrays/nested-syntax/nested-syntax-tests.factor
new file mode 100644 (file)
index 0000000..a709840
--- /dev/null
@@ -0,0 +1,11 @@
+USING: arrays.nested-syntax kernel tools.test ;
+IN: arrays.nested-syntax.tests
+
+[ { { 1 } { 2 3 } { 4 5 6 } } ]
+[ {{ 1 ;; 2 3 ;; 4 5 6 }} ] unit-test
+
+[ H{ { "foo" 1 } { "bar" 2 } { "bas" 3 } } ]
+[ H{{ "foo" 1 ;; "bar" 2 ;; "bas" 3 }} ] unit-test
+
+[ { [ drop ] [ nip ] } ]
+[ [[ drop ;; nip ]] ] unit-test
diff --git a/extra/arrays/nested-syntax/nested-syntax.factor b/extra/arrays/nested-syntax/nested-syntax.factor
new file mode 100644 (file)
index 0000000..9fae0fb
--- /dev/null
@@ -0,0 +1,10 @@
+USING: arrays hashtables kernel parser quotations sequences splitting ;
+IN: arrays.nested-syntax
+
+: ;; ( -- * ) ";; can only be used in [[ ]] , {{ }} , or H{{ }} blocks" throw ;
+DEFER: ]] delimiter
+DEFER: }} delimiter
+
+: [[ \ ]] [ { POSTPONE: ;; } split [ >quotation ] map ] parse-literal ; parsing
+: {{ \ }} [ { POSTPONE: ;; } split [ >array ] map ] parse-literal ; parsing
+: H{{ \ }} [ { POSTPONE: ;; } split >hashtable ] parse-literal ; parsing
diff --git a/extra/arrays/nested-syntax/summary.txt b/extra/arrays/nested-syntax/summary.txt
new file mode 100644 (file)
index 0000000..a8d507f
--- /dev/null
@@ -0,0 +1 @@
+Shorthand syntax for defining arrays of quotations or arrays of arrays
diff --git a/extra/arrays/nested-syntax/tags.txt b/extra/arrays/nested-syntax/tags.txt
new file mode 100644 (file)
index 0000000..f427429
--- /dev/null
@@ -0,0 +1 @@
+extensions