Commit 2d08fa9013b8401bd910d327ffbc82b735508c97

Golmote 2015-10-10T21:32:45

Add support for Icon

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
diff --git a/components.js b/components.js
index c33e015..d28585a 100644
--- a/components.js
+++ b/components.js
@@ -223,6 +223,10 @@ var components = {
 			"title": "HTTP",
 			"owner": "danielgtaylor"
 		},
+		"icon": {
+			"title": "Icon",
+			"owner": "Golmote"
+		},
 		"inform7": {
 			"title": "Inform 7",
 			"owner": "Golmote"
diff --git a/components/prism-icon.js b/components/prism-icon.js
new file mode 100644
index 0000000..96e5ac4
--- /dev/null
+++ b/components/prism-icon.js
@@ -0,0 +1,17 @@
+Prism.languages.icon = {
+	'comment': /#.*/,
+	'string': /(["'])(?:(?!\1)[^\\\r\n]|\\.|_(?:\r?\n|\r))*\1/,
+	'number': /\b(?:\d+r[a-z\d]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b|\.\d+\b/i,
+	'builtin-keyword': {
+		pattern: /&(?:allocated|ascii|clock|collections|cset|current|date|dateline|digits|dump|e|error(?:number|text|value)?|errout|fail|features|file|host|input|lcase|letters|level|line|main|null|output|phi|pi|pos|progname|random|regions|source|storage|subject|time|trace|ucase|version)\b/,
+		alias: 'variable'
+	},
+	'directive': {
+		pattern: /\$\w+/,
+		alias: 'builtin'
+	},
+	'keyword': /\b(?:break|by|case|create|default|do|else|end|every|fail|global|if|initial|invocable|link|local|next|not|of|procedure|record|repeat|return|static|suspend|then|to|until|while)\b/,
+	'function': /(?!\d)\w+(?=\s*[({]|\s*!\s*\[)/,
+	'operator': /[+-]:(?!=)|(?:[\/?@^%&]|\+\+?|--?|==?=?|~==?=?|\*\*?|\|\|\|?|<(?:->?|<?=?)|>>?=?)(?::=)?|:(?:=:?)?|[!.\\|~]/,
+	'punctuation': /[\[\](){},;]/
+};
\ No newline at end of file
diff --git a/components/prism-icon.min.js b/components/prism-icon.min.js
new file mode 100644
index 0000000..4c55b55
--- /dev/null
+++ b/components/prism-icon.min.js
@@ -0,0 +1 @@
+Prism.languages.icon={comment:/#.*/,string:/(["'])(?:(?!\1)[^\\\r\n]|\\.|_(?:\r?\n|\r))*\1/,number:/\b(?:\d+r[a-z\d]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b|\.\d+\b/i,"builtin-keyword":{pattern:/&(?:allocated|ascii|clock|collections|cset|current|date|dateline|digits|dump|e|error(?:number|text|value)?|errout|fail|features|file|host|input|lcase|letters|level|line|main|null|output|phi|pi|pos|progname|random|regions|source|storage|subject|time|trace|ucase|version)\b/,alias:"variable"},directive:{pattern:/\$\w+/,alias:"builtin"},keyword:/\b(?:break|by|case|create|default|do|else|end|every|fail|global|if|initial|invocable|link|local|next|not|of|procedure|record|repeat|return|static|suspend|then|to|until|while)\b/,"function":/(?!\d)\w+(?=\s*[({]|\s*!\s*\[)/,operator:/[+-]:(?!=)|(?:[\/?@^%&]|\+\+?|--?|==?=?|~==?=?|\*\*?|\|\|\|?|<(?:->?|<?=?)|>>?=?)(?::=)?|:(?:=:?)?|[!.\\|~]/,punctuation:/[\[\](){},;]/};
\ No newline at end of file
diff --git a/examples/prism-icon.html b/examples/prism-icon.html
new file mode 100644
index 0000000..8fb01af
--- /dev/null
+++ b/examples/prism-icon.html
@@ -0,0 +1,186 @@
+<h1>Icon</h1>
+<p>To use this language, use the class "language-icon".</p>
+
+<h2>Comments</h2>
+<pre><code>#
+# Foobar</code></pre>
+
+<h2>Strings and csets</h2>
+<pre><code>""
+"Foo\"bar"
+''
+'a\'bcdefg'</code></pre>
+
+<h2>Numbers</h2>
+<pre><code>42
+3.14159
+5.2E+8
+16rface
+2r1101</code></pre>
+
+<h2>Full example</h2>
+<pre><code># Author: Robert J. Alexander
+global GameObject, Tree, Learn
+record Question(question, yes, no)
+procedure main()
+   GameObject := "animal"
+   Tree := Question("Does it live in water", "goldfish", "canary")
+   Get()                                  # Recall prior knowledge
+   Game()                                 # Play a game
+   return
+end
+#  Game() -- Conducts a game.
+#
+procedure Game()
+   while Confirm("Are you thinking of ", Article(GameObject), " ",
+      GameObject) do Ask(Tree)
+   write("Thanks for a great game.")
+   if \Learn &Confirm("Want to save knowledge learned this session")
+   then Save()
+   return
+end
+#  Confirm() -- Handles yes/no questions and answers.
+#
+procedure Confirm(q[])
+   local answer, s
+   static ok
+   initial {
+      ok := table()
+      every ok["y" | "yes" | "yeah" | "uh huh"] := "yes"
+      every ok["n" | "no"  | "nope" | "uh uh" ] := "no"
+      }
+   while /answer do {
+      every writes(!q)
+      write("?")
+      case s := read() | exit(1) of {
+         #  Commands recognized at a yes/no prompt.
+         #
+         "save":    Save()
+         "get":     Get()
+         "list":    List()
+         "dump":    Output(Tree)
+         default:   {
+            (answer := \ok[map(s, &ucase, &lcase)]) |
+               write("This is a \"yes\" or \"no\" question.")
+            }
+         }
+      }
+   return answer == "yes"
+end
+#  Ask() -- Navigates through the barrage of questions leading to a
+#  guess.
+#
+procedure Ask(node)
+   local guess, question
+   case type(node) of {
+      "string":        {
+         if not Confirm("It must be ", Article(node), " ", node, ", right") then {
+            Learn := "yes"
+            write("What were you thinking of?")
+            guess := read() | exit(1)
+            write("What question would distinguish ", Article(guess), " ",
+               guess, " from ", Article(node), " ", node, "?")
+            question := read() | exit(1)
+            if question[-1] == "?" then question[-1] := ""
+            question[1] := map(question[1], &lcase, &ucase)
+            if Confirm("For ", Article(guess), " ", guess, ", what would the answer be")
+            then return Question(question, guess, node)
+         else return Question(question, node, guess)
+         }
+      }
+      "Question":  {
+         if Confirm(node.question) then node.yes := Ask(node.yes)
+         else node.no := Ask(node.no)
+         }
+      }
+end
+#  Article() -- Come up with the appropriate indefinite article.
+#
+procedure Article(word)
+   return if any('aeiouAEIOU', word) then "an" else "a"
+end
+#  Save() -- Store our acquired knowledge in a disk file name
+#  based on the GameObject.
+#
+procedure Save()
+   local f
+   f := open(GameObject || "s", "w")
+   Output(Tree, f)
+   close(f)
+   return
+end
+#  Output() -- Recursive procedure used to output the knowledge tree.
+#
+procedure Output(node, f, sense)
+   static indent
+   initial indent := 0
+   /f := &output
+   /sense := " "
+   case type(node) of {
+      "string":        write(f, repl(" ", indent), sense, "A: ", node)
+      "Question":  {
+         write(f, repl(" ", indent), sense, "Q: ", node.question)
+         indent +:= 1
+         Output(node.yes, f, "y")
+         Output(node.no, f, "n")
+         indent -:= 1
+         }
+      }
+   return
+end
+#  Get() -- Read in a knowledge base from a file.
+#
+procedure Get()
+   local f
+   f := open(GameObject || "s", "r") | fail
+   Tree := Input(f)
+   close(f)
+   return
+end
+#  Input() -- Recursive procedure used to input the knowledge tree.
+#
+procedure Input(f)
+   local nodetype, s
+   read(f) ? (tab(upto(~' \t')) & =("y" | "n" | "") &
+      nodetype := move(1) & move(2) & s := tab(0))
+   return if nodetype == "Q" then Question(s, Input(f), Input(f)) else s
+end
+#  List() -- Lists the objects in the knowledge base.
+#
+$define Length           78
+procedure List()
+   local lst, line, item
+   lst := Show(Tree, [ ])
+   line := ""
+   every item := !sort(lst) do {
+      if *line + *item > Length then {
+         write(trim(line))
+         line := ""
+         }
+      line ||:= item || ", "
+      }
+   write(line[1:-2])
+   return
+end
+#
+#  Show() -- Recursive procedure used to navigate the knowledge tree.
+#
+procedure Show(node, lst)
+   if type(node) == "Question" then {
+      lst := Show(node.yes, lst)
+      lst := Show(node.no, lst)
+      }
+   else put(lst, node)
+   return lst
+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>
+
+<h3>Comment-like substrings and csets containing a hash</h3>
+<pre><code>"foo # bar";
+'abc#def'</code></pre>
diff --git a/tests/languages/icon/builtin-keyword_feature.test b/tests/languages/icon/builtin-keyword_feature.test
new file mode 100644
index 0000000..1d25764
--- /dev/null
+++ b/tests/languages/icon/builtin-keyword_feature.test
@@ -0,0 +1,91 @@
+&allocated
+&ascii
+&clock
+&collections
+&cset
+&current
+&date
+&dateline
+&digits
+&dump
+&e
+&error
+&errornumber
+&errortext
+&errorvalue
+&errout
+&fail
+&features
+&file
+&host
+&input
+&lcase
+&letters
+&level
+&line
+&main
+&null
+&output
+&phi
+&pi
+&pos
+&progname
+&random
+&regions
+&source
+&storage
+&subject
+&time
+&trace
+&ucase
+&version
+
+----------------------------------------------------
+
+[
+	["builtin-keyword", "&allocated"],
+	["builtin-keyword", "&ascii"],
+	["builtin-keyword", "&clock"],
+	["builtin-keyword", "&collections"],
+	["builtin-keyword", "&cset"],
+	["builtin-keyword", "&current"],
+	["builtin-keyword", "&date"],
+	["builtin-keyword", "&dateline"],
+	["builtin-keyword", "&digits"],
+	["builtin-keyword", "&dump"],
+	["builtin-keyword", "&e"],
+	["builtin-keyword", "&error"],
+	["builtin-keyword", "&errornumber"],
+	["builtin-keyword", "&errortext"],
+	["builtin-keyword", "&errorvalue"],
+	["builtin-keyword", "&errout"],
+	["builtin-keyword", "&fail"],
+	["builtin-keyword", "&features"],
+	["builtin-keyword", "&file"],
+	["builtin-keyword", "&host"],
+	["builtin-keyword", "&input"],
+	["builtin-keyword", "&lcase"],
+	["builtin-keyword", "&letters"],
+	["builtin-keyword", "&level"],
+	["builtin-keyword", "&line"],
+	["builtin-keyword", "&main"],
+	["builtin-keyword", "&null"],
+	["builtin-keyword", "&output"],
+	["builtin-keyword", "&phi"],
+	["builtin-keyword", "&pi"],
+	["builtin-keyword", "&pos"],
+	["builtin-keyword", "&progname"],
+	["builtin-keyword", "&random"],
+	["builtin-keyword", "&regions"],
+	["builtin-keyword", "&source"],
+	["builtin-keyword", "&storage"],
+	["builtin-keyword", "&subject"],
+	["builtin-keyword", "&time"],
+	["builtin-keyword", "&trace"],
+	["builtin-keyword", "&ucase"],
+	["builtin-keyword", "&version"]
+]
+
+----------------------------------------------------
+
+Checks for builtin keywords.
\ No newline at end of file
diff --git a/tests/languages/icon/comment_feature.test b/tests/languages/icon/comment_feature.test
new file mode 100644
index 0000000..09493ab
--- /dev/null
+++ b/tests/languages/icon/comment_feature.test
@@ -0,0 +1,13 @@
+#
+# Foobar
+
+----------------------------------------------------
+
+[
+	["comment", "#"],
+	["comment", "# Foobar"]
+]
+
+----------------------------------------------------
+
+Checks for comments.
\ No newline at end of file
diff --git a/tests/languages/icon/directive_feature.test b/tests/languages/icon/directive_feature.test
new file mode 100644
index 0000000..ede5ebc
--- /dev/null
+++ b/tests/languages/icon/directive_feature.test
@@ -0,0 +1,21 @@
+$include
+$line
+$define
+$undef
+$ifdef
+$ifndef
+
+----------------------------------------------------
+
+[
+	["directive", "$include"],
+	["directive", "$line"],
+	["directive", "$define"],
+	["directive", "$undef"],
+	["directive", "$ifdef"],
+	["directive", "$ifndef"]
+]
+
+----------------------------------------------------
+
+Checks for preprocessor directives.
\ No newline at end of file
diff --git a/tests/languages/icon/function_feature.test b/tests/languages/icon/function_feature.test
new file mode 100644
index 0000000..715452f
--- /dev/null
+++ b/tests/languages/icon/function_feature.test
@@ -0,0 +1,15 @@
+foo()
+Foobar_42{}
+Foo_Bar ! []
+
+----------------------------------------------------
+
+[
+	["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
+	["function", "Foobar_42"], ["punctuation", "{"], ["punctuation", "}"],
+	["function", "Foo_Bar"], ["operator", "!"], ["punctuation", "["], ["punctuation", "]"]
+]
+
+----------------------------------------------------
+
+Checks for functions.
\ No newline at end of file
diff --git a/tests/languages/icon/keyword_feature.test b/tests/languages/icon/keyword_feature.test
new file mode 100644
index 0000000..0816911
--- /dev/null
+++ b/tests/languages/icon/keyword_feature.test
@@ -0,0 +1,67 @@
+break
+by
+case
+create
+default
+do
+else
+end
+every
+fail
+global
+if
+initial
+invocable
+link
+local
+next
+not
+of
+procedure
+record
+repeat
+return
+static
+suspend
+then
+to
+until
+while
+
+----------------------------------------------------
+
+[
+	["keyword", "break"],
+	["keyword", "by"],
+	["keyword", "case"],
+	["keyword", "create"],
+	["keyword", "default"],
+	["keyword", "do"],
+	["keyword", "else"],
+	["keyword", "end"],
+	["keyword", "every"],
+	["keyword", "fail"],
+	["keyword", "global"],
+	["keyword", "if"],
+	["keyword", "initial"],
+	["keyword", "invocable"],
+	["keyword", "link"],
+	["keyword", "local"],
+	["keyword", "next"],
+	["keyword", "not"],
+	["keyword", "of"],
+	["keyword", "procedure"],
+	["keyword", "record"],
+	["keyword", "repeat"],
+	["keyword", "return"],
+	["keyword", "static"],
+	["keyword", "suspend"],
+	["keyword", "then"],
+	["keyword", "to"],
+	["keyword", "until"],
+	["keyword", "while"]
+]
+
+----------------------------------------------------
+
+Checks for keywords.
\ No newline at end of file
diff --git a/tests/languages/icon/number_feature.test b/tests/languages/icon/number_feature.test
new file mode 100644
index 0000000..fc8efc8
--- /dev/null
+++ b/tests/languages/icon/number_feature.test
@@ -0,0 +1,33 @@
+0
+.42
+42
+3.14159
+2e8
+3.2E-7
+47E+19
+
+2r11
+8R751
+16rbadface
+36razerty
+
+----------------------------------------------------
+
+[
+	["number", "0"],
+	["number", ".42"],
+	["number", "42"],
+	["number", "3.14159"],
+	["number", "2e8"],
+	["number", "3.2E-7"],
+	["number", "47E+19"],
+
+	["number", "2r11"],
+	["number", "8R751"],
+	["number", "16rbadface"],
+	["number", "36razerty"]
+]
+
+----------------------------------------------------
+
+Checks for numbers.
\ No newline at end of file
diff --git a/tests/languages/icon/operator_feature.test b/tests/languages/icon/operator_feature.test
new file mode 100644
index 0000000..a2e29ff
--- /dev/null
+++ b/tests/languages/icon/operator_feature.test
@@ -0,0 +1,69 @@
+!
+% %:=
+& &:=
+* *:= ** **:=
++ ++ +:= ++:=
+- -:= -- --:=
+.
+/ /:=
+:= :=:
+< <- <-> <:=
+<< <<:=
+<<= <<=:=
+<= <=:=
+= =:=
+== ==:=
+=== ===:=
+> >:=
+>= >=:=
+>> >>:=
+>>= >>=:=
+? ?:=
+@ @:=
+\
+^ ^:=
+| || ||:=
+||| |||:=
+~ ~= ~=:=
+~== ~==:=
+~=== ~===:=
+: +: -:
+
+----------------------------------------------------
+
+[
+	["operator", "!"],
+	["operator", "%"], ["operator", "%:="],
+	["operator", "&"], ["operator", "&:="],
+	["operator", "*"], ["operator", "*:="], ["operator", "**"], ["operator", "**:="],
+	["operator", "+"], ["operator", "++"], ["operator", "+:="], ["operator", "++:="],
+	["operator", "-"], ["operator", "-:="], ["operator", "--"], ["operator", "--:="],
+	["operator", "."],
+	["operator", "/"], ["operator", "/:="],
+	["operator", ":="], ["operator", ":=:"],
+	["operator", "<"], ["operator", "<-"], ["operator", "<->"], ["operator", "<:="],
+	["operator", "<<"], ["operator", "<<:="],
+	["operator", "<<="], ["operator", "<<=:="],
+	["operator", "<="], ["operator", "<=:="],
+	["operator", "="], ["operator", "=:="],
+	["operator", "=="], ["operator", "==:="],
+	["operator", "==="], ["operator", "===:="],
+	["operator", ">"], ["operator", ">:="],
+	["operator", ">="], ["operator", ">=:="],
+	["operator", ">>"], ["operator", ">>:="],
+	["operator", ">>="], ["operator", ">>=:="],
+	["operator", "?"], ["operator", "?:="],
+	["operator", "@"], ["operator", "@:="],
+	["operator", "\\"],
+	["operator", "^"], ["operator", "^:="],
+	["operator", "|"], ["operator", "||"], ["operator", "||:="],
+	["operator", "|||"], ["operator", "|||:="],
+	["operator", "~"], ["operator", "~="], ["operator", "~=:="],
+	["operator", "~=="], ["operator", "~==:="],
+	["operator", "~==="], ["operator", "~===:="],
+	["operator", ":"], ["operator", "+:"], ["operator", "-:"]
+]
+
+----------------------------------------------------
+
+Checks for operators.
\ No newline at end of file
diff --git a/tests/languages/icon/string_feature.test b/tests/languages/icon/string_feature.test
new file mode 100644
index 0000000..78bc034
--- /dev/null
+++ b/tests/languages/icon/string_feature.test
@@ -0,0 +1,22 @@
+""
+"Fo\"obar"
+"Foo_
+bar_
+baz"
+
+''
+'a\'zerty'
+
+----------------------------------------------------
+
+[
+	["string", "\"\""],
+	["string", "\"Fo\\\"obar\""],
+	["string", "\"Foo_\r\nbar_\r\nbaz\""],
+	["string", "''"],
+	["string", "'a\\'zerty'"]
+]
+
+----------------------------------------------------
+
+Checks for strings and csets.
\ No newline at end of file