-
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 #621 from Golmote/prism-monkey
Add support for Monkey
- Loading branch information
Showing
12 changed files
with
378 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,25 @@ | ||
Prism.languages.monkey = { | ||
'string': /"[^"\r\n]*"/, | ||
'comment': [ | ||
/^#Rem\s+[\s\S]*?^#End/im, | ||
/'.+/, | ||
], | ||
'preprocessor': { | ||
pattern: /(^[ \t]*)#.+/m, | ||
lookbehind: true, | ||
alias: 'comment' | ||
}, | ||
'function': /\w+(?=\()/, | ||
'type-char': { | ||
pattern: /(\w)[?%#$]/, | ||
lookbehind: true, | ||
alias: 'variable' | ||
}, | ||
'number': { | ||
pattern: /((?:\.\.)?)(?:(?:\b|\B-\.?|\B\.)\d+((?!\.\.)\.\d*)?|\$[\da-f]+)/i, | ||
lookbehind: true | ||
}, | ||
'keyword': /\b(?:Void|Strict|Public|Private|Property|Bool|Int|Float|String|Array|Object|Continue|Exit|Import|Extern|New|Self|Super|Try|Catch|Eachin|True|False|Extends|Abstract|Final|Select|Case|Default|Const|Local|Global|Field|Method|Function|Class|End|If|Then|Else|ElseIf|EndIf|While|Wend|Repeat|Until|Forever|For|To|Step|Next|Return|Module|Interface|Implements|Inline|Throw|Null)\b/i, | ||
'operator': /\.\.|<[=>]?|>=?|:?=|(?:[+\-*\/&~|]|\b(?:Mod|Shl|Shr)\b)=?|\b(?:And|Not|Or)\b/i, | ||
'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,90 @@ | ||
<h1>Monkey</h1> | ||
<p>To use this language, use the class "language-monkey".</p> | ||
|
||
<h2>Comments</h2> | ||
<pre><code>' This is a comment | ||
|
||
#Rem ' This is the start of a comment block | ||
Some comment ' We are inside the comment block | ||
#End</code></pre> | ||
|
||
<h2>Strings</h2> | ||
<pre><code>"Hello World" | ||
"~qHello World~q" | ||
"~tIndented~n"</code></pre> | ||
|
||
<h2>Numbers</h2> | ||
<pre><code>0 | ||
1234 | ||
$3D0DEAD | ||
$CAFEBABE | ||
|
||
.0 | ||
0.0 | ||
.5 | ||
0.5 | ||
1.0 | ||
1.5 | ||
1.00001 | ||
3.14159265</code></pre> | ||
|
||
<h2>Variable types</h2> | ||
<pre><code>Local myVariable:Bool = True | ||
Local myVariable? = True | ||
Local myVariable:Int = 1024 | ||
Local myVariable% = 1024 | ||
Local myVariable:Float = 3.141516 | ||
Local myVariable# = 3.141516 | ||
Local myVariable:String = "Hello world" | ||
Local myVariable$ = "Hello world"</code></pre> | ||
|
||
<h2>Full example</h2> | ||
<pre><code>Import mojo | ||
|
||
Class MyApp Extends App | ||
|
||
Method OnCreate() | ||
|
||
SetUpdateRate 60 | ||
|
||
End | ||
|
||
Method OnRender() | ||
|
||
Local date:=GetDate() | ||
|
||
Local months:=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] | ||
|
||
Local day:=("0"+date[2])[-2..] | ||
Local month:=months[date[1]-1] | ||
Local year:=date[0] | ||
Local hour:=("0"+date[3])[-2..] | ||
Local min:=("0"+date[4])[-2..] | ||
Local sec:=("0"+date[5])[-2..] + "." + ("00"+date[6])[-3..] | ||
|
||
Local now:=hour+":"+min+":"+sec+" "+day+" "+month+" "+year | ||
|
||
Cls | ||
DrawText now,DeviceWidth/2,DeviceHeight/2,.5,.5 | ||
End | ||
|
||
End | ||
|
||
Function Main() | ||
|
||
New MyApp | ||
|
||
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> | ||
|
||
<h2>Two double quotes inside a comment</h2> | ||
<pre><code>' This "comment" is broken | ||
#Rem | ||
This "comment" is broken | ||
#End</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,15 @@ | ||
' Foobar | ||
#Rem Foo | ||
Bar 'Baz | ||
#End | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "' Foobar"], | ||
["comment", "#Rem Foo\r\nBar 'Baz\r\n#End"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,13 @@ | ||
foobar() | ||
Foo_Bar_42() | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["function", "foobar"], ["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,125 @@ | ||
Void | ||
Strict | ||
Public | ||
Private | ||
Property | ||
Bool | ||
Int | ||
Float | ||
String | ||
Array | ||
Object | ||
Continue | ||
Exit | ||
Import | ||
Extern | ||
New | ||
Self | ||
Super | ||
Try | ||
Catch | ||
Eachin | ||
True | ||
False | ||
Extends | ||
Abstract | ||
Final | ||
Select | ||
Case | ||
Default | ||
Const | ||
Local | ||
Global | ||
Field | ||
Method | ||
Function | ||
Class | ||
End | ||
If | ||
Then | ||
Else | ||
ElseIf | ||
EndIf | ||
While | ||
Wend | ||
Repeat | ||
Until | ||
Forever | ||
For | ||
To | ||
Step | ||
Next | ||
Return | ||
Module | ||
Interface | ||
Implements | ||
Inline | ||
Throw | ||
Null | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "Void"], | ||
["keyword", "Strict"], | ||
["keyword", "Public"], | ||
["keyword", "Private"], | ||
["keyword", "Property"], | ||
["keyword", "Bool"], | ||
["keyword", "Int"], | ||
["keyword", "Float"], | ||
["keyword", "String"], | ||
["keyword", "Array"], | ||
["keyword", "Object"], | ||
["keyword", "Continue"], | ||
["keyword", "Exit"], | ||
["keyword", "Import"], | ||
["keyword", "Extern"], | ||
["keyword", "New"], | ||
["keyword", "Self"], | ||
["keyword", "Super"], | ||
["keyword", "Try"], | ||
["keyword", "Catch"], | ||
["keyword", "Eachin"], | ||
["keyword", "True"], | ||
["keyword", "False"], | ||
["keyword", "Extends"], | ||
["keyword", "Abstract"], | ||
["keyword", "Final"], | ||
["keyword", "Select"], | ||
["keyword", "Case"], | ||
["keyword", "Default"], | ||
["keyword", "Const"], | ||
["keyword", "Local"], | ||
["keyword", "Global"], | ||
["keyword", "Field"], | ||
["keyword", "Method"], | ||
["keyword", "Function"], | ||
["keyword", "Class"], | ||
["keyword", "End"], | ||
["keyword", "If"], | ||
["keyword", "Then"], | ||
["keyword", "Else"], | ||
["keyword", "ElseIf"], | ||
["keyword", "EndIf"], | ||
["keyword", "While"], | ||
["keyword", "Wend"], | ||
["keyword", "Repeat"], | ||
["keyword", "Until"], | ||
["keyword", "Forever"], | ||
["keyword", "For"], | ||
["keyword", "To"], | ||
["keyword", "Step"], | ||
["keyword", "Next"], | ||
["keyword", "Return"], | ||
["keyword", "Module"], | ||
["keyword", "Interface"], | ||
["keyword", "Implements"], | ||
["keyword", "Inline"], | ||
["keyword", "Throw"], | ||
["keyword", "Null"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,19 @@ | ||
0 | ||
42 | ||
3.14159 | ||
.5 | ||
$BadFace | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "0"], | ||
["number", "42"], | ||
["number", "3.14159"], | ||
["number", ".5"], | ||
["number", "$BadFace"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,41 @@ | ||
.. | ||
< <> <= | ||
> >= | ||
= | ||
:= | ||
+ += | ||
- -= | ||
* *= | ||
/ /= | ||
& &= | ||
~ ~= | ||
| |= | ||
Mod Mod= | ||
Shl Shl= | ||
Shr Shr= | ||
And Not Or | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["operator", ".."], | ||
["operator", "<"], ["operator", "<>"], ["operator", "<="], | ||
["operator", ">"], ["operator", ">="], | ||
["operator", "="], | ||
["operator", ":="], | ||
["operator", "+"], ["operator", "+="], | ||
["operator", "-"], ["operator", "-="], | ||
["operator", "*"], ["operator", "*="], | ||
["operator", "/"], ["operator", "/="], | ||
["operator", "&"], ["operator", "&="], | ||
["operator", "~"], ["operator", "~="], | ||
["operator", "|"], ["operator", "|="], | ||
["operator", "Mod"], ["operator", "Mod="], | ||
["operator", "Shl"], ["operator", "Shl="], | ||
["operator", "Shr"], ["operator", "Shr="], | ||
["operator", "And"], ["operator", "Not"], ["operator", "Or"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,15 @@ | ||
#If HOST | ||
#ElseIf | ||
#Else | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["preprocessor", "#If HOST"], | ||
["preprocessor", "#ElseIf"], | ||
["preprocessor", "#Else"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for preprocessor directives. |
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,13 @@ | ||
"" | ||
"Foo ~qBar~q" | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["string", "\"\""], | ||
["string", "\"Foo ~qBar~q\""] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for strings. |
Oops, something went wrong.