summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2011-08-29 07:06:27 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2011-08-29 07:06:27 +0200
commit02e41d8e589183586ad50ad22d9352fca64f4336 (patch)
tree658a79fed5238a9e7bb51c41418cc11ac03cac26
parentcb0e91a18be79d1bfeeb344b99b046f3c2305f2e (diff)
downloadcoderay-02e41d8e589183586ad50ad22d9352fca64f4336.tar.gz
fixed YAML scanner (Scanner#column rewrite broke it)
-rw-r--r--lib/coderay/scanner.rb3
-rw-r--r--lib/coderay/scanners/yaml.rb11
2 files changed, 5 insertions, 9 deletions
diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb
index cce8633..7ecbe4f 100644
--- a/lib/coderay/scanner.rb
+++ b/lib/coderay/scanner.rb
@@ -231,9 +231,6 @@ module CodeRay
# The current column position of the scanner, starting with 1.
# See also: #line.
- #
- # Beware, this is implemented inefficiently. It should be used
- # for debugging only.
def column pos = self.pos
return 1 if pos <= 0
pos - (binary_string.rindex(?\n, pos - 1) || -1)
diff --git a/lib/coderay/scanners/yaml.rb b/lib/coderay/scanners/yaml.rb
index 386265d..5e74f2f 100644
--- a/lib/coderay/scanners/yaml.rb
+++ b/lib/coderay/scanners/yaml.rb
@@ -15,9 +15,8 @@ module Scanners
def scan_tokens encoder, options
- value_expected = nil
state = :initial
- key_indent = indent = 0
+ key_indent = string_indent = 0
until eos?
@@ -55,14 +54,14 @@ module Scanners
when match = scan(/[|>][-+]?/)
encoder.begin_group :string
encoder.text_token match, :delimiter
- string_indent = key_indent || column(pos - match.size - 1)
+ string_indent = key_indent || column(pos - match.size) - 1
encoder.text_token matched, :content if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
encoder.end_group :string
next
when match = scan(/(?![!"*&]).+?(?=$|\s+#)/)
encoder.begin_group :string
encoder.text_token match, :content
- string_indent = key_indent || column(pos - match.size - 1)
+ string_indent = key_indent || column(pos - match.size) - 1
encoder.text_token matched, :content if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
encoder.end_group :string
next
@@ -79,7 +78,7 @@ module Scanners
next
when state == :initial && match = scan(/[\w.() ]*\S(?= *:(?: |$))/)
encoder.text_token match, :key
- key_indent = column(pos - match.size - 1)
+ key_indent = column(pos - match.size) - 1
state = :colon
next
when match = scan(/(?:"[^"\n]*"|'[^'\n]*')(?= *:(?: |$))/)
@@ -88,7 +87,7 @@ module Scanners
encoder.text_token match[1..-2], :content
encoder.text_token match[-1,1], :delimiter
encoder.end_group :key
- key_indent = column(pos - match.size - 1)
+ key_indent = column(pos - match.size) - 1
state = :colon
next
when match = scan(/(![\w\/]+)(:([\w:]+))?/)