From 59b7164d1b400f44d7aca2ec3d558e2b95153c4a Mon Sep 17 00:00:00 2001 From: murphy Date: Fri, 20 Feb 2009 18:23:16 +0000 Subject: JavaScript scanner: Fixed string keys (closes #85). --- lib/coderay/scanners/java_script.rb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'lib/coderay/scanners/java_script.rb') diff --git a/lib/coderay/scanners/java_script.rb b/lib/coderay/scanners/java_script.rb index e9ae14f..6a10ed4 100644 --- a/lib/coderay/scanners/java_script.rb +++ b/lib/coderay/scanners/java_script.rb @@ -42,6 +42,10 @@ module Scanners '"' => /[^\\"]+/, '/' => /[^\\\/]+/, } + KEY_CHECK_PATTERN = { + "'" => / [^\\']* (?: \\.? [^\\']* )* '? \s* : /x, + '"' => / [^\\"]* (?: \\.? [^\\"]* )* "? \s* : /x, + } def scan_tokens tokens, options @@ -102,18 +106,13 @@ module Scanners end key_expected = false - # TODO: string key recognition - # There's a problem with expressions like: PAIRS: { 'slide': ['SlideDown','SlideUp'], ... }. - # The commas in the array are confusing the scanner here. - # elsif key_expected && match = scan(/["']/) - # tokens << [:open, :key] - # state = :key - # string_delimiter = match - # kind = :delimiter - elsif match = scan(/["']/) - tokens << [:open, :string] - state = :string + if key_expected && check(KEY_CHECK_PATTERN[match]) + state = :key + else + state = :string + end + tokens << [:open, state] string_delimiter = match kind = :delimiter -- cgit v1.2.1