Merge branch 'highlight' of git://github.com/mrjbq7/factor
commit
26838cce8e
|
@ -0,0 +1 @@
|
||||||
|
John Benediktsson
|
|
@ -0,0 +1,27 @@
|
||||||
|
! Copyright (C) 2011 John Benediktsson
|
||||||
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
|
USING: help.markup help.syntax sequences strings xmode.catalog
|
||||||
|
xmode.highlight xmode.tokens ;
|
||||||
|
|
||||||
|
IN: xmode.highlight
|
||||||
|
|
||||||
|
HELP: highlight-tokens
|
||||||
|
{ $values { "tokens" sequence } }
|
||||||
|
{ $description
|
||||||
|
"Highlight a sequence of " { $link token } " objects."
|
||||||
|
} ;
|
||||||
|
|
||||||
|
HELP: highlight-lines
|
||||||
|
{ $values { "lines" sequence } { "mode" string } }
|
||||||
|
{ $description
|
||||||
|
"Highlight lines of code, according to the specified " { $link mode }
|
||||||
|
"."
|
||||||
|
} ;
|
||||||
|
|
||||||
|
HELP: highlight.
|
||||||
|
{ $values { "path" string } }
|
||||||
|
{ $description
|
||||||
|
"Highlight and print code from the specified file (represented by "
|
||||||
|
{ $snippet "path" } "). The mode is determined using the file extension."
|
||||||
|
} ;
|
|
@ -0,0 +1,61 @@
|
||||||
|
! Copyright (C) 2011 John Benediktsson
|
||||||
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
|
USING: accessors assocs colors.hex io io.encodings.utf8 io.files
|
||||||
|
io.styles kernel locals math math.parser namespaces sequences
|
||||||
|
xmode.catalog xmode.marker ;
|
||||||
|
|
||||||
|
IN: xmode.highlight
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
CONSTANT: STYLES H{
|
||||||
|
{ "NULL" H{ { foreground HEXCOLOR: 000000 } } }
|
||||||
|
{ "COMMENT1" H{ { foreground HEXCOLOR: cc0000 } } }
|
||||||
|
{ "COMMENT2" H{ { foreground HEXCOLOR: ff8400 } } }
|
||||||
|
{ "COMMENT3" H{ { foreground HEXCOLOR: 6600cc } } }
|
||||||
|
{ "COMMENT4" H{ { foreground HEXCOLOR: cc6600 } } }
|
||||||
|
{ "DIGIT" H{ { foreground HEXCOLOR: ff0000 } } }
|
||||||
|
{ "FUNCTION" H{ { foreground HEXCOLOR: 9966ff } } }
|
||||||
|
{ "INVALID" H{ { background HEXCOLOR: ffffcc }
|
||||||
|
{ foreground HEXCOLOR: ff0066 } } }
|
||||||
|
{ "KEYWORD1" H{ { foreground HEXCOLOR: 006699 }
|
||||||
|
{ font-style bold } } }
|
||||||
|
{ "KEYWORD2" H{ { foreground HEXCOLOR: 009966 }
|
||||||
|
{ font-style bold } } }
|
||||||
|
{ "KEYWORD3" H{ { foreground HEXCOLOR: 0099ff }
|
||||||
|
{ font-style bold } } }
|
||||||
|
{ "KEYWORD4" H{ { foreground HEXCOLOR: 66ccff }
|
||||||
|
{ font-style bold } } }
|
||||||
|
{ "LABEL" H{ { foreground HEXCOLOR: 02b902 } } }
|
||||||
|
{ "LITERAL1" H{ { foreground HEXCOLOR: ff00cc } } }
|
||||||
|
{ "LITERAL2" H{ { foreground HEXCOLOR: cc00cc } } }
|
||||||
|
{ "LITERAL3" H{ { foreground HEXCOLOR: 9900cc } } }
|
||||||
|
{ "LITERAL4" H{ { foreground HEXCOLOR: 6600cc } } }
|
||||||
|
{ "MARKUP" H{ { foreground HEXCOLOR: 0000ff } } }
|
||||||
|
{ "OPERATOR" H{ { foreground HEXCOLOR: 000000 }
|
||||||
|
{ font-style bold } } }
|
||||||
|
}
|
||||||
|
|
||||||
|
CONSTANT: BASE H{
|
||||||
|
{ font-name "monospace" }
|
||||||
|
}
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: highlight-tokens ( tokens -- )
|
||||||
|
[
|
||||||
|
[ str>> ] [ id>> ] bi
|
||||||
|
[ name>> STYLES at ] [ f ] if* BASE assoc-union
|
||||||
|
format
|
||||||
|
] each nl ;
|
||||||
|
|
||||||
|
: highlight-lines ( lines mode -- )
|
||||||
|
[ f ] 2dip load-mode [
|
||||||
|
tokenize-line highlight-tokens
|
||||||
|
] curry each drop ;
|
||||||
|
|
||||||
|
:: highlight. ( path -- )
|
||||||
|
path utf8 file-lines [
|
||||||
|
path over first find-mode highlight-lines
|
||||||
|
] unless-empty ;
|
|
@ -0,0 +1 @@
|
||||||
|
Syntax highlighting tool
|
|
@ -46,8 +46,8 @@ set-file-lines
|
||||||
USING: sequences xml.syntax xml.writer ;
|
USING: sequences xml.syntax xml.writer ;
|
||||||
|
|
||||||
{ "three" "blind" "mice" }
|
{ "three" "blind" "mice" }
|
||||||
[ [XML <li><-></li> XML] ] map
|
[ [XML <li><-></li> XML] ] map
|
||||||
[XML <ul><-></ul> XML]
|
[XML <ul><-></ul> XML]
|
||||||
pprint-xml
|
pprint-xml
|
||||||
----
|
----
|
||||||
USING: inspector io.files.info io.pathnames system tools.files ;
|
USING: inspector io.files.info io.pathnames system tools.files ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<% USING: namespaces http.client kernel io.files splitting random io io.encodings.utf8 sequences
|
<% USING: namespaces http.client kernel io.files splitting random io io.encodings.utf8 sequences
|
||||||
webapps.mason.version.data webapps.mason.backend webapps.mason.grids webapps.mason.downloads
|
webapps.mason.version.data webapps.mason.backend webapps.mason.grids webapps.mason.downloads
|
||||||
webapps.mason.utils html.elements accessors
|
webapps.mason.utils html.elements html.streams accessors
|
||||||
xml.writer ; %>
|
xml.writer xmode.highlight ; %>
|
||||||
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
@ -45,12 +45,12 @@ xml.writer ; %>
|
||||||
|
|
||||||
<p>Factor belongs to the family of <em><a href="http://concatenative.org/wiki/view/Concatenative%20language">concatenative languages</a></em>: this means that, at the lowest level, a Factor program is a series of words (functions) that manipulate a stack of references to dynamically-typed values. This gives the language a powerful foundation which allows many abstractions and paradigms to be built on top. Reload this page to see a random code example below.</p>
|
<p>Factor belongs to the family of <em><a href="http://concatenative.org/wiki/view/Concatenative%20language">concatenative languages</a></em>: this means that, at the lowest level, a Factor program is a series of words (functions) that manipulate a stack of references to dynamically-typed values. This gives the language a powerful foundation which allows many abstractions and paradigms to be built on top. Reload this page to see a random code example below.</p>
|
||||||
|
|
||||||
<pre>
|
<pre><%
|
||||||
<%
|
|
||||||
"resource:extra/websites/factorcode/examples.txt" utf8 file-lines
|
"resource:extra/websites/factorcode/examples.txt" utf8 file-lines
|
||||||
{ "----" } split random "\n" join write
|
{ "----" } split random
|
||||||
%>
|
"factor" [ highlight-lines ] with-html-writer
|
||||||
</pre>
|
[ xml>string write ] each
|
||||||
|
%></pre>
|
||||||
|
|
||||||
<p>See the <a href="http://concatenative.org/wiki/view/Factor/Examples">example programs</a> page on the wiki for more.</p>
|
<p>See the <a href="http://concatenative.org/wiki/view/Factor/Examples">example programs</a> page on the wiki for more.</p>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue