Commit 84ed3edf52bb07dfa7efd5ef43e02d2ecd3d259b

Ales Tsurko 2018-01-02T10:58:10

add Io syntax (#1251) * add Io * Io: fix strings and operators, add tests * fix indent * add package-lock.json to gitignore * exclude gitignore and package.json changes * use tabs * io: apply requested changes * fix indent * fix indent * io: add example file

diff --git a/.gitignore b/.gitignore
old mode 100644
new mode 100755
diff --git a/components.js b/components.js
index 3c7ea79..024b625 100644
--- a/components.js
+++ b/components.js
@@ -281,6 +281,10 @@ var components = {
 			"title": "Ini",
 			"owner": "aviaryan"
 		},
+		"io": {
+			"title": "Io",
+			"owner": "AlesTsurko"
+		},
 		"j": {
 			"title": "J",
 			"owner": "Golmote"
diff --git a/components/prism-io.js b/components/prism-io.js
new file mode 100644
index 0000000..54a90a1
--- /dev/null
+++ b/components/prism-io.js
@@ -0,0 +1,31 @@
+Prism.languages.io = {
+	'comment': [
+		{
+			pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
+			lookbehind: true
+		},
+		{
+			pattern: /(^|[^\\])\/\/.*/,
+			lookbehind: true
+		},
+		{
+			pattern: /(^|[^\\])#.*/,
+			lookbehind: true
+		}
+	],
+	'triple-quoted-string': {
+		pattern: /"""(?:\\[\s\S]|(?!""")[^\\])*"""/,
+		greedy: true,
+		alias: 'string'
+	},
+	'string': {
+		pattern: /"(?:\\.|[^\\\r\n"])*"/,
+		greedy: true
+	},
+	'keyword': /\b(?:activate|activeCoroCount|asString|block|break|catch|clone|collectGarbage|compileString|continue|do|doFile|doMessage|doString|else|elseif|exit|for|foreach|forward|getSlot|getEnvironmentVariable|hasSlot|if|ifFalse|ifNil|ifNilEval|ifTrue|isActive|isNil|isResumable|list|message|method|parent|pass|pause|perform|performWithArgList|print|println|proto|raise|raiseResumable|removeSlot|resend|resume|schedulerSleepSeconds|self|sender|setSchedulerSleepSeconds|setSlot|shallowCopy|slotNames|super|system|then|thisBlock|thisContext|call|try|type|uniqueId|updateSlot|wait|while|write|yield)\b/,
+	'builtin':/\b(?:Array|AudioDevice|AudioMixer|Block|Box|Buffer|CFunction|CGI|Color|Curses|DBM|DNSResolver|DOConnection|DOProxy|DOServer|Date|Directory|Duration|DynLib|Error|Exception|FFT|File|Fnmatch|Font|Future|GL|GLE|GLScissor|GLU|GLUCylinder|GLUQuadric|GLUSphere|GLUT|Host|Image|Importer|LinkList|List|Lobby|Locals|MD5|MP3Decoder|MP3Encoder|Map|Message|Movie|Notification|Number|Object|OpenGL|Point|Protos|Regex|SGML|SGMLElement|SGMLParser|SQLite|Server|Sequence|ShowMessage|SleepyCat|SleepyCatCursor|Socket|SocketManager|Sound|Soup|Store|String|Tree|UDPSender|UPDReceiver|URL|User|Warning|WeakLink|Random|BigNum|Sequence)\b/,
+	'boolean': /\b(?:true|false|nil)\b/,
+	'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e-?\d+)?)\b/i,
+	'operator': /[=!*/%+-^&|]=|>>?=?|<<?=?|:?:?=|\+\+?|--?|\*\*?|\/\/?|%|\|\|?|&&?|(\b(?:return|and|or|not)\b)|@@?|\?\??|\.\./,
+	'punctuation': /[{}[\];(),.:]/
+};
diff --git a/components/prism-io.min.js b/components/prism-io.min.js
new file mode 100644
index 0000000..ef921f0
--- /dev/null
+++ b/components/prism-io.min.js
@@ -0,0 +1 @@
+Prism.languages.io={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0},{pattern:/(^|[^\\:])#.*/,lookbehind:!0}],"triple-quoted-string":{pattern:/"""(?:\\.|(?!""")[^\\])*"""/,greedy:!0,alias:"string"},string:{pattern:/"(?:\\.|(?!")[^\\\r\n])*"/,greedy:!0},keyword:/\b(?:activate|activeCoroCount|asString|block|break|catch|clone|collectGarbage|compileString|continue|do|doFile|doMessage|doString|else|elseif|exit|for|foreach|forward|getSlot|getEnvironmentVariable|hasSlot|if|ifFalse|ifNil|ifNilEval|ifTrue|isActive|isNil|isResumable|list|message|method|parent|pass|pause|perform|performWithArgList|print|println|proto|raise|raiseResumable|removeSlot|resend|resume|schedulerSleepSeconds|self|sender|setSchedulerSleepSeconds|setSlot|shallowCopy|slotNames|super|system|then|thisBlock|thisContext|call|try|type|uniqueId|updateSlot|wait|while|write|yield)\b/,builtin:/\b(?:Array|AudioDevice|AudioMixer|Block|Box|Buffer|CFunction|CGI|Color|Curses|DBM|DNSResolver|DOConnection|DOProxy|DOServer|Date|Directory|Duration|DynLib|Error|Exception|FFT|File|Fnmatch|Font|Future|GL|GLE|GLScissor|GLU|GLUCylinder|GLUQuadric|GLUSphere|GLUT|Host|Image|Importer|LinkList|List|Lobby|Locals|MD5|MP3Decoder|MP3Encoder|Map|Message|Movie|Notification|Number|Object|OpenGL|Point|Protos|Regex|SGML|SGMLElement|SGMLParser|SQLite|Server|Sequence|ShowMessage|SleepyCat|SleepyCatCursor|Socket|SocketManager|Sound|Soup|Store|String|Tree|UDPSender|UPDReceiver|URL|User|Warning|WeakLink|Random|BigNum|Sequence)\b/,"boolean":/\b(?:true|false|nil)\b/,number:/\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e-?\d+)?)\b/i,operator:/==|\!=|\*=|\/=|%=|\+=|-=|\^=|>>?=?|<<?=?|&=|\|=|:?:?=|\+\+?|--?|\*\*?|\/\/?|%|\|\|?|&&?|return|and|or|not|@@?|\?\??|\.\./,punctuation:/[{}[\];(),.:]/};
\ No newline at end of file
diff --git a/examples/prism-io.html b/examples/prism-io.html
new file mode 100644
index 0000000..7397639
--- /dev/null
+++ b/examples/prism-io.html
@@ -0,0 +1,34 @@
+<h1>Io</h1>
+<p>To use this language, use the class "language-io".</p>
+
+<h2>Comments</h2>
+<pre><code>//
+// Foobar
+#!/usr/bin/env io
+/* multiline
+comment
+*/</code></pre>
+
+<h2>Strings</h2>
+<pre><code>"this is a \"test\".\nThis is only a test."
+"""this is a "test".
+This is only a test."""</code></pre>
+
+<h2>Numbers</h2>
+<pre><code>123
+123.456
+0.456
+123e-4
+123e4
+123.456e-7
+123.456e2
+</code></pre>
+
+<h2>Full example</h2>
+<pre><code>"Hello, world!" println
+A := Object clone    // creates a new, empty object named "A"
+factorial := method(n,
+    if(n == 0, return 1)
+    res := 1
+    Range 1 to(n) foreach(i, res = res * i)
+)</code></pre>
diff --git a/package.json b/package.json
old mode 100644
new mode 100755
diff --git a/tests/languages/io/comment_feature.test b/tests/languages/io/comment_feature.test
new file mode 100644
index 0000000..fb67d07
--- /dev/null
+++ b/tests/languages/io/comment_feature.test
@@ -0,0 +1,19 @@
+//
+// Foobar
+#!/usr/bin/env io
+/* multiline
+comment
+*/
+
+----------------------------------------------------
+
+[
+	["comment", "//"],
+	["comment", "// Foobar"],
+	["comment", "#!/usr/bin/env io"],
+	["comment", "/* multiline\ncomment\n*/"]
+]
+
+----------------------------------------------------
+
+Checks for comments.
diff --git a/tests/languages/io/number_feature.test b/tests/languages/io/number_feature.test
new file mode 100644
index 0000000..371be06
--- /dev/null
+++ b/tests/languages/io/number_feature.test
@@ -0,0 +1,23 @@
+123
+123.456
+0.456
+123e-4
+123e4
+123.456e-7
+123.456e2
+
+------------------------------
+
+[
+    ["number", "123"],
+    ["number", "123.456"],
+    ["number", "0.456"],
+    ["number", "123e-4"],
+    ["number", "123e4"],
+    ["number", "123.456e-7"],
+    ["number", "123.456e2"]
+]
+
+------------------------------
+
+Check numbers.
diff --git a/tests/languages/io/operator_feature.test b/tests/languages/io/operator_feature.test
new file mode 100644
index 0000000..5378bc5
--- /dev/null
+++ b/tests/languages/io/operator_feature.test
@@ -0,0 +1,26 @@
+::= := = 
+== != >= <=
+&& and || or not
+..
++ - / * **
+%= &= *= += -= /= <<= >>= ^= |=
+? ?? @ @@
+return
+
+-------------------------------------------------------------------------------------------------------------------------
+
+[
+	["operator", "::="    ] , ["operator", ":="  ] , ["operator", "="   ] ,
+	["operator", "=="     ] , ["operator", "!="  ] , ["operator", ">="  ] , ["operator", "<=" ] ,
+	["operator", "&&"     ] , ["operator", "and" ] , ["operator", "||"  ] , ["operator", "or" ] , ["operator", "not" ] ,
+	["operator", ".."     ] ,
+	["operator", "+"      ] , ["operator", "-"   ] , ["operator", "/"   ] , ["operator", "*"  ] , ["operator", "**"  ] ,
+	["operator", "%="     ] , ["operator", "&="  ] , ["operator", "*="  ] , ["operator", "+=" ] , ["operator", "-="  ] ,
+	["operator", "/="     ] , ["operator", "<<=" ] , ["operator", ">>=" ] , ["operator", "^=" ] , ["operator", "|="  ] ,
+	["operator", "?"      ] , ["operator", "??"  ] , ["operator", "@"   ] , ["operator", "@@" ] ,
+	["operator", "return" ]
+]
+
+-------------------------------------------------------------------------------------------------------------------------
+
+Check operators.
diff --git a/tests/languages/io/string_feature.test b/tests/languages/io/string_feature.test
new file mode 100644
index 0000000..5b4f003
--- /dev/null
+++ b/tests/languages/io/string_feature.test
@@ -0,0 +1,18 @@
+""
+""""""
+"this is a \"test\".\nThis is only a test."
+"""this is a "test".
+This is only a test."""
+
+-------------------------------------------------------------------------
+
+[
+	["string", "\"\""],
+	["triple-quoted-string", "\"\"\"\"\"\""],
+	["string", "\"this is a \\\"test\\\".\\nThis is only a test.\""],
+	["triple-quoted-string", "\"\"\"this is a \"test\".\nThis is only a test.\"\"\""]
+]
+
+-------------------------------------------------------------------------
+
+Check strings.