Skip to content

Commit ffe0c90

Browse files
committed
Merge branch 'master' into cleanup-output
2 parents 196b729 + 2abfc49 commit ffe0c90

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

lib/coderay/helpers/file_type.rb

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def shebang filename
120120
'sass' => :sass,
121121
'sql' => :sql,
122122
'taskpaper' => :taskpaper,
123+
'template' => :json, # AWS CloudFormation template
123124
'tmproj' => :xml,
124125
'xaml' => :xml,
125126
'xhtml' => :html,

lib/coderay/scanners/json.rb

+11-12
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ class JSON < Scanner
1414

1515
ESCAPE = / [bfnrt\\"\/] /x # :nodoc:
1616
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} /x # :nodoc:
17+
KEY = / (?> (?: [^\\"]+ | \\. )* ) " \s* : /x
1718

1819
protected
1920

21+
def setup
22+
@state = :initial
23+
end
24+
2025
# See http://json.org/ for a definition of the JSON lexic/grammar.
2126
def scan_tokens encoder, options
22-
23-
state = :initial
24-
stack = []
25-
key_expected = false
27+
state = options[:state] || @state
2628

2729
until eos?
2830

@@ -32,18 +34,11 @@ def scan_tokens encoder, options
3234
if match = scan(/ \s+ /x)
3335
encoder.text_token match, :space
3436
elsif match = scan(/"/)
35-
state = key_expected ? :key : :string
37+
state = check(/#{KEY}/o) ? :key : :string
3638
encoder.begin_group state
3739
encoder.text_token match, :delimiter
3840
elsif match = scan(/ [:,\[{\]}] /x)
3941
encoder.text_token match, :operator
40-
case match
41-
when ':' then key_expected = false
42-
when ',' then key_expected = true if stack.last == :object
43-
when '{' then stack << :object; key_expected = true
44-
when '[' then stack << :array
45-
when '}', ']' then stack.pop # no error recovery, but works for valid JSON
46-
end
4742
elsif match = scan(/ true | false | null /x)
4843
encoder.text_token match, :value
4944
elsif match = scan(/ -? (?: 0 | [1-9]\d* ) /x)
@@ -82,6 +77,10 @@ def scan_tokens encoder, options
8277
end
8378
end
8479

80+
if options[:keep_state]
81+
@state = state
82+
end
83+
8584
if [:string, :key].include? state
8685
encoder.end_group state
8786
end

lib/coderay/styles/alpha.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Alpha < Style
123123
.symbol { color:#A60 }
124124
.symbol .content { color:#A60 }
125125
.symbol .delimiter { color:#630 }
126-
.tag { color:#070 }
126+
.tag { color:#070; font-weight:bold }
127127
.type { color:#339; font-weight:bold }
128128
.value { color: #088 }
129129
.variable { color:#037 }

test/executable/suite.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TestCodeRayExecutable < Test::Unit::TestCase
1414

1515
ROOT_DIR = Pathname.new(File.dirname(__FILE__)) + '..' + '..'
1616
EXECUTABLE = ROOT_DIR + 'bin' + 'coderay'
17-
RUBY_COMMAND = RUBY_VERSION < '2.0.0' ? 'ruby -w' : 'ruby' # Ruby 2 currently throws warnings for bundler
17+
RUBY_COMMAND = 'ruby'
1818
EXE_COMMAND =
1919
if RUBY_PLATFORM === 'java' && `ruby --ng -e '' 2> /dev/null` && $?.success?
2020
# use Nailgun

0 commit comments

Comments
 (0)