8000 New Ruby 2.1, 2.2, 2.3 Syntax by korny · Pull Request #189 · rubychan/coderay · GitHub
[go: up one dir, main page]

Skip to content

New Ruby 2.1, 2.2, 2.3 Syntax #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
check for keys with escape sequences, too
  • Loading branch information
korny committed Feb 13, 2016
commit c33f3f5c43064f7b468a59e086dc4a9a4f949ff7
5 changes: 3 additions & 2 deletions lib/coderay/scanners/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ def scan_tokens encoder, options

elsif match = scan(/ ' (?:(?>[^'\\]*) ')? | " (?:(?>[^"\\\#]*) ")? /mx)
if match.size == 1
encoder.begin_group :string
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
Expand Down
8 changes: 8 additions & 0 deletions lib/coderay/scanners/ruby/string_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class StringState < Struct.new :type, :interpreted, :delim, :heredoc,
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
Expand Down
0