summaryrefslogtreecommitdiff
path: root/lib/coderay/scanners/java_script.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2009-02-20 18:23:16 +0000
committermurphy <murphy@rubychan.de>2009-02-20 18:23:16 +0000
commit59b7164d1b400f44d7aca2ec3d558e2b95153c4a (patch)
treee3d12de585a39abb1ea660c83a511b53fc807961 /lib/coderay/scanners/java_script.rb
parent349a43acf6a75f0fbc2e9a2247708785e2e1c4d1 (diff)
downloadcoderay-59b7164d1b400f44d7aca2ec3d558e2b95153c4a.tar.gz
JavaScript scanner: Fixed string keys (closes #85).
Diffstat (limited to 'lib/coderay/scanners/java_script.rb')
-rw-r--r--lib/coderay/scanners/java_script.rb21
1 files changed, 10 insertions, 11 deletions
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