From 11ff829f74fc9004757d853f4eb05cffd2fd0bf0 Mon Sep 17 00:00:00 2001 From: Golmote Date: Sat, 5 Sep 2015 11:35:00 +0200 Subject: [PATCH] Tcl: Add operators and punctuation + add examples --- components/prism-tcl.js | 4 +- components/prism-tcl.min.js | 2 +- examples/prism-tcl.html | 39 ++++++++++++++++++++ tests/languages/tcl/operator_feature.test | 45 +++++++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 examples/prism-tcl.html create mode 100644 tests/languages/tcl/operator_feature.test diff --git a/components/prism-tcl.js b/components/prism-tcl.js index 48b53dc1fa..b9e2206d6c 100644 --- a/components/prism-tcl.js +++ b/components/prism-tcl.js @@ -37,5 +37,7 @@ Prism.languages.tcl = { 'keyword': { pattern: /(^\s*|\[)(after|append|apply|array|auto_(?:execok|import|load|mkindex|qualify|reset)|automkindex_old|bgerror|binary|catch|cd|chan|clock|close|concat|dde|dict|encoding|eof|exec|expr|fblocked|fconfigure|fcopy|file(?:event|name)?|flush|gets|glob|history|http|incr|info|interp|join|lappend|lassign|lindex|linsert|list|llength|load|lrange|lrepeat|lreplace|lreverse|lsearch|lset|lsort|math(?:func|op)|memory|msgcat|namespace|open|package|parray|pid|pkg_mkIndex|platform|puts|pwd|re_syntax|read|refchan|regexp|registry|regsub|rename|Safe_Base|scan|seek|set|socket|source|split|string|subst|Tcl|tcl(?:_endOfWord|_findLibrary|startOf(?:Next|Previous)Word|wordBreak(?:After|Before)|test|vars)|tell|time|tm|trace|unknown|unload|unset|update|uplevel|vwait)\b/m, lookbehind: true - } + }, + 'operator': /!=?|\*\*?|==|&&?|\|\|?|<[=<]?|>[=>]?|[-+~\/%?^]|\b(?:eq|ne|in|ni)\b/, + 'punctuation': /[{}()\[\]]/ }; diff --git a/components/prism-tcl.min.js b/components/prism-tcl.min.js index 0b786e4826..84a6cfe7d1 100644 --- a/components/prism-tcl.min.js +++ b/components/prism-tcl.min.js @@ -1 +1 @@ -Prism.languages.tcl={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0},string:/"(?:[^"\\\r\n]|\\(?:\r\n|[\s\S]))*"/,variable:[{pattern:/(\$)(?:::)?(?:[a-zA-Z0-9]+::)*[a-zA-Z0-9_]+/,lookbehind:!0},{pattern:/(\$){[^}]+}/,lookbehind:!0},{pattern:/(^\s*set[ \t]+)(?:::)?(?:[a-zA-Z0-9]+::)*[a-zA-Z0-9_]+/m,lookbehind:!0}],"function":{pattern:/(^\s*proc[ \t]+)[^\s]+/m,lookbehind:!0},builtin:[{pattern:/(^\s*)(?:proc|return|class|error|eval|exit|for|foreach|if|switch|while|break|continue)\b/m,lookbehind:!0},/\b(elseif|else)\b/],scope:{pattern:/(^\s*)(global|upvar|variable)\b/m,lookbehind:!0,alias:"constant"},keyword:{pattern:/(^\s*|\[)(after|append|apply|array|auto_(?:execok|import|load|mkindex|qualify|reset)|automkindex_old|bgerror|binary|catch|cd|chan|clock|close|concat|dde|dict|encoding|eof|exec|expr|fblocked|fconfigure|fcopy|file(?:event|name)?|flush|gets|glob|history|http|incr|info|interp|join|lappend|lassign|lindex|linsert|list|llength|load|lrange|lrepeat|lreplace|lreverse|lsearch|lset|lsort|math(?:func|op)|memory|msgcat|namespace|open|package|parray|pid|pkg_mkIndex|platform|puts|pwd|re_syntax|read|refchan|regexp|registry|regsub|rename|Safe_Base|scan|seek|set|socket|source|split|string|subst|Tcl|tcl(?:_endOfWord|_findLibrary|startOf(?:Next|Previous)Word|wordBreak(?:After|Before)|test|vars)|tell|time|tm|trace|unknown|unload|unset|update|uplevel|vwait)\b/m,lookbehind:!0}}; \ No newline at end of file +Prism.languages.tcl={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0},string:/"(?:[^"\\\r\n]|\\(?:\r\n|[\s\S]))*"/,variable:[{pattern:/(\$)(?:::)?(?:[a-zA-Z0-9]+::)*[a-zA-Z0-9_]+/,lookbehind:!0},{pattern:/(\$){[^}]+}/,lookbehind:!0},{pattern:/(^\s*set[ \t]+)(?:::)?(?:[a-zA-Z0-9]+::)*[a-zA-Z0-9_]+/m,lookbehind:!0}],"function":{pattern:/(^\s*proc[ \t]+)[^\s]+/m,lookbehind:!0},builtin:[{pattern:/(^\s*)(?:proc|return|class|error|eval|exit|for|foreach|if|switch|while|break|continue)\b/m,lookbehind:!0},/\b(elseif|else)\b/],scope:{pattern:/(^\s*)(global|upvar|variable)\b/m,lookbehind:!0,alias:"constant"},keyword:{pattern:/(^\s*|\[)(after|append|apply|array|auto_(?:execok|import|load|mkindex|qualify|reset)|automkindex_old|bgerror|binary|catch|cd|chan|clock|close|concat|dde|dict|encoding|eof|exec|expr|fblocked|fconfigure|fcopy|file(?:event|name)?|flush|gets|glob|history|http|incr|info|interp|join|lappend|lassign|lindex|linsert|list|llength|load|lrange|lrepeat|lreplace|lreverse|lsearch|lset|lsort|math(?:func|op)|memory|msgcat|namespace|open|package|parray|pid|pkg_mkIndex|platform|puts|pwd|re_syntax|read|refchan|regexp|registry|regsub|rename|Safe_Base|scan|seek|set|socket|source|split|string|subst|Tcl|tcl(?:_endOfWord|_findLibrary|startOf(?:Next|Previous)Word|wordBreak(?:After|Before)|test|vars)|tell|time|tm|trace|unknown|unload|unset|update|uplevel|vwait)\b/m,lookbehind:!0},operator:/!=?|\*\*?|==|&&?|\|\|?|<[=<]?|>[=>]?|[-+~\/%?^]|\b(?:eq|ne|in|ni)\b/,punctuation:/[{}()\[\]]/}; \ No newline at end of file diff --git a/examples/prism-tcl.html b/examples/prism-tcl.html new file mode 100644 index 0000000000..9489724d46 --- /dev/null +++ b/examples/prism-tcl.html @@ -0,0 +1,39 @@ +

Tcl

+

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

+ +

Comments

+
# This is a comment
+ +

Strings

+
"foo \"bar\" baz"
+"foo\
+bar\
+baz"
+ +

Variables

+
$foo
+$foo::bar_42
+$::baz
+${foobar}
+set foo::bar "baz"
+ +

Functions

+
proc foobar {baz} {
+	puts $baz
+}
+
+proc RESTORE/post/:post_id/comment/:comment_id {post_id comment_id} {
+    #| Restore a comment handler
+    comment_restore $comment_id
+    qc::actions redirect [url "/post/$post_id" show_deleted_comment_ids $comment_id]
+}
+ +

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

+ +

Comment-like substrings

+
"This string is #broken"
\ No newline at end of file diff --git a/tests/languages/tcl/operator_feature.test b/tests/languages/tcl/operator_feature.test new file mode 100644 index 0000000000..84426a0a84 --- /dev/null +++ b/tests/languages/tcl/operator_feature.test @@ -0,0 +1,45 @@ ++ +- +~ +! != +* ** +/ +% +< <= << +> >= >> +== +& && +| || +? +^ +eq +ne +in +ni + +---------------------------------------------------- + +[ + ["operator", "+"], + ["operator", "-"], + ["operator", "~"], + ["operator", "!"], ["operator", "!="], + ["operator", "*"], ["operator", "**"], + ["operator", "/"], + ["operator", "%"], + ["operator", "<"], ["operator", "<="], ["operator", "<<"], + ["operator", ">"], ["operator", ">="], ["operator", ">>"], + ["operator", "=="], + ["operator", "&"], ["operator", "&&"], + ["operator", "|"], ["operator", "||"], + ["operator", "?"], + ["operator", "^"], + ["operator", "eq"], + ["operator", "ne"], + ["operator", "in"], + ["operator", "ni"] +] + +---------------------------------------------------- + +Checks for all operators. \ No newline at end of file