Long literals, with continuations: Difference between revisions

m
→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics
(Added Delphi example)
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
Line 900:
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
Back-ticks and triple-quotes permit multi-line strings. We first replace all/any cr/lf/tab characters with spaces, then split (by default on a single space), omitting empty elements. You could use spaced_elements = join(elements) to join them back up into a space-separated single string, if that's really what you want, and you could then, like Go, use rfind(' ',spaced_elements) to re-extract the last one.
You could also, like Julia, use get_file_date(command_line()[2]) instead of the hand-written last_updated constant. Phix code is free-format, indent things however you like, there is no specific maximum line length.
 
<lang Phix>constant last_updated = "March 24th, 2020",
<!--<lang Phix>-->
elements_text = `
<span style="color: #008080;">constant</span> <span style="color: #000000;">last_updated</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"March 24th, 2020"</span><span style="color: #0000FF;">,</span>
hydrogen helium lithium beryllium
<span style="color: #000000;">elements_text</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`
boron carbon nitrogen oxygen
fluorine hydrogen neon helium lithium sodium magnesiumberyllium
aluminum boron silicon carbon phosphorous sulfur nitrogen oxygen
chlorine fluorine argon neon potassium sodium calcium magnesium
scandium aluminum titanium silicon vanadium phosphorous chromiumsulfur
manganese chlorine iron argon cobalt potassium nickelcalcium
copper scandium titanium zinc vanadium gallium germaniumchromium
arsenic manganese iron selenium bromine cobalt krypton nickel
rubidium copper strontium zinc yttrium zirconium gallium germanium
niobium arsenic molybdenum selenium technetium rutheniumbromine krypton
rhodium rubidium palladiumstrontium silveryttrium cadmiumzirconium
indium niobium tinmolybdenum technetium antimony telluriumruthenium
iodine rhodium xenonpalladium silver cesium bariumcadmium
lanthanum indium cerium tin praseodymium neodymium antimony tellurium
promethium iodine samarium xenon europium gadolinium cesium barium
terbium lanthanum cerium dysprosium holmium praseodymium erbiumneodymium
thulium promethium samarium ytterbium europium lutetium hafniumgadolinium
tantalum terbium tungsten dysprosium rheniumholmium osmiumerbium
iridium thulium platinum ytterbium goldlutetium mercuryhafnium
thallium tantalum lead tungsten rhenium bismuth poloniumosmium
astatine iridium radon platinum gold francium radium mercury
actinium thallium thorium lead protactinium uranium bismuth polonium
neptunium astatine plutonium radon americium curium francium radium
actinium thorium protactinium uranium
berkelium californium einsteinium fermium
neptunium plutonium americium curium
mendelevium nobelium lawrencium rutherfordium
berkelium californium einsteinium fermium
dubnium seaborgium bohrium hassium
mendelevium nobelium lawrencium rutherfordium
meitnerium darmstadtium roentgenium copernicium
nihonium dubnium flerovium seaborgium moscovium bohrium livermorium hassium
meitnerium darmstadtium roentgenium copernicium
tennessine oganesson
nihonium flerovium moscovium livermorium
`,
tennessine oganesson
elements = split(substitute_all(elements_text,"\n\r\t"," "),no_empty:=true),
`</span><span style="color: #0000FF;">,</span>
fmt = """
<span style="color: #000000;">elements</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">elements_text</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n\r\t"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">),</span><span style="color: #000000;">no_empty</span><span style="color: #0000FF;">:=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">),</span>
Last revision: %s
<span style="color: #000000;">fmt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
Number of elements: %d
Last revision: %s
The last of which is: `%s`
Number of elements: %d
"""
The last of which is: `%s`
printf(1,fmt,{last_updated,length(elements),elements[$]})</lang>
"""</span>
<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: #000000;">fmt</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">last_updated</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">elements</span><span style="color: #0000FF;">),</span><span style="color: #000000;">elements</span><span style="color: #0000FF;">[$]})</span>
<!--</lang>-->
 
{{out}}
<pre>
7,818

edits