diff --git a/extra/code-arrays/authors.txt b/extra/code-arrays/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/code-arrays/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/code-arrays/code-arrays-tests.factor b/extra/code-arrays/code-arrays-tests.factor new file mode 100644 index 0000000000..98adefe189 --- /dev/null +++ b/extra/code-arrays/code-arrays-tests.factor @@ -0,0 +1,13 @@ +! Copyright (C) 2011 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: code-arrays locals math tools.test ; +IN: code-arrays.tests + +[ { 1 2 9 } ] [ {{ 1 2 3 sq }} ] unit-test +[ { 1 2 { 9 } } ] [ {{ 1 2 {{ 3 sq }} }} ] unit-test + +[ H{ { 9 3 } { 4 1 } } ] [ H{{ {{ 3 sq 3 }} {{ 2 sq 1 }} }} ] unit-test + +:: local-code-arrays ( -- seq ) {{ 1 2 3 + }} ; + +[ { 1 5 } ] [ local-code-arrays ] unit-test diff --git a/extra/code-arrays/code-arrays.factor b/extra/code-arrays/code-arrays.factor new file mode 100644 index 0000000000..080f3b5424 --- /dev/null +++ b/extra/code-arrays/code-arrays.factor @@ -0,0 +1,25 @@ +! Copyright (C) 2011 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: combinators.smart hashtables kernel parser quotations +sequences vectors ; +IN: code-arrays + +: parse-code-array ( delimiter quot stack -- seq ) + [ parse-until >quotation ] dip curry append! ; + +DEFER: }} +DEFER: ]] + +SYNTAX: {{ \ }} [ output>array ] parse-code-array ; + +SYNTAX: [[ \ ]] [ [ ] output>sequence ] parse-code-array ; + +SYNTAX: H{{ \ }} [ output>array >hashtable ] parse-code-array ; + +SYNTAX: V{{ \ }} [ V{ } output>sequence ] parse-code-array ; + +: vector ( seq -- vector ) >vector ; + +: hashtable ( seq -- hashtable ) >hashtable ; + +: quotation ( seq -- vector ) >quotation ;