coderay 1.0.0 → 1.0.0.598.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/FOLDERS +49 -0
  2. data/Rakefile +6 -5
  3. data/bin/coderay +74 -190
  4. data/bin/coderay_stylesheet +4 -0
  5. data/{README_INDEX.rdoc → lib/README} +20 -10
  6. data/lib/coderay.rb +60 -62
  7. data/lib/coderay/duo.rb +55 -2
  8. data/lib/coderay/encoder.rb +39 -52
  9. data/lib/coderay/encoders/_map.rb +7 -11
  10. data/lib/coderay/encoders/comment_filter.rb +61 -0
  11. data/lib/coderay/encoders/count.rb +26 -11
  12. data/lib/coderay/encoders/debug.rb +60 -11
  13. data/lib/coderay/encoders/div.rb +8 -9
  14. data/lib/coderay/encoders/filter.rb +52 -12
  15. data/lib/coderay/encoders/html.rb +113 -106
  16. data/lib/coderay/encoders/html/css.rb +7 -2
  17. data/lib/coderay/encoders/html/numbering.rb +27 -24
  18. data/lib/coderay/encoders/html/output.rb +58 -15
  19. data/lib/coderay/encoders/json.rb +44 -37
  20. data/lib/coderay/encoders/lines_of_code.rb +56 -9
  21. data/lib/coderay/encoders/null.rb +13 -6
  22. data/lib/coderay/encoders/page.rb +8 -8
  23. data/lib/coderay/encoders/span.rb +9 -10
  24. data/lib/coderay/encoders/statistic.rb +114 -51
  25. data/lib/coderay/encoders/terminal.rb +10 -7
  26. data/lib/coderay/encoders/text.rb +36 -17
  27. data/lib/coderay/encoders/token_kind_filter.rb +58 -1
  28. data/lib/coderay/encoders/xml.rb +11 -13
  29. data/lib/coderay/encoders/yaml.rb +14 -16
  30. data/lib/coderay/for_redcloth.rb +1 -1
  31. data/lib/coderay/helpers/file_type.rb +240 -125
  32. data/lib/coderay/helpers/gzip_simple.rb +123 -0
  33. data/lib/coderay/helpers/plugin.rb +307 -241
  34. data/lib/coderay/helpers/word_list.rb +126 -65
  35. data/lib/coderay/scanner.rb +103 -153
  36. data/lib/coderay/scanners/_map.rb +16 -18
  37. data/lib/coderay/scanners/c.rb +13 -13
  38. data/lib/coderay/scanners/cpp.rb +6 -6
  39. data/lib/coderay/scanners/css.rb +48 -47
  40. data/lib/coderay/scanners/debug.rb +55 -9
  41. data/lib/coderay/scanners/delphi.rb +4 -4
  42. data/lib/coderay/scanners/diff.rb +25 -43
  43. data/lib/coderay/scanners/groovy.rb +2 -2
  44. data/lib/coderay/scanners/html.rb +30 -107
  45. data/lib/coderay/scanners/java.rb +5 -6
  46. data/lib/coderay/scanners/java/builtin_types.rb +0 -2
  47. data/lib/coderay/scanners/java_script.rb +6 -6
  48. data/lib/coderay/scanners/json.rb +6 -7
  49. data/lib/coderay/scanners/nitro_xhtml.rb +136 -0
  50. data/lib/coderay/scanners/php.rb +12 -13
  51. data/lib/coderay/scanners/plaintext.rb +26 -0
  52. data/lib/coderay/scanners/python.rb +4 -4
  53. data/lib/coderay/scanners/{erb.rb → rhtml.rb} +11 -19
  54. data/lib/coderay/scanners/ruby.rb +208 -219
  55. data/lib/coderay/scanners/ruby/patterns.rb +85 -18
  56. data/lib/coderay/scanners/scheme.rb +136 -0
  57. data/lib/coderay/scanners/sql.rb +22 -29
  58. data/lib/coderay/scanners/yaml.rb +10 -11
  59. data/lib/coderay/styles/_map.rb +2 -2
  60. data/lib/coderay/styles/alpha.rb +104 -102
  61. data/lib/coderay/styles/cycnus.rb +143 -0
  62. data/lib/coderay/styles/murphy.rb +123 -0
  63. data/lib/coderay/token_kinds.rb +86 -87
  64. data/lib/coderay/tokens.rb +169 -26
  65. data/test/functional/basic.rb +14 -200
  66. data/test/functional/examples.rb +14 -20
  67. data/test/functional/for_redcloth.rb +8 -15
  68. data/test/functional/load_plugin_scanner.rb +11 -0
  69. data/test/functional/suite.rb +6 -9
  70. data/test/functional/vhdl.rb +126 -0
  71. data/test/functional/word_list.rb +79 -0
  72. metadata +129 -107
  73. data/lib/coderay/helpers/gzip.rb +0 -41
  74. data/lib/coderay/scanners/clojure.rb +0 -217
  75. data/lib/coderay/scanners/haml.rb +0 -168
  76. data/lib/coderay/scanners/ruby/string_state.rb +0 -71
  77. data/lib/coderay/scanners/text.rb +0 -26
  78. data/lib/coderay/tokens_proxy.rb +0 -55
  79. data/lib/coderay/version.rb +0 -3
@@ -1,41 +0,0 @@
1
- module CodeRay
2
-
3
- # A simplified interface to the gzip library +zlib+ (from the Ruby Standard Library.)
4
- module GZip
5
-
6
- require 'zlib'
7
-
8
- # The default zipping level. 7 zips good and fast.
9
- DEFAULT_GZIP_LEVEL = 7
10
-
11
- # Unzips the given string +s+.
12
- #
13
- # Example:
14
- # require 'gzip_simple'
15
- # print GZip.gunzip(File.read('adresses.gz'))
16
- def GZip.gunzip s
17
- Zlib::Inflate.inflate s
18
- end
19
-
20
- # Zips the given string +s+.
21
- #
22
- # Example:
23
- # require 'gzip_simple'
24
- # File.open('adresses.gz', 'w') do |file
25
- # file.write GZip.gzip('Mum: 0123 456 789', 9)
26
- # end
27
- #
28
- # If you provide a +level+, you can control how strong
29
- # the string is compressed:
30
- # - 0: no compression, only convert to gzip format
31
- # - 1: compress fast
32
- # - 7: compress more, but still fast (default)
33
- # - 8: compress more, slower
34
- # - 9: compress best, very slow
35
- def GZip.gzip s, level = DEFAULT_GZIP_LEVEL
36
- Zlib::Deflate.new(level).deflate s, Zlib::FINISH
37
- end
38
-
39
- end
40
-
41
- end
@@ -1,217 +0,0 @@
1
- # encoding: utf-8
2
- module CodeRay
3
- module Scanners
4
-
5
- # Clojure scanner by Licenser.
6
- class Clojure < Scanner
7
-
8
- register_for :clojure
9
- file_extension 'clj'
10
-
11
- SPECIAL_FORMS = %w[
12
- def if do let quote var fn loop recur throw try catch monitor-enter monitor-exit .
13
- new
14
- ] # :nodoc:
15
-
16
- CORE_FORMS = %w[
17
- + - -> ->> .. / * <= < = == >= > accessor aclone add-classpath add-watch
18
- agent agent-error agent-errors aget alength alias all-ns alter alter-meta!
19
- alter-var-root amap ancestors and apply areduce array-map aset aset-boolean
20
- aset-byte aset-char aset-double aset-float aset-int aset-long aset-short
21
- assert assoc assoc! assoc-in associative? atom await await-for bases bean
22
- bigdec bigint binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or
23
- bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array
24
- booleans bound-fn bound-fn* bound? butlast byte byte-array bytes case cast char
25
- char-array char-escape-string char-name-string char? chars class class?
26
- clear-agent-errors clojure-version coll? comment commute comp comparator
27
- compare compare-and-set! compile complement concat cond condp conj conj!
28
- cons constantly construct-proxy contains? count counted? create-ns
29
- create-struct cycle dec decimal? declare definline defmacro defmethod defmulti
30
- defn defn- defonce defprotocol defrecord defstruct deftype delay delay?
31
- deliver denominator deref derive descendants disj disj! dissoc dissoc!
32
- distinct distinct? doall doc dorun doseq dosync dotimes doto double
33
- double-array doubles drop drop-last drop-while empty empty? ensure
34
- enumeration-seq error-handler error-mode eval even? every? extend
35
- extend-protocol extend-type extenders extends? false? ffirst file-seq
36
- filter find find-doc find-ns find-var first float float-array float?
37
- floats flush fn fn? fnext for force format future future-call future-cancel
38
- future-cancelled? future-done? future? gen-class gen-interface gensym get
39
- get-in get-method get-proxy-class get-thread-bindings get-validator hash
40
- hash-map hash-set identical? identity if-let if-not ifn? import in-ns
41
- inc init-proxy instance? int int-array integer? interleave intern
42
- interpose into into-array ints io! isa? iterate iterator-seq juxt key
43
- keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list list*
44
- list? load load-file load-reader load-string loaded-libs locking long
45
- long-array longs loop macroexpand macroexpand-1 make-array make-hierarchy
46
- map map? mapcat max max-key memfn memoize merge merge-with meta methods
47
- min min-key mod name namespace neg? newline next nfirst nil? nnext not
48
- not-any? not-empty not-every? not= ns ns-aliases ns-imports ns-interns
49
- ns-map ns-name ns-publics ns-refers ns-resolve ns-unalias ns-unmap nth
50
- nthnext num number? numerator object-array odd? or parents partial
51
- partition pcalls peek persistent! pmap pop pop! pop-thread-bindings
52
- pos? pr pr-str prefer-method prefers print print-namespace-doc
53
- print-str printf println println-str prn prn-str promise proxy
54
- proxy-mappings proxy-super push-thread-bindings pvalues quot rand
55
- rand-int range ratio? rationalize re-find re-groups re-matcher
56
- re-matches re-pattern re-seq read read-line read-string reduce ref
57
- ref-history-count ref-max-history ref-min-history ref-set refer
58
- refer-clojure reify release-pending-sends rem remove remove-all-methods
59
- remove-method remove-ns remove-watch repeat repeatedly replace replicate
60
- require reset! reset-meta! resolve rest restart-agent resultset-seq
61
- reverse reversible? rseq rsubseq satisfies? second select-keys send
62
- send-off seq seq? seque sequence sequential? set set-error-handler!
63
- set-error-mode! set-validator! set? short short-array shorts
64
- shutdown-agents slurp some sort sort-by sorted-map sorted-map-by
65
- sorted-set sorted-set-by sorted? special-form-anchor special-symbol?
66
- split-at split-with str string? struct struct-map subs subseq subvec
67
- supers swap! symbol symbol? sync syntax-symbol-anchor take take-last
68
- take-nth take-while test the-ns thread-bound? time to-array to-array-2d
69
- trampoline transient tree-seq true? type unchecked-add unchecked-dec
70
- unchecked-divide unchecked-inc unchecked-multiply unchecked-negate
71
- unchecked-remainder unchecked-subtract underive update-in update-proxy
72
- use val vals var-get var-set var? vary-meta vec vector vector-of vector?
73
- when when-first when-let when-not while with-bindings with-bindings*
74
- with-in-str with-local-vars with-meta with-open with-out-str
75
- with-precision xml-seq zero? zipmap
76
- ] # :nodoc:
77
-
78
- PREDEFINED_CONSTANTS = %w[
79
- true false nil *1 *2 *3 *agent* *clojure-version* *command-line-args*
80
- *compile-files* *compile-path* *e *err* *file* *flush-on-newline*
81
- *in* *ns* *out* *print-dup* *print-length* *print-level* *print-meta*
82
- *print-readably* *read-eval* *warn-on-reflection*
83
- ] # :nodoc:
84
-
85
- IDENT_KIND = WordList.new(:ident).
86
- add(SPECIAL_FORMS, :keyword).
87
- add(CORE_FORMS, :keyword).
88
- add(PREDEFINED_CONSTANTS, :predefined_constant)
89
-
90
- KEYWORD_NEXT_TOKEN_KIND = WordList.new(nil).
91
- add(%w[ def defn defn- definline defmacro defmulti defmethod defstruct defonce declare ], :function).
92
- add(%w[ ns ], :namespace).
93
- add(%w[ defprotocol defrecord ], :class)
94
-
95
- BASIC_IDENTIFIER = /[a-zA-Z$%*\/_+!?&<>\-=]=?[a-zA-Z0-9$&*+!\/_?<>\-\#]*/
96
- IDENTIFIER = /(?!-\d)(?:(?:#{BASIC_IDENTIFIER}\.)*#{BASIC_IDENTIFIER}(?:\/#{BASIC_IDENTIFIER})?\.?)|\.\.?/
97
- SYMBOL = /::?#{IDENTIFIER}/o
98
- DIGIT = /\d/
99
- DIGIT10 = DIGIT
100
- DIGIT16 = /[0-9a-f]/i
101
- DIGIT8 = /[0-7]/
102
- DIGIT2 = /[01]/
103
- RADIX16 = /\#x/i
104
- RADIX8 = /\#o/i
105
- RADIX2 = /\#b/i
106
- RADIX10 = /\#d/i
107
- EXACTNESS = /#i|#e/i
108
- SIGN = /[\+-]?/
109
- EXP_MARK = /[esfdl]/i
110
- EXP = /#{EXP_MARK}#{SIGN}#{DIGIT}+/
111
- SUFFIX = /#{EXP}?/
112
- PREFIX10 = /#{RADIX10}?#{EXACTNESS}?|#{EXACTNESS}?#{RADIX10}?/
113
- PREFIX16 = /#{RADIX16}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX16}/
114
- PREFIX8 = /#{RADIX8}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX8}/
115
- PREFIX2 = /#{RADIX2}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX2}/
116
- UINT10 = /#{DIGIT10}+#*/
117
- UINT16 = /#{DIGIT16}+#*/
118
- UINT8 = /#{DIGIT8}+#*/
119
- UINT2 = /#{DIGIT2}+#*/
120
- DECIMAL = /#{DIGIT10}+#+\.#*#{SUFFIX}|#{DIGIT10}+\.#{DIGIT10}*#*#{SUFFIX}|\.#{DIGIT10}+#*#{SUFFIX}|#{UINT10}#{EXP}/
121
- UREAL10 = /#{UINT10}\/#{UINT10}|#{DECIMAL}|#{UINT10}/
122
- UREAL16 = /#{UINT16}\/#{UINT16}|#{UINT16}/
123
- UREAL8 = /#{UINT8}\/#{UINT8}|#{UINT8}/
124
- UREAL2 = /#{UINT2}\/#{UINT2}|#{UINT2}/
125
- REAL10 = /#{SIGN}#{UREAL10}/
126
- REAL16 = /#{SIGN}#{UREAL16}/
127
- REAL8 = /#{SIGN}#{UREAL8}/
128
- REAL2 = /#{SIGN}#{UREAL2}/
129
- IMAG10 = /i|#{UREAL10}i/
130
- IMAG16 = /i|#{UREAL16}i/
131
- IMAG8 = /i|#{UREAL8}i/
132
- IMAG2 = /i|#{UREAL2}i/
133
- COMPLEX10 = /#{REAL10}@#{REAL10}|#{REAL10}\+#{IMAG10}|#{REAL10}-#{IMAG10}|\+#{IMAG10}|-#{IMAG10}|#{REAL10}/
134
- COMPLEX16 = /#{REAL16}@#{REAL16}|#{REAL16}\+#{IMAG16}|#{REAL16}-#{IMAG16}|\+#{IMAG16}|-#{IMAG16}|#{REAL16}/
135
- COMPLEX8 = /#{REAL8}@#{REAL8}|#{REAL8}\+#{IMAG8}|#{REAL8}-#{IMAG8}|\+#{IMAG8}|-#{IMAG8}|#{REAL8}/
136
- COMPLEX2 = /#{REAL2}@#{REAL2}|#{REAL2}\+#{IMAG2}|#{REAL2}-#{IMAG2}|\+#{IMAG2}|-#{IMAG2}|#{REAL2}/
137
- NUM10 = /#{PREFIX10}?#{COMPLEX10}/
138
- NUM16 = /#{PREFIX16}#{COMPLEX16}/
139
- NUM8 = /#{PREFIX8}#{COMPLEX8}/
140
- NUM2 = /#{PREFIX2}#{COMPLEX2}/
141
- NUM = /#{NUM10}|#{NUM16}|#{NUM8}|#{NUM2}/
142
-
143
- protected
144
-
145
- def scan_tokens encoder, options
146
-
147
- state = :initial
148
- kind = nil
149
-
150
- until eos?
151
-
152
- case state
153
- when :initial
154
- if match = scan(/ \s+ | \\\n | , /x)
155
- encoder.text_token match, :space
156
- elsif match = scan(/['`\(\[\)\]\{\}]|\#[({]|~@?|[@\^]/)
157
- encoder.text_token match, :operator
158
- elsif match = scan(/;.*/)
159
- encoder.text_token match, :comment # TODO: recognize (comment ...) too
160
- elsif match = scan(/\#?\\(?:newline|space|.?)/)
161
- encoder.text_token match, :char
162
- elsif match = scan(/\#[ft]/)
163
- encoder.text_token match, :predefined_constant
164
- elsif match = scan(/#{IDENTIFIER}/o)
165
- kind = IDENT_KIND[match]
166
- encoder.text_token match, kind
167
- if rest? && kind == :keyword
168
- if kind = KEYWORD_NEXT_TOKEN_KIND[match]
169
- encoder.text_token match, :space if match = scan(/\s+/o)
170
- encoder.text_token match, kind if match = scan(/#{IDENTIFIER}/o)
171
- end
172
- end
173
- elsif match = scan(/#{SYMBOL}/o)
174
- encoder.text_token match, :symbol
175
- elsif match = scan(/\./)
176
- encoder.text_token match, :operator
177
- elsif match = scan(/ \# \^ #{IDENTIFIER} /ox)
178
- encoder.text_token match, :type
179
- elsif match = scan(/ (\#)? " /x)
180
- state = self[1] ? :regexp : :string
181
- encoder.begin_group state
182
- encoder.text_token match, :delimiter
183
- elsif match = scan(/#{NUM}/o) and not matched.empty?
184
- encoder.text_token match, match[/[.e\/]/i] ? :float : :integer
185
- else
186
- encoder.text_token getch, :error
187
- end
188
-
189
- when :string, :regexp
190
- if match = scan(/[^"\\]+|\\.?/)
191
- encoder.text_token match, :content
192
- elsif match = scan(/"/)
193
- encoder.text_token match, :delimiter
194
- encoder.end_group state
195
- state = :initial
196
- else
197
- raise_inspect "else case \" reached; %p not handled." % peek(1),
198
- encoder, state
199
- end
200
-
201
- else
202
- raise 'else case reached'
203
-
204
- end
205
-
206
- end
207
-
208
- if [:string, :regexp].include? state
209
- encoder.end_group state
210
- end
211
-
212
- encoder
213
-
214
- end
215
- end
216
- end
217
- end
@@ -1,168 +0,0 @@
1
- module CodeRay
2
- module Scanners
3
-
4
- load :ruby
5
- load :html
6
- load :java_script
7
-
8
- class HAML < Scanner
9
-
10
- register_for :haml
11
- title 'HAML Template'
12
-
13
- KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
14
-
15
- protected
16
-
17
- def setup
18
- super
19
- @ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true
20
- @embedded_ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true, :state => @ruby_scanner.interpreted_string_state
21
- @html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true
22
- end
23
-
24
- def scan_tokens encoder, options
25
-
26
- match = nil
27
- code = ''
28
-
29
- until eos?
30
-
31
- if bol?
32
- if match = scan(/!!!.*/)
33
- encoder.text_token match, :doctype
34
- next
35
- end
36
-
37
- if match = scan(/(?>( *)(\/(?!\[if)|-\#|:javascript|:ruby|:\w+) *)(?=\n)/)
38
- encoder.text_token match, :comment
39
-
40
- code = self[2]
41
- if match = scan(/(?:\n+#{self[1]} .*)+/)
42
- case code
43
- when '/', '-#'
44
- encoder.text_token match, :comment
45
- when ':javascript'
46
- # TODO: recognize #{...} snippets inside JavaScript
47
- @java_script_scanner ||= CodeRay.scanner :java_script, :tokens => @tokens, :keep_tokens => true
48
- @java_script_scanner.tokenize match, :tokens => encoder
49
- when ':ruby'
50
- @ruby_scanner.tokenize match, :tokens => encoder
51
- when /:\w+/
52
- encoder.text_token match, :comment
53
- else
54
- raise 'else-case reached: %p' % [code]
55
- end
56
- end
57
- end
58
-
59
- if match = scan(/ +/)
60
- encoder.text_token match, :space
61
- end
62
-
63
- if match = scan(/\/.*/)
64
- encoder.text_token match, :comment
65
- next
66
- end
67
-
68
- if match = scan(/\\/)
69
- encoder.text_token match, :plain
70
- if match = scan(/.+/)
71
- @html_scanner.tokenize match, :tokens => encoder
72
- end
73
- next
74
- end
75
-
76
- tag = false
77
-
78
- if match = scan(/%[\w:]+\/?/)
79
- encoder.text_token match, :tag
80
- # if match = scan(/( +)(.+)/)
81
- # encoder.text_token self[1], :space
82
- # @embedded_ruby_scanner.tokenize self[2], :tokens => encoder
83
- # end
84
- tag = true
85
- end
86
-
87
- while match = scan(/([.#])[-\w]*\w/)
88
- encoder.text_token match, self[1] == '#' ? :constant : :class
89
- tag = true
90
- end
91
-
92
- if tag && match = scan(/(\()([^)]+)?(\))?/)
93
- # TODO: recognize title=@title, class="widget_#{@widget.number}"
94
- encoder.text_token self[1], :plain
95
- @html_scanner.tokenize self[2], :tokens => encoder, :state => :attribute if self[2]
96
- encoder.text_token self[3], :plain if self[3]
97
- end
98
-
99
- if tag && match = scan(/\{/)
100
- encoder.text_token match, :plain
101
-
102
- code = ''
103
- level = 1
104
- while true
105
- code << scan(/([^\{\},\n]|, *\n?)*/)
106
- case match = getch
107
- when '{'
108
- level += 1
109
- code << match
110
- when '}'
111
- level -= 1
112
- if level > 0
113
- code << match
114
- else
115
- break
116
- end
117
- when "\n", ",", nil
118
- break
119
- end
120
- end
121
- @ruby_scanner.tokenize code, :tokens => encoder unless code.empty?
122
-
123
- encoder.text_token match, :plain if match
124
- end
125
-
126
- if tag && match = scan(/(\[)([^\]\n]+)?(\])?/)
127
- encoder.text_token self[1], :plain
128
- @ruby_scanner.tokenize self[2], :tokens => encoder if self[2]
129
- encoder.text_token self[3], :plain if self[3]
130
- end
131
-
132
- if tag && match = scan(/\//)
133
- encoder.text_token match, :tag
134
- end
135
-
136
- if scan(/(>?<?[-=]|[&!]=|(& |!)|~)( *)([^,\n\|]+(?:(, *|\|(?=.|\n.*\|$))\n?[^,\n\|]*)*)?/)
137
- encoder.text_token self[1] + self[3], :plain
138
- if self[4]
139
- if self[2]
140
- @embedded_ruby_scanner.tokenize self[4], :tokens => encoder
141
- else
142
- @ruby_scanner.tokenize self[4], :tokens => encoder
143
- end
144
- end
145
- elsif match = scan(/((?:<|><?)(?![!?\/\w]))?(.+)?/)
146
- encoder.text_token self[1], :plain if self[1]
147
- # TODO: recognize #{...} snippets
148
- @html_scanner.tokenize self[2], :tokens => encoder if self[2]
149
- end
150
-
151
- elsif match = scan(/.+/)
152
- @html_scanner.tokenize match, :tokens => encoder
153
-
154
- end
155
-
156
- if match = scan(/\n/)
157
- encoder.text_token match, :space
158
- end
159
- end
160
-
161
- encoder
162
-
163
- end
164
-
165
- end
166
-
167
- end
168
- end
@@ -1,71 +0,0 @@
1
- # encoding: utf-8
2
- module CodeRay
3
- module Scanners
4
-
5
- class Ruby
6
-
7
- class StringState < Struct.new :type, :interpreted, :delim, :heredoc,
8
- :opening_paren, :paren_depth, :pattern, :next_state # :nodoc: all
9
-
10
- CLOSING_PAREN = Hash[ *%w[
11
- ( )
12
- [ ]
13
- < >
14
- { }
15
- ] ].each { |k,v| k.freeze; v.freeze } # debug, if I try to change it with <<
16
-
17
- STRING_PATTERN = Hash.new do |h, k|
18
- delim, interpreted = *k
19
- # delim = delim.dup # workaround for old Ruby
20
- delim_pattern = Regexp.escape(delim)
21
- if closing_paren = CLOSING_PAREN[delim]
22
- delim_pattern << Regexp.escape(closing_paren)
23
- end
24
- delim_pattern << '\\\\' unless delim == '\\'
25
-
26
- # special_escapes =
27
- # case interpreted
28
- # when :regexp_symbols
29
- # '| [|?*+(){}\[\].^$]'
30
- # end
31
-
32
- h[k] =
33
- if interpreted && delim != '#'
34
- / (?= [#{delim_pattern}] | \# [{$@] ) /mx
35
- else
36
- / (?= [#{delim_pattern}] ) /mx
37
- end
38
- end
39
-
40
- def initialize kind, interpreted, delim, heredoc = false
41
- if heredoc
42
- pattern = heredoc_pattern delim, interpreted, heredoc == :indented
43
- delim = nil
44
- else
45
- pattern = STRING_PATTERN[ [delim, interpreted] ]
46
- if closing_paren = CLOSING_PAREN[delim]
47
- opening_paren = delim
48
- delim = closing_paren
49
- paren_depth = 1
50
- end
51
- end
52
- super kind, interpreted, delim, heredoc, opening_paren, paren_depth, pattern, :initial
53
- end
54
-
55
- def heredoc_pattern delim, interpreted, indented
56
- # delim = delim.dup # workaround for old Ruby
57
- delim_pattern = Regexp.escape(delim)
58
- delim_pattern = / (?:\A|\n) #{ '(?>[ \t]*)' if indented } #{ Regexp.new delim_pattern } $ /x
59
- if interpreted
60
- / (?= #{delim_pattern}() | \\ | \# [{$@] ) /mx # $1 set == end of heredoc
61
- else
62
- / (?= #{delim_pattern}() | \\ ) /mx
63
- end
64
- end
65
-
66
- end
67
-
68
- end
69
-
70
- end
71
- end