File: Heredoc.rb

package info (click to toggle)
dlr-languages 20090805%2Bgit.e6b28d27%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 51,484 kB
  • ctags: 59,257
  • sloc: cs: 298,829; ruby: 159,643; xml: 19,872; python: 2,820; yacc: 1,960; makefile: 96; sh: 65
file content (119 lines) | stat: -rw-r--r-- 1,319 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

x = <<EOT
bar
  EOT
 EOT
EOTTT
EOT;
EOT 
EOT

x = <<EOT         #whitespace and comment here
bar
EOT

# error:
# x = <<EOT   foo
# EOT

x = <<EOT

EOT

# following prints:
#blah
#foo
#bar

x = <<EOT1,<<EOT2,<<EOT3
blah
EOT1
foo
EOT2
bar
EOT3

puts x

# following prints:
#blah
#foo inner foos
#
#bar

puts <<EOT1,      <<EOT2,            <<EOT3
blah
EOT1
foo #{ "inner " + x = <<EOT5
foos
EOT5
}
EOT2
bar
EOT3

puts <<'EOT1'
cup<\t>
EOT1

puts <<'EOT1 blah'
cup<\t>
EOT1 blah

puts <<"EOT1 blah"
cup<\t>
EOT1 blah

puts <<"EOT1-bar", <<'  EOT2', <<-"EOT3".upcase, <<-'EOT4'
really cool cup <\t>
EOT1-bar
one more cup <\t>
  EOT2
space-indent-ended heredoc here "\t"
     EOT3
one more space-indent-ended heredoc here "\t"
       EOT4

puts "---------"

x = <<"EOT".downcase() << "FOO" + "BAR" + <<"GOO"
A
FOO
B
EOT
C
GOO

puts x

puts "---------"

def foo(a,b)
  yield
  "[#{a} #{b}]"
end

# block must be on the same line (next line is part of heredoc)
puts x = foo(<<"FOO", <<"BAR") { puts "BLOCK" }
foofoo
FOO
barbar
BAR

# puts <<-" space"
# doesn't work because lexer eats all whitespace and then doesn't see a space as a part of heredoc-end token
#      space

# no whitespace following <<:
#puts <<  "EOT1 blah"  
#cup<\t>
#EOT1 blah

#error:
#x = <<EOT1,
# 
#         <<EOT2,
#             <<EOT3
#blah
#EOT1