Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki

This commit is contained in:
Jacques Distler 2009-12-24 00:52:39 -06:00
commit e6673c4cee
11 changed files with 627 additions and 58 deletions

View file

@ -21,8 +21,10 @@
color: #<%= @web ? @web.color : "393" %>;
}
<%= Rails.root.join('public', 'stylesheets', 'instiki.css').read if @inline_style %>
<%= Rails.root.join('public', 'stylesheets', 'syntax.css').read if @inline_style %>
</style>
<%= stylesheet_link_tag 'instiki', :media => 'all' unless @inline_style %>
<%= stylesheet_link_tag 'syntax', :media => 'all' unless @inline_style %>
<%= "<style type='text/css'>#{@style_additions}</style>" if @style_additions %>
<style type="text/css"><!--/*--><![CDATA[/*><!--*/
<%= @web ? @web.additional_style : '' %>

View file

@ -13,6 +13,7 @@
<meta name="defaultView" content="slideshow" />
<meta name="controlVis" content="hidden" />
<!-- style sheet links -->
<%= stylesheet_link_tag "/stylesheets/syntax.css", :media => 'all', :id => 'syntaxStyle' %>
<%= stylesheet_link_tag "/s5/ui/core/outline.css", :media => 'screen', :id => 'outlineStyle' %>
<%= stylesheet_link_tag "/s5/ui/core/print.css", :media => 'print', :id => 'slidePrint' %>
<%= stylesheet_link_tag "/s5/ui/core/opera.css", :media => 'projection', :id => 'operaFix' %>
@ -20,8 +21,8 @@
<%= stylesheet_link_tag "/s5/themes/#{@s5_theme}/slides.css", :media => 'projection', :id => 'slideProj' %>
<!-- S5 JS -->
<%= javascript_include_tag "/s5/ui/core/slides.js" %>
<%= javascript_include_tag 'prototype' %>
<%= javascript_include_tag "/s5/ui/core/slides.js" %>
</head>
<body>

View file

@ -102,4 +102,11 @@ li:after {content:" [" attr(class) "]";color:#F88}
*/
pre.ruby span.ident { color: #AAF; }
pre.ruby span.punct { color: #9C8CFF; }
pre.xml .punct { color: #8DF; font-weight: bold; }
pre.yaml span.punct { color: #99F; font-weight: bold; }
pre.ansic span.other, pre.ansic span.ident { color: #FFF; }
pre.sqlite span.other, pre.sqlite span.ident { color: #FFF; }
pre.javascript span.ident { color: #FFF; }
pre.javascript .other { color: #F0F; }
pre.css21 span.ident { color: #FFF; }
pre.javascript span.comment { color: #88F; }
pre.xml span.punct { color: #8DF; font-weight: bold; }

View file

@ -97,4 +97,7 @@ li:after {content:" [" attr(class) "]";color:#F88}
*/
pre.ruby span.ident { color: #229; }
pre.ruby span.punct { color: #4838AB; }
pre.yaml .key { color: #833; }
pre.ansic .preprocessor { color: #808; }
pre.javascript .other { color: #F0F; }
pre.xml .punct { color: #059; font-weight: bold; }

View file

@ -41,34 +41,6 @@ span.theorem_label {font-style:normal; font-weight:bold;}
.num_note .theorem_label:after {
content: " " counter(note); counter-increment: note;}
pre.ruby .normal {}
pre.ruby span.attribute { color: #090; }
pre.ruby span.char { color: #F00; }
pre.ruby span.class { color: #A020F0; font-weight: bold; }
pre.ruby span.comment { color: #00F; }
pre.ruby span.constant { color: #008B8B; }
pre.ruby span.escape { color: #6A5ACD; }
pre.ruby span.expr { color: #22C; }
pre.ruby span.global { color: #1A4; }
pre.ruby span.ident { color: #004; }
pre.ruby span.keyword { color: #A52A2A; font-weight: bold; }
pre.ruby span.method { color: #008B8B; }
pre.ruby span.module { color: #A020F0; font-weight: bold; }
pre.ruby span.number { color: #D0D; }
pre.ruby span.punct { color: #6A5ACD; }
pre.ruby span.regex { color: #D0D; }
pre.ruby span.string { color: #D0D; }
pre.ruby span.symbol { color: #008B8B; }
pre.xml .normal {}
pre.xml .namespace { color: #D66; font-weight: bold; }
pre.xml .tag { color: #F55; }
pre.xml .comment { color: #070; font-style: italic; }
pre.xml .punct { color: #449; font-weight: bold; }
pre.xml .string { color: #949; }
pre.xml .number { color: #F99; }
pre.xml .attribute { color: #771; }
/* Hack for Mozilla bug 449396 */
[mathvariant="bold"] * {
font-style: normal;

View file

@ -459,34 +459,6 @@ span.theorem_label {font-style:normal; font-weight:bold;}
.num_note .theorem_label:after {
content: " " counter(note); counter-increment: note;}
pre.ruby .normal {}
pre.ruby span.attribute { color: #090; }
pre.ruby span.char { color: #F00; }
pre.ruby span.class { color: #A020F0; font-weight: bold; }
pre.ruby span.comment { color: #00F; }
pre.ruby span.constant { color: #008B8B; }
pre.ruby span.escape { color: #6A5ACD; }
pre.ruby span.expr { color: #22C; }
pre.ruby span.global { color: #1A4; }
pre.ruby span.ident { color: #004; }
pre.ruby span.keyword { color: #A52A2A; font-weight: bold; }
pre.ruby span.method { color: #008B8B; }
pre.ruby span.module { color: #A020F0; font-weight: bold; }
pre.ruby span.number { color: #D0D; }
pre.ruby span.punct { color: #6A5ACD; }
pre.ruby span.regex { color: #D0D; }
pre.ruby span.string { color: #D0D; }
pre.ruby span.symbol { color: #008B8B; }
pre.xml .normal {}
pre.xml .namespace { color: #D66; font-weight: bold; }
pre.xml .tag { color: #F55; }
pre.xml .comment { color: #070; font-style: italic; }
pre.xml .punct { color: #449; font-weight: bold; }
pre.xml .string { color: #949; }
pre.xml .number { color: #F99; }
pre.xml .attribute { color: #771; }
/* Hack for Mozilla bug 449396 */
[mathvariant="bold"] * {
font-style: normal;

View file

@ -0,0 +1,110 @@
pre.ansic .normal {}
pre.ansic .comment { color: #00F; }
pre.ansic .keyword { color: #A00; }
pre.ansic .predefined_types { color: #DD0000; }
pre.ansic .char { color: #F07; }
pre.ansic .ident { color: #004; }
pre.ansic .hex { color: #F99; }
pre.ansic .oct { color: #F99; }
pre.ansic .integer { color: #F99; }
pre.ansic .float { color: #F99; }
pre.ansic .string { color: #494; }
pre.ansic .preprocessor { color: #FF00FF; }
pre.ansic .other { color: black; }
pre.css21 .normal {}
pre.css21 .comment { color: #888; }
pre.css21 .cdo { color: #666; }
pre.css21 .cdc { color: #666; }
pre.css21 .string { color: #494; }
pre.css21 .invalid { color: #FF0000; }
pre.css21 .keyword { color: #BB0000; }
pre.css21 .property { color: #ff4500; }
pre.css21 .ident { color: #000080; }
pre.css21 .id { color: #0000FF; }
pre.css21 .important { color: #EE0000; background: #ffd700;}
/* @ keywords */
pre.css21 .import { color: #A0A; }
pre.css21 .page { color: #A0A; }
pre.css21 .media { color: #A0A; }
pre.css21 .charset { color: #A0A; }
pre.css21 .uri { color: #7BB; }
pre.css21 .function { color: #077; }
/* numbers */
pre.css21 .hash { color: #07F; }
pre.css21 .ems { color: #07F; }
pre.css21 .exs { color: #07F; }
pre.css21 .length { color: #07F; }
pre.css21 .angle { color: #07F; }
pre.css21 .time { color: #07F; }
pre.css21 .freq { color: #07F; }
pre.css21 .dimension { color: #07F; }
pre.css21 .percentage { color: #07F; }
pre.css21 .number { color: #07F; }
/* html 4.01 tags */
pre.css21 .tag { color: #008000; }
pre.javascript .normal {}
pre.javascript .comment { color: #00A; }
pre.javascript .keyword { color: #A00; }
pre.javascript .predefined_types { color: #DD0000; }
pre.javascript .char { color: #F07; }
pre.javascript .ident { color: #004; }
pre.javascript .hex { color: #F99; }
pre.javascript .oct { color: #F99; }
pre.javascript .integer { color: #F99; }
pre.javascript .float { color: #F99; }
pre.javascript .unicode { color: #F99; }
pre.javascript .string { color: #494;}
pre.javascript .other { color: #808; }
pre.sqlite .normal {}
pre.sqlite .comment { color: #33F; }
pre.sqlite .function { color: #077; }
pre.sqlite .keyword { color: #A00; }
pre.sqlite .operator { color: #0A0; }
pre.sqlite .datatype { color: #DD0000; }
pre.sqlite .ident { color: #004; }
pre.sqlite .string { color: #A4A; }
pre.sqlite .other { color: black; }
pre.yaml .normal {}
pre.yaml .document { font-weight: bold; color: #07F; }
pre.yaml .type { font-weight: bold; color: #05C; }
pre.yaml .key { color: #F88; }
pre.yaml .comment { color: #005; font-style: italic; }
pre.yaml .punct { color: #447; font-weight: bold; }
pre.yaml .string { color: #944; }
pre.yaml .number { color: #F99; }
pre.yaml .time { color: #F99; }
pre.yaml .date { color: #F99; }
pre.yaml .ref { color: #944; }
pre.yaml .anchor { color: #944; }
pre.ruby .normal {}
pre.ruby span.attribute { color: #090; }
pre.ruby span.char { color: #F00; }
pre.ruby span.class { color: #A020F0; font-weight: bold; }
pre.ruby span.comment { color: #00F; }
pre.ruby span.constant { color: #008B8B; }
pre.ruby span.escape { color: #6A5ACD; }
pre.ruby span.expr { color: #22C; }
pre.ruby span.global { color: #1A4; }
pre.ruby span.ident { color: #004; }
pre.ruby span.keyword { color: #A52A2A; font-weight: bold; }
pre.ruby span.method { color: #008B8B; }
pre.ruby span.module { color: #A020F0; font-weight: bold; }
pre.ruby span.number { color: #D0D; }
pre.ruby span.punct { color: #6A5ACD; }
pre.ruby span.regex { color: #D0D; }
pre.ruby span.string { color: #D0D; }
pre.ruby span.symbol { color: #008B8B; }
pre.xml .normal {}
pre.xml .namespace { color: #D66; font-weight: bold; }
pre.xml .tag { color: #F55; }
pre.xml .comment { color: #070; font-style: italic; }
pre.xml .punct { color: #449; font-weight: bold; }
pre.xml .string { color: #949; }
pre.xml .number { color: #F99; }
pre.xml .attribute { color: #771; }

View file

@ -0,0 +1,69 @@
require 'syntax'
module Syntax
class AnsiC < Tokenizer
def self.add_type(name)
ANSIC_PREDEFINED_TYPES << name
end
ANSIC_KEYWORDS =
%w{asm break case continue default do else for goto if return
switch while struct union enum typedef static register
auto extern sizeof volatile const inline restrict} unless const_defined?(:ANSIC_KEYWORDS)
ANSIC_PREDEFINED_TYPES =
%w{int long short char void signed unsigned
float double bool complex} unless const_defined?(:ANSIC_PREDEFINED_TYPES)
ANSIC_PREDEFINED_CONSTANTS =
%w{EOF NULL true false} unless const_defined?(:ANSIC_PREDEFINED_CONSTANTS)
ANSIC_ESCAPE = / [rbfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x unless const_defined?(:ANSIC_ESCAPE)
def step
case
when scan(/\s+/)
start_group :normal, matched
when match = scan(/#\s*(\w*)/)
match << scan_until(/\n/)
start_group :preprocessor, match
when scan(/ L?' (?: [^\'\n\\] | \\ #{ANSIC_ESCAPE} )? '? /ox)
start_group :char, matched
when scan(/0[xX][0-9A-Fa-f]+/)
start_group :hex, matched
when scan(/(?:0[0-7]+)(?![89.eEfF])/)
start_group :oct, matched
when scan(/(?:\d+)(?![.eEfF])/)
start_group :integer, matched
when scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
start_group :float, matched
when scan(/"(?:[^"\\]|\\.)*"/)
start_group :string, matched
when scan( %r{ ('(?: . | [\t\b\n] )') }x )
start_group :char, matched
when scan(/[a-z_][a-z_\d]+/)
if ANSIC_KEYWORDS.include?( matched )
start_group :keyword, matched
elsif ANSIC_PREDEFINED_TYPES.include?( matched )
start_group :predefined_types, matched
else
start_group :ident, matched
end
when scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
start_group :comment, matched
else
start_group :other, scan(/./x)
end
end
end
SYNTAX["ansic"] = AnsiC
end

View file

@ -0,0 +1,298 @@
require 'syntax'
module Syntax
class CSS21 < Tokenizer
CSS21_PROPERTIES = %w{font-family font-style font-variant font-weight
font-size font background-color background-image
background-repeat background-attachment background-position
color background word-spacing letter-spacing
border-top-width border-right-width border-left-width
border-bottom-width border-width list-style-type
list-style-image list-style-position text-decoration
vertical-align text-transform text-align text-indent
line-height margin-top margin-right margin-bottom
margin-left margin padding-top padding-right padding-bottom
padding-left padding border-top border-right border-bottom
border-left border width height float clear display
list-style white-space border-style border-color
azimuth border-bottom-color border-bottom-style
border-collapse border-left-color border-left-style
border-right-color border-right-style border-top-color
border-top-style caption-side cell-spacing clip column-span
content cue cue-after cue-before cursor direction
elevation font-size-adjust marks max-height max-width
min-height min-width orphans overflow page-break-after
page-break-before pause pause-after pause-before pitch
pitch-range play-during position richness right row-span
size speak speak-date speak-header speak-punctuation
speak-time speech-rate stress table-layout text-shadow top
visibility voice-family volume
widows z-index quotes
marker-offset outline outline-color outline-style outline-width
border-spacing border-collapse
page-break-before page-break-after page-break-inside
orphans widows} unless const_defined?(:CSS21_PROPERTIES)
CSS21_KEYWORDS = %w{maroon red orange yellow olive purple
fuchsia white lime green navy blue aqua teal black silver gray
scroll fixed transparent none top center bottom
left right repeat repeat-x repeat-y no-repeat
thin medium thick dotted dashed solid double groove ridge
inset outset both block inline list-item
xx-small x-small small medium large x-large xx-large
smaller italic oblique small-caps bold bolder lighter auto
disc circle square decimal lower-roman upper-roman lower-alpha
upper-alpha inside outside justify underline overline line-through
blink capitalize uppercase lowercase baseline sub super
top text-top middle bottom text-bottom pre nowrap
compact run-in inherit caption icon menu message-box small-caption
status-bar marker
table inline-table table-column-group table-column
table-row-group table-row table-cell table-caption
table-header-group table-footer-group
screen print projection braille embosed aural tv
tty handheld cross hidden open-quote close-quote
absolute relative normal collapse
serif sans-serif monospace cursive
fantasy, always} unless const_defined?(:CSS21_KEYWORDS)
HTML401_TAGS = %w{a abbr acronym address area b base bdo
big blockquote body br button caption cite code
col colgroup dd del dfn div dl DOCTYPE
dt em fieldset form h1 h2 h3 h4 h5 h6 head html hr
i img input ins kbd label legend li
link visited hover before after
map meta noscript object ol optgroup option
p param pre q samp script select small
span strong style sub sup table tbody td
textarea tfoot th thead title tr tt ul
var} unless const_defined?(:HTML401_TAGS)
def setup
@selector = true
@macros = {}
@tokens = {}
# http://www.w3.org/TR/CSS21/syndata.html
macro(:h, /([0-9a-fA-F])/ ) # uppercase A-Z added?
macro(:nonascii, /([\200-\377])/ )
macro(:nl, /(\n|\r\n|\r|\f)/ )
macro(:unicode, /(\\#{m(:h)}{1,6}(\r\n|[ \t\r\n\f])?)/ )
macro(:escape, /(#{m(:unicode)}|\\[^\r\n\f0-9a-f])/ )
macro(:nmstart, /([_a-z]|#{m(:nonascii)}|#{m(:escape)})/ )
macro(:nmchar, /([_a-z0-9-]|#{m(:nonascii)}|#{m(:escape)})/ )
macro(:string1, /(\"([^\n\r\f\\\"]|\\#{m(:nl)}|#{m(:escape)})*\")/ )
macro(:string2, /(\'([^\n\r\f\\']|\\#{m(:nl)}|#{m(:escape)})*\')/ )
macro(:invalid1, /(\"([^\n\r\f\\\"]|\\#{m(:nl)}|#{m(:escape)})*)/ )
macro(:invalid2, /(\'([^\n\r\f\\']|\\#{m(:nl)}|#{m(:escape)})*)/ )
macro(:comment, /(\/\*[^*]*\*+([^\/*][^*]*\*+)*\/)/ )
macro(:ident, /(-?#{m(:nmstart)}#{m(:nmchar)}*)/ )
macro(:name, /(#{m(:nmchar)}+)/ )
macro(:num, /([0-9]+|[0-9]*\.[0-9]+)/ )
macro(:string, /(#{m(:string1)}|#{m(:string2)})/ )
macro(:invalid, /(#{m(:invalid1)}|#{m(:invalid2)})/ )
macro(:s, /([ \t\r\n\f]+)/ )
macro(:w, /(#{m(:s)}?)/ )
macro(:A, /(a|\\0{0,4}(41|61)(\r\n|[ \t\r\n\f])?)/ )
macro(:C, /(c|\\0{0,4}(43|63)(\r\n|[ \t\r\n\f])?)/ )
macro(:D, /(d|\\0{0,4}(44|64)(\r\n|[ \t\r\n\f])?)/ )
macro(:E, /(e|\\0{0,4}(45|65)(\r\n|[ \t\r\n\f])?)/ )
macro(:G, /(g|\\0{0,4}(47|67)(\r\n|[ \t\r\n\f])?|\\g)/ )
macro(:H, /(h|\\0{0,4}(48|68)(\r\n|[ \t\r\n\f])?|\\h)/ )
macro(:I, /(i|\\0{0,4}(49|69)(\r\n|[ \t\r\n\f])?|\\i)/ )
macro(:K, /(k|\\0{0,4}(4b|6b)(\r\n|[ \t\r\n\f])?|\\k)/ )
macro(:M, /(m|\\0{0,4}(4d|6d)(\r\n|[ \t\r\n\f])?|\\m)/ )
macro(:N, /(n|\\0{0,4}(4e|6e)(\r\n|[ \t\r\n\f])?|\\n)/ )
macro(:O, /(o|\\0{0,4}(51|71)(\r\n|[ \t\r\n\f])?|\\o)/ )
macro(:P, /(p|\\0{0,4}(50|70)(\r\n|[ \t\r\n\f])?|\\p)/ )
macro(:R, /(r|\\0{0,4}(52|72)(\r\n|[ \t\r\n\f])?|\\r)/ )
macro(:S, /(s|\\0{0,4}(53|73)(\r\n|[ \t\r\n\f])?|\\s)/ )
macro(:T, /(t|\\0{0,4}(54|74)(\r\n|[ \t\r\n\f])?|\\t)/ )
macro(:X, /(x|\\0{0,4}(58|78)(\r\n|[ \t\r\n\f])?|\\x)/ )
macro(:Z, /(z|\\0{0,4}(5a|7a)(\r\n|[ \t\r\n\f])?|\\z)/ )
token(:COMMENT, /#{m(:comment)}/)
token(:HASH, /\#/)
token(:IDENT, /#{m(:ident)}/)
token(:LBRACE, /#{m(:w)}\{/)
token(:RBRACE, /#{m(:w)}\}/)
token(:S, /#{m(:s)}/)
token(:FUNCTION, /#{m(:ident)}(?=\()/)
token(:PLUS, /#{m(:w)}\+/)
token(:GREATER, /#{m(:w)}>/)
token(:COMMA, /#{m(:w)},/)
token(:CDO, /<!--/)
token(:CDC, /-->/)
token(:INCLUDES, /~=/)
token(:DASHMATCH, /\|=/)
token(:STRING, /#{m(:string)}/)
token(:INVALID, /#{m(:invalid)}/)
token(:IMPORT_SYM, /@#{m(:I)}#{m(:M)}#{m(:P)}#{m(:O)}#{m(:R)}#{m(:T)}/)
token(:PAGE_SYM, /@#{m(:P)}#{m(:A)}#{m(:G)}#{m(:E)}/)
token(:MEDIA_SYM, /@#{m(:M)}#{m(:E)}#{m(:D)}#{m(:I)}#{m(:A)}/)
token(:CHARSET_SYM, /@#{m(:C)}#{m(:H)}#{m(:A)}#{m(:R)}#{m(:S)}#{m(:E)}#{m(:T)}/)
token(:IMPORTANT_SYM, /!(#{m(:w)}|#{m(:comment)})*#{m(:I)}#{m(:M)}#{m(:P)}#{m(:O)}#{m(:R)}#{m(:T)}#{m(:A)}#{m(:N)}#{m(:T)}/)
token(:EMS, /#{m(:num)}#{m(:E)}#{m(:M)}/)
token(:EXS, /#{m(:num)}#{m(:E)}#{m(:X)}/)
token :LENGTH do |patterns|
patterns << /#{m(:num)}#{m(:P)}#{m(:X)}/
patterns << /#{m(:num)}#{m(:C)}#{m(:M)}/
patterns << /#{m(:num)}#{m(:M)}#{m(:M)}/
patterns << /#{m(:num)}#{m(:I)}#{m(:N)}/
patterns << /#{m(:num)}#{m(:P)}#{m(:T)}/
patterns << /#{m(:num)}#{m(:P)}#{m(:C)}/
end
token :ANGLE do |patterns|
patterns << /#{m(:num)}#{m(:D)}#{m(:E)}#{m(:G)}/
patterns << /#{m(:num)}#{m(:R)}#{m(:A)}#{m(:D)}/
patterns << /#{m(:num)}#{m(:G)}#{m(:R)}#{m(:A)}#{m(:D)}/
end
token :TIME do |patterns|
patterns << /#{m(:num)}#{m(:M)}#{m(:S)}/
patterns << /#{m(:num)}#{m(:S)}/
end
token :FREQ do |patterns|
patterns << /#{m(:num)}#{m(:H)}#{m(:Z)}/
patterns << /#{m(:num)}#{m(:K)}#{m(:H)}#{m(:Z)}/
end
token :URI do |patterns|
patterns << /url\(#{m(:w)}#{m(:string)}#{m(:w)}\)/
patterns << /url\(#{m(:w)}([!$%&*-~]|#{m(:nonascii)}|#{m(:escape)})*#{m(:w)}\)/
end
token(:DIMENSION, /#{m(:num)}#{m(:ident)}/)
token(:PERCENTAGE, /#{m(:num)}%/)
token(:HEXNUM, /##{m(:h)}{2,6}/)
token(:NUMBER, /#{m(:num)}/)
end
def step
case
# scanning selectors only
when @selector && scan(@tokens[:LBRACE])
@selector = false
start_group :normal, matched
when @selector && scan(@tokens[:IMPORT_SYM])
start_group :import, matched
when @selector && scan(@tokens[:PAGE_SYM])
start_group :page, matched
when @selector && scan(@tokens[:MEDIA_SYM])
start_group :media, matched
when @selector && scan(@tokens[:CHARSET_SYM])
start_group :charset, matched
when @selector && scan(@tokens[:HASH])
start_group :normal, matched
when @selector && scan(@tokens[:URI])
start_group :uri, matched
when @selector && scan(@tokens[:IDENT])
if HTML401_TAGS.include?( matched )
start_group :tag, matched
else
start_group :ident, matched
end
# scanning declarations only
when !@selector && scan(@tokens[:RBRACE]): @selector = true
start_group :normal, matched
when !@selector && scan(@tokens[:FUNCTION])
start_group :function, matched
when !@selector && scan(@tokens[:EMS])
start_group :ems, matched
when !@selector && scan(@tokens[:EXS])
start_group :exs, matched
when !@selector && scan(@tokens[:LENGTH])
start_group :length, matched
when !@selector && scan(@tokens[:ANGLE])
start_group :angle, matched
when !@selector && scan(@tokens[:TIME])
start_group :time, matched
when !@selector && scan(@tokens[:FREQ])
start_group :freq, matched
when !@selector && scan(@tokens[:PERCENTAGE])
start_group :percentage, matched
when !@selector && scan(@tokens[:DIMENSION])
start_group :dimension, matched
when !@selector && scan(@tokens[:NUMBER])
start_group :number, matched
when !@selector && scan(@tokens[:HEXNUM])
start_group :number, matched
when !@selector && scan(@tokens[:IMPORTANT_SYM])
start_group :important, matched
when !@selector && scan(@tokens[:IDENT])
if CSS21_PROPERTIES.include?( matched ) # are they disjoint?
start_group :property, matched
elsif CSS21_KEYWORDS.include?( matched )
start_group :keyword, matched
else
start_group :ident, matched
end
# scanning both
when scan(@tokens[:S])
start_group :normal, matched
when scan(@tokens[:COMMENT])
start_group :comment, matched
when scan(@tokens[:STRING])
start_group :string, matched
when scan(@tokens[:CDO])
start_group :cdo, matched
when scan(@tokens[:CDC])
start_group :cdc, matched
when scan(@tokens[:INVALID])
start_group :invalid, matched
else
start_group :normal, scan(/./x)
end
end
private
def macro(name, regex=nil)
regex ? @macros[name] = regex : @macros[name].source
end
def token(name, pattern=nil, &block)
raise ArgumentError, "name required" unless name
patterns = []
patterns << pattern if pattern
yield(patterns) if block_given?
if patterns.empty?
raise ArgumentError, "at least one pattern required"
end
patterns.collect! do |pattern|
source = pattern.source
source = "\\A#{source}"
Regexp.new(source, Regexp::IGNORECASE + Regexp::MULTILINE)
end
@tokens[name] = Regexp.union(*patterns)
end
alias :m :macro
end
SYNTAX["css21"] = CSS21
end

View file

@ -0,0 +1,58 @@
require 'syntax'
module Syntax
class Javascript < Tokenizer
JAVASCRIPT_KEYWORDS =
%w{abstract break case catch class const continue
debugger default delete do else enum export extends
final finally for function goto if implements
import in instanceof interface native new
package private protected public return
static super switch synchronized this throw
throws transient try typeof
var void volatile while with} unless const_defined?(:JAVASCRIPT_KEYWORDS)
JAVASCRIPT_PREDEFINED_TYPES =
%w{boolean byte char double float int long short} unless const_defined?(:JAVASCRIPT_PREDEFINED_TYPES)
JAVASCRIPT_PREDEFINED_CONSTANTS =
%w{null true false} unless const_defined?(:JAVASCRIPT_PREDEFINED_CONSTANTS)
def step
case
when scan(/\s+/)
start_group :normal, matched
when scan(/\\u[0-9a-f]{4}/i)
start_group :unicode, matched
when scan(/0[xX][0-9A-Fa-f]+/)
start_group :hex, matched
when scan(/(?:0[0-7]+)(?![89.eEfF])/)
start_group :oct, matched
when scan(/(?:\d+)(?![.eEfF])/)
start_group :integer, matched
when scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
start_group :float, matched
when (scan(/"(?:[^"\\]|\\.)*"/) or scan(/'(?:[^'\\]|\\.)*'/) )
start_group :string, matched
when scan(/[a-z_$][a-z_\d]*/i)
if JAVASCRIPT_KEYWORDS.include?( matched )
start_group :keyword, matched
elsif JAVASCRIPT_PREDEFINED_TYPES.include?( matched )
start_group :predefined_types, matched
else
start_group :ident, matched
end
when scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
start_group :comment, matched
else
start_group :other, scan(/./x)
end
end
end
SYNTAX["javascript"] = Javascript
end

View file

@ -0,0 +1,77 @@
require 'syntax'
module Syntax
class SQLite < Tokenizer
def self.add_function(name)
SQLite_PREDEFINED_FUNCTIONS << name
end
SQLite_PREDEFINED_FUNCTIONS = %w{abs avg coalesce count glob hex ifnull
last_insert_rowid length like load_extension lower
ltrim max min sum nullif
quote random randomblob replace round
rtrim soundex sqlite_version substr total
trim typeof upper zeroblob
date time datetime julianday
strftime over} unless const_defined?(:SQLite_PREDEFINED_FUNCTIONS)
SQLite_KEYWORDS = %w{abort add after all alter analyze
asc attach autoincrement before by cascade
check commit conflict constraint create cross
current_date current_time current_timestamp database default
deferrable deferred delete desc detach distinct drop each
escape except exclusive explain fail for foreign from
full group having if ignore immediate
index initially inner insert instead intersect into is
join key left limit natural of offset on or order
outer plan pragma primary query raise references reindex
rename replace restrict right rollback row select set
table temp temporary to transaction trigger union
unique update using vacuum values view virtual
where partition} unless const_defined?(:SQLite_KEYWORDS)
SQLite_DATATYPES = %w{null none text numeric integer text blob
int varchar char real float
double} unless const_defined?(:SQLite_DATATYPES)
SQLite_OPERATORS = %w{not escape isnull notnull between and
in exists case when then else begin end cast as collate
like glob regexp < > || * / % + - << >>
& | <= >= = == != <>
match} unless const_defined?(:SQLite_OPERATORS)
def step
case
when scan(/\s+/)
start_group :normal, matched
when scan(%r{ "(?: \\. | \\" | [^"\n])*" }x)
start_group :string, matched
when scan(%r{ '(?: \\. | \\' | [^'\n])*' }x )
start_group :string, matched
when (scan(/[a-z_][a-z_\d]+/i) or scan(/[<>\|\*%&!=]+/))
m = matched.downcase
if SQLite_PREDEFINED_FUNCTIONS.include?( m )
start_group :function, matched
elsif SQLite_KEYWORDS.include?( m )
start_group :keyword, matched
elsif SQLite_DATATYPES.include?( m )
start_group :datatype, matched
elsif SQLite_OPERATORS.include?( m )
start_group :operator, matched
else
start_group :ident, matched
end
when scan(/--.*$/)
start_group :comment, matched
else
start_group :other, scan(/./x)
end
end
end
SYNTAX["sqlite"] = SQLite
end