]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/go.js
Initial commit.
[flow-web.git] / static / highlight / languages / go.js
1 /*! `go` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: Go
8 Author: Stephan Kountso aka StepLg <steplg@gmail.com>
9 Contributors: Evgeny Stepanischev <imbolk@gmail.com>
10 Description: Google go language (golang). For info about language
11 Website: http://golang.org/
12 Category: common, system
13 */
14
15 function go(hljs) {
16 const LITERALS = [
17 "true",
18 "false",
19 "iota",
20 "nil"
21 ];
22 const BUILT_INS = [
23 "append",
24 "cap",
25 "close",
26 "complex",
27 "copy",
28 "imag",
29 "len",
30 "make",
31 "new",
32 "panic",
33 "print",
34 "println",
35 "real",
36 "recover",
37 "delete"
38 ];
39 const TYPES = [
40 "bool",
41 "byte",
42 "complex64",
43 "complex128",
44 "error",
45 "float32",
46 "float64",
47 "int8",
48 "int16",
49 "int32",
50 "int64",
51 "string",
52 "uint8",
53 "uint16",
54 "uint32",
55 "uint64",
56 "int",
57 "uint",
58 "uintptr",
59 "rune"
60 ];
61 const KWS = [
62 "break",
63 "case",
64 "chan",
65 "const",
66 "continue",
67 "default",
68 "defer",
69 "else",
70 "fallthrough",
71 "for",
72 "func",
73 "go",
74 "goto",
75 "if",
76 "import",
77 "interface",
78 "map",
79 "package",
80 "range",
81 "return",
82 "select",
83 "struct",
84 "switch",
85 "type",
86 "var",
87 ];
88 const KEYWORDS = {
89 keyword: KWS,
90 type: TYPES,
91 literal: LITERALS,
92 built_in: BUILT_INS
93 };
94 return {
95 name: 'Go',
96 aliases: [ 'golang' ],
97 keywords: KEYWORDS,
98 illegal: '</',
99 contains: [
100 hljs.C_LINE_COMMENT_MODE,
101 hljs.C_BLOCK_COMMENT_MODE,
102 {
103 className: 'string',
104 variants: [
105 hljs.QUOTE_STRING_MODE,
106 hljs.APOS_STRING_MODE,
107 {
108 begin: '`',
109 end: '`'
110 }
111 ]
112 },
113 {
114 className: 'number',
115 variants: [
116 {
117 match: /-?\b0[xX]\.[a-fA-F0-9](_?[a-fA-F0-9])*[pP][+-]?\d(_?\d)*i?/, // hex without a present digit before . (making a digit afterwards required)
118 relevance: 0
119 },
120 {
121 match: /-?\b0[xX](_?[a-fA-F0-9])+((\.([a-fA-F0-9](_?[a-fA-F0-9])*)?)?[pP][+-]?\d(_?\d)*)?i?/, // hex with a present digit before . (making a digit afterwards optional)
122 relevance: 0
123 },
124 {
125 match: /-?\b0[oO](_?[0-7])*i?/, // leading 0o octal
126 relevance: 0
127 },
128 {
129 match: /-?\.\d(_?\d)*([eE][+-]?\d(_?\d)*)?i?/, // decimal without a present digit before . (making a digit afterwards required)
130 relevance: 0
131 },
132 {
133 match: /-?\b\d(_?\d)*(\.(\d(_?\d)*)?)?([eE][+-]?\d(_?\d)*)?i?/, // decimal with a present digit before . (making a digit afterwards optional)
134 relevance: 0
135 }
136 ]
137 },
138 { begin: /:=/ // relevance booster
139 },
140 {
141 className: 'function',
142 beginKeywords: 'func',
143 end: '\\s*(\\{|$)',
144 excludeEnd: true,
145 contains: [
146 hljs.TITLE_MODE,
147 {
148 className: 'params',
149 begin: /\(/,
150 end: /\)/,
151 endsParent: true,
152 keywords: KEYWORDS,
153 illegal: /["']/
154 }
155 ]
156 }
157 ]
158 };
159 }
160
161 return go;
162
163 })();
164
165 hljs.registerLanguage('go', hljsGrammar);
166 })();