From 3275c884a88fef5b1716472d12f8d293362f240a Mon Sep 17 00:00:00 2001 From: Golmote Date: Fri, 3 Jul 2015 22:55:59 +0200 Subject: [PATCH 1/3] Add support for Monkey --- components.js | 4 ++ components/prism-monkey.js | 24 +++++++++ components/prism-monkey.min.js | 1 + examples/prism-monkey.html | 90 ++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 components/prism-monkey.js create mode 100644 components/prism-monkey.min.js create mode 100644 examples/prism-monkey.html diff --git a/components.js b/components.js index 919b3c13ae..fc07c5da05 100644 --- a/components.js +++ b/components.js @@ -219,6 +219,10 @@ var components = { "title": "MATLAB", "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..a1bc8a5fac --- /dev/null +++ b/components/prism-monkey.js @@ -0,0 +1,24 @@ +Prism.languages.monkey = { + 'string': /"[^"\r\n]*"/, + 'comment': [ + /^#Rem\s+[\s\S]*?^#End/im, + /'.+/, + ], + 'preprocessor': { + pattern: /^\s*#.+/, + 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..4a89577ef6 --- /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:/^\s*#.+/,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 @@ +

Monkey

+

To use this language, use the class "language-monkey".

+ +

Comments

+
' This is a comment
+
+#Rem            ' This is the start of a comment block
+Some comment    ' We are inside the comment block
+#End
+ +

Strings

+
"Hello World"
+"~qHello World~q"
+"~tIndented~n"
+ +

Numbers

+
0
+1234
+$3D0DEAD
+$CAFEBABE
+
+.0
+0.0
+.5
+0.5
+1.0
+1.5
+1.00001
+3.14159265
+ +

Variable types

+
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"
+ +

Full example

+
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
+ +

Known failures

+

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. +

+ +

Two double quotes inside a comment

+
' This "comment" is broken
+#Rem
+This "comment" is broken
+#End
\ No newline at end of file From 9379417c3f06c10c629c5433011a28702c7b8ca8 Mon Sep 17 00:00:00 2001 From: Golmote Date: Mon, 7 Sep 2015 21:51:51 +0200 Subject: [PATCH 2/3] Monkey: Fix preprocessor + optimized operators --- components/prism-monkey.js | 5 +++-- components/prism-monkey.min.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/components/prism-monkey.js b/components/prism-monkey.js index a1bc8a5fac..f9cb36032f 100644 --- a/components/prism-monkey.js +++ b/components/prism-monkey.js @@ -5,7 +5,8 @@ Prism.languages.monkey = { /'.+/, ], 'preprocessor': { - pattern: /^\s*#.+/, + pattern: /(^[ \t]*)#.+/m, + lookbehind: true, alias: 'comment' }, 'function': /\w+(?=\()/, @@ -19,6 +20,6 @@ Prism.languages.monkey = { 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, + '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 index 4a89577ef6..79d0d54283 100644 --- a/components/prism-monkey.min.js +++ b/components/prism-monkey.min.js @@ -1 +1 @@ -Prism.languages.monkey={string:/"[^"\r\n]*"/,comment:[/^#Rem\s+[\s\S]*?^#End/im,/'.+/],preprocessor:{pattern:/^\s*#.+/,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 +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 From dd417d7dab9dca98bc7e285af58ff9a977c6db58 Mon Sep 17 00:00:00 2001 From: Golmote Date: Mon, 7 Sep 2015 21:52:09 +0200 Subject: [PATCH 3/3] Add tests for Monkey --- tests/languages/monkey/comment_feature.test | 15 +++ tests/languages/monkey/function_feature.test | 13 ++ tests/languages/monkey/keyword_feature.test | 125 ++++++++++++++++++ tests/languages/monkey/number_feature.test | 19 +++ tests/languages/monkey/operator_feature.test | 41 ++++++ .../monkey/preprocessor_feature.test | 15 +++ tests/languages/monkey/string_feature.test | 13 ++ tests/languages/monkey/type-char_feature.test | 17 +++ 8 files changed, 258 insertions(+) create mode 100644 tests/languages/monkey/comment_feature.test create mode 100644 tests/languages/monkey/function_feature.test create mode 100644 tests/languages/monkey/keyword_feature.test create mode 100644 tests/languages/monkey/number_feature.test create mode 100644 tests/languages/monkey/operator_feature.test create mode 100644 tests/languages/monkey/preprocessor_feature.test create mode 100644 tests/languages/monkey/string_feature.test create mode 100644 tests/languages/monkey/type-char_feature.test 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