modern.out: Deal with ARITY: words.

locals-and-roots
Doug Coleman 2016-06-27 19:59:11 -07:00
parent 7ac0b9c254
commit 44de5f8b6a
1 changed files with 49 additions and 7 deletions

View File

@ -1,11 +1,11 @@
! Copyright (C) 2016 Doug Coleman. ! Copyright (C) 2016 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators combinators.short-circuit USING: accessors arrays assocs combinators
combinators.smart continuations fry io io.encodings.utf8 combinators.short-circuit combinators.smart continuations fry io
io.files io.streams.string kernel modern modern.paths io.encodings.utf8 io.files io.streams.string kernel math modern
modern.slices namespaces prettyprint sequences modern.paths modern.refactor modern.slices namespaces
sequences.extras sets splitting splitting.monotonic strings prettyprint sequences sequences.extras sets splitting
unicode math ; splitting.monotonic strings unicode ;
IN: modern.out IN: modern.out
SYMBOL: last-slice SYMBOL: last-slice
@ -24,6 +24,29 @@ SYMBOL: last-slice
length modify-from io:write length modify-from io:write
] [ drop last-slice namespaces:set ] 2bi ; ] [ drop last-slice namespaces:set ] 2bi ;
CONSTANT: janky-arities H{
`DEFER 1 --
`FORGET 1 --
`IN 1 --
`USE 1 --
`UNUSE 1 --
`SYMBOL 1 --
`SINGLETON 1 --
`B 1 --
`MAIN 1 --
`LEFT-DECORATOR 1 --
`ALIAS 2 --
`ARITY 2 --
`C 2 --
`CONSTANT 2 --
`INSTANCE 2 --
`GENERIC 2 --
`PRIMITIVE 2 --
`GENERIC# 3 --
`HOOK 3
} ;
DEFER: write-literal DEFER: write-literal
GENERIC: write-literal ( obj -- ) ; GENERIC: write-literal ( obj -- ) ;
@ -215,9 +238,28 @@ M: compound-sequence-literal write-literal
$[ [ path>literals [ _ map-literals ] map ] [ ] bi write-modern-path ] $[ [ path>literals [ _ map-literals ] map ] [ ] bi write-modern-path ]
[ drop . ] recover ; inline [ drop . ] recover ; inline
GENERIC: split-arity ( obj -- seq ) ;
M: uppercase-colon-literal split-arity
dup { [ uppercase-colon-literal? ] [ tag>> janky-arities at ] } 1&& [
dup tag>> janky-arities at
$[ _ swap [ any-comment? not ] cut-nth-match swap ] change-payload
swap 2array
dup first f >>closing-tag drop
! dup first " ;" >>closing-tag drop
] when ;
M: less-than-literal split-arity
[ [ split-arity ] map ] change-payload ;
M: object split-arity ;
: rewrite-string ( string quot -- ) : rewrite-string ( string quot -- )
! dup print ! dup print
[ string>literals ] dip $[ _ map-literals ] map write-modern-string ; inline [ string>literals ] dip $[ _ map-literals ] map
! colons
[ split-arity ] map
write-modern-string ; inline
: rewrite-paths ( seq quot -- ) $[ _ rewrite-path ] each ; inline : rewrite-paths ( seq quot -- ) $[ _ rewrite-path ] each ; inline