coderay 1.1.0.rc1 → 1.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88c4f8c3def05dd733e1e3b7707fb7e1f2d20d54
4
- data.tar.gz: fe1abf58ddac324444cf7659d9d5d335bf470b46
3
+ metadata.gz: 4c0077f84e2d594d0f25b74fa857af9ef648296f
4
+ data.tar.gz: 8a18fd96a16808dcad2244f2ed61f32d60fb4f54
5
5
  SHA512:
6
- metadata.gz: fad90cb9e8943b9cf55c8d54a5ab099d1012dcbdfa5208d58abb74aa6111d3d6d86cdb1f0f937b46533d813b59aa9ed1673942ab184618110349f38314117f2e
7
- data.tar.gz: 1a2f782f48e427d181f557fded51236567200dd9b10a33a8668da98a5cccdb52872e4bbf0c68f2490a685b01430157bfb471ae892075cd25b56bb52e7fe7b56c
6
+ metadata.gz: a62e8ec122a108c5585d8539d3a6885c1adb51c7b1042231c0b27a5d3d44f998329285aacb72d2e575e8e11e09a653741f5eceaece1bb14340d45f07e1f3d72e
7
+ data.tar.gz: 50ee917b13eaec6627578d14d6b324c887a3b89600c6f313afb8004a578d7dbcb0465812500c89894c6a9e0140904d7c6a427d64e6a6235fb2a4bf08791732db
@@ -86,6 +86,7 @@ module CodeRay
86
86
  'dpr' => :delphi,
87
87
  'erb' => :erb,
88
88
  'gemspec' => :ruby,
89
+ 'go' => :go,
89
90
  'groovy' => :groovy,
90
91
  'gvy' => :groovy,
91
92
  'h' => :c,
@@ -0,0 +1,209 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ # Scanner for Go, copy from c
5
+ class Go < Scanner
6
+
7
+ register_for :go
8
+ file_extension 'go'
9
+
10
+ # http://golang.org/ref/spec#Keywords
11
+ KEYWORDS = [
12
+ 'break', 'default', 'func', 'interface', 'select',
13
+ 'case', 'defer', 'go', 'map', 'struct',
14
+ 'chan', 'else', 'goto', 'package', 'switch',
15
+ 'const', 'fallthrough', 'if', 'range', 'type',
16
+ 'continue', 'for', 'import', 'return', 'var',
17
+ ] # :nodoc:
18
+
19
+ # http://golang.org/ref/spec#Types
20
+ PREDEFINED_TYPES = [
21
+ 'bool',
22
+ 'uint8', 'uint16', 'uint32', 'uint64',
23
+ 'int8', 'int16', 'int32', 'int64',
24
+ 'float32', 'float64',
25
+ 'complex64', 'complex128',
26
+ 'byte', 'rune', 'string', 'error',
27
+ 'uint', 'int', 'uintptr',
28
+ ] # :nodoc:
29
+
30
+ PREDEFINED_CONSTANTS = [
31
+ 'nil', 'iota',
32
+ 'true', 'false',
33
+ ] # :nodoc:
34
+
35
+ PREDEFINED_FUNCTIONS = %w[
36
+ append cap close complex copy delete imag len
37
+ make new panic print println real recover
38
+ ] # :nodoc:
39
+
40
+ IDENT_KIND = WordList.new(:ident).
41
+ add(KEYWORDS, :keyword).
42
+ add(PREDEFINED_TYPES, :predefined_type).
43
+ add(PREDEFINED_CONSTANTS, :predefined_constant).
44
+ add(PREDEFINED_FUNCTIONS, :predefined) # :nodoc:
45
+
46
+ ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
47
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
48
+
49
+ protected
50
+
51
+ def scan_tokens encoder, options
52
+
53
+ state = :initial
54
+ label_expected = true
55
+ case_expected = false
56
+ label_expected_before_preproc_line = nil
57
+ in_preproc_line = false
58
+
59
+ until eos?
60
+
61
+ case state
62
+
63
+ when :initial
64
+
65
+ if match = scan(/ \s+ | \\\n /x)
66
+ if in_preproc_line && match != "\\\n" && match.index(?\n)
67
+ in_preproc_line = false
68
+ case_expected = false
69
+ label_expected = label_expected_before_preproc_line
70
+ end
71
+ encoder.text_token match, :space
72
+
73
+ elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
74
+ encoder.text_token match, :comment
75
+
76
+ elsif match = scan(/ <?- (?![\d.]) | [+*=<>?:;,!&^|()\[\]{}~%]+ | \/=? | \.(?!\d) /x)
77
+ if case_expected
78
+ label_expected = true if match == ':'
79
+ case_expected = false
80
+ end
81
+ encoder.text_token match, :operator
82
+
83
+ elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
84
+ kind = IDENT_KIND[match]
85
+ if kind == :ident && label_expected && !in_preproc_line && scan(/:(?!:)/)
86
+ kind = :label
87
+ label_expected = false
88
+ match << matched
89
+ else
90
+ label_expected = false
91
+ if kind == :keyword
92
+ case match
93
+ when 'case', 'default'
94
+ case_expected = true
95
+ end
96
+ end
97
+ end
98
+ encoder.text_token match, kind
99
+
100
+ elsif match = scan(/L?"/)
101
+ encoder.begin_group :string
102
+ if match[0] == ?L
103
+ encoder.text_token 'L', :modifier
104
+ match = '"'
105
+ end
106
+ encoder.text_token match, :delimiter
107
+ state = :string
108
+
109
+ elsif match = scan(/ ` ([^`]+)? (`)? /x)
110
+ encoder.begin_group :shell
111
+ encoder.text_token '`', :delimiter
112
+ encoder.text_token self[1], :content if self[1]
113
+ encoder.text_token self[2], :delimiter if self[2]
114
+ encoder.end_group :shell
115
+
116
+ elsif match = scan(/ \# \s* if \s* 0 /x)
117
+ match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos?
118
+ encoder.text_token match, :comment
119
+
120
+ elsif match = scan(/#[ \t]*(\w*)/)
121
+ encoder.text_token match, :preprocessor
122
+ in_preproc_line = true
123
+ label_expected_before_preproc_line = label_expected
124
+ state = :include_expected if self[1] == 'include'
125
+
126
+ elsif match = scan(/ L?' (?: [^\'\n\\] | \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) )? '? /ox)
127
+ label_expected = false
128
+ encoder.text_token match, :char
129
+
130
+ elsif match = scan(/\$/)
131
+ encoder.text_token match, :ident
132
+
133
+ elsif match = scan(/-?\d*(\.\d*)?([eE][+-]?\d+)?i/)
134
+ label_expected = false
135
+ encoder.text_token match, :imaginary
136
+
137
+ elsif match = scan(/-?0[xX][0-9A-Fa-f]+/)
138
+ label_expected = false
139
+ encoder.text_token match, :hex
140
+
141
+ elsif match = scan(/-?(?:0[0-7]+)(?![89.eEfF])/)
142
+ label_expected = false
143
+ encoder.text_token match, :octal
144
+
145
+ elsif match = scan(/-?(?:\d*\.\d+|\d+\.)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+/)
146
+ label_expected = false
147
+ encoder.text_token match, :float
148
+
149
+ elsif match = scan(/-?(?:\d+)(?![.eEfF])L?L?/)
150
+ label_expected = false
151
+ encoder.text_token match, :integer
152
+
153
+ else
154
+ encoder.text_token getch, :error
155
+
156
+ end
157
+
158
+ when :string
159
+ if match = scan(/[^\\\n"]+/)
160
+ encoder.text_token match, :content
161
+ elsif match = scan(/"/)
162
+ encoder.text_token match, :delimiter
163
+ encoder.end_group :string
164
+ state = :initial
165
+ label_expected = false
166
+ elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
167
+ encoder.text_token match, :char
168
+ elsif match = scan(/ \\ /x)
169
+ encoder.text_token match, :error
170
+ elsif match = scan(/$/)
171
+ encoder.end_group :string
172
+ state = :initial
173
+ label_expected = false
174
+ else
175
+ raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
176
+ end
177
+
178
+ when :include_expected
179
+ if match = scan(/<[^>\n]+>?|"[^"\n\\]*(?:\\.[^"\n\\]*)*"?/)
180
+ encoder.text_token match, :include
181
+ state = :initial
182
+
183
+ elsif match = scan(/\s+/)
184
+ encoder.text_token match, :space
185
+ state = :initial if match.index ?\n
186
+
187
+ else
188
+ state = :initial
189
+
190
+ end
191
+
192
+ else
193
+ raise_inspect 'Unknown state', encoder
194
+
195
+ end
196
+
197
+ end
198
+
199
+ if state == :string
200
+ encoder.end_group :string
201
+ end
202
+
203
+ encoder
204
+ end
205
+
206
+ end
207
+
208
+ end
209
+ end
@@ -107,7 +107,7 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
107
107
  .operator { }
108
108
  .predefined { color:#369; font-weight:bold }
109
109
  .predefined-constant { color:#069 }
110
- .predefined-type { color:#0a5; font-weight:bold }
110
+ .predefined-type { color:#0a8; font-weight:bold }
111
111
  .preprocessor { color:#579 }
112
112
  .pseudo-class { color:#00C; font-weight:bold }
113
113
  .regexp { background-color:hsla(300,100%,50%,0.06); }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coderay
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.rc1
4
+ version: 1.1.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kornelius Kalnbach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-13 00:00:00.000000000 Z
11
+ date: 2013-07-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fast and easy syntax highlighting for selected languages, written in
14
14
  Ruby. Comes with RedCloth integration and LOC counter.
@@ -62,6 +62,7 @@ files:
62
62
  - lib/coderay/scanners/delphi.rb
63
63
  - lib/coderay/scanners/diff.rb
64
64
  - lib/coderay/scanners/erb.rb
65
+ - lib/coderay/scanners/go.rb
65
66
  - lib/coderay/scanners/groovy.rb
66
67
  - lib/coderay/scanners/haml.rb
67
68
  - lib/coderay/scanners/html.rb