Skip to content

Commit fdd4a3c

Browse files
committed
Merge pull request #621 from Golmote/prism-monkey
Add support for Monkey
2 parents d66235f + dd417d7 commit fdd4a3c

12 files changed

+378
-0
lines changed

components.js

+4
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ var components = {
258258
"title": "Mizar",
259259
"owner": "Golmote"
260260
},
261+
"monkey": {
262+
"title": "Monkey",
263+
"owner": "Golmote"
264+
},
261265
"nasm": {
262266
"title": "NASM",
263267
"owner": "rbmj"

components/prism-monkey.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Prism.languages.monkey = {
2+
'string': /"[^"\r\n]*"/,
3+
'comment': [
4+
/^#Rem\s+[\s\S]*?^#End/im,
5+
/'.+/,
6+
],
7+
'preprocessor': {
8+
pattern: /(^[ \t]*)#.+/m,
9+
lookbehind: true,
10+
alias: 'comment'
11+
},
12+
'function': /\w+(?=\()/,
13+
'type-char': {
14+
pattern: /(\w)[?%#$]/,
15+
lookbehind: true,
16+
alias: 'variable'
17+
},
18+
'number': {
19+
pattern: /((?:\.\.)?)(?:(?:\b|\B-\.?|\B\.)\d+((?!\.\.)\.\d*)?|\$[\da-f]+)/i,
20+
lookbehind: true
21+
},
22+
'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,
23+
'operator': /\.\.|<[=>]?|>=?|:?=|(?:[+\-*\/&~|]|\b(?:Mod|Shl|Shr)\b)=?|\b(?:And|Not|Or)\b/i,
24+
'punctuation': /[.,:;()\[\]]/
25+
};

components/prism-monkey.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-monkey.html

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<h1>Monkey</h1>
2+
<p>To use this language, use the class "language-monkey".</p>
3+
4+
<h2>Comments</h2>
5+
<pre><code>' This is a comment
6+
7+
#Rem ' This is the start of a comment block
8+
Some comment ' We are inside the comment block
9+
#End</code></pre>
10+
11+
<h2>Strings</h2>
12+
<pre><code>"Hello World"
13+
"~qHello World~q"
14+
"~tIndented~n"</code></pre>
15+
16+
<h2>Numbers</h2>
17+
<pre><code>0
18+
1234
19+
$3D0DEAD
20+
$CAFEBABE
21+
22+
.0
23+
0.0
24+
.5
25+
0.5
26+
1.0
27+
1.5
28+
1.00001
29+
3.14159265</code></pre>
30+
31+
<h2>Variable types</h2>
32+
<pre><code>Local myVariable:Bool = True
33+
Local myVariable? = True
34+
Local myVariable:Int = 1024
35+
Local myVariable% = 1024
36+
Local myVariable:Float = 3.141516
37+
Local myVariable# = 3.141516
38+
Local myVariable:String = "Hello world"
39+
Local myVariable$ = "Hello world"</code></pre>
40+
41+
<h2>Full example</h2>
42+
<pre><code>Import mojo
43+
44+
Class MyApp Extends App
45+
46+
Method OnCreate()
47+
48+
SetUpdateRate 60
49+
50+
End
51+
52+
Method OnRender()
53+
54+
Local date:=GetDate()
55+
56+
Local months:=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
57+
58+
Local day:=("0"+date[2])[-2..]
59+
Local month:=months[date[1]-1]
60+
Local year:=date[0]
61+
Local hour:=("0"+date[3])[-2..]
62+
Local min:=("0"+date[4])[-2..]
63+
Local sec:=("0"+date[5])[-2..] + "." + ("00"+date[6])[-3..]
64+
65+
Local now:=hour+":"+min+":"+sec+" "+day+" "+month+" "+year
66+
67+
Cls
68+
DrawText now,DeviceWidth/2,DeviceHeight/2,.5,.5
69+
End
70+
71+
End
72+
73+
Function Main()
74+
75+
New MyApp
76+
77+
End</code></pre>
78+
79+
<h2>Known failures</h2>
80+
<p>There are certain edge cases where Prism will fail.
81+
There are always such cases in every regex-based syntax highlighter.
82+
However, Prism dares to be open and honest about them.
83+
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.
84+
</p>
85+
86+
<h2>Two double quotes inside a comment</h2>
87+
<pre><code>' This "comment" is broken
88+
#Rem
89+
This "comment" is broken
90+
#End</code></pre>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
' Foobar
2+
#Rem Foo
3+
Bar 'Baz
4+
#End
5+
6+
----------------------------------------------------
7+
8+
[
9+
["comment", "' Foobar"],
10+
["comment", "#Rem Foo\r\nBar 'Baz\r\n#End"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for comments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
foobar()
2+
Foo_Bar_42()
3+
4+
----------------------------------------------------
5+
6+
[
7+
["function", "foobar"], ["punctuation", "("], ["punctuation", ")"],
8+
["function", "Foo_Bar_42"], ["punctuation", "("], ["punctuation", ")"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for functions.
+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
Void
2+
Strict
3+
Public
4+
Private
5+
Property
6+
Bool
7+
Int
8+
Float
9+
String
10+
Array
11+
Object
12+
Continue
13+
Exit
14+
Import
15+
Extern
16+
New
17+
Self
18+
Super
19+
Try
20+
Catch
21+
Eachin
22+
True
23+
False
24+
Extends
25+
Abstract
26+
Final
27+
Select
28+
Case
29+
Default
30+
Const
31+
Local
32+
Global
33+
Field
34+
Method
35+
Function
36+
Class
37+
End
38+
If
39+
Then
40+
Else
41+
ElseIf
42+
EndIf
43+
While
44+
Wend
45+
Repeat
46+
Until
47+
Forever
48+
For
49+
To
50+
Step
51+
Next
52+
Return
53+
Module
54+
Interface
55+
Implements
56+
Inline
57+
Throw
58+
Null
59+
60+
----------------------------------------------------
61+
62+
[
63+
["keyword", "Void"],
64+
["keyword", "Strict"],
65+
["keyword", "Public"],
66+
["keyword", "Private"],
67+
["keyword", "Property"],
68+
["keyword", "Bool"],
69+
["keyword", "Int"],
70+
["keyword", "Float"],
71+
["keyword", "String"],
72+
["keyword", "Array"],
73+
["keyword", "Object"],
74+
["keyword", "Continue"],
75+
["keyword", "Exit"],
76+
["keyword", "Import"],
77+
["keyword", "Extern"],
78+
["keyword", "New"],
79+
["keyword", "Self"],
80+
["keyword", "Super"],
81+
["keyword", "Try"],
82+
["keyword", "Catch"],
83+
["keyword", "Eachin"],
84+
["keyword", "True"],
85+
["keyword", "False"],
86+
["keyword", "Extends"],
87+
["keyword", "Abstract"],
88+
["keyword", "Final"],
89+
["keyword", "Select"],
90+
["keyword", "Case"],
91+
["keyword", "Default"],
92+
["keyword", "Const"],
93+
["keyword", "Local"],
94+
["keyword", "Global"],
95+
["keyword", "Field"],
96+
["keyword", "Method"],
97+
["keyword", "Function"],
98+
["keyword", "Class"],
99+
["keyword", "End"],
100+
["keyword", "If"],
101+
["keyword", "Then"],
102+
["keyword", "Else"],
103+
["keyword", "ElseIf"],
104+
["keyword", "EndIf"],
105+
["keyword", "While"],
106+
["keyword", "Wend"],
107+
["keyword", "Repeat"],
108+
["keyword", "Until"],
109+
["keyword", "Forever"],
110+
["keyword", "For"],
111+
["keyword", "To"],
112+
["keyword", "Step"],
113+
["keyword", "Next"],
114+
["keyword", "Return"],
115+
["keyword", "Module"],
116+
["keyword", "Interface"],
117+
["keyword", "Implements"],
118+
["keyword", "Inline"],
119+
["keyword", "Throw"],
120+
["keyword", "Null"]
121+
]
122+
123+
----------------------------------------------------
124+
125+
Checks for keywords.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
0
2+
42
3+
3.14159
4+
.5
5+
$BadFace
6+
7+
----------------------------------------------------
8+
9+
[
10+
["number", "0"],
11+
["number", "42"],
12+
["number", "3.14159"],
13+
["number", ".5"],
14+
["number", "$BadFace"]
15+
]
16+
17+
----------------------------------------------------
18+
19+
Checks for numbers.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
..
2+
< <> <=
3+
> >=
4+
=
5+
:=
6+
+ +=
7+
- -=
8+
* *=
9+
/ /=
10+
& &=
11+
~ ~=
12+
| |=
13+
Mod Mod=
14+
Shl Shl=
15+
Shr Shr=
16+
And Not Or
17+
18+
----------------------------------------------------
19+
20+
[
21+
["operator", ".."],
22+
["operator", "<"], ["operator", "<>"], ["operator", "<="],
23+
["operator", ">"], ["operator", ">="],
24+
["operator", "="],
25+
["operator", ":="],
26+
["operator", "+"], ["operator", "+="],
27+
["operator", "-"], ["operator", "-="],
28+
["operator", "*"], ["operator", "*="],
29+
["operator", "/"], ["operator", "/="],
30+
["operator", "&"], ["operator", "&="],
31+
["operator", "~"], ["operator", "~="],
32+
["operator", "|"], ["operator", "|="],
33+
["operator", "Mod"], ["operator", "Mod="],
34+
["operator", "Shl"], ["operator", "Shl="],
35+
["operator", "Shr"], ["operator", "Shr="],
36+
["operator", "And"], ["operator", "Not"], ["operator", "Or"]
37+
]
38+
39+
----------------------------------------------------
40+
41+
Checks for operators.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#If HOST
2+
#ElseIf
3+
#Else
4+
5+
----------------------------------------------------
6+
7+
[
8+
["preprocessor", "#If HOST"],
9+
["preprocessor", "#ElseIf"],
10+
["preprocessor", "#Else"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for preprocessor directives.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
""
2+
"Foo ~qBar~q"
3+
4+
----------------------------------------------------
5+
6+
[
7+
["string", "\"\""],
8+
["string", "\"Foo ~qBar~q\""]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for strings.

0 commit comments

Comments
 (0)