summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2016-02-13 17:05:38 +0100
committerKornelius Kalnbach <murphy@rubychan.de>2016-02-13 17:05:38 +0100
commit0b19ccfa96e1c7e4999e6e2619ae0b266b54402a (patch)
tree974590b0902ca01731a90d8c9dcc25c34e2b3ff8
parente93cdf6cc6b8fb9179fa82a1f9bad77eae1e9830 (diff)
parent0ad3ddc26da51b3bdd0454859f894761a0155c1b (diff)
downloadcoderay-0b19ccfa96e1c7e4999e6e2619ae0b266b54402a.tar.gz
Merge branch 'master' into possible-speedups
-rw-r--r--.travis.yml4
-rw-r--r--Changes.textile10
-rw-r--r--Gemfile1
-rw-r--r--lib/coderay/encoders/html.rb3
-rw-r--r--lib/coderay/scanners/ruby.rb19
-rw-r--r--lib/coderay/scanners/ruby/patterns.rb2
-rw-r--r--lib/coderay/scanners/ruby/string_state.rb8
-rw-r--r--lib/coderay/scanners/sql.rb2
-rw-r--r--lib/coderay/styles/alpha.rb3
9 files changed, 40 insertions, 12 deletions
diff --git a/.travis.yml b/.travis.yml
index 8e18c0a..f815698 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,9 +2,10 @@ rvm:
- 1.8.7
- ree
- 1.9.3
- - 2.0.0
+ - 2.0
- 2.1
- 2.2
+ - 2.3.0
- ruby-head
- jruby-18mode
- jruby-19mode
@@ -21,3 +22,4 @@ matrix:
- rvm: rbx-18mode
- rvm: rbx-19mode
script: "rake test" # test:scanners"
+sudo: false
diff --git a/Changes.textile b/Changes.textile
index 137460a..50da5c7 100644
--- a/Changes.textile
+++ b/Changes.textile
@@ -4,7 +4,15 @@ p=. _This files lists all changes in the CodeRay library since the 0.9.8 release
h2. Changes in 1.1.1
-* SQL scanner: fix open strings [#163, thanks to Adam]
+* SQL scanner: Allow @$@ signs in SQL identifiers [#164, thanks to jasir and Ben Basson]
+* SQL scanner: Fix open strings [#163, thanks to Adam]
+* Ruby scanner: Accept number literal suffixes @r@ and @i@ (Ruby 2.1)
+* Ruby scanner: Accept quoted hash keys like @{ "a": boss }@ (Ruby 2.2)
+* Ruby scanner: Accept save navigation operator @&.@ (Ruby 2.3)
+* Ruby scanner: Accept squiggly heredoc @<<~@ (Ruby 2.3)
+* Diff scanner: Prevent running out of regexp stack.
+* HTML encoder: You can keep tabs intact now by setting @tab_width: false@.
+* Alpha style: Tweaked colors for @:function@ group with @:content@.
h2. Changes in 1.1
diff --git a/Gemfile b/Gemfile
index 0fae04b..6d3a176 100644
--- a/Gemfile
+++ b/Gemfile
@@ -10,6 +10,7 @@ group :development do
gem "rake"
gem "RedCloth", RUBY_PLATFORM == 'java' ? ">= 4.2.7" : ">= 4.0.3"
gem "term-ansicolor"
+ gem 'tins', '~> 1.6.0'
gem "shoulda-context"
gem "test-unit"
gem "json" if RUBY_VERSION < '1.9'
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb
index a2c274f..55b1291 100644
--- a/lib/coderay/encoders/html.rb
+++ b/lib/coderay/encoders/html.rb
@@ -25,7 +25,8 @@ module Encoders
# == Options
#
# === :tab_width
- # Convert \t characters to +n+ spaces (a number.)
+ # Convert \t characters to +n+ spaces (a number or false.)
+ # false will keep tab characters untouched.
#
# Default: 8
#
diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb
index 80165ca..5b8de42 100644
--- a/lib/coderay/scanners/ruby.rb
+++ b/lib/coderay/scanners/ruby.rb
@@ -164,15 +164,19 @@ module Scanners
end
elsif match = scan(/ ' (?:(?>[^'\\]*) ')? | " (?:(?>[^"\\\#]*) ")? /mx)
- encoder.begin_group :string
if match.size == 1
+ kind = check(self.class::StringState.simple_key_pattern(match)) ? :key : :string
+ encoder.begin_group kind
encoder.text_token match, :delimiter
- state = self.class::StringState.new :string, match == '"', match # important for streaming
+ state = self.class::StringState.new kind, match == '"', match # important for streaming
else
+ kind = value_expected == true && scan(/:/) ? :key : :string
+ encoder.begin_group kind
encoder.text_token match[0,1], :delimiter
encoder.text_token match[1..-2], :content if match.size > 2
encoder.text_token match[-1,1], :delimiter
- encoder.end_group :string
+ encoder.end_group kind
+ encoder.text_token ':', :operator if kind == :key
value_expected = false
end
@@ -191,11 +195,14 @@ module Scanners
encoder.text_token match, :error
method_call_expected = false
else
- encoder.text_token match, self[1] ? :float : :integer # TODO: send :hex/:octal/:binary
+ kind = self[1] ? :float : :integer # TODO: send :hex/:octal/:binary
+ match << 'r' if match !~ /e/i && scan(/r/)
+ match << 'i' if scan(/i/)
+ encoder.text_token match, kind
end
value_expected = false
- elsif match = scan(/ [-+!~^\/]=? | [:;] | [*|&]{1,2}=? | >>? /x)
+ elsif match = scan(/ [-+!~^\/]=? | [:;] | &\. | [*|&]{1,2}=? | >>? /x)
value_expected = true
encoder.text_token match, :operator
@@ -208,7 +215,7 @@ module Scanners
encoder.end_group kind
heredocs ||= [] # create heredocs if empty
heredocs << self.class::StringState.new(kind, quote != "'", delim,
- self[1] == '-' ? :indented : :linestart)
+ self[1] ? :indented : :linestart)
value_expected = false
elsif value_expected && match = scan(/#{patterns::FANCY_STRING_START}/o)
diff --git a/lib/coderay/scanners/ruby/patterns.rb b/lib/coderay/scanners/ruby/patterns.rb
index 0b36e13..e5a156d 100644
--- a/lib/coderay/scanners/ruby/patterns.rb
+++ b/lib/coderay/scanners/ruby/patterns.rb
@@ -114,7 +114,7 @@ module Scanners
# NOTE: This is not completely correct, but
# nobody needs heredoc delimiters ending with \n.
HEREDOC_OPEN = /
- << (-)? # $1 = float
+ << ([-~])? # $1 = float
(?:
( [A-Za-z_0-9]+ ) # $2 = delim
|
diff --git a/lib/coderay/scanners/ruby/string_state.rb b/lib/coderay/scanners/ruby/string_state.rb
index 28ddd6c..95f1e83 100644
--- a/lib/coderay/scanners/ruby/string_state.rb
+++ b/lib/coderay/scanners/ruby/string_state.rb
@@ -37,6 +37,14 @@ module Scanners
end
end
+ def self.simple_key_pattern delim
+ if delim == "'"
+ / (?> (?: [^\\']+ | \\. )* ) ' : /mx
+ else
+ / (?> (?: [^\\"\#]+ | \\. | \#\$[\\"] | \#\{[^\{\}]+\} | \#(?!\{) )* ) " : /mx
+ end
+ end
+
def initialize kind, interpreted, delim, heredoc = false
if heredoc
pattern = heredoc_pattern delim, interpreted, heredoc == :indented
diff --git a/lib/coderay/scanners/sql.rb b/lib/coderay/scanners/sql.rb
index c25f6d2..7d57f77 100644
--- a/lib/coderay/scanners/sql.rb
+++ b/lib/coderay/scanners/sql.rb
@@ -96,7 +96,7 @@ module Scanners
state = :string
encoder.text_token match, :delimiter
- elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9]* /x)
+ elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9\$]* /x)
encoder.text_token match, name_expected ? :ident : (match[0] == ?@ ? :variable : IDENT_KIND[match])
name_expected = false
diff --git a/lib/coderay/styles/alpha.rb b/lib/coderay/styles/alpha.rb
index d304dc4..f21cefe 100644
--- a/lib/coderay/styles/alpha.rb
+++ b/lib/coderay/styles/alpha.rb
@@ -82,7 +82,8 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
.exception { color:#C00; font-weight:bold }
.float { color:#60E }
.function { color:#06B; font-weight:bold }
-.function .delimiter { color:#024; font-weight:bold }
+.function .delimiter { color:#059 }
+.function .content { color:#037 }
.global-variable { color:#d70 }
.hex { color:#02b }
.id { color:#33D; font-weight:bold }