Syntax highlighting using Mediawiki formatting: Difference between revisions

m
→‎{{header|Julia}}: more comments
(Added Algol W)
m (→‎{{header|Julia}}: more comments)
Line 485:
=={{header|Julia}}==
''#= Keywords in Julia. Handles two word reserved keywords. #= Also''
'' #= handles nested comments such as this. =# =#''
''=#''
'''const''' KEYWORDS = map(
w -> Regex("^" * w * "\\W"),
Line 556:
idx, len = 1, length(txt)
'''while''' idx <= len
'''if''' !isvalid(txt, idx) ''# exclude internal positions of multibyte Char''
idx += 1
'''continue'''
'''end'''
c = txt[idx]
'''if''' c == '\\' ''# escape the next char, send as is''
push!(outtxt, c, txt[idx+1])
idx += 2
'''elseif''' c == '\"' ''# quotation start''
'''if''' idx < len - 2 && c == txt[idx+1] == txt[idx+2] ''# """ quotes """''
qlen = findfirst(r"(?<!\\)\"\"\""sa, txt[idx+3:'''end'''])
qlen == nothing &amp;&amp; error("error with terminator of quote at $idx")
app'''end'''!(outtxt, collect(replace(txt[idx:idx+qlen.stop+2], "\n" =&gt; "\n ")))
idx += qlen.stop + 3
'''else''' ''# " quote "''
qlen = findfirst(r"(?<!\\)\"", txt[idx+1:'''end'''])
qlen == nothing &amp;&amp; error("error with terminator of quote at $idx")
Line 577:
idx += qlen.stop + 2
'''end'''
'''elseif''' c == &apos;#&apos; &amp;&amp; txt[max(1, idx - 1)] != &apos;&apos;&apos; ''# start comment''
'''if''' idx &lt; len &amp;&amp; txt[idx+1] == &apos;=&apos; ''#= comment =#''
start, stop = nestedcommentlimits(txt[idx:'''end'''])
s = replace(txt[idx:idx+stop-1], "\n" =&gt; "''\n ''")
app'''end'''!(outtxt, collect("\'\'$s\'\'"))
idx += stop
'''else''' ''# found a line comment, like this comment''
newlinepos = something(findfirst(==(&apos;\n&apos;), txt[idx+1:'''end''']), len - idx)
app'''end'''!(outtxt, collect("\'\'$(txt[idx:idx+newlinepos-1])\'\'"))
idx += newlinepos
'''end'''
'''elseif''' c ∈ &apos;a&apos;:&apos;z&apos; ''# lowercase char so check for keyword match''
'''for''' (j, reg) '''in''' enumerate(KEYWORDS)
m = match(reg, txt[idx:'''end'''])
'''if''' m != nothing
wlen = m.match.ncodeunits - 2
app'''end'''!(outtxt, collect("\'\'\'$(txt[idx:idx+wlen])\'\'\'"))
idx += wlen + 1
'''break'''
'''elseif''' j == lastindex(KEYWORDS) ''# no keyword found, send char to output''
push!(outtxt, c)
idx += 1
'''end'''
'''end'''
'''elseif''' c '''in''' [&apos;&apos;&apos;, &apos;&amp;&apos;, &apos;&lt;&apos;, &apos;&gt;&apos;] ''# \x26 is char & for HTML entity translation''
s = c == &apos;&apos;&apos; ? "&apos\x26apos;" : c == &apos;&amp;&apos; ? "&amp\x26amp;" : c == &apos;&lt;&apos; ? "&lt\x26lt;" : "&gt\x26gt;"
app'''end'''!(outtxt, collect(s))
idx += 1
'''else''' ''# nothing special found, so pass char to output and increment index into input''
'''else'''
push!(outtxt, c)
idx += 1
Line 614:
'''end'''
println(partialhighlight(read(PROGRAM_FILE"/users/wherr/onedrive/documents/julia programs/test1.jl", String)), "\n")
 
=={{header|Phix}}==
4,108

edits