summaryrefslogtreecommitdiff
path: root/lib/coderay
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2010-09-12 11:18:24 +0000
committermurphy <murphy@rubychan.de>2010-09-12 11:18:24 +0000
commitf3cd0a4b28dad1e447d3247797d8e346fe9339e5 (patch)
treec46ce57b704536c38dbe2fc910a15e6fb7d3c87c /lib/coderay
parentf655f0ef853a32c892526f8891f76c8991b3719c (diff)
downloadcoderay-f3cd0a4b28dad1e447d3247797d8e346fe9339e5.tar.gz
Cleanups in the JSON scanner; eliminated the kind local variable.
Diffstat (limited to 'lib/coderay')
-rw-r--r--lib/coderay/scanners/json.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/coderay/scanners/json.rb b/lib/coderay/scanners/json.rb
index b36811f..0c90c34 100644
--- a/lib/coderay/scanners/json.rb
+++ b/lib/coderay/scanners/json.rb
@@ -13,10 +13,11 @@ module Scanners
] # :nodoc:
ESCAPE = / [bfnrt\\"\/] /x # :nodoc:
- UNICODE_ESCAPE = / u[a-fA-F0-9]{4} /x # :nodoc:
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} /x # :nodoc:
protected
+ # See http://json.org/ for a definition of the JSON lexic/grammar.
def scan_tokens encoder, options
state = :initial
@@ -44,14 +45,14 @@ module Scanners
when '}', ']' then stack.pop # no error recovery, but works for valid JSON
end
elsif match = scan(/ true | false | null /x)
- encoder.text_token match, :value
+ encoder.text_token match, :value
elsif match = scan(/ -? (?: 0 | [1-9]\d* ) /x)
- kind = :integer
if scan(/ \.\d+ (?:[eE][-+]?\d+)? | [eE][-+]? \d+ /x)
match << matched
- kind = :float
+ encoder.text_token match, :float
+ else
+ encoder.text_token match, :integer
end
- encoder.text_token match, kind
else
encoder.text_token getch, :error
end
@@ -76,7 +77,7 @@ module Scanners
end
else
- raise_inspect 'Unknown state', encoder
+ raise_inspect 'Unknown state: %p' % [state], encoder
end
end