diff options
Diffstat (limited to 'lib/coderay')
-rw-r--r-- | lib/coderay/helpers/file_type.rb | 3 | ||||
-rw-r--r-- | lib/coderay/scanner.rb | 8 | ||||
-rw-r--r-- | lib/coderay/scanners/ruby.rb | 1 | ||||
-rw-r--r-- | lib/coderay/scanners/scheme.rb | 142 | ||||
-rw-r--r-- | lib/coderay/styles/cycnus.rb | 4 | ||||
-rw-r--r-- | lib/coderay/styles/murphy.rb | 4 | ||||
-rwxr-xr-x | lib/coderay/token_classes.rb | 2 |
7 files changed, 159 insertions, 5 deletions
diff --git a/lib/coderay/helpers/file_type.rb b/lib/coderay/helpers/file_type.rb index 13b669d..3d29d78 100644 --- a/lib/coderay/helpers/file_type.rb +++ b/lib/coderay/helpers/file_type.rb @@ -80,6 +80,7 @@ module FileType 'rb' => :ruby, 'rbw' => :ruby, 'rake' => :ruby, + 'mab' => :ruby, 'cpp' => :c, 'c' => :c, 'h' => :c, @@ -89,6 +90,8 @@ module FileType 'xhtml' => :xhtml, 'raydebug' => :debug, 'rhtml' => :rhtml, + 'ss' => :scheme, + 'sch' => :scheme, 'yaml' => :yaml, 'yml' => :yaml, } diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb index 5993b4c..6ea57eb 100644 --- a/lib/coderay/scanner.rb +++ b/lib/coderay/scanner.rb @@ -68,6 +68,14 @@ module CodeRay def normify code code = code.to_s.to_unix end + + def file_extension extension = nil + if extension + @file_extension = extension.to_s + else + @file_extension ||= plugin_id.to_s + end + end end diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index b373a2b..d497731 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -18,6 +18,7 @@ module Scanners include Streamable register_for :ruby + file_extension 'rb' helper :patterns diff --git a/lib/coderay/scanners/scheme.rb b/lib/coderay/scanners/scheme.rb new file mode 100644 index 0000000..2aee223 --- /dev/null +++ b/lib/coderay/scanners/scheme.rb @@ -0,0 +1,142 @@ +module CodeRay + module Scanners + + # Scheme scanner for CodeRay (by closure). + # Thanks to murphy for putting CodeRay into public. + class Scheme < Scanner + + register_for :scheme + file_extension :scm + + CORE_FORMS = %w[ + lambda let let* letrec syntax-case define-syntax let-syntax + letrec-syntax begin define quote if or and cond case do delay + quasiquote set! cons force call-with-current-continuation call/cc + ] + + IDENT_KIND = CaseIgnoringWordList.new(:ident). + add(CORE_FORMS, :reserved) + + #IDENTIFIER_INITIAL = /[a-z!@\$%&\*\/\:<=>\?~_\^]/i + #IDENTIFIER_SUBSEQUENT = /#{IDENTIFIER_INITIAL}|\d|\.|\+|-/ + #IDENTIFIER = /#{IDENTIFIER_INITIAL}#{IDENTIFIER_SUBSEQUENT}*|\+|-|\.{3}/ + IDENTIFIER = /[a-zA-Z!@$%&*\/:<=>?~_^][\w!@$%&*\/:<=>?~^.+\-]*|[+-]|\.\.\./ + DIGIT = /\d/ + DIGIT10 = DIGIT + DIGIT16 = /[0-9a-f]/i + DIGIT8 = /[0-7]/ + DIGIT2 = /[01]/ + RADIX16 = /\#x/i + RADIX8 = /\#o/i + RADIX2 = /\#b/i + RADIX10 = /\#d/i + EXACTNESS = /#i|#e/i + SIGN = /[\+-]?/ + EXP_MARK = /[esfdl]/i + EXP = /#{EXP_MARK}#{SIGN}#{DIGIT}+/ + SUFFIX = /#{EXP}?/ + PREFIX10 = /#{RADIX10}?#{EXACTNESS}?|#{EXACTNESS}?#{RADIX10}?/ + PREFIX16 = /#{RADIX16}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX16}/ + PREFIX8 = /#{RADIX8}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX8}/ + PREFIX2 = /#{RADIX2}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX2}/ + UINT10 = /#{DIGIT10}+#*/ + UINT16 = /#{DIGIT16}+#*/ + UINT8 = /#{DIGIT8}+#*/ + UINT2 = /#{DIGIT2}+#*/ + DECIMAL = /#{DIGIT10}+#+\.#*#{SUFFIX}|#{DIGIT10}+\.#{DIGIT10}*#*#{SUFFIX}|\.#{DIGIT10}+#*#{SUFFIX}|#{UINT10}#{EXP}/ + UREAL10 = /#{UINT10}\/#{UINT10}|#{DECIMAL}|#{UINT10}/ + UREAL16 = /#{UINT16}\/#{UINT16}|#{UINT16}/ + UREAL8 = /#{UINT8}\/#{UINT8}|#{UINT8}/ + UREAL2 = /#{UINT2}\/#{UINT2}|#{UINT2}/ + REAL10 = /#{SIGN}#{UREAL10}/ + REAL16 = /#{SIGN}#{UREAL16}/ + REAL8 = /#{SIGN}#{UREAL8}/ + REAL2 = /#{SIGN}#{UREAL2}/ + IMAG10 = /i|#{UREAL10}i/ + IMAG16 = /i|#{UREAL16}i/ + IMAG8 = /i|#{UREAL8}i/ + IMAG2 = /i|#{UREAL2}i/ + COMPLEX10 = /#{REAL10}@#{REAL10}|#{REAL10}\+#{IMAG10}|#{REAL10}-#{IMAG10}|\+#{IMAG10}|-#{IMAG10}|#{REAL10}/ + COMPLEX16 = /#{REAL16}@#{REAL16}|#{REAL16}\+#{IMAG16}|#{REAL16}-#{IMAG16}|\+#{IMAG16}|-#{IMAG16}|#{REAL16}/ + COMPLEX8 = /#{REAL8}@#{REAL8}|#{REAL8}\+#{IMAG8}|#{REAL8}-#{IMAG8}|\+#{IMAG8}|-#{IMAG8}|#{REAL8}/ + COMPLEX2 = /#{REAL2}@#{REAL2}|#{REAL2}\+#{IMAG2}|#{REAL2}-#{IMAG2}|\+#{IMAG2}|-#{IMAG2}|#{REAL2}/ + NUM10 = /#{PREFIX10}?#{COMPLEX10}/ + NUM16 = /#{PREFIX16}#{COMPLEX16}/ + NUM8 = /#{PREFIX8}#{COMPLEX8}/ + NUM2 = /#{PREFIX2}#{COMPLEX2}/ + NUM = /#{NUM10}|#{NUM16}|#{NUM8}|#{NUM2}/ + + private + def scan_tokens tokens,options + + state = :initial + ident_kind = IDENT_KIND + + until eos? + kind = match = nil + + case state + when :initial + if scan(/ \s+ | \\\n /x) + kind = :space + elsif scan(/['\(\[\)\]]|#\(/) + kind = :operator_fat + elsif scan(/;.*/) + kind = :comment + elsif scan(/#\\(?:newline|space|.?)/) + kind = :char + elsif scan(/#[ft]/) + kind = :pre_constant + elsif scan(/#{IDENTIFIER}/o) + kind = ident_kind[matched] + elsif scan(/\./) + kind = :operator + elsif scan(/"/) + tokens << [:open, :string] + state = :string + tokens << ['"', :delimiter] + next + elsif scan(/#{NUM}/o) and not matched.empty? + kind = :integer + elsif getch + kind = :error + end + + when :string + if scan(/[^"\\]+/) or scan(/\\.?/) + kind = :content + elsif scan(/"/) + tokens << ['"', :delimiter] + tokens << [:close, :string] + state = :initial + next + else + raise_inspect "else case \" reached; %p not handled." % peek(1), + tokens, state + end + + else + raise "else case reached" + end + + match ||= matched + if $DEBUG and not kind + raise_inspect 'Error token %p in line %d' % + [[match, kind], line], tokens + end + raise_inspect 'Empty token', tokens, state unless match + + tokens << [match, kind] + + end # until eos + + if state == :string + tokens << [:close, :string] + end + + tokens + + end #scan_tokens + end #class + end #module scanners +end #module coderay
\ No newline at end of file diff --git a/lib/coderay/styles/cycnus.rb b/lib/coderay/styles/cycnus.rb index 7430e9e..7747c75 100644 --- a/lib/coderay/styles/cycnus.rb +++ b/lib/coderay/styles/cycnus.rb @@ -49,7 +49,7 @@ ol.CodeRay li { white-space: pre } .av { color:#700 } .aw { color:#C00 } .bi { color:#509; font-weight:bold } -.c { color:#888 } +.c { color:#666; } .ch { color:#04D } .ch .k { color:#04D } @@ -85,7 +85,7 @@ ol.CodeRay li { white-space: pre } .la { color:#970; font-weight:bold } .lv { color:#963 } .oc { color:#40E; font-weight:bold } -.on { color:#000; font-weight:bold } +.of { color:#000; font-weight:bold } .op { } .pc { color:#038; font-weight:bold } .pd { color:#369; font-weight:bold } diff --git a/lib/coderay/styles/murphy.rb b/lib/coderay/styles/murphy.rb index 1079f62..b42f0e0 100644 --- a/lib/coderay/styles/murphy.rb +++ b/lib/coderay/styles/murphy.rb @@ -47,7 +47,7 @@ ol.CodeRay li { white-space: pre; } .av { color:#700; } .aw { color:#C00; } .bi { color:#509; font-weight:bold; } -.c { color:#666; } +.c { color:#555; background-color: black; } .ch { color:#88F; } .ch .k { color:#04D; } @@ -77,7 +77,7 @@ ol.CodeRay li { white-space: pre; } .la { color:#970; font-weight:bold; } .lv { color:#963; } .oc { color:#40E; font-weight:bold; } -.on { color:#000; font-weight:bold; } +.of { color:#000; font-weight:bold; } .op { } .pc { color:#08f; font-weight:bold; } .pd { color:#369; font-weight:bold; } diff --git a/lib/coderay/token_classes.rb b/lib/coderay/token_classes.rb index b19e512..d0de855 100755 --- a/lib/coderay/token_classes.rb +++ b/lib/coderay/token_classes.rb @@ -39,7 +39,7 @@ module CodeRay :local_variable => 'lv', :modifier => 'mod', :oct => 'oc', - :operator_name => 'on', + :operator_fat => 'of', :pre_constant => 'pc', :pre_type => 'pt', :predefined => 'pd', |