summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2013-06-22 23:43:29 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2013-06-22 23:43:29 +0200
commitffe0c90999c0b7255a5dfc608c84e683440475b1 (patch)
treedaa3914a8ff8f3272c7838dc4f057c4589126d85
parent196b7296666c12b0c04fa6b8dc42e46ed9331432 (diff)
parent2abfc49bdc9a9f4e86c90aa968c302ca76c20812 (diff)
downloadcoderay-ffe0c90999c0b7255a5dfc608c84e683440475b1.tar.gz
Merge branch 'master' into cleanup-output
-rw-r--r--lib/coderay/helpers/file_type.rb1
-rw-r--r--lib/coderay/scanners/json.rb23
-rw-r--r--lib/coderay/styles/alpha.rb2
-rw-r--r--test/executable/suite.rb2
4 files changed, 14 insertions, 14 deletions
diff --git a/lib/coderay/helpers/file_type.rb b/lib/coderay/helpers/file_type.rb
index 6144e8c..19f27ac 100644
--- a/lib/coderay/helpers/file_type.rb
+++ b/lib/coderay/helpers/file_type.rb
@@ -120,6 +120,7 @@ module CodeRay
'sass' => :sass,
'sql' => :sql,
'taskpaper' => :taskpaper,
+ 'template' => :json, # AWS CloudFormation template
'tmproj' => :xml,
'xaml' => :xml,
'xhtml' => :html,
diff --git a/lib/coderay/scanners/json.rb b/lib/coderay/scanners/json.rb
index 4e0f462..3754a9b 100644
--- a/lib/coderay/scanners/json.rb
+++ b/lib/coderay/scanners/json.rb
@@ -14,15 +14,17 @@ module Scanners
ESCAPE = / [bfnrt\\"\/] /x # :nodoc:
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} /x # :nodoc:
+ KEY = / (?> (?: [^\\"]+ | \\. )* ) " \s* : /x
protected
+ def setup
+ @state = :initial
+ end
+
# See http://json.org/ for a definition of the JSON lexic/grammar.
def scan_tokens encoder, options
-
- state = :initial
- stack = []
- key_expected = false
+ state = options[:state] || @state
until eos?
@@ -32,18 +34,11 @@ module Scanners
if match = scan(/ \s+ /x)
encoder.text_token match, :space
elsif match = scan(/"/)
- state = key_expected ? :key : :string
+ state = check(/#{KEY}/o) ? :key : :string
encoder.begin_group state
encoder.text_token match, :delimiter
elsif match = scan(/ [:,\[{\]}] /x)
encoder.text_token match, :operator
- case match
- when ':' then key_expected = false
- when ',' then key_expected = true if stack.last == :object
- when '{' then stack << :object; key_expected = true
- when '[' then stack << :array
- 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
elsif match = scan(/ -? (?: 0 | [1-9]\d* ) /x)
@@ -82,6 +77,10 @@ module Scanners
end
end
+ if options[:keep_state]
+ @state = state
+ end
+
if [:string, :key].include? state
encoder.end_group state
end
diff --git a/lib/coderay/styles/alpha.rb b/lib/coderay/styles/alpha.rb
index 9a94091..f4d07f1 100644
--- a/lib/coderay/styles/alpha.rb
+++ b/lib/coderay/styles/alpha.rb
@@ -123,7 +123,7 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
.symbol { color:#A60 }
.symbol .content { color:#A60 }
.symbol .delimiter { color:#630 }
-.tag { color:#070 }
+.tag { color:#070; font-weight:bold }
.type { color:#339; font-weight:bold }
.value { color: #088 }
.variable { color:#037 }
diff --git a/test/executable/suite.rb b/test/executable/suite.rb
index d386f4b..997405c 100644
--- a/test/executable/suite.rb
+++ b/test/executable/suite.rb
@@ -14,7 +14,7 @@ class TestCodeRayExecutable < Test::Unit::TestCase
ROOT_DIR = Pathname.new(File.dirname(__FILE__)) + '..' + '..'
EXECUTABLE = ROOT_DIR + 'bin' + 'coderay'
- RUBY_COMMAND = RUBY_VERSION < '2.0.0' ? 'ruby -w' : 'ruby' # Ruby 2 currently throws warnings for bundler
+ RUBY_COMMAND = 'ruby'
EXE_COMMAND =
if RUBY_PLATFORM === 'java' && `ruby --ng -e '' 2> /dev/null` && $?.success?
# use Nailgun