CS-Notes/docs/_style/prism-master/examples/prism-lua.html
2018-12-19 14:09:39 +08:00

90 lines
2.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h2>Comments</h2>
<pre><code>#!/usr/local/bin/lua
--
-- Single line comment
--[[ Multi line
comment ]]
--[====[ Multi line
comment ]====]</code></pre>
<h2>Strings</h2>
<pre><code>""
"Foo\"bar"
"Foo\
bar \z
baz"
''
'Foo\'bar'
'Foo\
bar \z
baz'
[[Multi "line"
string]]
[==[Multi [["line"]]
string]==]</code></pre>
<h2>Numbers</h2>
<pre><code>3
345
0xff
0xBEBADA
3, 3., 3.1, .3,
3e12, 3.e-41, 3.1E+1, .3e1
0x0.1E
0xA23p-4
0X1.921FB54442D18P+1</code></pre>
<h2>Full example</h2>
<pre><code>function To_Functable(t, fn)
return setmetatable(t,
{
__index = function(t, k) return fn(k) end,
__call = function(t, k) return t[k] end
})
end
-- Functable bottles of beer implementation
spell_out = {
"One", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
[0] = "No more",
[-1] = "Lots more"
}
spell_out = To_Functable(spell_out, function(i) return i end)
bottles = To_Functable({"Just one bottle of beer"},
function(i)
return spell_out(i) .. " bottles of beer"
end)
function line1(i)
return bottles(i) .. " on the wall, " .. bottles(i) .. "\n"
end
line2 = To_Functable({[0] = "Go to the store, Buy some more,\n"},
function(i)
return "Take one down and pass it around,\n"
end)
function line3(i)
return bottles(i) .. " on the wall.\n"
end
function song(n)
for i = n, 0, -1 do
io.write(line1(i), line2(i), line3(i - 1), "\n")
end
end</code></pre>
<h2>Known failures</h2>
<p>There are certain edge cases where Prism will fail.
There are always such cases in every regex-based syntax highlighter.
However, Prism dares to be open and honest about them.
If a failure is listed here, it doesnt mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
</p>
<h3>Functions with a single string parameter not using parentheses are not highlighted</h3>
<pre><code>foobar"param";</code></pre>