From c9eac585f167788dd590db06776b132923455a93 Mon Sep 17 00:00:00 2001 From: murphy Date: Thu, 1 Jan 2009 03:19:28 +0000 Subject: 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. --- lib/coderay/scanner.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/coderay/scanner.rb') 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], -- cgit v1.2.1