summaryrefslogtreecommitdiff
path: root/lib/coderay/scanner.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2009-01-01 03:19:28 +0000
committermurphy <murphy@rubychan.de>2009-01-01 03:19:28 +0000
commitc9eac585f167788dd590db06776b132923455a93 (patch)
treee4f8ade4d74b66fba6062f9d7be20c9454d777fc /lib/coderay/scanner.rb
parentb9c0dd7c02467e633e195ef97e0f4748e588e799 (diff)
downloadcoderay-c9eac585f167788dd590db06776b132923455a93.tar.gz
Completed YAML Scanner (closes #34).
YAML Scanner: * Added another example (multiline). * Added multiline string recognition. * This should be enough for most people. Else: * New method: Scanner#column (very useful and fast!) * Added new token type :doctype, used also by HTML scanner. * coderay_suite: minor output tweaks.
Diffstat (limited to 'lib/coderay/scanner.rb')
-rw-r--r--lib/coderay/scanner.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb
index 831fc39..371c858 100644
--- a/lib/coderay/scanner.rb
+++ b/lib/coderay/scanner.rb
@@ -180,6 +180,11 @@ module CodeRay
def line
string[0..pos].count("\n") + 1
end
+
+ def column pos = self.pos
+ return 0 if pos <= 0
+ pos - (string.rindex(?\n, pos) || 0)
+ end
protected
@@ -216,7 +221,7 @@ module CodeRay
tokens:
%s
-current line: %d pos = %d
+current line: %d column: %d pos: %d
matched: %p state: %p
bol? = %p, eos? = %p
@@ -231,7 +236,7 @@ surrounding code:
msg,
tokens.size,
tokens.last(10).map { |t| t.inspect }.join("\n"),
- line, pos,
+ line, column, pos,
matched, state, bol?, eos?,
string[pos - ambit, ambit],
string[pos, ambit],