Skip to content

Commit bbe4d72

Browse files
committed
tweak numeral tokens handling (rubychan#147)
1 parent 4c24863 commit bbe4d72

File tree

1 file changed

+10
-10
lines changed
  • lib/coderay/scanners

1 file changed

+10
-10
lines changed

lib/coderay/scanners/go.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Go < Scanner
3131
'nil', 'iota',
3232
'true', 'false',
3333
] # :nodoc:
34-
34+
3535
PREDEFINED_FUNCTIONS = %w[
3636
append cap close complex copy delete imag len
3737
make new panic print println real recover
@@ -73,7 +73,7 @@ def scan_tokens encoder, options
7373
elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
7474
encoder.text_token match, :comment
7575

76-
elsif match = scan(/ [-+*=<>?:;,!&^|()\[\]{}~%]+ | \/=? | \.(?!\d) /x)
76+
elsif match = scan(/ <?- (?![\d.]) | [+*=<>?:;,!&^|()\[\]{}~%]+ | \/=? | \.(?!\d) /x)
7777
if case_expected
7878
label_expected = true if match == ':'
7979
case_expected = false
@@ -129,24 +129,24 @@ def scan_tokens encoder, options
129129

130130
elsif match = scan(/\$/)
131131
encoder.text_token match, :ident
132-
133-
elsif match = scan(/\d*(\.\d*)?([eE][+-]?\d+)?i/)
132+
133+
elsif match = scan(/-?\d*(\.\d*)?([eE][+-]?\d+)?i/)
134134
label_expected = false
135135
encoder.text_token match, :imaginary
136-
137-
elsif match = scan(/0[xX][0-9A-Fa-f]+/)
136+
137+
elsif match = scan(/-?0[xX][0-9A-Fa-f]+/)
138138
label_expected = false
139139
encoder.text_token match, :hex
140140

141-
elsif match = scan(/(?:0[0-7]+)(?![89.eEfF])/)
141+
elsif match = scan(/-?(?:0[0-7]+)(?![89.eEfF])/)
142142
label_expected = false
143143
encoder.text_token match, :octal
144144

145-
elsif match = scan(/\d|\d*\.\d+(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+/)
145+
elsif match = scan(/-?(?:\d*\.\d+|\d+\.)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+/)
146146
label_expected = false
147147
encoder.text_token match, :float
148-
149-
elsif match = scan(/(?:\d+)(?![.eEfF])L?L?/)
148+
149+
elsif match = scan(/-?(?:\d+)(?![.eEfF])L?L?/)
150150
label_expected = false
151151
encoder.text_token match, :integer
152152

0 commit comments

Comments
 (0)