From f3cd0a4b28dad1e447d3247797d8e346fe9339e5 Mon Sep 17 00:00:00 2001 From: murphy Date: Sun, 12 Sep 2010 11:18:24 +0000 Subject: Cleanups in the JSON scanner; eliminated the kind local variable. --- lib/coderay/scanners/json.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/coderay/scanners/json.rb') 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 -- cgit v1.2.1