diff options
author | murphy <murphy@rubychan.de> | 2008-10-20 14:18:18 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2008-10-20 14:18:18 +0000 |
commit | ceed015b2d5a237a6f3dfc0f2272f13c9f758771 (patch) | |
tree | c52ff27205bbefaebf5e8f67960244cd921ece01 /lib/coderay | |
parent | 23e5605488f613bd864671a322562ecfcb2d945d (diff) | |
download | coderay-ceed015b2d5a237a6f3dfc0f2272f13c9f758771.tar.gz |
New: *YAML* (#53). Preparing for version 0.8.1.
* Based on the YAML scanner from Jamis Buck's Syntax lib.
* Some YAML examples from Ruby gems.
* Doesn't handle string yet; alpha state.
More changes:
* coderay_suite: new parameter "fast" makes testing faster (for development).
* Changed the title of HTML page output (Page Encoder).
* FileType: Added new file types.
* cYcnus style: simplified some token group styles.
* Cleanup in CSS and HTML Scanners.
Diffstat (limited to 'lib/coderay')
-rw-r--r-- | lib/coderay/encoders/html/output.rb | 2 | ||||
-rw-r--r-- | lib/coderay/helpers/file_type.rb | 5 | ||||
-rw-r--r-- | lib/coderay/scanners/_map.rb | 3 | ||||
-rw-r--r-- | lib/coderay/scanners/css.rb | 1 | ||||
-rw-r--r-- | lib/coderay/scanners/html.rb | 2 | ||||
-rw-r--r-- | lib/coderay/scanners/yaml.rb | 114 | ||||
-rw-r--r-- | lib/coderay/styles/cycnus.rb | 8 |
7 files changed, 126 insertions, 9 deletions
diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb index 8def95e..32ee5be 100644 --- a/lib/coderay/encoders/html/output.rb +++ b/lib/coderay/encoders/html/output.rb @@ -177,7 +177,7 @@ module Encoders <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> - <title>CodeRay HTML Encoder Example</title> + <title>CodeRay Output</title> <style type="text/css"> <%CSS%> </style> diff --git a/lib/coderay/helpers/file_type.rb b/lib/coderay/helpers/file_type.rb index e955b9d..fbc95ec 100644 --- a/lib/coderay/helpers/file_type.rb +++ b/lib/coderay/helpers/file_type.rb @@ -88,7 +88,12 @@ module FileType 'cpp' => :c, 'c' => :c, 'h' => :c, + 'java' => :java, 'js' => :java_script, + 'json' => :json, + 'diff' => :diff, + 'patch' => :diff, + 'css' => :css, 'xml' => :xml, 'htm' => :html, 'html' => :html, diff --git a/lib/coderay/scanners/_map.rb b/lib/coderay/scanners/_map.rb index e8dfa07..60d57ae 100644 --- a/lib/coderay/scanners/_map.rb +++ b/lib/coderay/scanners/_map.rb @@ -7,7 +7,8 @@ module Scanners :irb => :ruby, :xhtml => :nitro_xhtml, :javascript => :java_script, - :nitro => :nitro_xhtml + :nitro => :nitro_xhtml, + :yml => :yaml default :plain diff --git a/lib/coderay/scanners/css.rb b/lib/coderay/scanners/css.rb index 897e27a..848f136 100644 --- a/lib/coderay/scanners/css.rb +++ b/lib/coderay/scanners/css.rb @@ -168,7 +168,6 @@ module Scanners raise_inspect 'Empty token', tokens unless match tokens << [match, kind] - # tokens << [states.inspect, :error] end diff --git a/lib/coderay/scanners/html.rb b/lib/coderay/scanners/html.rb index 5f647d3..bb7ad3a 100644 --- a/lib/coderay/scanners/html.rb +++ b/lib/coderay/scanners/html.rb @@ -2,8 +2,6 @@ module CodeRay module Scanners # HTML Scanner - # - # $Id$ class HTML < Scanner include Streamable diff --git a/lib/coderay/scanners/yaml.rb b/lib/coderay/scanners/yaml.rb new file mode 100644 index 0000000..06da907 --- /dev/null +++ b/lib/coderay/scanners/yaml.rb @@ -0,0 +1,114 @@ +module CodeRay +module Scanners + + # YAML Scanner + # + # Based on the YAML scanner from Syntax by Jamis Buck. + class XML < Scanner + + register_for :yaml + file_extension 'yml' + + def scan_tokens tokens, options + + value_expected = nil + states = :initial + + until eos? + + kind = nil + match = nil + + if match = scan(/\s+/) + kind = :space + state = :initial if match.index(?\n) + + elsif match = scan(/#.*/) + kind = :comment + + elsif bol? and case + when scan(/---/) + kind = :tag + end + + elsif state == :value and case + when scan(/(?![!*&]).+(?=$|\s+#)/) + kind = :string + end + + elsif case + when match = scan(/[-:](?= )/) + state = :value if state == :colon && (match == ':' || match == '-') + kind = :operator + when match = scan(/[,{}\[\]]/) + kind = :operator + when state == :initial && scan(/\w+(?=:)/) + kind = :key + state = :colon + when state == :initial && match = scan(/(?:"[^"]*"|'[^']*')(?=:)/) + tokens << [:open, :key] + tokens << [match[0,1], :delimiter] + tokens << [match[1..-2], :content] + tokens << [match[-1,1], :delimiter] + tokens << [:close, :key] + state = :colon + next + when scan(/(![\w\/]+)(:([\w:]+))?/) + tokens << [self[1], :type] + if self[2] + tokens << [':', :operator] + tokens << [self[3], :class] + end + next + when scan(/&\S+/) + kind = :variable + when scan(/\*\w+/) + kind = :global_variable + when scan(/\d\d:\d\d:\d\d/) + kind = :oct + when scan(/\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d(\.\d+)? [-+]\d\d:\d\d/) + kind = :oct + when scan(/:\w+/) + kind = :symbol + when scan(/[^:\s]+/) + kind = :string + # when scan(/>-?/) + # kind = :punct + # kind = :normal, scan(/.*$/) + # append getch until eos? || bol? + # return if eos? + # indent = check(/ */) + # kind = :string + # loop do + # line = check_until(/[\n\r]|\Z/) + # break if line.nil? + # if line.chomp.length > 0 + # this_indent = line.chomp.match( /^\s*/ )[0] + # break if this_indent.length < indent.length + # end + # append scan_until(/[\n\r]|\Z/) + # end + end + + else + getch + kind = :error + + end + + match ||= matched + + raise_inspect 'Error token %p in line %d' % [[match, kind], line], tokens if $DEBUG && !kind + raise_inspect 'Empty token', tokens unless match + + tokens << [match, kind] + + end + + tokens + end + + end + +end +end diff --git a/lib/coderay/styles/cycnus.rb b/lib/coderay/styles/cycnus.rb index c0dab99..0a1c6f8 100644 --- a/lib/coderay/styles/cycnus.rb +++ b/lib/coderay/styles/cycnus.rb @@ -107,15 +107,15 @@ ol.CodeRay li { white-space: pre } .rx .mod { color:#C2C } .rx .fu { color:#404; font-weight: bold } -.s { background-color:#fff0f0 } +.s { background-color:#fff0f0; color: #D20; } .s .s { background-color:#ffe0e0 } .s .s .s { background-color:#ffd0d0 } -.s .k { color: #D20; } +.s .k { } .s .ch { color: #b0b; } .s .dl { color: #710; } -.sh { background-color:#f0fff0 } -.sh .k { color:#2B2 } +.sh { background-color:#f0fff0; color:#2B2 } +.sh .k { } .sh .dl { color:#161 } .sy { color:#A60 } |