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