2008-09-03 20:43:36 -04:00
|
|
|
! Copyright (C) 2008 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: assocs io.files hashtables kernel namespaces sequences
|
|
|
|
vocabs.loader io combinators io.encodings.utf8 calendar accessors
|
|
|
|
math.parser io.streams.string ui.tools.operations quotations
|
2008-09-05 20:29:14 -04:00
|
|
|
strings arrays prettyprint words vocabs sorting sets
|
2008-09-24 20:05:03 -04:00
|
|
|
classes math alien urls splitting ascii ;
|
2008-09-03 20:43:36 -04:00
|
|
|
IN: tools.scaffold
|
|
|
|
|
|
|
|
SYMBOL: developer-name
|
2008-09-03 21:08:39 -04:00
|
|
|
SYMBOL: using
|
2008-09-03 20:43:36 -04:00
|
|
|
|
|
|
|
ERROR: not-a-vocab-root string ;
|
2008-09-04 02:29:46 -04:00
|
|
|
ERROR: vocab-name-contains-separator path ;
|
|
|
|
ERROR: vocab-name-contains-dot path ;
|
2008-09-04 02:34:01 -04:00
|
|
|
ERROR: no-vocab vocab ;
|
2008-09-03 20:43:36 -04:00
|
|
|
|
2008-09-04 02:50:26 -04:00
|
|
|
<PRIVATE
|
2008-10-21 22:03:37 -04:00
|
|
|
|
|
|
|
: root? ( string -- ? ) vocab-roots get member? ;
|
|
|
|
|
|
|
|
: length-changes? ( seq quot -- ? )
|
|
|
|
dupd call [ length ] bi@ = not ; inline
|
2008-09-03 20:43:36 -04:00
|
|
|
|
2008-09-03 21:30:38 -04:00
|
|
|
: check-vocab-name ( string -- string )
|
2008-10-21 22:03:37 -04:00
|
|
|
dup [ [ CHAR: . = ] trim ] length-changes?
|
|
|
|
[ vocab-name-contains-dot ] when
|
|
|
|
|
2008-09-03 20:43:36 -04:00
|
|
|
".." over subseq? [ vocab-name-contains-dot ] when
|
2008-10-21 22:03:37 -04:00
|
|
|
|
2008-09-03 20:43:36 -04:00
|
|
|
dup [ path-separator? ] contains?
|
|
|
|
[ vocab-name-contains-separator ] when ;
|
|
|
|
|
2008-09-03 21:30:38 -04:00
|
|
|
: check-root ( string -- string )
|
2008-09-03 20:43:36 -04:00
|
|
|
check-vocab-name
|
|
|
|
dup "resource:" head? [ "resource:" prepend ] unless
|
|
|
|
dup root? [ not-a-vocab-root ] unless ;
|
|
|
|
|
|
|
|
: directory-exists ( path -- )
|
|
|
|
"Not creating a directory, it already exists: " write print ;
|
|
|
|
|
|
|
|
: scaffold-directory ( path -- )
|
|
|
|
dup exists? [ directory-exists ] [ make-directories ] if ;
|
|
|
|
|
|
|
|
: not-scaffolding ( path -- )
|
|
|
|
"Not creating scaffolding for " write <pathname> . ;
|
|
|
|
|
|
|
|
: scaffolding ( path -- )
|
|
|
|
"Creating scaffolding for " write <pathname> . ;
|
|
|
|
|
2008-10-21 22:03:37 -04:00
|
|
|
: (scaffold-path) ( path string -- path )
|
|
|
|
dupd [ file-name ] dip append append-path ;
|
|
|
|
|
2008-09-03 21:30:38 -04:00
|
|
|
: scaffold-path ( path string -- path ? )
|
2008-10-21 22:03:37 -04:00
|
|
|
(scaffold-path)
|
2008-09-03 20:43:36 -04:00
|
|
|
dup exists? [ dup not-scaffolding f ] [ dup scaffolding t ] if ;
|
|
|
|
|
|
|
|
: scaffold-copyright ( -- )
|
|
|
|
"! Copyright (C) " write now year>> number>string write
|
|
|
|
developer-name get [ "Your name" ] unless* bl write "." print
|
|
|
|
"! See http://factorcode.org/license.txt for BSD license." print ;
|
|
|
|
|
2008-09-03 21:30:38 -04:00
|
|
|
: main-file-string ( vocab -- string )
|
2008-09-03 20:43:36 -04:00
|
|
|
[
|
|
|
|
scaffold-copyright
|
|
|
|
"USING: ;" print
|
|
|
|
"IN: " write print
|
|
|
|
] with-string-writer ;
|
|
|
|
|
|
|
|
: set-scaffold-main-file ( path vocab -- )
|
|
|
|
main-file-string swap utf8 set-file-contents ;
|
|
|
|
|
|
|
|
: scaffold-main ( path vocab -- )
|
|
|
|
[ ".factor" scaffold-path ] dip
|
|
|
|
swap [ set-scaffold-main-file ] [ 2drop ] if ;
|
|
|
|
|
2008-09-03 21:30:38 -04:00
|
|
|
: tests-file-string ( vocab -- string )
|
2008-09-03 20:43:36 -04:00
|
|
|
[
|
|
|
|
scaffold-copyright
|
|
|
|
"USING: tools.test " write dup write " ;" print
|
|
|
|
"IN: " write write ".tests" print
|
|
|
|
] with-string-writer ;
|
|
|
|
|
|
|
|
: set-scaffold-tests-file ( path vocab -- )
|
|
|
|
tests-file-string swap utf8 set-file-contents ;
|
|
|
|
|
|
|
|
: scaffold-tests ( path vocab -- )
|
|
|
|
[ "-tests.factor" scaffold-path ] dip
|
|
|
|
swap [ set-scaffold-tests-file ] [ 2drop ] if ;
|
|
|
|
|
|
|
|
: scaffold-authors ( path -- )
|
|
|
|
"authors.txt" append-path dup exists? [
|
|
|
|
not-scaffolding
|
|
|
|
] [
|
|
|
|
dup scaffolding
|
|
|
|
developer-name get swap utf8 set-file-contents
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
: lookup-type ( string -- object/string ? )
|
2008-09-24 20:05:03 -04:00
|
|
|
"new" ?head drop [ [ CHAR: ' = ] [ digit? ] bi or ] trim-right
|
2008-09-03 20:43:36 -04:00
|
|
|
H{
|
2008-09-03 21:30:38 -04:00
|
|
|
{ "object" object } { "obj" object }
|
2008-09-24 20:05:03 -04:00
|
|
|
{ "quot" quotation }
|
|
|
|
{ "string" string }
|
2008-09-03 20:43:36 -04:00
|
|
|
{ "str" string }
|
2008-09-03 21:30:38 -04:00
|
|
|
{ "hash" hashtable }
|
2008-09-03 20:43:36 -04:00
|
|
|
{ "hashtable" hashtable }
|
|
|
|
{ "?" "a boolean" }
|
|
|
|
{ "ch" "a character" }
|
2008-09-03 21:30:38 -04:00
|
|
|
{ "word" word }
|
|
|
|
{ "array" array }
|
2008-09-05 18:41:14 -04:00
|
|
|
{ "duration" duration }
|
2008-09-03 21:30:38 -04:00
|
|
|
{ "path" "a pathname string" }
|
|
|
|
{ "vocab" "a vocabulary specifier" }
|
|
|
|
{ "vocab-root" "a vocabulary root string" }
|
2008-09-05 18:41:14 -04:00
|
|
|
{ "c-ptr" c-ptr }
|
2008-09-24 20:05:03 -04:00
|
|
|
{ "seq" sequence }
|
|
|
|
{ "assoc" assoc }
|
2008-09-05 18:41:14 -04:00
|
|
|
{ "alist" "an array of key/value pairs" }
|
|
|
|
{ "keys" sequence } { "values" sequence }
|
2008-09-08 10:28:30 -04:00
|
|
|
{ "class" class } { "tuple" tuple }
|
2008-09-24 20:05:03 -04:00
|
|
|
{ "url" url }
|
2008-09-03 20:43:36 -04:00
|
|
|
} at* ;
|
|
|
|
|
2008-09-03 21:08:39 -04:00
|
|
|
: add-using ( object -- )
|
2008-09-04 02:29:46 -04:00
|
|
|
vocabulary>> using get [ conjoin ] [ drop ] if* ;
|
2008-09-03 21:08:39 -04:00
|
|
|
|
2008-09-03 20:43:36 -04:00
|
|
|
: ($values.) ( array -- )
|
|
|
|
[
|
|
|
|
" { " write
|
|
|
|
dup array? [ first ] when
|
|
|
|
dup lookup-type [
|
|
|
|
[ unparse write bl ]
|
2008-09-03 22:38:16 -04:00
|
|
|
[ [ pprint ] [ dup string? [ drop ] [ add-using ] if ] bi ] bi*
|
2008-09-03 20:43:36 -04:00
|
|
|
] [
|
2008-09-03 21:30:38 -04:00
|
|
|
drop unparse write bl null pprint
|
|
|
|
null add-using
|
2008-09-03 20:43:36 -04:00
|
|
|
] if
|
|
|
|
" }" write
|
|
|
|
] each ;
|
|
|
|
|
|
|
|
: $values. ( word -- )
|
|
|
|
"declared-effect" word-prop [
|
|
|
|
[ in>> ] [ out>> ] bi
|
2008-09-03 21:30:38 -04:00
|
|
|
2dup [ empty? ] bi@ and [
|
|
|
|
2drop
|
|
|
|
] [
|
|
|
|
"{ $values" print
|
|
|
|
[ " " write ($values.) ]
|
|
|
|
[ [ nl " " write ($values.) ] unless-empty ] bi*
|
2008-11-11 14:04:20 -05:00
|
|
|
nl "}" print
|
2008-09-03 21:30:38 -04:00
|
|
|
] if
|
2008-09-03 20:43:36 -04:00
|
|
|
] when* ;
|
|
|
|
|
|
|
|
: $description. ( word -- )
|
|
|
|
drop
|
2008-09-04 13:37:50 -04:00
|
|
|
"{ $description \"\" } ;" print ;
|
2008-09-03 20:43:36 -04:00
|
|
|
|
|
|
|
: help-header. ( word -- )
|
2008-09-24 20:05:03 -04:00
|
|
|
"HELP: " write name>> print ;
|
2008-09-03 20:43:36 -04:00
|
|
|
|
2008-09-04 03:03:04 -04:00
|
|
|
: (help.) ( word -- )
|
2008-09-03 20:43:36 -04:00
|
|
|
[ help-header. ] [ $values. ] [ $description. ] tri ;
|
|
|
|
|
2008-09-04 13:36:47 -04:00
|
|
|
: interesting-words ( vocab -- array )
|
|
|
|
words
|
|
|
|
[ [ "help" word-prop ] [ predicate? ] bi or not ] filter
|
|
|
|
natural-sort ;
|
|
|
|
|
|
|
|
: interesting-words. ( vocab -- )
|
|
|
|
interesting-words [ (help.) nl ] each ;
|
|
|
|
|
2008-09-24 20:05:03 -04:00
|
|
|
: help-file-string ( vocab -- str2 )
|
2008-09-03 20:43:36 -04:00
|
|
|
[
|
2008-09-05 20:29:14 -04:00
|
|
|
{
|
|
|
|
[ "IN: " write print nl ]
|
|
|
|
[ interesting-words. ]
|
2008-09-07 01:13:05 -04:00
|
|
|
[
|
|
|
|
[ "ARTICLE: " write unparse dup write bl print ]
|
|
|
|
[ "{ $vocab-link " write pprint " }" print ] bi
|
|
|
|
";" print nl
|
|
|
|
]
|
2008-09-05 20:29:14 -04:00
|
|
|
[ "ABOUT: " write unparse print ]
|
|
|
|
} cleave
|
2008-09-03 20:43:36 -04:00
|
|
|
] with-string-writer ;
|
|
|
|
|
2008-09-24 20:05:03 -04:00
|
|
|
: write-using ( vocab -- )
|
2008-09-03 21:08:39 -04:00
|
|
|
"USING:" write
|
|
|
|
using get keys
|
2008-09-24 20:05:03 -04:00
|
|
|
{ "help.markup" "help.syntax" } append natural-sort remove
|
2008-09-03 21:08:39 -04:00
|
|
|
[ bl write ] each
|
|
|
|
" ;" print ;
|
|
|
|
|
2008-09-03 20:43:36 -04:00
|
|
|
: set-scaffold-help-file ( path vocab -- )
|
2008-09-03 21:08:39 -04:00
|
|
|
swap utf8 <file-writer> [
|
2008-09-24 20:05:03 -04:00
|
|
|
scaffold-copyright
|
|
|
|
[ help-file-string ] [ write-using ] bi
|
|
|
|
write
|
2008-09-03 21:08:39 -04:00
|
|
|
] with-output-stream ;
|
2008-09-03 20:43:36 -04:00
|
|
|
|
2008-09-03 21:30:38 -04:00
|
|
|
: check-scaffold ( vocab-root string -- vocab-root string )
|
2008-09-03 20:43:36 -04:00
|
|
|
[ check-root ] [ check-vocab-name ] bi* ;
|
|
|
|
|
2008-09-03 21:30:38 -04:00
|
|
|
: vocab>scaffold-path ( vocab-root string -- path )
|
2008-09-03 20:43:36 -04:00
|
|
|
path-separator first CHAR: . associate substitute
|
|
|
|
append-path ;
|
|
|
|
|
2008-09-03 21:30:38 -04:00
|
|
|
: prepare-scaffold ( vocab-root string -- string path )
|
2008-09-03 20:43:36 -04:00
|
|
|
check-scaffold [ vocab>scaffold-path ] keep ;
|
|
|
|
|
2008-09-04 01:43:18 -04:00
|
|
|
: with-scaffold ( quot -- )
|
|
|
|
[ H{ } clone using ] dip with-variable ; inline
|
2008-09-04 02:34:01 -04:00
|
|
|
|
|
|
|
: check-vocab ( vocab -- vocab )
|
|
|
|
dup find-vocab-root [ no-vocab ] unless ;
|
2008-10-21 22:03:37 -04:00
|
|
|
|
2008-09-04 02:29:46 -04:00
|
|
|
PRIVATE>
|
2008-09-04 01:43:18 -04:00
|
|
|
|
2008-09-04 03:03:04 -04:00
|
|
|
: link-vocab ( vocab -- )
|
|
|
|
check-vocab
|
|
|
|
"Edit documentation: " write
|
2008-10-21 22:03:37 -04:00
|
|
|
[ find-vocab-root ]
|
|
|
|
[ vocab>scaffold-path ] bi
|
|
|
|
"-docs.factor" (scaffold-path) <pathname> . ;
|
2008-09-04 03:03:04 -04:00
|
|
|
|
|
|
|
: help. ( word -- )
|
|
|
|
[ (help.) ] [ nl vocabulary>> link-vocab ] bi ;
|
2008-09-04 02:34:01 -04:00
|
|
|
|
2008-10-01 18:52:54 -04:00
|
|
|
: scaffold-help ( string -- )
|
2008-09-04 01:43:18 -04:00
|
|
|
[
|
2008-10-01 18:52:54 -04:00
|
|
|
[ find-vocab-root ] [ check-vocab ] bi
|
2008-09-03 21:08:39 -04:00
|
|
|
prepare-scaffold
|
|
|
|
[ "-docs.factor" scaffold-path ] dip
|
|
|
|
swap [ set-scaffold-help-file ] [ 2drop ] if
|
2008-09-04 01:43:18 -04:00
|
|
|
] with-scaffold ;
|
|
|
|
|
|
|
|
: scaffold-undocumented ( string -- )
|
2008-09-04 13:36:47 -04:00
|
|
|
[ interesting-words. ] [ link-vocab ] bi ;
|
2008-09-03 20:43:36 -04:00
|
|
|
|
2008-09-03 21:30:38 -04:00
|
|
|
: scaffold-vocab ( vocab-root string -- )
|
2008-09-03 20:43:36 -04:00
|
|
|
prepare-scaffold
|
|
|
|
{
|
|
|
|
[ drop scaffold-directory ]
|
|
|
|
[ scaffold-main ]
|
|
|
|
[ scaffold-tests ]
|
|
|
|
[ drop scaffold-authors ]
|
2008-09-03 23:21:09 -04:00
|
|
|
[ nip require ]
|
2008-09-03 20:43:36 -04:00
|
|
|
} 2cleave ;
|
2008-09-05 18:41:14 -04:00
|
|
|
|
|
|
|
SYMBOL: examples-flag
|
|
|
|
|
|
|
|
: example ( -- )
|
|
|
|
{
|
|
|
|
"{ $example \"\" \"USING: prettyprint ;\""
|
|
|
|
" \"\""
|
|
|
|
" \"\""
|
|
|
|
"}"
|
|
|
|
} [ examples-flag get [ " " write ] when print ] each ;
|
|
|
|
|
|
|
|
: examples ( n -- )
|
|
|
|
t \ examples-flag [
|
|
|
|
"{ $examples " print
|
|
|
|
[ example ] times
|
|
|
|
"}" print
|
|
|
|
] with-variable ;
|
2008-11-13 15:27:28 -05:00
|
|
|
|
|
|
|
: scaffold-rc ( path -- )
|
|
|
|
[ touch-file ] [ "Click to edit: " write <pathname> . ] bi ;
|
|
|
|
|
|
|
|
: scaffold-factor-boot-rc ( -- )
|
|
|
|
home ".factor-boot-rc" append-path scaffold-rc ;
|
|
|
|
|
|
|
|
: scaffold-factor-rc ( -- )
|
|
|
|
home ".factor-rc" append-path scaffold-rc ;
|