Syntax highlighting using Mediawiki formatting: Difference between revisions
Syntax highlighting using Mediawiki formatting (view source)
Revision as of 09:01, 11 October 2023
, 8 months ago→{{header|Wren}}: Now allows for nesting of multi-line comments.
(→{{header|ALGOL 68}}: Much simpler parsing (as in other samples), fixed multi-line comments) |
(→{{header|Wren}}: Now allows for nesting of multi-line comments.) |
||
Line 634:
=={{header|Wren}}==
{{libheader|Wren-ioutil}}
Note that, rightly or wrongly, this code would not highlight keywords occurring in interpolated string expressions.
Line 659 ⟶ 660:
'''var''' inRaw = '''false''' ''// within a raw string literal''
'''var''' inCom = '''false''' ''// within a multi-line comment''
'''var''' level = 0 ''// nesting level for multi-line comment''
'''for''' (line '''in''' lines) {
System.write(" ")
Line 665 ⟶ 667:
'''var''' word = ""
'''var''' chrs = line.toList ''// convert to list of unicode characters''
'''var''' cc = chrs.count
'''var''' i = 0
'''if''' (inCom) System.write("''")
'''while''' (i <
'''var''' c = chrs[i]
'''if''' (inCom) { ''// if inside a multi-line comment''
'''if''' (c == "
System.write("
i = i + 1
} '''else''' '''if''' (c == "*" && i < cc-1 && chrs[i+1] == "/") {
level = level - 1
System.write("*/")
i = i + 1
'''if''' (level == 0) {
inCom = '''false'''
System.write("''")
}
} '''else''' {
System.write(c)
}
} '''else''' '''if''' (inStr && c == "\\" && i <
''/* escaped double quote in string literal */''
System.write("\\\"")
Line 691 ⟶ 702:
System.write(c)
} '''else''' '''if''' (c == "/") { ''// forward slash''
'''if''' (i <
System.write("''" + chrs[i..-1].join() + "''")
'''break'''
} '''else''' '''if''' (i <
inCom = '''true'''
level = 1
System.write("''" + "/*")
i = i + 1
Line 733 ⟶ 745:
highlight.call(lines)
''/* this code should now be saved to''
'' /* a file named */''
'' syntax_highlighting.wren */''
|