Merge branch 'hardening_types'
[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 define(['highlight'], function(hljs) {
20 hljs.registerLanguage('nit', function(hljs) {
21 var METHOD_RE = '[a-z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?';
22 var KEYWORDS = {
23 keyword: 'abort abstract and as assert break class continue do else end enum extern for fun ' +
24 'if import in init interface intern intrude is isa isset label loop module new nullable not ' +
25 'once or protected private redef return self super then type universal var ' +
26 'when while writable',
27 literal: "true false null"
28 };
29 var COMMENT = {
30 className: 'comment',
31 begin: '#', end: '$',
32 };
33 var SUBST = {
34 className: 'subst',
35 begin: '{', end: '}',
36 keywords: KEYWORDS
37 };
38 var STRING = {
39 className: 'string',
40 contains: [hljs.BACKSLASH_ESCAPE, SUBST],
41 variants: [
42 {begin: /"/, end: /"/},
43 ]
44 };
45 var CHAR = {
46 className: 'char',
47 contains: [hljs.BACKSLASH_ESCAPE, SUBST],
48 begin: /'/, end: /'/,
49 };
50 var TYPE = {
51 className: 'type',
52 begin: '[A-Z]\\w*'
53 }
54 var PARAMS = {
55 className: 'params',
56 begin: '\\(', end: '\\)',
57 keywords: KEYWORDS,
58 contains: [TYPE]
59 };
60 var RET_TYPE = {
61 className: 'rettype',
62 begin: ':', end: '$|do|is|=',
63 keywords: 'nullable',
64 returnEnd: true,
65 contains: [TYPE]
66 }
67 var DO_BLOCK = {
68 className: 'block',
69 begin: 'do', end: '$|end',
70 keywords: KEYWORDS
71 }
72 var IS_BLOCK = {
73 className: 'modifiers',
74 begin: 'is', end: '$',
75 keywords: KEYWORDS
76 }
77 var CONTAINS = [
78 STRING,
79 CHAR,
80 COMMENT,
81 TYPE,
82 {
83 className: 'module',
84 beginKeywords: 'module', end: '$',
85 contains: [
86 hljs.inherit(hljs.TITLE_MODE, {begin: '[a-z_]\\w*'}),
87 COMMENT
88 ]
89 },
90 {
91 className: 'import',
92 begin: '(intrude )?import', end: '$',
93 keywords: 'intrude import',
94 contains: [
95 {
96 className: 'module',
97 begin: '[a-z_]\\w*'
98 },
99 COMMENT
100 ]
101 },
102 {
103 className: 'class',
104 begin: '(redef |private |protected )?(abstract )?(class|interface)', end: '$',
105 keywords: 'redef private protected abstract class interface',
106 contains: [
107 hljs.inherit(hljs.TITLE_MODE, {begin: '[A-Z]\\w*'}),
108 {
109 className: 'super',
110 begin: '\\bsuper', end: '$',
111 keywords: 'super',
112 contains: [TYPE]
113 },
114 COMMENT
115 ]
116 },
117 {
118 className: 'fun',
119 begin: '(redef |private |protected )?(fun|init|type)\\b', end: '$',
120 keywords: KEYWORDS,
121 contains: [
122 PARAMS,
123 RET_TYPE,
124 DO_BLOCK,
125 IS_BLOCK,
126 {
127 className: 'title',
128 begin: '\\b[a-zA-Z_][a-zA-Z_]*\\b'
129 },
130 COMMENT
131 ]
132 },
133 {
134 className: 'number',
135 begin: '(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b',
136 relevance: 0
137 }
138 ];
139 SUBST.contains = CONTAINS;
140
141 return {
142 keywords: KEYWORDS,
143 contains: CONTAINS
144 };
145 });
146 });