@@ -43,53 +43,7 @@ Revise a multiline string according to the provided style and chomp encoded in t
43
43
- "lk" / "|+": literal and keep
44
44
"""
45
45
function multiline (str:: AbstractString , indicators:: AbstractString )
46
- indicators_len = length (indicators)
47
- indicators_len > 2 && throw (ArgumentError (" Too many indicators provided" ))
48
-
49
- # Note: Using '\0` to indicate undefined
50
- yaml_chomp = false
51
- style_char, chomp_char = if indicators_len == 2
52
- indicators
53
- elseif indicators_len == 1
54
- ind = indicators[1 ]
55
- if ind in (' f' , ' l' )
56
- ind, ' \0 '
57
- elseif ind in (' >' , ' |' )
58
- yaml_chomp = true
59
- ind, ' \0 '
60
- else
61
- ' \0 ' , ind
62
- end
63
- else
64
- ' \0 ' , ' \0 '
65
- end
66
-
67
- if style_char != ' \0 ' && chomp_char != ' \0 ' && isletter (style_char) ⊻ isletter (chomp_char)
68
- throw (ArgumentError (" Can't mix YAML style block indicators with letter indicators" ))
69
- end
70
-
71
- style = if style_char == ' f' || style_char == ' >'
72
- :folded
73
- elseif style_char == ' l' || style_char == ' |'
74
- :literal
75
- elseif style_char == ' \0 '
76
- DEFAULT_STYLE
77
- else
78
- throw (ArgumentError (" Unknown style indicator: $(repr (style_char)) " ))
79
- end
80
-
81
- chomp = if chomp_char == ' c' || yaml_chomp
82
- :clip
83
- elseif chomp_char == ' s' || chomp_char == ' -'
84
- :strip
85
- elseif chomp_char == ' k' || chomp_char == ' +'
86
- :keep
87
- elseif chomp_char == ' \0 '
88
- DEFAULT_CHOMP
89
- else
90
- throw (ArgumentError (" Unknown chomping indicator: $(repr (chomp_char)) " ))
91
- end
92
-
46
+ style, chomp = _process_indicators (indicators)
93
47
return multiline (str, style, chomp)
94
48
end
95
49
@@ -148,16 +102,17 @@ julia> m\"\"\"
148
102
```
149
103
"""
150
104
macro m_str (str:: AbstractString , indicators:: AbstractString = " " )
105
+ style, chomp = _process_indicators (indicators)
151
106
parsed = interpolate (str)
152
107
153
108
# When no string interpolation needs to take place we can just process the multiline
154
109
# string during parse time. If string interpolation needs to take place we'll evaluate
155
110
# the multiline string at runtime so that we can process after interpolation has taken
156
111
# place.
157
112
result = if parsed isa String
158
- multiline (unescape_string (parsed), indicators )
113
+ multiline (unescape_string (parsed), style, chomp )
159
114
else
160
- Expr (:call , :(MultilineStrings. multiline), parsed, indicators )
115
+ Expr (:call , :(MultilineStrings. multiline), parsed, QuoteNode (style), QuoteNode (chomp) )
161
116
end
162
117
163
118
return esc (result)
@@ -193,4 +148,55 @@ function interpolate(str::AbstractString)
193
148
return Expr (:string , components... )
194
149
end
195
150
151
+ function _process_indicators (indicators:: AbstractString )
152
+ indicators_len = length (indicators)
153
+ indicators_len > 2 && throw (ArgumentError (" Too many indicators provided" ))
154
+
155
+ # Note: Using '\0` to indicate undefined
156
+ yaml_chomp = false
157
+ style_char, chomp_char = if indicators_len == 2
158
+ indicators
159
+ elseif indicators_len == 1
160
+ ind = indicators[1 ]
161
+ if ind in (' f' , ' l' )
162
+ ind, ' \0 '
163
+ elseif ind in (' >' , ' |' )
164
+ yaml_chomp = true
165
+ ind, ' \0 '
166
+ else
167
+ ' \0 ' , ind
168
+ end
169
+ else
170
+ ' \0 ' , ' \0 '
171
+ end
172
+
173
+ if style_char != ' \0 ' && chomp_char != ' \0 ' && isletter (style_char) ⊻ isletter (chomp_char)
174
+ throw (ArgumentError (" Can't mix YAML style block indicators with letter indicators" ))
175
+ end
176
+
177
+ style = if style_char == ' f' || style_char == ' >'
178
+ :folded
179
+ elseif style_char == ' l' || style_char == ' |'
180
+ :literal
181
+ elseif style_char == ' \0 '
182
+ DEFAULT_STYLE
183
+ else
184
+ throw (ArgumentError (" Unknown style indicator: $(repr (style_char)) " ))
185
+ end
186
+
187
+ chomp = if chomp_char == ' c' || yaml_chomp
188
+ :clip
189
+ elseif chomp_char == ' s' || chomp_char == ' -'
190
+ :strip
191
+ elseif chomp_char == ' k' || chomp_char == ' +'
192
+ :keep
193
+ elseif chomp_char == ' \0 '
194
+ DEFAULT_CHOMP
195
+ else
196
+ throw (ArgumentError (" Unknown chomping indicator: $(repr (chomp_char)) " ))
197
+ end
198
+
199
+ return style, chomp
200
+ end
201
+
196
202
end
0 commit comments