]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/ada.js
Initial commit.
[flow-web.git] / static / highlight / languages / ada.js
1 /*! `ada` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: Ada
8 Author: Lars Schulna <kartoffelbrei.mit.muskatnuss@gmail.org>
9 Description: Ada is a general-purpose programming language that has great support for saftey critical and real-time applications.
10 It has been developed by the DoD and thus has been used in military and safety-critical applications (like civil aviation).
11 The first version appeared in the 80s, but it's still actively developed today with
12 the newest standard being Ada2012.
13 */
14
15 // We try to support full Ada2012
16 //
17 // We highlight all appearances of types, keywords, literals (string, char, number, bool)
18 // and titles (user defined function/procedure/package)
19 // CSS classes are set accordingly
20 //
21 // Languages causing problems for language detection:
22 // xml (broken by Foo : Bar type), elm (broken by Foo : Bar type), vbscript-html (broken by body keyword)
23 // sql (ada default.txt has a lot of sql keywords)
24
25 /** @type LanguageFn */
26 function ada(hljs) {
27 // Regular expression for Ada numeric literals.
28 // stolen form the VHDL highlighter
29
30 // Decimal literal:
31 const INTEGER_RE = '\\d(_|\\d)*';
32 const EXPONENT_RE = '[eE][-+]?' + INTEGER_RE;
33 const DECIMAL_LITERAL_RE = INTEGER_RE + '(\\.' + INTEGER_RE + ')?' + '(' + EXPONENT_RE + ')?';
34
35 // Based literal:
36 const BASED_INTEGER_RE = '\\w+';
37 const BASED_LITERAL_RE = INTEGER_RE + '#' + BASED_INTEGER_RE + '(\\.' + BASED_INTEGER_RE + ')?' + '#' + '(' + EXPONENT_RE + ')?';
38
39 const NUMBER_RE = '\\b(' + BASED_LITERAL_RE + '|' + DECIMAL_LITERAL_RE + ')';
40
41 // Identifier regex
42 const ID_REGEX = '[A-Za-z](_?[A-Za-z0-9.])*';
43
44 // bad chars, only allowed in literals
45 const BAD_CHARS = `[]\\{\\}%#'"`;
46
47 // Ada doesn't have block comments, only line comments
48 const COMMENTS = hljs.COMMENT('--', '$');
49
50 // variable declarations of the form
51 // Foo : Bar := Baz;
52 // where only Bar will be highlighted
53 const VAR_DECLS = {
54 // TODO: These spaces are not required by the Ada syntax
55 // however, I have yet to see handwritten Ada code where
56 // someone does not put spaces around :
57 begin: '\\s+:\\s+',
58 end: '\\s*(:=|;|\\)|=>|$)',
59 // endsWithParent: true,
60 // returnBegin: true,
61 illegal: BAD_CHARS,
62 contains: [
63 {
64 // workaround to avoid highlighting
65 // named loops and declare blocks
66 beginKeywords: 'loop for declare others',
67 endsParent: true
68 },
69 {
70 // properly highlight all modifiers
71 className: 'keyword',
72 beginKeywords: 'not null constant access function procedure in out aliased exception'
73 },
74 {
75 className: 'type',
76 begin: ID_REGEX,
77 endsParent: true,
78 relevance: 0
79 }
80 ]
81 };
82
83 const KEYWORDS = [
84 "abort",
85 "else",
86 "new",
87 "return",
88 "abs",
89 "elsif",
90 "not",
91 "reverse",
92 "abstract",
93 "end",
94 "accept",
95 "entry",
96 "select",
97 "access",
98 "exception",
99 "of",
100 "separate",
101 "aliased",
102 "exit",
103 "or",
104 "some",
105 "all",
106 "others",
107 "subtype",
108 "and",
109 "for",
110 "out",
111 "synchronized",
112 "array",
113 "function",
114 "overriding",
115 "at",
116 "tagged",
117 "generic",
118 "package",
119 "task",
120 "begin",
121 "goto",
122 "pragma",
123 "terminate",
124 "body",
125 "private",
126 "then",
127 "if",
128 "procedure",
129 "type",
130 "case",
131 "in",
132 "protected",
133 "constant",
134 "interface",
135 "is",
136 "raise",
137 "use",
138 "declare",
139 "range",
140 "delay",
141 "limited",
142 "record",
143 "when",
144 "delta",
145 "loop",
146 "rem",
147 "while",
148 "digits",
149 "renames",
150 "with",
151 "do",
152 "mod",
153 "requeue",
154 "xor"
155 ];
156
157 return {
158 name: 'Ada',
159 case_insensitive: true,
160 keywords: {
161 keyword: KEYWORDS,
162 literal: [
163 "True",
164 "False"
165 ]
166 },
167 contains: [
168 COMMENTS,
169 // strings "foobar"
170 {
171 className: 'string',
172 begin: /"/,
173 end: /"/,
174 contains: [
175 {
176 begin: /""/,
177 relevance: 0
178 }
179 ]
180 },
181 // characters ''
182 {
183 // character literals always contain one char
184 className: 'string',
185 begin: /'.'/
186 },
187 {
188 // number literals
189 className: 'number',
190 begin: NUMBER_RE,
191 relevance: 0
192 },
193 {
194 // Attributes
195 className: 'symbol',
196 begin: "'" + ID_REGEX
197 },
198 {
199 // package definition, maybe inside generic
200 className: 'title',
201 begin: '(\\bwith\\s+)?(\\bprivate\\s+)?\\bpackage\\s+(\\bbody\\s+)?',
202 end: '(is|$)',
203 keywords: 'package body',
204 excludeBegin: true,
205 excludeEnd: true,
206 illegal: BAD_CHARS
207 },
208 {
209 // function/procedure declaration/definition
210 // maybe inside generic
211 begin: '(\\b(with|overriding)\\s+)?\\b(function|procedure)\\s+',
212 end: '(\\bis|\\bwith|\\brenames|\\)\\s*;)',
213 keywords: 'overriding function procedure with is renames return',
214 // we need to re-match the 'function' keyword, so that
215 // the title mode below matches only exactly once
216 returnBegin: true,
217 contains:
218 [
219 COMMENTS,
220 {
221 // name of the function/procedure
222 className: 'title',
223 begin: '(\\bwith\\s+)?\\b(function|procedure)\\s+',
224 end: '(\\(|\\s+|$)',
225 excludeBegin: true,
226 excludeEnd: true,
227 illegal: BAD_CHARS
228 },
229 // 'self'
230 // // parameter types
231 VAR_DECLS,
232 {
233 // return type
234 className: 'type',
235 begin: '\\breturn\\s+',
236 end: '(\\s+|;|$)',
237 keywords: 'return',
238 excludeBegin: true,
239 excludeEnd: true,
240 // we are done with functions
241 endsParent: true,
242 illegal: BAD_CHARS
243
244 }
245 ]
246 },
247 {
248 // new type declarations
249 // maybe inside generic
250 className: 'type',
251 begin: '\\b(sub)?type\\s+',
252 end: '\\s+',
253 keywords: 'type',
254 excludeBegin: true,
255 illegal: BAD_CHARS
256 },
257
258 // see comment above the definition
259 VAR_DECLS
260
261 // no markup
262 // relevance boosters for small snippets
263 // {begin: '\\s*=>\\s*'},
264 // {begin: '\\s*:=\\s*'},
265 // {begin: '\\s+:=\\s+'},
266 ]
267 };
268 }
269
270 return ada;
271
272 })();
273
274 hljs.registerLanguage('ada', hljsGrammar);
275 })();