nitdoc: remove `require.js` dependency
[nit.git] / share / nitdoc / js / lib / nit.js
1 /* This file is part of NIT ( http://www.nitlanguage.org ).
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14
15 Documentation generator for the nit language.
16 Generate API documentation in HTML format from nit source code.
17 */
18
19 hljs.registerLanguage('nit', function(hljs) {
20 var METHOD_RE = '[a-z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?';
21 var KEYWORDS = {
22 keyword: 'abort abstract and as assert break class continue do else end enum extern for fun ' +
23 'if import in init interface intern intrude is isa isset label loop module new nullable not ' +
24 'once or protected private redef return self super then type universal var ' +
25 'when while writable',
26 literal: "true false null"
27 };
28 var COMMENT = {
29 className: 'comment',
30 begin: '#', end: '$',
31 };
32 var SUBST = {
33 className: 'subst',
34 begin: '{', end: '}',
35 keywords: KEYWORDS
36 };
37 var STRING = {
38 className: 'string',
39 contains: [hljs.BACKSLASH_ESCAPE, SUBST],
40 variants: [
41 {begin: /"/, end: /"/},
42 ]
43 };
44 var CHAR = {
45 className: 'char',
46 contains: [hljs.BACKSLASH_ESCAPE, SUBST],
47 begin: /'/, end: /'/,
48 };
49 var TYPE = {
50 className: 'type',
51 begin: '[A-Z]\\w*'
52 }
53 var PARAMS = {
54 className: 'params',
55 begin: '\\(', end: '\\)',
56 keywords: KEYWORDS,
57 contains: [TYPE]
58 };
59 var RET_TYPE = {
60 className: 'rettype',
61 begin: ':', end: '$|do|is|=',
62 keywords: 'nullable',
63 returnEnd: true,
64 contains: [TYPE]
65 }
66 var DO_BLOCK = {
67 className: 'block',
68 begin: 'do', end: '$|end',
69 keywords: KEYWORDS
70 }
71 var IS_BLOCK = {
72 className: 'modifiers',
73 begin: 'is', end: '$',
74 keywords: KEYWORDS
75 }
76 var CONTAINS = [
77 STRING,
78 CHAR,
79 COMMENT,
80 TYPE,
81 {
82 className: 'module',
83 beginKeywords: 'module', end: '$',
84 contains: [
85 hljs.inherit(hljs.TITLE_MODE, {begin: '[a-z_]\\w*'}),
86 COMMENT
87 ]
88 },
89 {
90 className: 'import',
91 begin: '(intrude )?import', end: '$',
92 keywords: 'intrude import',
93 contains: [
94 {
95 className: 'module',
96 begin: '[a-z_]\\w*'
97 },
98 COMMENT
99 ]
100 },
101 {
102 className: 'class',
103 begin: '(redef |private |protected )?(abstract )?(class|interface)', end: '$',
104 keywords: 'redef private protected abstract class interface',
105 contains: [
106 hljs.inherit(hljs.TITLE_MODE, {begin: '[A-Z]\\w*'}),
107 {
108 className: 'super',
109 begin: '\\bsuper', end: '$',
110 keywords: 'super',
111 contains: [TYPE]
112 },
113 COMMENT
114 ]
115 },
116 {
117 className: 'fun',
118 begin: '(redef |private |protected )?(fun|init|type)\\b', end: '$',
119 keywords: KEYWORDS,
120 contains: [
121 PARAMS,
122 RET_TYPE,
123 DO_BLOCK,
124 IS_BLOCK,
125 {
126 className: 'title',
127 begin: '\\b[a-zA-Z_][a-zA-Z_]*\\b'
128 },
129 COMMENT
130 ]
131 },
132 {
133 className: 'number',
134 begin: '(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b',
135 relevance: 0
136 }
137 ];
138 SUBST.contains = CONTAINS;
139
140 return {
141 keywords: KEYWORDS,
142 contains: CONTAINS
143 };
144 });