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