UNPKG

2.19 kBJavaScriptView Raw
1/*
2Language: AutoHotkey
3Author: Seongwon Lee <dlimpid@gmail.com>
4Description: AutoHotkey language definition
5Category: scripting
6*/
7
8/** @type LanguageFn */
9function autohotkey(hljs) {
10 const BACKTICK_ESCAPE = { begin: '`[\\s\\S]' };
11
12 return {
13 name: 'AutoHotkey',
14 case_insensitive: true,
15 aliases: [ 'ahk' ],
16 keywords: {
17 keyword: 'Break Continue Critical Exit ExitApp Gosub Goto New OnExit Pause return SetBatchLines SetTimer Suspend Thread Throw Until ahk_id ahk_class ahk_pid ahk_exe ahk_group',
18 literal: 'true false NOT AND OR',
19 built_in: 'ComSpec Clipboard ClipboardAll ErrorLevel'
20 },
21 contains: [
22 BACKTICK_ESCAPE,
23 hljs.inherit(hljs.QUOTE_STRING_MODE, { contains: [ BACKTICK_ESCAPE ] }),
24 hljs.COMMENT(';', '$', { relevance: 0 }),
25 hljs.C_BLOCK_COMMENT_MODE,
26 {
27 className: 'number',
28 begin: hljs.NUMBER_RE,
29 relevance: 0
30 },
31 {
32 // subst would be the most accurate however fails the point of
33 // highlighting. variable is comparably the most accurate that actually
34 // has some effect
35 className: 'variable',
36 begin: '%[a-zA-Z0-9#_$@]+%'
37 },
38 {
39 className: 'built_in',
40 begin: '^\\s*\\w+\\s*(,|%)'
41 // I don't really know if this is totally relevant
42 },
43 {
44 // symbol would be most accurate however is highlighted just like
45 // built_in and that makes up a lot of AutoHotkey code meaning that it
46 // would fail to highlight anything
47 className: 'title',
48 variants: [
49 { begin: '^[^\\n";]+::(?!=)' },
50 {
51 begin: '^[^\\n";]+:(?!=)',
52 // zero relevance as it catches a lot of things
53 // followed by a single ':' in many languages
54 relevance: 0
55 }
56 ]
57 },
58 {
59 className: 'meta',
60 begin: '^\\s*#\\w+',
61 end: '$',
62 relevance: 0
63 },
64 {
65 className: 'built_in',
66 begin: 'A_[a-zA-Z0-9]+'
67 },
68 {
69 // consecutive commas, not for highlighting but just for relevance
70 begin: ',\\s*,' }
71 ]
72 };
73}
74
75module.exports = autohotkey;