Syntax highlighting using Mediawiki formatting: Difference between revisions
Syntax highlighting using Mediawiki formatting (view source)
Revision as of 07:28, 18 October 2023
, 8 months ago→{{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
'''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 && error("error with terminator of quote at $idx")
app'''end'''!(outtxt, collect(replace(txt[idx:idx+qlen.stop+2], "\n" => "\n ")))
idx += qlen.stop + 3
'''else''' ''# " quote "''
qlen = findfirst(r"(?<!\\)\"", txt[idx+1:'''end'''])
qlen == nothing && error("error with terminator of quote at $idx")
Line 577:
idx += qlen.stop + 2
'''end'''
'''elseif''' c == '#' && txt[max(1, idx - 1)] != ''' ''# start comment''
'''if''' idx < len && txt[idx+1] == '=' ''#= comment =#''
start, stop = nestedcommentlimits(txt[idx:'''end'''])
s = replace(txt[idx:idx+stop-1], "\n" => "
app'''end'''!(outtxt, collect("\'\'$s\'\'"))
idx += stop
'''else''' ''# found a line comment, like this comment''
newlinepos = something(findfirst(==('\n'), txt[idx+1:'''end''']), len - idx)
app'''end'''!(outtxt, collect("\'\'$(txt[idx:idx+newlinepos-1])\'\'"))
idx += newlinepos
'''end'''
'''elseif''' c ∈ 'a':'z' ''# 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''' [''', '&', '<', '>'] ''# \x26 is char & for HTML entity translation''
s = c == ''' ? "
app'''end'''!(outtxt, collect(s))
idx += 1
'''else''' ''# nothing special found, so pass char to output and increment index into input''
push!(outtxt, c)
idx += 1
Line 614:
'''end'''
println(partialhighlight(read(
=={{header|Phix}}==
|