coderay 0.9.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/{lib/README → README_INDEX.rdoc} +10 -21
  2. data/Rakefile +6 -6
  3. data/bin/coderay +193 -64
  4. data/lib/coderay.rb +61 -105
  5. data/lib/coderay/duo.rb +17 -21
  6. data/lib/coderay/encoder.rb +100 -112
  7. data/lib/coderay/encoders/_map.rb +12 -7
  8. data/lib/coderay/encoders/comment_filter.rb +12 -30
  9. data/lib/coderay/encoders/count.rb +29 -11
  10. data/lib/coderay/encoders/debug.rb +32 -20
  11. data/lib/coderay/encoders/div.rb +13 -9
  12. data/lib/coderay/encoders/filter.rb +34 -51
  13. data/lib/coderay/encoders/html.rb +155 -161
  14. data/lib/coderay/encoders/html/css.rb +4 -9
  15. data/lib/coderay/encoders/html/numbering.rb +115 -0
  16. data/lib/coderay/encoders/html/output.rb +22 -70
  17. data/lib/coderay/encoders/json.rb +59 -45
  18. data/lib/coderay/encoders/lines_of_code.rb +12 -57
  19. data/lib/coderay/encoders/null.rb +6 -14
  20. data/lib/coderay/encoders/page.rb +13 -9
  21. data/lib/coderay/encoders/span.rb +13 -9
  22. data/lib/coderay/encoders/statistic.rb +58 -39
  23. data/lib/coderay/encoders/terminal.rb +179 -0
  24. data/lib/coderay/encoders/text.rb +31 -17
  25. data/lib/coderay/encoders/token_kind_filter.rb +111 -0
  26. data/lib/coderay/encoders/xml.rb +19 -18
  27. data/lib/coderay/encoders/yaml.rb +37 -9
  28. data/lib/coderay/for_redcloth.rb +4 -4
  29. data/lib/coderay/helpers/file_type.rb +127 -246
  30. data/lib/coderay/helpers/gzip.rb +41 -0
  31. data/lib/coderay/helpers/plugin.rb +241 -306
  32. data/lib/coderay/helpers/word_list.rb +65 -126
  33. data/lib/coderay/scanner.rb +173 -156
  34. data/lib/coderay/scanners/_map.rb +18 -17
  35. data/lib/coderay/scanners/c.rb +63 -77
  36. data/lib/coderay/scanners/clojure.rb +217 -0
  37. data/lib/coderay/scanners/cpp.rb +71 -84
  38. data/lib/coderay/scanners/css.rb +103 -120
  39. data/lib/coderay/scanners/debug.rb +47 -44
  40. data/lib/coderay/scanners/delphi.rb +70 -76
  41. data/lib/coderay/scanners/diff.rb +141 -50
  42. data/lib/coderay/scanners/erb.rb +81 -0
  43. data/lib/coderay/scanners/groovy.rb +104 -113
  44. data/lib/coderay/scanners/haml.rb +168 -0
  45. data/lib/coderay/scanners/html.rb +181 -110
  46. data/lib/coderay/scanners/java.rb +73 -75
  47. data/lib/coderay/scanners/java/builtin_types.rb +2 -0
  48. data/lib/coderay/scanners/java_script.rb +90 -101
  49. data/lib/coderay/scanners/json.rb +40 -53
  50. data/lib/coderay/scanners/php.rb +123 -147
  51. data/lib/coderay/scanners/python.rb +93 -91
  52. data/lib/coderay/scanners/raydebug.rb +66 -0
  53. data/lib/coderay/scanners/ruby.rb +343 -326
  54. data/lib/coderay/scanners/ruby/patterns.rb +40 -106
  55. data/lib/coderay/scanners/ruby/string_state.rb +71 -0
  56. data/lib/coderay/scanners/sql.rb +80 -66
  57. data/lib/coderay/scanners/text.rb +26 -0
  58. data/lib/coderay/scanners/xml.rb +1 -1
  59. data/lib/coderay/scanners/yaml.rb +74 -73
  60. data/lib/coderay/style.rb +10 -7
  61. data/lib/coderay/styles/_map.rb +3 -3
  62. data/lib/coderay/styles/alpha.rb +143 -0
  63. data/lib/coderay/token_kinds.rb +90 -0
  64. data/lib/coderay/tokens.rb +102 -277
  65. data/lib/coderay/tokens_proxy.rb +55 -0
  66. data/lib/coderay/version.rb +3 -0
  67. data/test/functional/basic.rb +200 -18
  68. data/test/functional/examples.rb +130 -0
  69. data/test/functional/for_redcloth.rb +15 -8
  70. data/test/functional/suite.rb +9 -6
  71. metadata +103 -123
  72. data/FOLDERS +0 -53
  73. data/bin/coderay_stylesheet +0 -4
  74. data/lib/coderay/encoders/html/numerization.rb +0 -133
  75. data/lib/coderay/encoders/term.rb +0 -158
  76. data/lib/coderay/encoders/token_class_filter.rb +0 -84
  77. data/lib/coderay/helpers/gzip_simple.rb +0 -123
  78. data/lib/coderay/scanners/nitro_xhtml.rb +0 -136
  79. data/lib/coderay/scanners/plaintext.rb +0 -20
  80. data/lib/coderay/scanners/rhtml.rb +0 -78
  81. data/lib/coderay/scanners/scheme.rb +0 -145
  82. data/lib/coderay/styles/cycnus.rb +0 -152
  83. data/lib/coderay/styles/murphy.rb +0 -134
  84. data/lib/coderay/token_classes.rb +0 -86
  85. data/test/functional/load_plugin_scanner.rb +0 -11
  86. data/test/functional/vhdl.rb +0 -126
  87. data/test/functional/word_list.rb +0 -79
@@ -1,86 +0,0 @@
1
- module CodeRay
2
- class Tokens
3
- ClassOfKind = Hash.new do |h, k|
4
- h[k] = k.to_s
5
- end
6
- ClassOfKind.update with = {
7
- :annotation => 'at',
8
- :attribute_name => 'an',
9
- :attribute_name_fat => 'af',
10
- :attribute_value => 'av',
11
- :attribute_value_fat => 'aw',
12
- :bin => 'bi',
13
- :char => 'ch',
14
- :class => 'cl',
15
- :class_variable => 'cv',
16
- :color => 'cr',
17
- :comment => 'c',
18
- :complex => 'cm',
19
- :constant => 'co',
20
- :content => 'k',
21
- :decorator => 'de',
22
- :definition => 'df',
23
- :delimiter => 'dl',
24
- :directive => 'di',
25
- :doc => 'do',
26
- :doctype => 'dt',
27
- :doc_string => 'ds',
28
- :entity => 'en',
29
- :error => 'er',
30
- :escape => 'e',
31
- :exception => 'ex',
32
- :float => 'fl',
33
- :function => 'fu',
34
- :global_variable => 'gv',
35
- :hex => 'hx',
36
- :imaginary => 'cm',
37
- :important => 'im',
38
- :include => 'ic',
39
- :inline => 'il',
40
- :inline_delimiter => 'idl',
41
- :instance_variable => 'iv',
42
- :integer => 'i',
43
- :interpreted => 'in',
44
- :keyword => 'kw',
45
- :key => 'ke',
46
- :label => 'la',
47
- :local_variable => 'lv',
48
- :modifier => 'mod',
49
- :oct => 'oc',
50
- :operator_fat => 'of',
51
- :pre_constant => 'pc',
52
- :pre_type => 'pt',
53
- :predefined => 'pd',
54
- :preprocessor => 'pp',
55
- :pseudo_class => 'ps',
56
- :regexp => 'rx',
57
- :reserved => 'r',
58
- :shell => 'sh',
59
- :string => 's',
60
- :symbol => 'sy',
61
- :tag => 'ta',
62
- :tag_fat => 'tf',
63
- :tag_special => 'ts',
64
- :type => 'ty',
65
- :variable => 'v',
66
- :value => 'vl',
67
- :xml_text => 'xt',
68
-
69
- :insert => 'ins',
70
- :delete => 'del',
71
- :change => 'chg',
72
- :head => 'head',
73
-
74
- :ident => :NO_HIGHLIGHT, # 'id'
75
- #:operator => 'op',
76
- :operator => :NO_HIGHLIGHT, # 'op'
77
- :space => :NO_HIGHLIGHT, # 'sp'
78
- :plain => :NO_HIGHLIGHT,
79
- }
80
- ClassOfKind[:method] = ClassOfKind[:function]
81
- ClassOfKind[:open] = ClassOfKind[:close] = ClassOfKind[:delimiter]
82
- ClassOfKind[:nesting_delimiter] = ClassOfKind[:delimiter]
83
- ClassOfKind[:escape] = ClassOfKind[:delimiter]
84
- #ClassOfKind.default = ClassOfKind[:error] or raise 'no class found for :error!'
85
- end
86
- end
@@ -1,11 +0,0 @@
1
- require 'test/unit'
2
- require 'coderay'
3
-
4
- class PluginScannerTest < Test::Unit::TestCase
5
-
6
- def test_load
7
- require File.join(File.dirname(__FILE__), 'vhdl')
8
- assert_equal 'VHDL', CodeRay.scanner(:vhdl).class.name
9
- end
10
-
11
- end
@@ -1,126 +0,0 @@
1
- class VHDL < CodeRay::Scanners::Scanner
2
-
3
- register_for :vhdl
4
-
5
- RESERVED_WORDS = [
6
- 'access','after','alias','all','assert','architecture','begin',
7
- 'block','body','buffer','bus','case','component','configuration','constant',
8
- 'disconnect','downto','else','elsif','end','entity','exit','file','for',
9
- 'function','generate','generic','group','guarded','if','impure','in',
10
- 'inertial','inout','is','label','library','linkage','literal','loop',
11
- 'map','new','next','null','of','on','open','others','out','package',
12
- 'port','postponed','procedure','process','pure','range','record','register',
13
- 'reject','report','return','select','severity','signal','shared','subtype',
14
- 'then','to','transport','type','unaffected','units','until','use','variable',
15
- 'wait','when','while','with','note','warning','error','failure','and',
16
- 'or','xor','not','nor',
17
- 'array'
18
- ]
19
-
20
- PREDEFINED_TYPES = [
21
- 'bit','bit_vector','character','boolean','integer','real','time','string',
22
- 'severity_level','positive','natural','signed','unsigned','line','text',
23
- 'std_logic','std_logic_vector','std_ulogic','std_ulogic_vector','qsim_state',
24
- 'qsim_state_vector','qsim_12state','qsim_12state_vector','qsim_strength',
25
- 'mux_bit','mux_vector','reg_bit','reg_vector','wor_bit','wor_vector'
26
- ]
27
-
28
- PREDEFINED_CONSTANTS = [
29
-
30
- ]
31
-
32
- IDENT_KIND = CodeRay::CaseIgnoringWordList.new(:ident).
33
- add(RESERVED_WORDS, :reserved).
34
- add(PREDEFINED_TYPES, :pre_type).
35
- add(PREDEFINED_CONSTANTS, :pre_constant)
36
-
37
- ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
38
- UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
39
-
40
- def scan_tokens tokens, options
41
-
42
- state = :initial
43
-
44
- until eos?
45
-
46
- kind = nil
47
- match = nil
48
-
49
- case state
50
-
51
- when :initial
52
-
53
- if scan(/ \s+ | \\\n /x)
54
- kind = :space
55
-
56
- elsif scan(/-- .*/x)
57
- kind = :comment
58
-
59
- elsif scan(/ [-+*\/=<>?:;,!&^|()\[\]{}~%]+ | \.(?!\d) /x)
60
- kind = :operator
61
-
62
- elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
63
- kind = IDENT_KIND[match.downcase]
64
-
65
- elsif match = scan(/[a-z]?"/i)
66
- tokens << [:open, :string]
67
- state = :string
68
- kind = :delimiter
69
-
70
- elsif scan(/ L?' (?: [^\'\n\\] | \\ #{ESCAPE} )? '? /ox)
71
- kind = :char
72
-
73
- elsif scan(/(?:\d+)(?![.eEfF])/)
74
- kind = :integer
75
-
76
- elsif scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
77
- kind = :float
78
-
79
- else
80
- getch
81
- kind = :error
82
-
83
- end
84
-
85
- when :string
86
- if scan(/[^\\\n"]+/)
87
- kind = :content
88
- elsif scan(/"/)
89
- tokens << ['"', :delimiter]
90
- tokens << [:close, :string]
91
- state = :initial
92
- next
93
- elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
94
- kind = :char
95
- elsif scan(/ \\ | $ /x)
96
- tokens << [:close, :string]
97
- kind = :error
98
- state = :initial
99
- else
100
- raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
101
- end
102
-
103
- else
104
- raise_inspect 'Unknown state', tokens
105
-
106
- end
107
-
108
- match ||= matched
109
- if $DEBUG and not kind
110
- raise_inspect 'Error token %p in line %d' %
111
- [[match, kind], line], tokens
112
- end
113
- raise_inspect 'Empty token', tokens unless match
114
-
115
- tokens << [match, kind]
116
-
117
- end
118
-
119
- if state == :string
120
- tokens << [:close, :string]
121
- end
122
-
123
- tokens
124
- end
125
-
126
- end
@@ -1,79 +0,0 @@
1
- require 'test/unit'
2
- require 'coderay'
3
-
4
- class WordListTest < Test::Unit::TestCase
5
-
6
- include CodeRay
7
-
8
- # define word arrays
9
- RESERVED_WORDS = %w[
10
- asm break case continue default do else
11
- ...
12
- ]
13
-
14
- PREDEFINED_TYPES = %w[
15
- int long short char void
16
- ...
17
- ]
18
-
19
- PREDEFINED_CONSTANTS = %w[
20
- EOF NULL ...
21
- ]
22
-
23
- # make a WordList
24
- IDENT_KIND = WordList.new(:ident).
25
- add(RESERVED_WORDS, :reserved).
26
- add(PREDEFINED_TYPES, :pre_type).
27
- add(PREDEFINED_CONSTANTS, :pre_constant)
28
-
29
- def test_word_list_example
30
- assert_equal :pre_type, IDENT_KIND['void']
31
- # assert_equal :pre_constant, IDENT_KIND['...'] # not specified
32
- end
33
-
34
- def test_word_list
35
- list = WordList.new(:ident).add(['foobar'], :reserved)
36
- assert_equal :reserved, list['foobar']
37
- assert_equal :ident, list['FooBar']
38
- end
39
-
40
- def test_word_list_cached
41
- list = WordList.new(:ident, true).add(['foobar'], :reserved)
42
- assert_equal :reserved, list['foobar']
43
- assert_equal :ident, list['FooBar']
44
- end
45
-
46
- def test_case_ignoring_word_list
47
- list = CaseIgnoringWordList.new(:ident).add(['foobar'], :reserved)
48
- assert_equal :ident, list['foo']
49
- assert_equal :reserved, list['foobar']
50
- assert_equal :reserved, list['FooBar']
51
-
52
- list = CaseIgnoringWordList.new(:ident).add(['FooBar'], :reserved)
53
- assert_equal :ident, list['foo']
54
- assert_equal :reserved, list['foobar']
55
- assert_equal :reserved, list['FooBar']
56
- end
57
-
58
- def test_case_ignoring_word_list_cached
59
- list = CaseIgnoringWordList.new(:ident, true).add(['foobar'], :reserved)
60
- assert_equal :ident, list['foo']
61
- assert_equal :reserved, list['foobar']
62
- assert_equal :reserved, list['FooBar']
63
-
64
- list = CaseIgnoringWordList.new(:ident, true).add(['FooBar'], :reserved)
65
- assert_equal :ident, list['foo']
66
- assert_equal :reserved, list['foobar']
67
- assert_equal :reserved, list['FooBar']
68
- end
69
-
70
- def test_dup
71
- list = WordList.new(:ident).add(['foobar'], :reserved)
72
- assert_equal :reserved, list['foobar']
73
- list2 = list.dup
74
- list2.add(%w[foobar], :keyword)
75
- assert_equal :keyword, list2['foobar']
76
- assert_equal :reserved, list['foobar']
77
- end
78
-
79
- end