-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #804 from Golmote/prism-lua
Add support for Lua
- Loading branch information
Showing
10 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Prism.languages.lua = { | ||
'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m, | ||
// \z may be used to skip the following space | ||
'string': /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[\s\S]))*\1|\[(=*)\[[\s\S]*?\]\2\]/, | ||
'number': /\b0x[a-f\d]+\.?[a-f\d]*(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|\.?\d*(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i, | ||
'keyword': /\b(?:and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b/, | ||
'function': /(?!\d)\w+(?=\s*(?:[({]))/, | ||
'operator': [ | ||
/[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/, | ||
{ | ||
// Match ".." but don't break "..." | ||
pattern: /(^|[^.])\.\.(?!\.)/, | ||
lookbehind: true | ||
} | ||
], | ||
'punctuation': /[\[\](){},;]|\.+|:+/ | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<h1>Lua</h1> | ||
<p>To use this language, use the class "language-lua".</p> | ||
|
||
<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 doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug. | ||
</p> | ||
|
||
<h3>Comment-like substrings</h3> | ||
<pre><code>"foo -- bar";</code></pre> | ||
|
||
<h3>Functions with a single string parameter not using parentheses are not highlighted</h3> | ||
<pre><code>foobar"param";</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/local/bin/lua | ||
-- | ||
-- Foobar | ||
--[[Foo | ||
bar]] | ||
--[====[Foo | ||
bar]=====] ]===] | ||
baz]====] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "#!/usr/local/bin/lua"], | ||
["comment", "--"], | ||
["comment", "-- Foobar"], | ||
["comment", "--[[Foo\r\nbar]]"], | ||
["comment", "--[====[Foo\r\nbar]=====] ]===]\r\nbaz]====]"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
foo () | ||
Foo_bar_42() | ||
foo {} | ||
Foo_bar_42{} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["function", "foo"], ["punctuation", "("], ["punctuation", ")"], | ||
["function", "Foo_bar_42"], ["punctuation", "("], ["punctuation", ")"], | ||
["function", "foo"], ["punctuation", "{"], ["punctuation", "}"], | ||
["function", "Foo_bar_42"], ["punctuation", "{"], ["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for functions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
and | ||
break | ||
do | ||
else | ||
elseif | ||
end | ||
false | ||
for | ||
function | ||
goto | ||
if | ||
in | ||
local | ||
nil | ||
not | ||
or | ||
repeat | ||
return | ||
then | ||
true | ||
until | ||
while | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "and"], | ||
["keyword", "break"], | ||
["keyword", "do"], | ||
["keyword", "else"], | ||
["keyword", "elseif"], | ||
["keyword", "end"], | ||
["keyword", "false"], | ||
["keyword", "for"], | ||
["keyword", "function"], | ||
["keyword", "goto"], | ||
["keyword", "if"], | ||
["keyword", "in"], | ||
["keyword", "local"], | ||
["keyword", "nil"], | ||
["keyword", "not"], | ||
["keyword", "or"], | ||
["keyword", "repeat"], | ||
["keyword", "return"], | ||
["keyword", "then"], | ||
["keyword", "true"], | ||
["keyword", "until"], | ||
["keyword", "while"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for keywords. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
0 | ||
42 | ||
3.14159 | ||
3. | ||
.42 | ||
4e14 | ||
3.14e+8 | ||
.7E-1 | ||
4.e12 | ||
0xBadFace | ||
0x0.1E | ||
0xA23p-4 | ||
0X1.921FB54442D18P+1 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "0"], | ||
["number", "42"], | ||
["number", "3.14159"], | ||
["number", "3."], | ||
["number", ".42"], | ||
["number", "4e14"], | ||
["number", "3.14e+8"], | ||
["number", ".7E-1"], | ||
["number", "4.e12"], | ||
["number", "0xBadFace"], | ||
["number", "0x0.1E"], | ||
["number", "0xA23p-4"], | ||
["number", "0X1.921FB54442D18P+1"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for numbers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
+ - * % | ||
^ & | # | ||
/ // | ||
< << <= | ||
> >> >= | ||
= == | ||
~ ~= | ||
.. | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["operator", "+"], ["operator", "-"], ["operator", "*"], ["operator", "%"], | ||
["operator", "^"], ["operator", "&"], ["operator", "|"], ["operator", "#"], | ||
["operator", "/"], ["operator", "//"], | ||
["operator", "<"], ["operator", "<<"], ["operator", "<="], | ||
["operator", ">"], ["operator", ">>"], ["operator", ">="], | ||
["operator", "="], ["operator", "=="], | ||
["operator", "~"], ["operator", "~="], | ||
["operator", ".."] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"" | ||
"Fo\"obar" | ||
"Foo\ | ||
bar\z | ||
baz" | ||
'' | ||
'Fo\'obar' | ||
'Foo\ | ||
bar\z | ||
baz' | ||
[[Foo | ||
bar]] | ||
[====[Foo | ||
bar]=====] ]===] | ||
baz]====] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["string", "\"\""], | ||
["string", "\"Fo\\\"obar\""], | ||
["string", "\"Foo\\\r\nbar\\z\r\nbaz\""], | ||
["string", "''"], | ||
["string", "'Fo\\'obar'"], | ||
["string", "'Foo\\\r\nbar\\z\r\nbaz'"], | ||
["string", "[[Foo\r\nbar]]"], | ||
["string", "[====[Foo\r\nbar]=====] ]===]\r\nbaz]====]"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for strings. |