Here document: Difference between revisions

(add sed)
 
(4 intermediate revisions by 4 users not shown)
Line 513:
"string"
sample</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
# The here-document is not here, but at the end of the program
repeat
s$ = input
until error = 1
print s$
.
input_data
This is a 'raw' string with the following properties:
- indention is preserved,
- an escape sequence such as a quotation mark "\\" is interpreted literally, and
- interpolation such as %(a) is also interpreted literally.
- """ is also interpreted literally.
 
`Have fun!`
</syntaxhighlight>
{{out}}
<pre>
This is a 'raw' string with the following properties:
- indention is preserved,
- an escape sequence such as a quotation mark "\\" is interpreted literally, and
- interpolation such as %(a) is also interpreted literally.
- """ is also interpreted literally.
 
`Have fun!`
</pre>
 
=={{header|EchoLisp}}==
Line 1,189 ⟶ 1,217:
 
=={{header|langur}}==
Use a block modifier on a string literal using the qs or QS form to generate a blockquote. The block modifier must be the last modifier.
{{works with|langur|0.6}}
 
<syntaxhighlight lang="langur">val .s = qs:block END
Use a block modifier on a string literal using the q or Q form to generate a blockquote. The block modifier must be the last modifier.
We put our text here.
Here we are, Doc.
END</syntaxhighlight>
 
Use the lead modifier to strip leading white space on each line.
 
<syntaxhighlight lang="langur">val .s = qqs:lead:block END
We put our text here.
Here we are, Doc.
Line 1,463 ⟶ 1,496:
=={{header|Phix}}==
Phix does not have here-docs. In Phix normal double quoted strings are single line and require escaping. Strings can also be entered by using triple doublequotes or single backticks to include linebreaks and avoid any backslash interpretation. If the literal begins with a newline, it is discarded and any immediately following leading underscores specify a (maximum) trimming that should be applied to all subsequent lines. Interpolation is left to printf and friends. Both """`""" and `"""` are valid. Examples:
<!--<syntaxhighlight lang="phix">string ts1 = """(phixonline)-->
<span style="color: #004080;">string</span> <span style="color: #000000;">ts1</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
this
this
"string"\thing"""
"string"\thing"""</span>
 
string ts2 = """this
<span style="color: #004080;">string</span> <span style="color: #000000;">ts2</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""this
"string"\thing"""
"string"\thing"""</span>
 
string ts3 = """
<span style="color: #004080;">string</span> <span style="color: #000000;">ts3</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
_____________this
_____________this
"string"\thing"""
"string"\thing"""</span>
 
string ts4 = `
<span style="color: #004080;">string</span> <span style="color: #000000;">ts4</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`
this
this
"string"\thing`
"string"\thing`</span>
 
string ts5 = `this
<span style="color: #004080;">string</span> <span style="color: #000000;">ts5</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`this
"string"\thing`
"string"\thing`</span>
 
string ts6 = `
<span style="color: #004080;">string</span> <span style="color: #000000;">ts6</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`
_____________this
_____________this
"string"\thing`
"string"\thing`</span>
 
string ts7 = "this\n\"string\"\\thing"
<span style="color: #004080;">string</span> <span style="color: #000000;">ts7</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"this\n\"string\"\\thing"</span>
 
constant tests={ts1,ts2,ts3,ts4,ts5,ts6,ts7}
<span style="color: #008080;">constant</span> <span style="color: #000000;">tests</span><span style="color: #0000FF;">={</span><span style="color: #000000;">ts1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts7</span><span style="color: #0000FF;">}</span>
for i=1 to length(tests) do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
for j=1 to length(tests) do
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
if tests[i]!=tests[j] then crash("error") end if
<span style="color: #008080;">if</span> <span style="color: #000000;">tests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"error"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
printf(1,"""
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"""
____________Everything
____________Everything
(all %d tests)
works (all %d tests)
justworks
file.""",length(tests)) just
file."""</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">))</span>
printf(1,"""`""")
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"""`"""</span><span style="color: #0000FF;">)</span>
printf(1,`"""`)</syntaxhighlight>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`"""`</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 2,446 ⟶ 2,481:
 
Borrowing the Ada example (appropriately adjusted) for an illustration of a raw string.
<syntaxhighlight lang="ecmascriptwren">var a = 42
var b = """
This is a 'raw' string with the following properties:
890

edits