prettyprint.stylesheet: USING/USE/IN are now dimmed out. Added documentation.

db4
Keith Lazuka 2009-09-09 15:27:49 -04:00
parent 28b8703b5b
commit 5421f4fcb4
3 changed files with 67 additions and 6 deletions

View File

@ -0,0 +1,44 @@
! Copyright (C) 2009 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel words ;
IN: prettyprint.stylesheet
HELP: effect-style
{ $values
{ "effect" "an effect" }
{ "style" "a style assoc" }
}
{ $description "The styling hook for stack effects" } ;
HELP: string-style
{ $values
{ "str" "a string" }
{ "style" "a style assoc" }
}
{ $description "The styling hook for string literals" } ;
HELP: vocab-style
{ $values
{ "vocab" "a vocabulary specifier" }
{ "style" "a style assoc" }
}
{ $description "The styling hook for vocab names" } ;
HELP: word-style
{ $values
{ "word" "a word" }
{ "style" "a style assoc" }
}
{ $description "The styling hook for word names" } ;
ARTICLE: "prettyprint.stylesheet" "Prettyprinter Formatted Output"
{ $vocab-link "prettyprint.stylesheet" }
$nl
"Control the way that the prettyprinter formats output based on object type. These hooks form a basic \"syntax\" highlighting system."
{ $subsection word-style }
{ $subsection string-style }
{ $subsection vocab-style }
{ $subsection effect-style }
;
ABOUT: "prettyprint.stylesheet"

View File

@ -1,16 +1,32 @@
! Copyright (C) 2009 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: colors.constants hashtables io.styles kernel namespaces
words words.symbol ;
USING: colors.constants combinators combinators.short-circuit
hashtables io.styles kernel namespaces sequences words
words.symbol ;
IN: prettyprint.stylesheet
<PRIVATE
CONSTANT: dim-color COLOR: cornsilk4
: dimly-lit-word? ( word -- ? )
{ POSTPONE: USING: POSTPONE: USE: POSTPONE: IN: } memq? ;
: parsing-word-color ( word -- color )
dimly-lit-word? dim-color COLOR: DarkSlateGray ? ;
PRIVATE>
: word-style ( word -- style )
dup "word-style" word-prop >hashtable [
[
[ presented set ] [
[ parsing-word? ] [ delimiter? ] [ symbol? ] tri
or or [ COLOR: DarkSlateGray ] [ COLOR: black ] if
foreground set
{
{ [ dup parsing-word? ] [ parsing-word-color ] }
{ [ dup delimiter? ] [ drop COLOR: DarkSlateGray ] }
{ [ dup symbol? ] [ drop COLOR: DarkSlateGray ] }
[ drop COLOR: black ]
} cond foreground set
] bi
] bind
] keep ;
@ -24,7 +40,7 @@ IN: prettyprint.stylesheet
: vocab-style ( vocab -- style )
[
presented set
COLOR: cornsilk4 foreground set
dim-color foreground set
] H{ } make-assoc ;
: effect-style ( effect -- style )

View File

@ -0,0 +1 @@
prettyprinter syntax highlighting and formatted output