File: highlight.rb.fold

package info (click to toggle)
kf6-syntax-highlighting 6.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 47,568 kB
  • sloc: xml: 197,750; cpp: 12,850; python: 3,023; sh: 955; perl: 546; ruby: 488; pascal: 393; javascript: 161; php: 150; jsp: 132; lisp: 131; haskell: 124; ada: 119; ansic: 107; makefile: 96; f90: 94; ml: 85; cobol: 81; yacc: 71; csh: 62; erlang: 54; sql: 51; java: 47; objc: 37; awk: 31; asm: 30; tcl: 29; fortran: 18; cs: 10
file content (665 lines) | stat: -rw-r--r-- 27,674 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
# This file is a testcase for the highlighting of Ruby code
# It's not executable code, but a collection of code snippets
#

require 'Config'
require 'DO/Clients'
require 'DO/DBClients'

  <beginfold id='1'>def</beginfold id='1'> CGI::escapeElement(string, *elements)
    elements = elements[0] if elements[0].kind_of?(Array)
    <beginfold id='1'>unless</beginfold id='1'> elements.empty?
      string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/ni) <beginfold id='1'>do</beginfold id='1'>
        CGI::escapeHTML($&)
      <endfold id='1'>end</endfold id='1'>
    <endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
      string
    <endfold id='1'>end</endfold id='1'>
  <endfold id='1'>end</endfold id='1'>

<beginfold id='1'>case</beginfold id='1'> inputLine
  when "debug"
    dumpDebugInfo
    dumpSymbols
  when /p\s+(\w+)/
    dumpVariable($1)
  when "quit", "exit"
    exit
  <endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
    print "Illegal command: #{inputLine}"
<endfold id='1'>end</endfold id='1'>


kind = <beginfold id='1'>case</beginfold id='1'> year #hi there
         when 1850..1889 then "Blues"
         when 1890..1909 then "Ragtime"
         when 1910..1929 then "New Orleans Jazz"
         when 1930..1939 then "Swing"
         when 1940..1950 then "Bebop"
         <endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>                 "Jazz"
       <endfold id='1'>end</endfold id='1'>

  # URL-encode a string.
  #   url_encoded_string = CGI::escape("'Stop!' said Fred")
  #      # => "%27Stop%21%27+said+Fred"
  <beginfold id='1'>def</beginfold id='1'> CGI::escape(string)
    string.gsub(/([^ a-zA-Z0-9_.-]+)/n) <beginfold id='1'>do</beginfold id='1'>
      '%' + $1.unpack('H2' * $1.size).join('%').upcase
    <endfold id='1'>end</endfold id='1'>.tr(' ', '+')
  <endfold id='1'>end</endfold id='1'>


# Class ClientManager
#
# definition : Import, store and export the various data used by the application.
# This class is the sole interface between the application and the underlying database.

mon, day, year = $1, $2, $3 if /(\d\d)-(\d\d)-(\d\d)/
puts "a = #{a}" if fDebug
print total unless total == 0

<beginfold id='1'>while</beginfold id='1'> gets
  next if /^#/            # Skip comments
  parseLine unless /^$/   # Don't parse empty lines
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>if</beginfold id='1'> artist == "John Coltrane" #hi there
  artist = "'Trane" #hi there
<endfold id='1'>end</endfold id='1'> unless nicknames == "no" #hi there

handle = <beginfold id='1'>if</beginfold id='1'> aSong.artist == "Gillespie" then #hi there
           "Dizzy"
         <endfold id='1'></endfold id='1'><beginfold id='1'>elsif</beginfold id='1'> aSong.artist == "Parker" then
           "Bird"
         <endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'> #hi there
           "unknown"
         <endfold id='1'>end</endfold id='1'>

<beginfold id='1'>if</beginfold id='1'> aSong.artist == "Gillespie" then  handle = "Dizzy"
<endfold id='1'></endfold id='1'><beginfold id='1'>elsif</beginfold id='1'> aSong.artist == "Parker" then  handle = "Bird"
<endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>  handle = "unknown"
<endfold id='1'>end</endfold id='1'> #hi there

<beginfold id='1'>if</beginfold id='1'> aSong.artist == "Gillespie" then
  handle = "Dizzy"
<endfold id='1'></endfold id='1'><beginfold id='1'>elsif</beginfold id='1'> aSong.artist == "Parker" then
  handle = "Bird"
<endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
  handle = "unknown"
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>if</beginfold id='1'> aSong.artist == "Gillespie"
  handle = "Dizzy"
<endfold id='1'></endfold id='1'><beginfold id='1'>elsif</beginfold id='1'> aSong.artist == "Parker"
  handle = "Bird"
<endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
  handle = "unknown"
<endfold id='1'>end</endfold id='1'>

 <beginfold id='1'>case</beginfold id='1'> line
  when /title=(.*)/
    puts "Title is #$1"
  when /track=(.*)/
    puts "Track is #$1"
  when /artist=(.*)/
    puts "Artist is #$1"
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>case</beginfold id='1'> shape
  when Square, Rectangle
    # ...
  when Circle
    # ...
  when Triangle
    # ...
  <endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
    # ...
<endfold id='1'>end</endfold id='1'> 


<beginfold id='1'>until</beginfold id='1'> playList.duration > 60 #hi there
  playList.add(songList.pop)
<endfold id='1'>end</endfold id='1'>

3.times <beginfold id='1'>do</beginfold id='1'>
  print "Ho! "
<endfold id='1'>end</endfold id='1'>

loop <beginfold id='2'>{</beginfold id='2'>
  # block ...
<endfold id='2'>}</endfold id='2'>

songList.each <beginfold id='1'>do</beginfold id='1'> |aSong|
  aSong.play
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>for</beginfold id='1'> aSong in songList
  aSong.play
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>for</beginfold id='1'> i in ['fee', 'fi', 'fo', 'fum']
  print i, " "
<endfold id='1'>end</endfold id='1'>
<beginfold id='1'>for</beginfold id='1'> i in 1..3
  print i, " "
<endfold id='1'>end</endfold id='1'>
<beginfold id='1'>for</beginfold id='1'> i in File.open("ordinal").find_all <beginfold id='2'>{</beginfold id='2'> |l| l =~ /d$/<endfold id='2'>}</endfold id='2'>
  print i.chomp, " "
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>class</beginfold id='1'> Periods
  <beginfold id='1'>def</beginfold id='1'> each
    yield "Classical"
    yield "Jazz"
    yield "Rock"
  <endfold id='1'>end</endfold id='1'>
<endfold id='1'>end</endfold id='1'>


periods = Periods.new
<beginfold id='1'>for</beginfold id='1'> genre in periods
  print genre, " "
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>while</beginfold id='1'> gets
  next if /^\s*#/   # skip comments
  break if /^END/   # stop at end
                    # substitute stuff in backticks and try again
  redo if gsub!(/`(.*?)`/) <beginfold id='2'>{</beginfold id='2'> eval($1) <endfold id='2'>}</endfold id='2'>
  # process line ...
<endfold id='1'>end</endfold id='1'>

i=0
loop <beginfold id='1'>do</beginfold id='1'>
  i += 1
  next if i < 3
  print i
  break if i > 4
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>for</beginfold id='1'> i in 1..100
  print "Now at #{i}. Restart? "
  retry if gets =~ /^y/i
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>def</beginfold id='1'> doUntil(cond)
  yield
  retry unless cond
<endfold id='1'>end</endfold id='1'>

i = 0
doUntil(i > 3) <beginfold id='2'>{</beginfold id='2'>
  print i, " "
  i += 1
<endfold id='2'>}</endfold id='2'>

<beginfold id='1'>def</beginfold id='1'> system_call
	# ... code which throws SystemCallError
<endfold id='1'></endfold id='1'><beginfold id='1'>rescue</beginfold id='1'> SystemCallError
	$stderr.print "IO failed: " + $!
	opFile.close
	File.delete(opName)
	raise
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>class</beginfold id='1'> ClientManager
	
	# constructor
	<beginfold id='1'>def</beginfold id='1'> initialize(dbase)
		@dbClient = DBClient.new(dbase)
		@clients = Clients.new
	<endfold id='1'>end</endfold id='1'>
	
	<beginfold id='1'>def</beginfold id='1'> prout(a, b, xy="jj") 24 <endfold id='1'>end</endfold id='1'> 
	###############################################################
	#
	# CLIENTS SECTION
	#
	###############################################################
	
	# update the clients object by retrieving the related data from the database
	# returns the number of clients
	<beginfold id='1'>def</beginfold id='1'> refreshClients
		@clients.clean
		<beginfold id='1'>unless</beginfold id='1'> @sqlQuery.nil? then
			@sqlQuery.selectClient.each <beginfold id='1'>do</beginfold id='1'> |row|
				@clients.addClient(row[0],row[1],row[2],row[3],row[4],row[5], row[6], row[7], row[8])
			<endfold id='1'>end</endfold id='1'>
		<endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
			puts "SqlQuery wasn't created : cannot read data from database"
		<endfold id='1'>end</endfold id='1'>
		return @clients.length
	<endfold id='1'>end</endfold id='1'>
	
	# insert a client in the database and refreshes the local clients object
	# we assume that none of the arguments is null
	# we assume that the client, identified by raison_sociale doesn't already exists
	<beginfold id='1'>def</beginfold id='1'> addClient(raison_sociale, division, departement, adresse, cp, ville, nom_contact, tel_contact)
		id = "0"
		<beginfold id='1'>unless</beginfold id='1'> @sqlQuery.nil? then
			id = @sqlQuery.insertClient(raison_sociale, division, departement, adresse, cp, ville, nom_contact,tel_contact)
		<endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
			puts "SqlQuery wasn't created : database update cannot be performed"
		<endfold id='1'>end</endfold id='1'>
		@clients.addClient(id, raison_sociale, division, departement, adresse, cp, ville, nom_contact, tel_contact) # synchronize local object with DB
	<endfold id='1'>end</endfold id='1'>
	
	# deletes a client from the database and updates the local Clients object accordingly
	<beginfold id='1'>def</beginfold id='1'> delClient(nomclient_brut)
		raison_sociale, div, dep = Clients.getIdentifiers(nomclient_brut)
		listeContratsExp, listeContratsSup, listeContratsProd, listePropositionsExp, listePropositionsSup = []

		listeContratsExp = @contratsExpertise.getContratsFromClient(nomclient_brut)
		listeContratsSup = @contratsSupport.getContratsFromClient(nomclient_brut)
		listeContratsProd = @contratsProduits.getContratsFromClient(nomclient_brut)
		listePropositionsExp = @propositionsExpertise.getPropositionsFromClient(nomclient_brut)
		listePropositionsSup = @propositionsSupport.getPropositionsFromClient(nomclient_brut)
		
		<beginfold id='1'>unless</beginfold id='1'> @sqlQuery.nil? then
			@sqlQuery.deleteClient(raison_sociale, div, dep)
			
			@sqlQuery.deleteContracts(Config::EXPERTISE,listeContratsExp) 
			@sqlQuery.deleteContracts(Config::SUPPORT,listeContratsSup)
			@sqlQuery.deleteContracts(Config::PRODUIT,listeContratsProd)
			@sqlQuery.deletePropositions(Config::EXPERTISE,listePropositionsExp)
			@sqlQuery.deletePropositions(Config::SUPPORT,listePropositionsSup)
		<endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
			puts "SqlQuery wasn't created : database update cannot be performed"
		<endfold id='1'>end</endfold id='1'>
		@clients.delClient(raison_sociale,div,dep)
	
		@contratsExpertise.deleteContracts(listeContratsExp)
		@contratsSupport.deleteContracts(listeContratsSup)
		@contratsProduits.deleteContracts(listeContratsProd)
		@propositionsExpertise.deletePropositions(listePropositionsExp)
		@propositionsSupport.deletePropositions(listePropositionsSup)
	<endfold id='1'>end</endfold id='1'>
<endfold id='1'>end</endfold id='1'>

  # Mixin module for HTML version 3 generation methods.
  <beginfold id='1'>module</beginfold id='1'> Html3 # :nodoc:

    # The DOCTYPE declaration for this version of HTML
    <beginfold id='1'>def</beginfold id='1'> doctype
      <beginfold id='3'>%</beginfold id='3'>|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><endfold id='3'>|</endfold id='3'>
    <endfold id='1'>end</endfold id='1'>

    # Initialise the HTML generation methods for this version.
    <beginfold id='1'>def</beginfold id='1'> element_init
      extend TagMaker
      methods = ""
      # - -
      <beginfold id='1'>for</beginfold id='1'> element in <beginfold id='3'>%</beginfold id='3'>w[ A TT I B U STRIKE BIG SMALL SUB SUP EM STRONG
          DFN CODE SAMP KBD VAR CITE FONT ADDRESS DIV center MAP
          APPLET PRE XMP LISTING DL OL UL DIR MENU SELECT table TITLE
          STYLE SCRIPT H1 H2 H3 H4 H5 H6 TEXTAREA FORM BLOCKQUOTE
          CAPTION <endfold id='3'>]</endfold id='3'>
        methods += <beginfold id='4'><<</beginfold id='4'>-BEGIN + nn_element_def(element) + <<-END
          def #{element.downcase}(attributes = {})
        <endfold id='4'>BEGIN</endfold id='4'>
          <endfold id='1'>end</endfold id='1'>
        END
      <endfold id='1'>end</endfold id='1'>

      # - O EMPTY
      <beginfold id='1'>for</beginfold id='1'> element in <beginfold id='3'>%</beginfold id='3'>w[ IMG BASE BASEFONT BR AREA LINK PARAM HR INPUT
          ISINDEX META <endfold id='3'>]</endfold id='3'>
        methods += <beginfold id='4'><<</beginfold id='4'>-BEGIN + nOE_element_def(element) + <<-END
          def #{element.downcase}(attributes = {})
        <endfold id='4'>BEGIN</endfold id='4'>
          <endfold id='1'>end</endfold id='1'>
        END
      <endfold id='1'>end</endfold id='1'>

      # O O or - O
      <beginfold id='1'>for</beginfold id='1'> element in <beginfold id='3'>%</beginfold id='3'>w[ HTML HEAD BODY P PLAINTEXT DT DD LI OPTION tr
          th td <endfold id='3'>]</endfold id='3'>
        methods += <beginfold id='4'><<</beginfold id='4'>-BEGIN + nO_element_def(element) + <<-END
          def #{element.downcase}(attributes = {})
        <endfold id='4'>BEGIN</endfold id='4'>
          <endfold id='1'>end</endfold id='1'>
        END
      <endfold id='1'>end</endfold id='1'>
      eval(methods)
    <endfold id='1'>end</endfold id='1'>

  <endfold id='1'>end</endfold id='1'>

# following snippet from Webrick's log.rb
# notice the erronous handling of the query method is_a?
<beginfold id='1'>def</beginfold id='1'> format(arg)
     str = <beginfold id='1'>if</beginfold id='1'> arg.is_a?(Exception)
        "#{arg.class}: #{arg.message}\n\t" <<
        arg.backtrace.join("\n\t") << "\n"
      <endfold id='1'></endfold id='1'><beginfold id='1'>elsif</beginfold id='1'> arg.respond_to?(:to_str)
        arg.to_str
      <endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
        arg.inspect
      <endfold id='1'>end</endfold id='1'>
<endfold id='1'>end</endfold id='1'>

# following snippet from Webrick's httputils.rb
# Splitting regexps on several lines might be bad form,
# but not illegal in Ruby. 
# This should probably be supported in the highlighting
<beginfold id='1'>def</beginfold id='1'> split_header_value(str)
      str.scan(/((?:"(?:\\.|[^"])+?"|[^",]+)+)
                (?:,\s*|\Z)/xn).collect<beginfold id='2'>{</beginfold id='2'>|v| v[0] <endfold id='2'>}</endfold id='2'>
<endfold id='1'>end</endfold id='1'>

# snippet from Net::Telnet
string.gsub(/#{IAC}(
                   [#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]|
                   [#{DO}#{DONT}#{WILL}#{WONT}]
                     [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}]|
                   #{SB}[^#{IAC}]*#{IAC}#{SE}
                 )/xno)

# following snippet from Webrick's httpresponse.rb
# the HEREDOC is not recognized as such
@body << <beginfold id='4'><<</beginfold id='4'>-_end_of_html_
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
  <HEAD><TITLE>#{HTMLUtils::escape(@reason_phrase)}</TITLE></HEAD>
  <BODY>
    <H1>#{HTMLUtils::escape(@reason_phrase)}</H1>
    #{HTMLUtils::escape(ex.message)}
    <HR>
<endfold id='4'>_end_of_html_</endfold id='4'>


# snippet from Webrick's httpproxy.rb
# here we should make sure that the symbol definition ':' doesn't override
# the module operator '::'
Net::HTTP::version_1_2 if RUBY_VERSION < "1.7"

# snippet from Webrick's cookie.rb
# the beginning of the regexp is erronously highlighted like an operator
key, val = x.split(/=/,2)

# the following are division operators
# it's a bit tricky to keep the operator apart from the regexp
result = 8 / 4
result /= divisor

# 2008-06-01 regexp and division operator syntax has been fixed:
result = 8/4    # division
result = 8/foo  # division
result = /8/    # regexp
result = 8//4/  # division and regexp

10/10           # division
10/ 10          # division
10 /10          # division
10 / 10         # division

foo/10          # division
foo/ 10         # division
foo /10/        # regexp
foo / 10        # division

foo/10/10       # both division
total/count/2   # both division
total/(count/2) # both division

@foo/10         # division
@foo /10        # division

"hello"/10      # division
"hello" / 10    # division

/regexp//10     # division
/regexp/ / 10   # division

Math::PI/10     # division
Math::foo /rx/  # regexp

# 2008-06-05 similar fix for modulo operator:

10%4            # modulo
10 %4           # modulo
10% 4           # modulo
10 % 4          # modulo

foo%4           # modulo
# foo %4          # illegal %string
foo% 4          # modulo
foo % 4         # modulo

foo % (4)       # modulo

foo <beginfold id='3'>%</beginfold id='3'>(4<endfold id='3'>)</endfold id='3'>        # %string
foo <beginfold id='3'>%</beginfold id='3'>q(4<endfold id='3'>)</endfold id='3'>       # %string
foo <beginfold id='3'>%</beginfold id='3'>Q(4<endfold id='3'>)</endfold id='3'>       # %string
foo <beginfold id='3'>%</beginfold id='3'>%4<endfold id='3'>%</endfold id='3'>        # %string

foo = <beginfold id='3'>%</beginfold id='3'>|blah<endfold id='3'>|</endfold id='3'>   # GDL input
foo % <beginfold id='3'>%</beginfold id='3'>|blah<endfold id='3'>|</endfold id='3'>   # modulo and GDL

# mix in any way you want
result = 10//regexp//20/foo//regexp//20

# test cases for general delimited input
# quoted strings
<beginfold id='3'>%</beginfold id='3'>Q_this is a string \n#{123} [<({nested})>]<endfold id='3'>_</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>Q|this is a string \n#{123} [<({nested})>]<endfold id='3'>|</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>Q{this is a string \n#{123} [<({nested})>]<endfold id='3'>}</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>Q(this is a string \n#{123} [<({nested})>]<endfold id='3'>)</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>Q<this is a string \n#{123} [<({nested})>]<endfold id='3'>></endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>Q[this is a string \n#{123} [<({nested})>]<endfold id='3'>]</endfold id='3'>

<beginfold id='3'>%</beginfold id='3'>_also a string \n#{123} [<({nested})>]<endfold id='3'>_</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>|also a string \n#{123} [<({nested})>]<endfold id='3'>|</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>{also a string \n#{123} [<({nested})>]<endfold id='3'>}</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>(also a string \n#{123} [<({nested})>]<endfold id='3'>)</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'><also a string \n#{123} [<({nested})>]<endfold id='3'>></endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>[also a string \n#{123} [<({nested})>]<endfold id='3'>]</endfold id='3'>

# array
<beginfold id='3'>%</beginfold id='3'>W_this is a string \n#{123} [<({nested})>]<endfold id='3'>_</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>W|this is a string \n#{123} [<({nested})>]<endfold id='3'>|</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>W{this is a string \n#{123} [<({nested})>]<endfold id='3'>}</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>W(this is a string \n#{123} [<({nested})>]<endfold id='3'>)</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>W<this is a string \n#{123} [<({nested})>]<endfold id='3'>></endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>W[this is a string \n#{123} [<({nested})>]<endfold id='3'>]</endfold id='3'>

# apostrophed strings
<beginfold id='3'>%</beginfold id='3'>q_apostrophed \n#{123} [<({nested})>]<endfold id='3'>_</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>q|apostrophed \n#{123} [<({nested})>]<endfold id='3'>|</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>q{apostrophed \n#{123} [<({nested})>]<endfold id='3'>}</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>q(apostrophed \n#{123} [<({nested})>]<endfold id='3'>)</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>q<apostrophed \n#{123} [<({nested})>]<endfold id='3'>></endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>q[apostrophed \n#{123} [<({nested})>]<endfold id='3'>]</endfold id='3'>

# regular expressions
<beginfold id='3'>%</beginfold id='3'>r_expression \n#{123} [<({nested})>]<endfold id='3'>_</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>r|expression \n#{123} [<({nested})>]<endfold id='3'>|</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>r{expression \n#{123} [<({nested})>]<endfold id='3'>}</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>r(expression \n#{123} [<({nested})>]<endfold id='3'>)</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>r<expression \n#{123} [<({nested})>]<endfold id='3'>></endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>r[expression \n#{123} [<({nested})>]<endfold id='3'>]</endfold id='3'>

# shell commands
<beginfold id='3'>%</beginfold id='3'>x_ls -l \n#{123} [<({nested})>]<endfold id='3'>_</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>x|ls -l \n#{123} [<({nested})>]<endfold id='3'>|</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>x{ls -l \n#{123} [<({nested})>]<endfold id='3'>}</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>x(ls -l \n#{123} [<({nested})>]<endfold id='3'>)</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>x<ls -l \n#{123} [<({nested})>]<endfold id='3'>></endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>x[ls -l \n#{123} [<({nested})>]<endfold id='3'>]</endfold id='3'>

# sometimes it's useful to have the command on multiple lines
<beginfold id='3'>%</beginfold id='3'>x{ls -l |
grep test <endfold id='3'>}</endfold id='3'>

# alternative syntax
`ls -l`
`echo ' '`

# token array
<beginfold id='3'>%</beginfold id='3'>w_one two three \n#{123} [<({nested})>]<endfold id='3'>_</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>w|one two three \n#{123} [<({nested})>]<endfold id='3'>|</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>w{one two three \n#{123} [<({nested})>]<endfold id='3'>}</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>w(one two three \n#{123} [<({nested})>]<endfold id='3'>)</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>w<one two three \n#{123} [<({nested})>]<endfold id='3'>></endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>w[one two three \n#{123} [<({nested})>]<endfold id='3'>]</endfold id='3'>

# symbol array
<beginfold id='3'>%</beginfold id='3'>s_one two three \n#{123} [<({nested})>]<endfold id='3'>_</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>s|one two three \n#{123} [<({nested})>]<endfold id='3'>|</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>s{one two three \n#{123} [<({nested})>]<endfold id='3'>}</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>s(one two three \n#{123} [<({nested})>]<endfold id='3'>)</endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>s<one two three \n#{123} [<({nested})>]<endfold id='3'>></endfold id='3'>
<beginfold id='3'>%</beginfold id='3'>s[one two three \n#{123} [<({nested})>]<endfold id='3'>]</endfold id='3'>

# number
# binary
0b001
0B1101_13 # bad
# octal
0123
01238 # bad
# decimal
0 10 0d10 120_12 0d23_23
0_1_2 0_1_ # bad
# hex
0x218 0x1a_23
0x218g 0x1a_23g # bad
# complex
0i 12i 03i 12.3i
012_i 12.3_i 123ia # bad
# rational
0r 12r 03r 12.3r
012_r 12.3_r 123ra # bad
# rational
0ri 12ri 03ri 12.3ri
012_ri 12.3_ri 123ir 123ria # bad

# Global constant
ABC ABC1 ABC1ABC ABC_ABC_ ___12 _1 _1ABC
# Contant
Abc A1b Ab1 ABC1a
# ident
ABC? ABC1? ABC1ABC? ABC_ABC_? ___12? _1? _1ABC?
Abc? A1b? Ab1? ABC1a?

# snippet from Net::IMAP
# I object to putting String, Integer and Array into kernel methods.
# While these classes are builtin in Ruby, this is an implementation detail
# that should not be exposed to the user.
# If we want to handle all std-lib classes, fine. But then they should be in their
# own std-lib keyword category.

<beginfold id='1'>def</beginfold id='1'> send_data(data)
      <beginfold id='1'>case</beginfold id='1'> data
      when nil
        put_string("NIL")
      when String
        send_string_data(data)
      when Integer
        send_number_data(data)
      when Array
        send_list_data(data)
      when Time
        send_time_data(data)
      when Symbol
        send_symbol_data(data)
      <endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'>
        data.send_data(self)
      <endfold id='1'>end</endfold id='1'>
<endfold id='1'>end</endfold id='1'>

# snippet from Net::POP
# class names can have numbers in them as long as they don't begin with numbers
# Ruby doesn't internally really make much of a difference between a class name and a constant

# class aliases
  POP = POP3
  POPSession  = POP3
  POP3Session = POP3

# "member access"
POP::Session.COUNT.attribute.calc_with(2)<beginfold id='2'>{</beginfold id='2'> |arg| puts arg <endfold id='2'>}</endfold id='2'>

# snippet from Net::SMTP
# This breaks the code folding. I think we would need to
# handle the '\' that continues the statement to the next line
# in some way to make these kind of things not break something.
raise ArgumentError, 'both user and secret are required'\
                      unless user and secret
 
# string escapes must detect escaping the escape char
str = "\\"
str = "\\\\"
# this is not part of the string
<beginfold id='3'>%</beginfold id='3'>x{echo \\\}\\<endfold id='3'>}</endfold id='3'>	# prints \}\
# this is not part of the command

# these are all symbols
:abc
:abc!
:abc?
:abc=
:[]
:[]=
:@abc
:@@abc
:$abc

# squiggly HEREDOC
    <beginfold id='4'><<</beginfold id='4'>~HEREDOC
      Hello!!
    <endfold id='4'>HEREDOC</endfold id='4'>

# HEREDOC with backticks
<beginfold id='4'><<</beginfold id='4'>`HEREDOC`
    echo "hello"
<endfold id='4'>HEREDOC</endfold id='4'>

# do not highlight HEREDOC markers after the "class" keyword
# (singleton class definition) (bug: #358273)
<beginfold id='1'>class</beginfold id='1'> <<Foo = Object.new
  attr_accessor :foo
<endfold id='1'>end</endfold id='1'>
singleton_class = ( <beginfold id='1'>class</beginfold id='1'> <<foo; self; <endfold id='1'>end</endfold id='1'> )

# highlight regular expressions after ": " (bug: #361875)
get 'files/:slug/:filename', to: 'files#download', slug: /^[a-z]+$/, filename: <beginfold id='3'>%</beginfold id='3'>r|^[/\s]+$<endfold id='3'>|</endfold id='3'>
@@hello!: /regexp/
[]=: <beginfold id='3'>%</beginfold id='3'>r!regexp<endfold id='3'>!</endfold id='3'>

# refinements and its usage
<beginfold id='1'>module</beginfold id='1'> Constantize
  refine String <beginfold id='1'>do</beginfold id='1'>
    <beginfold id='1'>def</beginfold id='1'> constantize
      ::Kernel.const_get(self)
    <endfold id='1'>end</endfold id='1'>
  <endfold id='1'>end</endfold id='1'>
<endfold id='1'>end</endfold id='1'>

<beginfold id='1'>class</beginfold id='1'> MyClass
  using Constantize

  SOME_CONST = "Kate is cool!"

  <beginfold id='1'>def</beginfold id='1'> self.method_using_refinement
    "MyClass::SOME_CONST".constantize
  <endfold id='1'>end</endfold id='1'>
<endfold id='1'>end</endfold id='1'>

puts MyClass.method_using_refinement

<beginfold id='1'>class</beginfold id='1'> Path
  <beginfold id='1'>def</beginfold id='1'> +(other) <endfold id='1'>end</endfold id='1'>
  alias / +
<endfold id='1'>end</endfold id='1'>

test_ok(<beginfold id='1'>if</beginfold id='1'> $x == $x then true <endfold id='1'></endfold id='1'><beginfold id='1'>else</beginfold id='1'> false <endfold id='1'>end</endfold id='1'>)

foo?(?a ? 1 : :a) # or
foo??a?1: :a
foo?(?a ? 1 : 2) # or
foo??a?1: 2

"#{<beginfold id='2'>{</beginfold id='2'>a:<endfold id='2'>}</endfold id='2'>}"
# break substitution
"#{1+1+?};<beginfold id='1'>if</beginfold id='1'>}"