Rename prettyprint:break to prettyprint:line-break
parent
1d8bd74d0f
commit
1ccca6cac0
|
@ -44,10 +44,10 @@ M: word pprint*
|
|||
dup parsing? [
|
||||
\ POSTPONE: [ pprint-word ] pprint-prefix
|
||||
] [
|
||||
dup "break-before" word-prop break
|
||||
dup "break-before" word-prop line-break
|
||||
dup pprint-word
|
||||
dup ?start-group dup ?end-group
|
||||
"break-after" word-prop break
|
||||
"break-after" word-prop line-break
|
||||
] if ;
|
||||
|
||||
M: real pprint* number>string text ;
|
||||
|
|
|
@ -72,7 +72,7 @@ $nl
|
|||
"Once the output sections have been generated, the tree of sections is traversed and intelligent decisions are made about indentation and line breaks. Finally, text is output."
|
||||
{ $subsection section }
|
||||
"Adding leaf sections:"
|
||||
{ $subsection break }
|
||||
{ $subsection line-break }
|
||||
{ $subsection text }
|
||||
{ $subsection styled-text }
|
||||
"Nesting and denesting sections:"
|
||||
|
|
|
@ -227,7 +227,7 @@ M: mixin-class see-class*
|
|||
\ MIXIN: pprint-word
|
||||
dup pprint-word <block
|
||||
dup members [
|
||||
hard break
|
||||
hard line-break
|
||||
\ INSTANCE: pprint-word pprint-word pprint-word
|
||||
] curry* each block> ;
|
||||
|
||||
|
|
|
@ -30,10 +30,10 @@ HELP: fresh-line
|
|||
{ $description "Advances the prettyprinter by one line unless the current line is empty. If the line limit is exceeded, escapes the prettyprinter by restoring a continuation captured in " { $link do-pprint } "." } ;
|
||||
|
||||
HELP: soft
|
||||
{ $description "Possible input parameter to " { $link break } "." } ;
|
||||
{ $description "Possible input parameter to " { $link line-break } "." } ;
|
||||
|
||||
HELP: hard
|
||||
{ $description "Possible input parameter to " { $link break } "." } ;
|
||||
{ $description "Possible input parameter to " { $link line-break } "." } ;
|
||||
|
||||
{ soft hard } related-words
|
||||
|
||||
|
@ -70,7 +70,7 @@ HELP: section
|
|||
{ $class-description "A piece of prettyprinter output. Instances of this class are not used directly, instead one instantiates various classes which delegate to this class:"
|
||||
{ $list
|
||||
{ $link text }
|
||||
{ $link break }
|
||||
{ $link line-break }
|
||||
{ $link block }
|
||||
{ $link inset }
|
||||
{ $link flow }
|
||||
|
@ -123,7 +123,7 @@ HELP: pprint-section
|
|||
{ $contract "Prints a section, performing wrapping and indentation using available formatting information." }
|
||||
$prettyprinting-note ;
|
||||
|
||||
HELP: break
|
||||
HELP: line-break
|
||||
{ $values { "type" { $link soft } " or " { $link hard } } }
|
||||
{ $description "Adds a section introducing a line break to the current block. If the block is output as a " { $link short-section } ", all breaks are ignored. Otherwise, hard breaks introduce unconditional newlines, and soft breaks introduce a newline if the position is more than half of the " { $link margin } "." }
|
||||
$prettyprinting-note ;
|
||||
|
@ -158,11 +158,11 @@ HELP: save-end-position
|
|||
|
||||
HELP: pprint-sections
|
||||
{ $values { "block" block } { "advancer" "a quotation with stack effect " { $snippet "( block -- )" } } }
|
||||
{ $description "Prints child sections of a block, ignoring any " { $link break } " sections. The " { $snippet "advancer" } " quotation is called between every pair of sections." } ;
|
||||
{ $description "Prints child sections of a block, ignoring any " { $link line-break } " sections. The " { $snippet "advancer" } " quotation is called between every pair of sections." } ;
|
||||
|
||||
HELP: do-break
|
||||
{ $values { "break" break } }
|
||||
{ $description "Prints a break section as per the policy outlined in " { $link break } "." } ;
|
||||
{ $values { "break" line-break } }
|
||||
{ $description "Prints a break section as per the policy outlined in " { $link line-break } "." } ;
|
||||
|
||||
HELP: empty-block?
|
||||
{ $values { "block" block } { "?" "a boolean" } }
|
||||
|
|
|
@ -124,15 +124,16 @@ M: object short-section? section-fits? ;
|
|||
] if ;
|
||||
|
||||
! Break section
|
||||
TUPLE: break type ;
|
||||
TUPLE: line-break type ;
|
||||
|
||||
: <break> ( type -- section )
|
||||
: <line-break> ( type -- section )
|
||||
H{ } 0 <section>
|
||||
{ set-break-type set-delegate } \ break construct ;
|
||||
{ set-line-break-type set-delegate }
|
||||
\ line-break construct ;
|
||||
|
||||
M: break short-section drop ;
|
||||
M: line-break short-section drop ;
|
||||
|
||||
M: break long-section drop ;
|
||||
M: line-break long-section drop ;
|
||||
|
||||
! Block sections
|
||||
TUPLE: block sections ;
|
||||
|
@ -149,7 +150,8 @@ TUPLE: block sections ;
|
|||
pprinter-block block-sections push ;
|
||||
|
||||
: last-section ( -- section )
|
||||
pprinter-block block-sections [ break? not ] find-last nip ;
|
||||
pprinter-block block-sections
|
||||
[ line-break? not ] find-last nip ;
|
||||
|
||||
: start-group ( -- )
|
||||
t last-section set-section-start-group? ;
|
||||
|
@ -162,13 +164,13 @@ TUPLE: block sections ;
|
|||
swap short-section? and
|
||||
[ bl ] when ;
|
||||
|
||||
: break ( type -- ) [ <break> add-section ] when* ;
|
||||
: line-break ( type -- ) [ <line-break> add-section ] when* ;
|
||||
|
||||
M: block section-fits? ( section -- ? )
|
||||
line-limit? [ drop t ] [ delegate section-fits? ] if ;
|
||||
|
||||
: pprint-sections ( block advancer -- )
|
||||
swap block-sections [ break? not ] subset
|
||||
swap block-sections [ line-break? not ] subset
|
||||
unclip pprint-section [
|
||||
dup rot call pprint-section
|
||||
] curry* each ; inline
|
||||
|
@ -177,7 +179,7 @@ M: block short-section ( block -- )
|
|||
[ advance ] pprint-sections ;
|
||||
|
||||
: do-break ( break -- )
|
||||
dup break-type hard eq?
|
||||
dup line-break-type hard eq?
|
||||
over section-end last-newline get - margin get 2/ > or
|
||||
[ <fresh-line ] [ drop ] if ;
|
||||
|
||||
|
@ -284,7 +286,7 @@ M: colon unindent-first-line? drop t ;
|
|||
|
||||
! Long section layout algorithm
|
||||
: chop-break ( seq -- seq )
|
||||
dup peek break? [ 1 head-slice* chop-break ] when ;
|
||||
dup peek line-break? [ 1 head-slice* chop-break ] when ;
|
||||
|
||||
SYMBOL: prev
|
||||
SYMBOL: next
|
||||
|
@ -322,7 +324,7 @@ M: block long-section ( block -- )
|
|||
[
|
||||
block-sections chop-break group-flow [
|
||||
dup ?break-group [
|
||||
dup break? [
|
||||
dup line-break? [
|
||||
do-break
|
||||
] [
|
||||
dup advance pprint-section
|
||||
|
|
Loading…
Reference in New Issue