]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/qml.js
Initial commit.
[flow-web.git] / static / highlight / languages / qml.js
1 /*! `qml` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: QML
8 Requires: javascript.js, xml.js
9 Author: John Foster <jfoster@esri.com>
10 Description: Syntax highlighting for the Qt Quick QML scripting language, based mostly off
11 the JavaScript parser.
12 Website: https://doc.qt.io/qt-5/qmlapplications.html
13 Category: scripting
14 */
15
16 function qml(hljs) {
17 const regex = hljs.regex;
18 const KEYWORDS = {
19 keyword:
20 'in of on if for while finally var new function do return void else break catch '
21 + 'instanceof with throw case default try this switch continue typeof delete '
22 + 'let yield const export super debugger as async await import',
23 literal:
24 'true false null undefined NaN Infinity',
25 built_in:
26 'eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent '
27 + 'encodeURI encodeURIComponent escape unescape Object Function Boolean Error '
28 + 'EvalError InternalError RangeError ReferenceError StopIteration SyntaxError '
29 + 'TypeError URIError Number Math Date String RegExp Array Float32Array '
30 + 'Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array '
31 + 'Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require '
32 + 'module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect '
33 + 'Behavior bool color coordinate date double enumeration font geocircle georectangle '
34 + 'geoshape int list matrix4x4 parent point quaternion real rect '
35 + 'size string url variant vector2d vector3d vector4d '
36 + 'Promise'
37 };
38
39 const QML_IDENT_RE = '[a-zA-Z_][a-zA-Z0-9\\._]*';
40
41 // Isolate property statements. Ends at a :, =, ;, ,, a comment or end of line.
42 // Use property class.
43 const PROPERTY = {
44 className: 'keyword',
45 begin: '\\bproperty\\b',
46 starts: {
47 className: 'string',
48 end: '(:|=|;|,|//|/\\*|$)',
49 returnEnd: true
50 }
51 };
52
53 // Isolate signal statements. Ends at a ) a comment or end of line.
54 // Use property class.
55 const SIGNAL = {
56 className: 'keyword',
57 begin: '\\bsignal\\b',
58 starts: {
59 className: 'string',
60 end: '(\\(|:|=|;|,|//|/\\*|$)',
61 returnEnd: true
62 }
63 };
64
65 // id: is special in QML. When we see id: we want to mark the id: as attribute and
66 // emphasize the token following.
67 const ID_ID = {
68 className: 'attribute',
69 begin: '\\bid\\s*:',
70 starts: {
71 className: 'string',
72 end: QML_IDENT_RE,
73 returnEnd: false
74 }
75 };
76
77 // Find QML object attribute. An attribute is a QML identifier followed by :.
78 // Unfortunately it's hard to know where it ends, as it may contain scalars,
79 // objects, object definitions, or javascript. The true end is either when the parent
80 // ends or the next attribute is detected.
81 const QML_ATTRIBUTE = {
82 begin: QML_IDENT_RE + '\\s*:',
83 returnBegin: true,
84 contains: [
85 {
86 className: 'attribute',
87 begin: QML_IDENT_RE,
88 end: '\\s*:',
89 excludeEnd: true,
90 relevance: 0
91 }
92 ],
93 relevance: 0
94 };
95
96 // Find QML object. A QML object is a QML identifier followed by { and ends at the matching }.
97 // All we really care about is finding IDENT followed by { and just mark up the IDENT and ignore the {.
98 const QML_OBJECT = {
99 begin: regex.concat(QML_IDENT_RE, /\s*\{/),
100 end: /\{/,
101 returnBegin: true,
102 relevance: 0,
103 contains: [ hljs.inherit(hljs.TITLE_MODE, { begin: QML_IDENT_RE }) ]
104 };
105
106 return {
107 name: 'QML',
108 aliases: [ 'qt' ],
109 case_insensitive: false,
110 keywords: KEYWORDS,
111 contains: [
112 {
113 className: 'meta',
114 begin: /^\s*['"]use (strict|asm)['"]/
115 },
116 hljs.APOS_STRING_MODE,
117 hljs.QUOTE_STRING_MODE,
118 { // template string
119 className: 'string',
120 begin: '`',
121 end: '`',
122 contains: [
123 hljs.BACKSLASH_ESCAPE,
124 {
125 className: 'subst',
126 begin: '\\$\\{',
127 end: '\\}'
128 }
129 ]
130 },
131 hljs.C_LINE_COMMENT_MODE,
132 hljs.C_BLOCK_COMMENT_MODE,
133 {
134 className: 'number',
135 variants: [
136 { begin: '\\b(0[bB][01]+)' },
137 { begin: '\\b(0[oO][0-7]+)' },
138 { begin: hljs.C_NUMBER_RE }
139 ],
140 relevance: 0
141 },
142 { // "value" container
143 begin: '(' + hljs.RE_STARTERS_RE + '|\\b(case|return|throw)\\b)\\s*',
144 keywords: 'return throw case',
145 contains: [
146 hljs.C_LINE_COMMENT_MODE,
147 hljs.C_BLOCK_COMMENT_MODE,
148 hljs.REGEXP_MODE,
149 { // E4X / JSX
150 begin: /</,
151 end: />\s*[);\]]/,
152 relevance: 0,
153 subLanguage: 'xml'
154 }
155 ],
156 relevance: 0
157 },
158 SIGNAL,
159 PROPERTY,
160 {
161 className: 'function',
162 beginKeywords: 'function',
163 end: /\{/,
164 excludeEnd: true,
165 contains: [
166 hljs.inherit(hljs.TITLE_MODE, { begin: /[A-Za-z$_][0-9A-Za-z$_]*/ }),
167 {
168 className: 'params',
169 begin: /\(/,
170 end: /\)/,
171 excludeBegin: true,
172 excludeEnd: true,
173 contains: [
174 hljs.C_LINE_COMMENT_MODE,
175 hljs.C_BLOCK_COMMENT_MODE
176 ]
177 }
178 ],
179 illegal: /\[|%/
180 },
181 {
182 // hack: prevents detection of keywords after dots
183 begin: '\\.' + hljs.IDENT_RE,
184 relevance: 0
185 },
186 ID_ID,
187 QML_ATTRIBUTE,
188 QML_OBJECT
189 ],
190 illegal: /#/
191 };
192 }
193
194 return qml;
195
196 })();
197
198 hljs.registerLanguage('qml', hljsGrammar);
199 })();