1 ! Copyright (C) 2011 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: accessors assocs colors io io.encodings.utf8 io.files
5 io.pathnames io.streams.string io.styles kernel locals see
6 sequences splitting strings vocabs vocabs.loader words
7 xmode.catalog xmode.marker ;
14 { "NULL" H{ { foreground COLOR: #000000 } } }
15 { "COMMENT1" H{ { foreground COLOR: #cc0000 } } }
16 { "COMMENT2" H{ { foreground COLOR: #ff8400 } } }
17 { "COMMENT3" H{ { foreground COLOR: #6600cc } } }
18 { "COMMENT4" H{ { foreground COLOR: #cc6600 } } }
19 { "DIGIT" H{ { foreground COLOR: #ff0000 } } }
20 { "FUNCTION" H{ { foreground COLOR: #9966ff } } }
21 { "INVALID" H{ { background COLOR: #ffffcc }
22 { foreground COLOR: #ff0066 } } }
23 { "KEYWORD1" H{ { foreground COLOR: #006699 }
24 { font-style bold } } }
25 { "KEYWORD2" H{ { foreground COLOR: #009966 }
26 { font-style bold } } }
27 { "KEYWORD3" H{ { foreground COLOR: #0099ff }
28 { font-style bold } } }
29 { "KEYWORD4" H{ { foreground COLOR: #66ccff }
30 { font-style bold } } }
31 { "LABEL" H{ { foreground COLOR: #02b902 } } }
32 { "LITERAL1" H{ { foreground COLOR: #ff00cc } } }
33 { "LITERAL2" H{ { foreground COLOR: #cc00cc } } }
34 { "LITERAL3" H{ { foreground COLOR: #9900cc } } }
35 { "LITERAL4" H{ { foreground COLOR: #6600cc } } }
36 { "MARKUP" H{ { foreground COLOR: #0000ff } } }
37 { "OPERATOR" H{ { foreground COLOR: #000000 }
38 { font-style bold } } }
42 { font-name "monospace" }
47 : highlight-tokens ( tokens -- )
50 [ name>> STYLES at BASE assoc-union ] [ BASE ] if*
54 : highlight-lines ( lines mode -- )
55 [ f ] 2dip load-mode [
56 tokenize-line highlight-tokens
59 GENERIC: highlight. ( obj -- )
61 M:: string highlight. ( path -- )
62 path utf8 file-lines [
63 path over first find-mode highlight-lines
66 M: pathname highlight.
70 vocab-source-path highlight. ;
73 [ see ] with-string-writer split-lines
74 "factor" highlight-lines ;