diff options
author | Kornelius Kalnbach <murphy@rubychan.de> | 2014-12-18 21:28:24 +0100 |
---|---|---|
committer | Kornelius Kalnbach <murphy@rubychan.de> | 2014-12-18 21:28:24 +0100 |
commit | 7aa6ea080d05b7e6a70b076b25f37b72fd7669ad (patch) | |
tree | 5134dda976acfa6746a53fd9def12937701d9850 /lib/coderay/scanners/sql.rb | |
parent | bc4854fa426a39c2bd51b2fd1cfa0322a5a9a412 (diff) | |
parent | 31a09b7599fb7c4b605869127e38617ce7619106 (diff) | |
download | coderay-7aa6ea080d05b7e6a70b076b25f37b72fd7669ad.tar.gz |
Merge branch 'master' into possible-speedups
Conflicts:
lib/coderay/encoders/html.rb
Diffstat (limited to 'lib/coderay/scanners/sql.rb')
-rw-r--r-- | lib/coderay/scanners/sql.rb | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/lib/coderay/scanners/sql.rb b/lib/coderay/scanners/sql.rb index 93aeaf3..c25f6d2 100644 --- a/lib/coderay/scanners/sql.rb +++ b/lib/coderay/scanners/sql.rb @@ -57,6 +57,12 @@ module Scanners STRING_PREFIXES = /[xnb]|_\w+/i + STRING_CONTENT_PATTERN = { + '"' => / (?: [^\\"] | "" )+ /x, + "'" => / (?: [^\\'] | '' )+ /x, + '`' => / (?: [^\\`] | `` )+ /x, + } + def scan_tokens encoder, options state = :initial @@ -115,40 +121,26 @@ module Scanners end elsif state == :string - if match = scan(/[^\\"'`]+/) - string_content << match - next + if match = scan(STRING_CONTENT_PATTERN[string_type]) + encoder.text_token match, :content elsif match = scan(/["'`]/) if string_type == match if peek(1) == string_type # doubling means escape - string_content << string_type << getch - next - end - unless string_content.empty? - encoder.text_token string_content, :content - string_content = '' + encoder.text_token match + getch, :content + else + encoder.text_token match, :delimiter + encoder.end_group :string + state = :initial + string_type = nil end - encoder.text_token match, :delimiter - encoder.end_group :string - state = :initial - string_type = nil else - string_content << match + encoder.text_token match, :content end elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox) - unless string_content.empty? - encoder.text_token string_content, :content - string_content = '' - end encoder.text_token match, :char elsif match = scan(/ \\ . /mox) - string_content << match - next + encoder.text_token match, :content elsif match = scan(/ \\ | $ /x) - unless string_content.empty? - encoder.text_token string_content, :content - string_content = '' - end encoder.text_token match, :error unless match.empty? encoder.end_group :string state = :initial |