diff options
author | murphy <murphy@rubychan.de> | 2010-09-12 11:18:24 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2010-09-12 11:18:24 +0000 |
commit | f3cd0a4b28dad1e447d3247797d8e346fe9339e5 (patch) | |
tree | c46ce57b704536c38dbe2fc910a15e6fb7d3c87c /lib/coderay/scanners/json.rb | |
parent | f655f0ef853a32c892526f8891f76c8991b3719c (diff) | |
download | coderay-f3cd0a4b28dad1e447d3247797d8e346fe9339e5.tar.gz |
Cleanups in the JSON scanner; eliminated the kind local variable.
Diffstat (limited to 'lib/coderay/scanners/json.rb')
-rw-r--r-- | lib/coderay/scanners/json.rb | 13 |
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 |