Skip to content

Commit

Permalink
Merge pull request #771 from Golmote/prism-autoit
Browse files Browse the repository at this point in the history
Add support for AutoIt. Fix #453
  • Loading branch information
Golmote committed Sep 22, 2015
2 parents bd3e9ea + 3f38673 commit 211a41c
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 2 deletions.
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ var components = {
"require": "markup",
"owner": "nauzilus"
},
"autoit": {
"title": "AutoIt",
"owner": "Golmote"
},
"autohotkey": {
"title": "AutoHotkey",
"owner": "aviaryan"
Expand Down
33 changes: 33 additions & 0 deletions components/prism-autoit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Prism.languages.autoit = {
"comment": [
/;.*/,
{
// The multi-line comments delimiters can actually be commented out with ";"
pattern: /(^\s*)#(?:comments-start|cs)[\s\S]*?^\s*#(?:comments-end|ce)/m,
lookbehind: true
}
],
"url": {
pattern: /(^\s*#include\s+)(?:<[^\r\n>]+>|"[^\r\n"]+")/m,
lookbehind: true
},
"string": {
pattern: /(["'])(?:\1\1|(?!\1)[^\r\n])*\1/,
inside: {
"variable": /([%$@])\w+\1/
}
},
"directive": {
pattern: /(^\s*)#\w+/m,
lookbehind: true,
alias: 'keyword'
},
"function": /\b\w+(?=\()/,
// Variables and macros
"variable": /[$@]\w+/,
"keyword": /\b(?:Case|Const|Continue(?:Case|Loop)|Default|Dim|Do|Else(?:If)?|End(?:Func|If|Select|Switch|With)|Enum|Exit(?:Loop)?|For|Func|Global|If|In|Local|Next|Null|ReDim|Select|Static|Step|Switch|Then|To|Until|Volatile|WEnd|While|With)\b/i,
"number": /\b(?:0x[\da-f]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/i,
"boolean": /\b(?:True|False)\b/i,
"operator": /<[=>]?|[-+*\/=&>]=?|[?^]|\b(?:And|Or|Not)\b/i,
"punctuation": /[\[\]().,:]/
};
1 change: 1 addition & 0 deletions components/prism-autoit.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions examples/prism-autoit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<h1>AutoIt</h1>
<p>To use this language, use the class "language-autoit".</p>

<h2>Comments</h2>
<pre><code>; Single-line comment
#comments-start
Multi-line
comment
#comments-end
#cs
Multi-line
comment
#ce
;#comments-start
foo()
;#comments-end</code></pre>

<h2>Strings</h2>
<pre><code>"foo'bar'baz"
"foo""bar""baz"
'foo"bar"baz'
'foo''bar''baz'</code></pre>

<h2>Numbers</h2>
<pre><code>2
4.566
1.5e3
0x4fff</code></pre>

<h2>Booleans</h2>
<pre><code>True
False</code></pre>

<h2>Keywords and variables</h2>
<pre><code>; Display all the numbers for 1 to 10 but skip displaying 7.
For $i = 1 To 10
If $i = 7 Then
ContinueLoop ; Skip displaying the message box when $i is equal to 7.
EndIf
MsgBox($MB_SYSTEMMODAL, "", "The value of $i is: " & $i)
Next</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</h3>
<pre><code>"This string ; is broken"</code></pre>

<h3>Nested block comments</h3>
<pre><code>#cs
#cs
foo()
#ce
#ce</code></pre>
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (typeof self === 'undefined' || !self.Prism || !self.document) {
}

// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","http":"HTTP","inform7":"Inform 7","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
var Languages = /*languages_placeholder[*/{"css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","http":"HTTP","inform7":"Inform 7","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
Prism.hooks.add('before-highlight', function(env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/languages/autoit/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
True
False

----------------------------------------------------

[
["boolean", "True"],
["boolean", "False"]
]

----------------------------------------------------

Checks for booleans.
33 changes: 33 additions & 0 deletions tests/languages/autoit/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;
; foo
#comments-start
foobar()
#comments-end
#cs
foobar()
#ce
;#comments-start
foobar()
;#comments-end
;#cs
foobar()
;#ce

----------------------------------------------------

[
["comment", ";"],
["comment", "; foo"],
["comment", "#comments-start\r\n\tfoobar()\r\n#comments-end"],
["comment", "#cs\r\n\tfoobar()\r\n#ce"],
["comment", ";#comments-start"],
["function", "foobar"], ["punctuation", "("], ["punctuation", ")"],
["comment", ";#comments-end"],
["comment", ";#cs"],
["function", "foobar"], ["punctuation", "("], ["punctuation", ")"],
["comment", ";#ce"]
]

----------------------------------------------------

Checks for comments.
13 changes: 13 additions & 0 deletions tests/languages/autoit/directive_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#NoTrayIcon
#OnAutoItStartRegister "Example"

----------------------------------------------------

[
["directive", "#NoTrayIcon"],
["directive", "#OnAutoItStartRegister"], ["string", ["\"Example\""]]
]

----------------------------------------------------

Checks for directives.
15 changes: 15 additions & 0 deletions tests/languages/autoit/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
foo()
foo_bar()
foo_bar_42()

----------------------------------------------------

[
["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
["function", "foo_bar"], ["punctuation", "("], ["punctuation", ")"],
["function", "foo_bar_42"], ["punctuation", "("], ["punctuation", ")"]
]

----------------------------------------------------

Checks for functions.
83 changes: 83 additions & 0 deletions tests/languages/autoit/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Case
Const
ContinueCase
ContinueLoop
Default
Dim
Do
Else
ElseIf
EndFunc
EndIf
EndSelect
EndSwitch
EndWith
Enum
Exit
ExitLoop
For
Func
Global
If
In
Local
Next
Null
ReDim
Select
Static
Step
Switch
Then
To
Until
Volatile
WEnd
While
With

----------------------------------------------------

[
["keyword", "Case"],
["keyword", "Const"],
["keyword", "ContinueCase"],
["keyword", "ContinueLoop"],
["keyword", "Default"],
["keyword", "Dim"],
["keyword", "Do"],
["keyword", "Else"],
["keyword", "ElseIf"],
["keyword", "EndFunc"],
["keyword", "EndIf"],
["keyword", "EndSelect"],
["keyword", "EndSwitch"],
["keyword", "EndWith"],
["keyword", "Enum"],
["keyword", "Exit"],
["keyword", "ExitLoop"],
["keyword", "For"],
["keyword", "Func"],
["keyword", "Global"],
["keyword", "If"],
["keyword", "In"],
["keyword", "Local"],
["keyword", "Next"],
["keyword", "Null"],
["keyword", "ReDim"],
["keyword", "Select"],
["keyword", "Static"],
["keyword", "Step"],
["keyword", "Switch"],
["keyword", "Then"],
["keyword", "To"],
["keyword", "Until"],
["keyword", "Volatile"],
["keyword", "WEnd"],
["keyword", "While"],
["keyword", "With"]
]

----------------------------------------------------

Checks for keywords.
21 changes: 21 additions & 0 deletions tests/languages/autoit/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
42
3.14159
4e8
3.5E-9
0.7e+12
0xBadFace

----------------------------------------------------

[
["number", "42"],
["number", "3.14159"],
["number", "4e8"],
["number", "3.5E-9"],
["number", "0.7e+12"],
["number", "0xBadFace"]
]

----------------------------------------------------

Checks for numbers.
23 changes: 23 additions & 0 deletions tests/languages/autoit/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
< <= <>
> >=
+ += - -=
* *= / /=
& &=
? ^
And Or Not

----------------------------------------------------

[
["operator", "<"], ["operator", "<="], ["operator", "<>"],
["operator", ">"], ["operator", ">="],
["operator", "+"], ["operator", "+="], ["operator", "-"], ["operator", "-="],
["operator", "*"], ["operator", "*="], ["operator", "/"], ["operator", "/="],
["operator", "&"], ["operator", "&="],
["operator", "?"], ["operator", "^"],
["operator", "And"], ["operator", "Or"], ["operator", "Not"]
]

----------------------------------------------------

Checks for operators.
37 changes: 37 additions & 0 deletions tests/languages/autoit/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
""
"foo""bar"
"foo %foo% bar $bar$ baz @baz@"
''
'foo''bar'
'foo %foo% bar $bar$ baz @baz@'

----------------------------------------------------

[
["string", ["\"\""]],
["string", ["\"foo\"\"bar\""]],
["string", [
"\"foo ",
["variable", "%foo%"],
" bar ",
["variable", "$bar$"],
" baz ",
["variable", "@baz@"],
"\""
]],
["string", ["''"]],
["string", ["'foo''bar'"]],
["string", [
"'foo ",
["variable", "%foo%"],
" bar ",
["variable", "$bar$"],
" baz ",
["variable", "@baz@"],
"'"
]]
]

----------------------------------------------------

Checks for strings and interpolation.
15 changes: 15 additions & 0 deletions tests/languages/autoit/url_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <foo.au3>
#include "foo.au3"

----------------------------------------------------

[
["directive", "#include"],
["url", "<foo.au3>"],
["directive", "#include"],
["url", "\"foo.au3\""]
]

----------------------------------------------------

Checks for files in includes.
Loading

0 comments on commit 211a41c

Please sign in to comment.