coderay 1.0.0 → 1.0.0.598.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/FOLDERS +49 -0
  2. data/Rakefile +6 -5
  3. data/bin/coderay +74 -190
  4. data/bin/coderay_stylesheet +4 -0
  5. data/{README_INDEX.rdoc → lib/README} +20 -10
  6. data/lib/coderay.rb +60 -62
  7. data/lib/coderay/duo.rb +55 -2
  8. data/lib/coderay/encoder.rb +39 -52
  9. data/lib/coderay/encoders/_map.rb +7 -11
  10. data/lib/coderay/encoders/comment_filter.rb +61 -0
  11. data/lib/coderay/encoders/count.rb +26 -11
  12. data/lib/coderay/encoders/debug.rb +60 -11
  13. data/lib/coderay/encoders/div.rb +8 -9
  14. data/lib/coderay/encoders/filter.rb +52 -12
  15. data/lib/coderay/encoders/html.rb +113 -106
  16. data/lib/coderay/encoders/html/css.rb +7 -2
  17. data/lib/coderay/encoders/html/numbering.rb +27 -24
  18. data/lib/coderay/encoders/html/output.rb +58 -15
  19. data/lib/coderay/encoders/json.rb +44 -37
  20. data/lib/coderay/encoders/lines_of_code.rb +56 -9
  21. data/lib/coderay/encoders/null.rb +13 -6
  22. data/lib/coderay/encoders/page.rb +8 -8
  23. data/lib/coderay/encoders/span.rb +9 -10
  24. data/lib/coderay/encoders/statistic.rb +114 -51
  25. data/lib/coderay/encoders/terminal.rb +10 -7
  26. data/lib/coderay/encoders/text.rb +36 -17
  27. data/lib/coderay/encoders/token_kind_filter.rb +58 -1
  28. data/lib/coderay/encoders/xml.rb +11 -13
  29. data/lib/coderay/encoders/yaml.rb +14 -16
  30. data/lib/coderay/for_redcloth.rb +1 -1
  31. data/lib/coderay/helpers/file_type.rb +240 -125
  32. data/lib/coderay/helpers/gzip_simple.rb +123 -0
  33. data/lib/coderay/helpers/plugin.rb +307 -241
  34. data/lib/coderay/helpers/word_list.rb +126 -65
  35. data/lib/coderay/scanner.rb +103 -153
  36. data/lib/coderay/scanners/_map.rb +16 -18
  37. data/lib/coderay/scanners/c.rb +13 -13
  38. data/lib/coderay/scanners/cpp.rb +6 -6
  39. data/lib/coderay/scanners/css.rb +48 -47
  40. data/lib/coderay/scanners/debug.rb +55 -9
  41. data/lib/coderay/scanners/delphi.rb +4 -4
  42. data/lib/coderay/scanners/diff.rb +25 -43
  43. data/lib/coderay/scanners/groovy.rb +2 -2
  44. data/lib/coderay/scanners/html.rb +30 -107
  45. data/lib/coderay/scanners/java.rb +5 -6
  46. data/lib/coderay/scanners/java/builtin_types.rb +0 -2
  47. data/lib/coderay/scanners/java_script.rb +6 -6
  48. data/lib/coderay/scanners/json.rb +6 -7
  49. data/lib/coderay/scanners/nitro_xhtml.rb +136 -0
  50. data/lib/coderay/scanners/php.rb +12 -13
  51. data/lib/coderay/scanners/plaintext.rb +26 -0
  52. data/lib/coderay/scanners/python.rb +4 -4
  53. data/lib/coderay/scanners/{erb.rb → rhtml.rb} +11 -19
  54. data/lib/coderay/scanners/ruby.rb +208 -219
  55. data/lib/coderay/scanners/ruby/patterns.rb +85 -18
  56. data/lib/coderay/scanners/scheme.rb +136 -0
  57. data/lib/coderay/scanners/sql.rb +22 -29
  58. data/lib/coderay/scanners/yaml.rb +10 -11
  59. data/lib/coderay/styles/_map.rb +2 -2
  60. data/lib/coderay/styles/alpha.rb +104 -102
  61. data/lib/coderay/styles/cycnus.rb +143 -0
  62. data/lib/coderay/styles/murphy.rb +123 -0
  63. data/lib/coderay/token_kinds.rb +86 -87
  64. data/lib/coderay/tokens.rb +169 -26
  65. data/test/functional/basic.rb +14 -200
  66. data/test/functional/examples.rb +14 -20
  67. data/test/functional/for_redcloth.rb +8 -15
  68. data/test/functional/load_plugin_scanner.rb +11 -0
  69. data/test/functional/suite.rb +6 -9
  70. data/test/functional/vhdl.rb +126 -0
  71. data/test/functional/word_list.rb +79 -0
  72. metadata +129 -107
  73. data/lib/coderay/helpers/gzip.rb +0 -41
  74. data/lib/coderay/scanners/clojure.rb +0 -217
  75. data/lib/coderay/scanners/haml.rb +0 -168
  76. data/lib/coderay/scanners/ruby/string_state.rb +0 -71
  77. data/lib/coderay/scanners/text.rb +0 -26
  78. data/lib/coderay/tokens_proxy.rb +0 -55
  79. data/lib/coderay/version.rb +0 -3
@@ -0,0 +1,126 @@
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 $CODERAY_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
@@ -0,0 +1,79 @@
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
metadata CHANGED
@@ -1,126 +1,148 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: coderay
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ - 598
10
+ - pre
11
+ version: 1.0.0.598.pre
6
12
  platform: ruby
7
- authors:
8
- - Kornelius Kalnbach
13
+ authors:
14
+ - murphy
9
15
  autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
- date: 2011-09-21 00:00:00.000000000Z
18
+
19
+ date: 2010-06-11 00:00:00 +02:00
20
+ default_executable:
13
21
  dependencies: []
14
- description: Fast and easy syntax highlighting for selected languages, written in
15
- Ruby. Comes with RedCloth integration and LOC counter.
16
- email:
17
- - murphy@rubychan.de
18
- executables:
22
+
23
+ description: |
24
+ Fast and easy syntax highlighting for selected languages, written in Ruby.
25
+ Comes with RedCloth integration and LOC counter.
26
+
27
+ email: murphy@rubychan.de
28
+ executables:
19
29
  - coderay
30
+ - coderay_stylesheet
20
31
  extensions: []
21
- extra_rdoc_files:
22
- - README_INDEX.rdoc
23
- files:
24
- - LICENSE
25
- - README_INDEX.rdoc
26
- - Rakefile
27
- - lib/coderay.rb
28
- - lib/coderay/duo.rb
29
- - lib/coderay/encoder.rb
30
- - lib/coderay/encoders/_map.rb
31
- - lib/coderay/encoders/comment_filter.rb
32
- - lib/coderay/encoders/count.rb
33
- - lib/coderay/encoders/debug.rb
34
- - lib/coderay/encoders/div.rb
35
- - lib/coderay/encoders/filter.rb
36
- - lib/coderay/encoders/html.rb
37
- - lib/coderay/encoders/html/css.rb
38
- - lib/coderay/encoders/html/numbering.rb
39
- - lib/coderay/encoders/html/output.rb
40
- - lib/coderay/encoders/json.rb
41
- - lib/coderay/encoders/lines_of_code.rb
42
- - lib/coderay/encoders/null.rb
43
- - lib/coderay/encoders/page.rb
44
- - lib/coderay/encoders/span.rb
45
- - lib/coderay/encoders/statistic.rb
46
- - lib/coderay/encoders/terminal.rb
47
- - lib/coderay/encoders/text.rb
48
- - lib/coderay/encoders/token_kind_filter.rb
49
- - lib/coderay/encoders/xml.rb
50
- - lib/coderay/encoders/yaml.rb
51
- - lib/coderay/for_redcloth.rb
52
- - lib/coderay/helpers/file_type.rb
53
- - lib/coderay/helpers/gzip.rb
54
- - lib/coderay/helpers/plugin.rb
55
- - lib/coderay/helpers/word_list.rb
56
- - lib/coderay/scanner.rb
57
- - lib/coderay/scanners/_map.rb
58
- - lib/coderay/scanners/c.rb
59
- - lib/coderay/scanners/clojure.rb
60
- - lib/coderay/scanners/cpp.rb
61
- - lib/coderay/scanners/css.rb
62
- - lib/coderay/scanners/debug.rb
63
- - lib/coderay/scanners/delphi.rb
64
- - lib/coderay/scanners/diff.rb
65
- - lib/coderay/scanners/erb.rb
66
- - lib/coderay/scanners/groovy.rb
67
- - lib/coderay/scanners/haml.rb
68
- - lib/coderay/scanners/html.rb
69
- - lib/coderay/scanners/java.rb
70
- - lib/coderay/scanners/java/builtin_types.rb
71
- - lib/coderay/scanners/java_script.rb
72
- - lib/coderay/scanners/json.rb
73
- - lib/coderay/scanners/php.rb
74
- - lib/coderay/scanners/python.rb
75
- - lib/coderay/scanners/raydebug.rb
76
- - lib/coderay/scanners/ruby.rb
77
- - lib/coderay/scanners/ruby/patterns.rb
78
- - lib/coderay/scanners/ruby/string_state.rb
79
- - lib/coderay/scanners/sql.rb
80
- - lib/coderay/scanners/text.rb
81
- - lib/coderay/scanners/xml.rb
82
- - lib/coderay/scanners/yaml.rb
83
- - lib/coderay/style.rb
84
- - lib/coderay/styles/_map.rb
85
- - lib/coderay/styles/alpha.rb
86
- - lib/coderay/token_kinds.rb
87
- - lib/coderay/tokens.rb
88
- - lib/coderay/tokens_proxy.rb
89
- - lib/coderay/version.rb
90
- - test/functional/basic.rb
91
- - test/functional/examples.rb
92
- - test/functional/for_redcloth.rb
93
- - test/functional/suite.rb
94
- - bin/coderay
32
+
33
+ extra_rdoc_files:
34
+ - lib/README
35
+ - FOLDERS
36
+ files:
37
+ - ./lib/coderay/duo.rb
38
+ - ./lib/coderay/encoder.rb
39
+ - ./lib/coderay/encoders/_map.rb
40
+ - ./lib/coderay/encoders/comment_filter.rb
41
+ - ./lib/coderay/encoders/count.rb
42
+ - ./lib/coderay/encoders/debug.rb
43
+ - ./lib/coderay/encoders/div.rb
44
+ - ./lib/coderay/encoders/filter.rb
45
+ - ./lib/coderay/encoders/html/css.rb
46
+ - ./lib/coderay/encoders/html/numbering.rb
47
+ - ./lib/coderay/encoders/html/output.rb
48
+ - ./lib/coderay/encoders/html.rb
49
+ - ./lib/coderay/encoders/json.rb
50
+ - ./lib/coderay/encoders/lines_of_code.rb
51
+ - ./lib/coderay/encoders/null.rb
52
+ - ./lib/coderay/encoders/page.rb
53
+ - ./lib/coderay/encoders/span.rb
54
+ - ./lib/coderay/encoders/statistic.rb
55
+ - ./lib/coderay/encoders/terminal.rb
56
+ - ./lib/coderay/encoders/text.rb
57
+ - ./lib/coderay/encoders/token_kind_filter.rb
58
+ - ./lib/coderay/encoders/xml.rb
59
+ - ./lib/coderay/encoders/yaml.rb
60
+ - ./lib/coderay/for_redcloth.rb
61
+ - ./lib/coderay/helpers/file_type.rb
62
+ - ./lib/coderay/helpers/gzip_simple.rb
63
+ - ./lib/coderay/helpers/plugin.rb
64
+ - ./lib/coderay/helpers/word_list.rb
65
+ - ./lib/coderay/scanner.rb
66
+ - ./lib/coderay/scanners/_map.rb
67
+ - ./lib/coderay/scanners/c.rb
68
+ - ./lib/coderay/scanners/cpp.rb
69
+ - ./lib/coderay/scanners/css.rb
70
+ - ./lib/coderay/scanners/debug.rb
71
+ - ./lib/coderay/scanners/delphi.rb
72
+ - ./lib/coderay/scanners/diff.rb
73
+ - ./lib/coderay/scanners/groovy.rb
74
+ - ./lib/coderay/scanners/html.rb
75
+ - ./lib/coderay/scanners/java/builtin_types.rb
76
+ - ./lib/coderay/scanners/java.rb
77
+ - ./lib/coderay/scanners/java_script.rb
78
+ - ./lib/coderay/scanners/json.rb
79
+ - ./lib/coderay/scanners/nitro_xhtml.rb
80
+ - ./lib/coderay/scanners/php.rb
81
+ - ./lib/coderay/scanners/plaintext.rb
82
+ - ./lib/coderay/scanners/python.rb
83
+ - ./lib/coderay/scanners/raydebug.rb
84
+ - ./lib/coderay/scanners/rhtml.rb
85
+ - ./lib/coderay/scanners/ruby/patterns.rb
86
+ - ./lib/coderay/scanners/ruby.rb
87
+ - ./lib/coderay/scanners/scheme.rb
88
+ - ./lib/coderay/scanners/sql.rb
89
+ - ./lib/coderay/scanners/xml.rb
90
+ - ./lib/coderay/scanners/yaml.rb
91
+ - ./lib/coderay/style.rb
92
+ - ./lib/coderay/styles/_map.rb
93
+ - ./lib/coderay/styles/alpha.rb
94
+ - ./lib/coderay/styles/cycnus.rb
95
+ - ./lib/coderay/styles/murphy.rb
96
+ - ./lib/coderay/token_kinds.rb
97
+ - ./lib/coderay/tokens.rb
98
+ - ./lib/coderay.rb
99
+ - ./Rakefile
100
+ - ./test/functional/basic.rb
101
+ - ./test/functional/examples.rb
102
+ - ./test/functional/for_redcloth.rb
103
+ - ./test/functional/load_plugin_scanner.rb
104
+ - ./test/functional/suite.rb
105
+ - ./test/functional/vhdl.rb
106
+ - ./test/functional/word_list.rb
107
+ - ./lib/README
108
+ - ./LICENSE
109
+ - lib/README
110
+ - FOLDERS
111
+ has_rdoc: true
95
112
  homepage: http://coderay.rubychan.de
96
113
  licenses: []
114
+
97
115
  post_install_message:
98
- rdoc_options:
116
+ rdoc_options:
99
117
  - -SNw2
100
- - -mREADME_INDEX.rdoc
118
+ - -mlib/README
101
119
  - -t CodeRay Documentation
102
- require_paths:
120
+ require_paths:
103
121
  - lib
104
- required_ruby_version: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: 1.8.6
110
- required_rubygems_version: !ruby/object:Gem::Requirement
111
- none: false
112
- requirements:
113
- - - ! '>='
114
- - !ruby/object:Gem::Version
115
- version: '0'
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 1
128
+ - 8
129
+ - 2
130
+ version: 1.8.2
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">"
134
+ - !ruby/object:Gem::Version
135
+ segments:
136
+ - 1
137
+ - 3
138
+ - 1
139
+ version: 1.3.1
116
140
  requirements: []
141
+
117
142
  rubyforge_project: coderay
118
- rubygems_version: 1.8.10
143
+ rubygems_version: 1.3.6
119
144
  signing_key:
120
145
  specification_version: 3
121
146
  summary: Fast syntax highlighting for selected languages.
122
- test_files:
123
- - test/functional/basic.rb
124
- - test/functional/examples.rb
125
- - test/functional/for_redcloth.rb
126
- - test/functional/suite.rb
147
+ test_files:
148
+ - ./test/functional/suite.rb