Skip to content

Commit 02e41d8

Browse files
committed
fixed YAML scanner (Scanner#column rewrite broke it)
1 parent cb0e91a commit 02e41d8

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

lib/coderay/scanner.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ def line pos = self.pos
231231

232232
# The current column position of the scanner, starting with 1.
233233
# See also: #line.
234-
#
235-
# Beware, this is implemented inefficiently. It should be used
236-
# for debugging only.
237234
def column pos = self.pos
238235
return 1 if pos <= 0
239236
pos - (binary_string.rindex(?\n, pos - 1) || -1)

lib/coderay/scanners/yaml.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ class YAML < Scanner
1515

1616
def scan_tokens encoder, options
1717

18-
value_expected = nil
1918
state = :initial
20-
key_indent = indent = 0
19+
key_indent = string_indent = 0
2120

2221
until eos?
2322

@@ -55,14 +54,14 @@ def scan_tokens encoder, options
5554
when match = scan(/[|>][-+]?/)
5655
encoder.begin_group :string
5756
encoder.text_token match, :delimiter
58-
string_indent = key_indent || column(pos - match.size - 1)
57+
string_indent = key_indent || column(pos - match.size) - 1
5958
encoder.text_token matched, :content if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
6059
encoder.end_group :string
6160
next
6261
when match = scan(/(?![!"*&]).+?(?=$|\s+#)/)
6362
encoder.begin_group :string
6463
encoder.text_token match, :content
65-
string_indent = key_indent || column(pos - match.size - 1)
64+
string_indent = key_indent || column(pos - match.size) - 1
6665
encoder.text_token matched, :content if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
6766
encoder.end_group :string
6867
next
@@ -79,7 +78,7 @@ def scan_tokens encoder, options
7978
next
8079
when state == :initial && match = scan(/[\w.() ]*\S(?= *:(?: |$))/)
8180
encoder.text_token match, :key
82-
key_indent = column(pos - match.size - 1)
81+
key_indent = column(pos - match.size) - 1
8382
state = :colon
8483
next
8584
when match = scan(/(?:"[^"\n]*"|'[^'\n]*')(?= *:(?: |$))/)
@@ -88,7 +87,7 @@ def scan_tokens encoder, options
8887
encoder.text_token match[1..-2], :content
8988
encoder.text_token match[-1,1], :delimiter
9089
encoder.end_group :key
91-
key_indent = column(pos - match.size - 1)
90+
key_indent = column(pos - match.size) - 1
9291
state = :colon
9392
next
9493
when match = scan(/(![\w\/]+)(:([\w:]+))?/)

0 commit comments

Comments
 (0)