diff --git a/components.js b/components.js index fff4655027..01cba3a46e 100644 --- a/components.js +++ b/components.js @@ -258,6 +258,10 @@ var components = { "title": "Mizar", "owner": "Golmote" }, + "monkey": { + "title": "Monkey", + "owner": "Golmote" + }, "nasm": { "title": "NASM", "owner": "rbmj" diff --git a/components/prism-monkey.js b/components/prism-monkey.js new file mode 100644 index 0000000000..f9cb36032f --- /dev/null +++ b/components/prism-monkey.js @@ -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': /[.,:;()\[\]]/ +}; \ No newline at end of file diff --git a/components/prism-monkey.min.js b/components/prism-monkey.min.js new file mode 100644 index 0000000000..79d0d54283 --- /dev/null +++ b/components/prism-monkey.min.js @@ -0,0 +1 @@ +Prism.languages.monkey={string:/"[^"\r\n]*"/,comment:[/^#Rem\s+[\s\S]*?^#End/im,/'.+/],preprocessor:{pattern:/(^[ \t]*)#.+/m,lookbehind:!0,alias:"comment"},"function":/\w+(?=\()/,"type-char":{pattern:/(\w)[?%#$]/,lookbehind:!0,alias:"variable"},number:{pattern:/((?:\.\.)?)(?:(?:\b|\B-\.?|\B\.)\d+((?!\.\.)\.\d*)?|\$[\da-f]+)/i,lookbehind:!0},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:/[.,:;()\[\]]/}; \ No newline at end of file diff --git a/examples/prism-monkey.html b/examples/prism-monkey.html new file mode 100644 index 0000000000..7a579f8b47 --- /dev/null +++ b/examples/prism-monkey.html @@ -0,0 +1,90 @@ +
To use this language, use the class "language-monkey".
+ +' This is a comment
+
+#Rem ' This is the start of a comment block
+Some comment ' We are inside the comment block
+#End
+
+"Hello World"
+"~qHello World~q"
+"~tIndented~n"
+
+0
+1234
+$3D0DEAD
+$CAFEBABE
+
+.0
+0.0
+.5
+0.5
+1.0
+1.5
+1.00001
+3.14159265
+
+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"
+
+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
+
+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. +
+ +' This "comment" is broken
+#Rem
+This "comment" is broken
+#End
\ No newline at end of file
diff --git a/tests/languages/monkey/comment_feature.test b/tests/languages/monkey/comment_feature.test
new file mode 100644
index 0000000000..da20a31827
--- /dev/null
+++ b/tests/languages/monkey/comment_feature.test
@@ -0,0 +1,15 @@
+' Foobar
+#Rem Foo
+Bar 'Baz
+#End
+
+----------------------------------------------------
+
+[
+ ["comment", "' Foobar"],
+ ["comment", "#Rem Foo\r\nBar 'Baz\r\n#End"]
+]
+
+----------------------------------------------------
+
+Checks for comments.
\ No newline at end of file
diff --git a/tests/languages/monkey/function_feature.test b/tests/languages/monkey/function_feature.test
new file mode 100644
index 0000000000..21debeb3be
--- /dev/null
+++ b/tests/languages/monkey/function_feature.test
@@ -0,0 +1,13 @@
+foobar()
+Foo_Bar_42()
+
+----------------------------------------------------
+
+[
+ ["function", "foobar"], ["punctuation", "("], ["punctuation", ")"],
+ ["function", "Foo_Bar_42"], ["punctuation", "("], ["punctuation", ")"]
+]
+
+----------------------------------------------------
+
+Checks for functions.
\ No newline at end of file
diff --git a/tests/languages/monkey/keyword_feature.test b/tests/languages/monkey/keyword_feature.test
new file mode 100644
index 0000000000..9e7d8b0a54
--- /dev/null
+++ b/tests/languages/monkey/keyword_feature.test
@@ -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.
\ No newline at end of file
diff --git a/tests/languages/monkey/number_feature.test b/tests/languages/monkey/number_feature.test
new file mode 100644
index 0000000000..5d943c1ecb
--- /dev/null
+++ b/tests/languages/monkey/number_feature.test
@@ -0,0 +1,19 @@
+0
+42
+3.14159
+.5
+$BadFace
+
+----------------------------------------------------
+
+[
+ ["number", "0"],
+ ["number", "42"],
+ ["number", "3.14159"],
+ ["number", ".5"],
+ ["number", "$BadFace"]
+]
+
+----------------------------------------------------
+
+Checks for numbers.
\ No newline at end of file
diff --git a/tests/languages/monkey/operator_feature.test b/tests/languages/monkey/operator_feature.test
new file mode 100644
index 0000000000..0a468b020b
--- /dev/null
+++ b/tests/languages/monkey/operator_feature.test
@@ -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.
\ No newline at end of file
diff --git a/tests/languages/monkey/preprocessor_feature.test b/tests/languages/monkey/preprocessor_feature.test
new file mode 100644
index 0000000000..dd9cc73d0b
--- /dev/null
+++ b/tests/languages/monkey/preprocessor_feature.test
@@ -0,0 +1,15 @@
+#If HOST
+#ElseIf
+#Else
+
+----------------------------------------------------
+
+[
+ ["preprocessor", "#If HOST"],
+ ["preprocessor", "#ElseIf"],
+ ["preprocessor", "#Else"]
+]
+
+----------------------------------------------------
+
+Checks for preprocessor directives.
\ No newline at end of file
diff --git a/tests/languages/monkey/string_feature.test b/tests/languages/monkey/string_feature.test
new file mode 100644
index 0000000000..21b2dc7d80
--- /dev/null
+++ b/tests/languages/monkey/string_feature.test
@@ -0,0 +1,13 @@
+""
+"Foo ~qBar~q"
+
+----------------------------------------------------
+
+[
+ ["string", "\"\""],
+ ["string", "\"Foo ~qBar~q\""]
+]
+
+----------------------------------------------------
+
+Checks for strings.
\ No newline at end of file
diff --git a/tests/languages/monkey/type-char_feature.test b/tests/languages/monkey/type-char_feature.test
new file mode 100644
index 0000000000..9590a7dded
--- /dev/null
+++ b/tests/languages/monkey/type-char_feature.test
@@ -0,0 +1,17 @@
+foo?
+bar%
+baz#
+foobar$
+
+----------------------------------------------------
+
+[
+ "foo", ["type-char", "?"],
+ "\r\nbar", ["type-char", "%"],
+ "\r\nbaz", ["type-char", "#"],
+ "\r\nfoobar", ["type-char", "$"]
+]
+
+----------------------------------------------------
+
+Checks for type chars.
\ No newline at end of file