591421f0a89f720e10ed7f9b0ca44ca7e33107a4
[Packages/TYPO3.CMS.git] / typo3 / sysext / t3editor / Resources / Public / JavaScript / Mode / typoscript / typoscript.js
1 (function(mod) {
2 if (typeof exports === "object" && typeof module === "object") // CommonJS
3 mod(require("cm/lib/codemirror"));
4 else if (typeof define === "function" && define.amd) // AMD
5 define(["cm/lib/codemirror"], mod);
6 else // Plain browser env
7 mod(CodeMirror);
8 })(function(CodeMirror) {
9 "use strict";
10
11 function expressionAllowed(stream, state, backUp) {
12 return /^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
13 (state.lastType === "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
14 }
15
16 CodeMirror.defineMode("typoscript", function(config, parserConfig) {
17 var indentUnit = config.indentUnit;
18 var statementIndent = parserConfig.statementIndent;
19 var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
20
21 // Tokenizer
22
23 var keywords = function() {
24 function kw(type) {
25 return {type: type, style: "keyword"};
26 }
27
28 var A = kw("keyword a"), B = kw("keyword b");
29
30 return {
31 '_CSS_DEFAULT_STYLE': kw('_CSS_DEFAULT_STYLE'),
32 '_DEFAULT_PI_VARS': kw('_DEFAULT_PI_VARS'),
33 '_GIFBUILDER': kw('_GIFBUILDER'),
34 '_LOCAL_LANG': kw('_LOCAL_LANG'),
35 '_offset': kw('_offset'),
36 'absRefPrefix': kw('absRefPrefix'),
37 'accessibility': kw('accessibility'),
38 'accessKey': kw('accessKey'),
39 'ACT': B,
40 'ACTIFSUB': B,
41 'ACTIFSUBRO': kw('ACTIFSUBRO'),
42 'ACTRO': B,
43 'addAttributes': kw('addAttributes'),
44 'addExtUrlsAndShortCuts': kw('addExtUrlsAndShortCuts'),
45 'addItems': kw('addItems'),
46 'additionalHeaders': kw('additionalHeaders'),
47 'additionalParams': kw('additionalParams'),
48 'addQueryString': kw('addQueryString'),
49 'adjustItemsH': kw('adjustItemsH'),
50 'adjustSubItemsH': kw('adjustSubItemsH'),
51 'admPanel': A,
52 'after': kw('after'),
53 'afterImg': kw('afterImg'),
54 'afterImgLink': kw('afterImgLink'),
55 'afterImgTagParams': kw('afterImgTagParams'),
56 'afterROImg': kw('afterROImg'),
57 'afterWrap': kw('afterWrap'),
58 'age': kw('age'),
59 'alertPopups': kw('alertPopups'),
60 'align': kw('align'),
61 'all': B,
62 'allow': kw('allow'),
63 'allowCaching': kw('allowCaching'),
64 'allowedAttribs': kw('allowedAttribs'),
65 'allowedClasses': kw('allowedClasses'),
66 'allowedCols': kw('allowedCols'),
67 'allowedNewTables': kw('allowedNewTables'),
68 'allowTags': kw('allowTags'),
69 'allStdWrap': kw('allStdWrap'),
70 'allWrap': kw('allWrap'),
71 'alt_print': A,
72 'alternativeSortingField': kw('alternativeSortingField'),
73 'alternativeTempPath': kw('alternativeTempPath'),
74 'altIcons': kw('altIcons'),
75 'altImgResource': kw('altImgResource'),
76 'altLabels': kw('altLabels'),
77 'altTarget': kw('altTarget'),
78 'altText': kw('altText'),
79 'altUrl': kw('altUrl'),
80 'altUrl_noDefaultParams': kw('altUrl_noDefaultParams'),
81 'altWrap': kw('altWrap'),
82 'always': kw('always'),
83 'alwaysActivePIDlist': kw('alwaysActivePIDlist'),
84 'alwaysLink': kw('alwaysLink'),
85 'andWhere': kw('andWhere'),
86 'angle': kw('angle'),
87 'antiAlias': kw('antiAlias'),
88 'append': kw('append'),
89 'applyTotalH': kw('applyTotalH'),
90 'applyTotalW': kw('applyTotalW'),
91 'archive': kw('archive'),
92 'ascii': B,
93 'ATagAfterWrap': kw('ATagAfterWrap'),
94 'ATagBeforeWrap': kw('ATagBeforeWrap'),
95 'ATagParams': kw('ATagParams'),
96 'ATagTitle': kw('ATagTitle'),
97 'atLeast': B,
98 'atMost': B,
99 'attribute': kw('attribute'),
100 'auth': A,
101 'autoLevels': kw('autoLevels'),
102 'autonumber': kw('autonumber'),
103 'backColor': kw('backColor'),
104 'background': kw('background'),
105 'baseURL': kw('baseURL'),
106 'BE': B,
107 'be_groups': B,
108 'be_users': B,
109 'before': kw('before'),
110 'beforeImg': kw('beforeImg'),
111 'beforeImgLink': kw('beforeImgLink'),
112 'beforeImgTagParams': kw('beforeImgTagParams'),
113 'beforeROImg': kw('beforeROImg'),
114 'beforeWrap': kw('beforeWrap'),
115 'begin': kw('begin'),
116 'bgCol': kw('bgCol'),
117 'bgImg': kw('bgImg'),
118 'blur': kw('blur'),
119 'bm': kw('bm'),
120 'bodyTag': kw('bodyTag'),
121 'bodyTagAdd': kw('bodyTagAdd'),
122 'bodyTagCObject': kw('bodyTagCObject'),
123 'bodytext': kw('bodytext'),
124 'border': kw('border'),
125 'borderCol': kw('borderCol'),
126 'borderThick': kw('borderThick'),
127 'bottomBackColor': kw('bottomBackColor'),
128 'bottomContent': kw('bottomContent'),
129 'bottomHeight': kw('bottomHeight'),
130 'bottomImg': kw('bottomImg'),
131 'bottomImg_mask': kw('bottomImg_mask'),
132 'BOX': B,
133 'br': kw('br'),
134 'browse': B,
135 'browser': A,
136 'brTag': kw('brTag'),
137 'bullet': kw('bullet'),
138 'bulletlist': kw('bulletlist'),
139 'bullets': B,
140 'bytes': kw('bytes'),
141 'cache': A,
142 'cache_clearAtMidnight': kw('cache_clearAtMidnight'),
143 'cache_period': kw('cache_period'),
144 'caption': kw('caption'),
145 'caption_stdWrap': kw('caption_stdWrap'),
146 'captionHeader': kw('captionHeader'),
147 'captionSplit': kw('captionSplit'),
148 'CARRAY': kw('CARRAY'),
149 'CASE': kw('CASE'),
150 'case': kw('case'),
151 'casesensitiveComp': kw('casesensitiveComp'),
152 'cellpadding': kw('cellpadding'),
153 'cellspacing': kw('cellspacing'),
154 'char': kw('char'),
155 'charcoal': kw('charcoal'),
156 'charMapConfig': kw('charMapConfig'),
157 'CHECK': A,
158 'check': kw('check'),
159 'class': kw('class'),
160 'classesAnchor': kw('classesAnchor'),
161 'classesCharacter': kw('classesCharacter'),
162 'classesImage': kw('classesImage'),
163 'classesParagraph': kw('classesParagraph'),
164 'clear': kw('clear'),
165 'clearCache': kw('clearCache'),
166 'clearCache_disable': kw('clearCache_disable'),
167 'clearCache_pageGrandParent': kw('clearCache_pageGrandParent'),
168 'clearCache_pageSiblingChildren': kw('clearCache_pageSiblingChildren'),
169 'clearCacheCmd': kw('clearCacheCmd'),
170 'clearCacheLevels': kw('clearCacheLevels'),
171 'clearCacheOfPages': kw('clearCacheOfPages'),
172 'clickTitleMode': kw('clickTitleMode'),
173 'clipboardNumberPads': kw('clipboardNumberPads'),
174 'cMargins': kw('cMargins'),
175 'COA': kw('COA'),
176 'COA_INT': kw('COA_INT'),
177 'cObj': A,
178 'COBJ_ARRAY': kw('COBJ_ARRAY'),
179 'cObject': A,
180 'cObjNum': kw('cObjNum'),
181 'collapse': kw('collapse'),
182 'collections': kw('collections'),
183 'color': kw('color'),
184 'color1': kw('color1'),
185 'color2': kw('color2'),
186 'color3': kw('color3'),
187 'color4': kw('color4'),
188 'colors': kw('colors'),
189 'colour': kw('colour'),
190 'colPos_list': kw('colPos_list'),
191 'colRelations': kw('colRelations'),
192 'cols': kw('cols'),
193 'colSpace': kw('colSpace'),
194 'COMMENT': A,
195 'comment_auto': kw('comment_auto'),
196 'commentWrap': kw('commentWrap'),
197 'compX': kw('compX'),
198 'compY': kw('compY'),
199 'conf': kw('conf'),
200 'CONFIG': kw('CONFIG'),
201 'config': A,
202 'CONSTANTS': kw('CONSTANTS'),
203 'constants': kw('constants'),
204 'CONTENT': kw('CONTENT'),
205 'content': A,
206 'content_from_pid_allowOutsideDomain': kw('content_from_pid_allowOutsideDomain'),
207 'contextMenu': kw('contextMenu'),
208 'copy': A,
209 'copyLevels': kw('copyLevels'),
210 'count_HMENU_MENUOBJ': kw('count_HMENU_MENUOBJ'),
211 'count_menuItems': kw('count_menuItems'),
212 'count_MENUOBJ': kw('count_MENUOBJ'),
213 'create': kw('create'),
214 'createFoldersInEB': kw('createFoldersInEB'),
215 'crop': kw('crop'),
216 'csConv': kw('csConv'),
217 'CSS_inlineStyle': A,
218 'CType': kw('CType'),
219 'CUR': B,
220 'CURIFSUB': B,
221 'CURIFSUBRO': B,
222 'current': kw('current'),
223 'CURRO': B,
224 'curUid': kw('curUid'),
225 'cut': A,
226 'cWidth': kw('cWidth'),
227 'data': kw('data'),
228 'dataArray': A,
229 'dataWrap': kw('dataWrap'),
230 'date': kw('date'),
231 'date_stdWrap': kw('date_stdWrap'),
232 'datePrefix': kw('datePrefix'),
233 'dayofmonth': A,
234 'dayofweek': A,
235 'DB': kw('DB'),
236 'db_list': A,
237 'debug': kw('debug'),
238 'debugData': kw('debugData'),
239 'debugFunc': kw('debugFunc'),
240 'debugItemConf': kw('debugItemConf'),
241 'debugRenumberedObject': kw('debugRenumberedObject'),
242 'default': B,
243 'defaultAlign': kw('defaultAlign'),
244 'defaultCmd': kw('defaultCmd'),
245 'defaultHeaderType': kw('defaultHeaderType'),
246 'defaultOutput': kw('defaultOutput'),
247 'defaults': kw('defaults'),
248 'defaultType': kw('defaultType'),
249 'delete': kw('delete'),
250 'denyTags': kw('denyTags'),
251 'depth': kw('depth'),
252 'DESC': kw('DESC'),
253 'description': B,
254 'dimensions': kw('dimensions'),
255 'direction': kw('direction'),
256 'directory': B,
257 'directReturn': B,
258 'disableAdvanced': kw('disableAdvanced'),
259 'disableAllHeaderCode': kw('disableAllHeaderCode'),
260 'disableAltText': kw('disableAltText'),
261 'disableBodyTag': kw('disableBodyTag'),
262 'disableCharsetHeader': kw('disableCharsetHeader'),
263 'disabled': kw('disabled'),
264 'disableDelete': kw('disableDelete'),
265 'disableHideAtCopy': kw('disableHideAtCopy'),
266 'disableItems': kw('disableItems'),
267 'disableNewContentElementWizard': kw('disableNewContentElementWizard'),
268 'disableNoMatchingValueElement': kw('disableNoMatchingValueElement'),
269 'disablePageExternalUrl': kw('disablePageExternalUrl'),
270 'disablePrefixComment': kw('disablePrefixComment'),
271 'disablePrependAtCopy': kw('disablePrependAtCopy'),
272 'disableSearchBox': kw('disableSearchBox'),
273 'disableSingleTableView': kw('disableSingleTableView'),
274 'displayContent': kw('displayContent'),
275 'displayFieldIcons': kw('displayFieldIcons'),
276 'displayIcons': kw('displayIcons'),
277 'displayMessages': kw('displayMessages'),
278 'displayRecord': kw('displayRecord'),
279 'displayTimes': kw('displayTimes'),
280 'distributeX': kw('distributeX'),
281 'distributeY': kw('distributeY'),
282 'div': B,
283 'DIV': kw('DIV'),
284 'doctype': kw('doctype'),
285 'doctypeSwitch': kw('doctypeSwitch'),
286 'DOCUMENT_BODY': kw('DOCUMENT_BODY'),
287 'doktype': kw('doktype'),
288 'doNotLinkIt': kw('doNotLinkIt'),
289 'doNotShowLink': kw('doNotShowLink'),
290 'doNotStripHTML': kw('doNotStripHTML'),
291 'dontCheckPid': kw('dontCheckPid'),
292 'dontLinkIfSubmenu': kw('dontLinkIfSubmenu'),
293 'dontWrapInTable': kw('dontWrapInTable'),
294 'doubleBrTag': kw('doubleBrTag'),
295 'dWorkArea': kw('dWorkArea'),
296 'dynCSS': A,
297 'edge': kw('edge'),
298 'edit': A,
299 'edit_access': A,
300 'edit_docModuleUpload': kw('edit_docModuleUpload'),
301 'edit_pageheader': A,
302 'edit_RTE': kw('edit_RTE'),
303 'editFieldsAtATime': kw('editFieldsAtATime'),
304 'editFormsOnPage': kw('editFormsOnPage'),
305 'editIcons': kw('editIcons'),
306 'editNoPopup': kw('editNoPopup'),
307 'EDITPANEL': kw('EDITPANEL'),
308 'editPanel': kw('editPanel'),
309 'EFFECT': kw('EFFECT'),
310 'elements': kw('elements'),
311 'else': B,
312 'email': B,
313 'emailMeAtLogin': kw('emailMeAtLogin'),
314 'emailMess': kw('emailMess'),
315 'emboss': kw('emboss'),
316 'enable': kw('enable'),
317 'encapsLines': kw('encapsLines'),
318 'encapsLinesStdWrap': kw('encapsLinesStdWrap'),
319 'encapsTagList': kw('encapsTagList'),
320 'end': B,
321 'entryLevel': kw('entryLevel'),
322 'equalH': kw('equalH'),
323 'equals': B,
324 'everybody': kw('everybody'),
325 'excludeDoktypes': kw('excludeDoktypes'),
326 'excludeUidList': kw('excludeUidList'),
327 'expAll': kw('expAll'),
328 'expand': kw('expand'),
329 'explode': kw('explode'),
330 'ext': kw('ext'),
331 'external': B,
332 'externalBlocks': kw('externalBlocks'),
333 'extTarget': kw('extTarget'),
334 'face': kw('face'),
335 'false': B,
336 'FE': B,
337 'fe_adminLib': kw('fe_adminLib'),
338 'fe_groups': B,
339 'fe_users': B,
340 'feadmin': B,
341 'field': kw('field'),
342 'fieldName': kw('fieldName'),
343 'fieldOrder': kw('fieldOrder'),
344 'fieldRequired': kw('fieldRequired'),
345 'fields': kw('fields'),
346 'fieldWrap': kw('fieldWrap'),
347 'FILE': kw('FILE'),
348 'file': kw('file'),
349 'file1': kw('file1'),
350 'file2': kw('file2'),
351 'file3': kw('file3'),
352 'file4': kw('file4'),
353 'file5': kw('file5'),
354 'FILES': kw('FILES'),
355 'files': kw('files'),
356 'firstLabel': kw('firstLabel'),
357 'firstLabelGeneral': kw('firstLabelGeneral'),
358 'fixAttrib': kw('fixAttrib'),
359 'flip': kw('flip'),
360 'flop': kw('flop'),
361 'FLUIDTEMPLATE': kw('FLUIDTEMPLATE'),
362 'folder': A,
363 'folders': kw('folders'),
364 'folderTree': A,
365 'foldoutMenu': A,
366 'fontColor': kw('fontColor'),
367 'fontFile': kw('fontFile'),
368 'fontOffset': kw('fontOffset'),
369 'fontSize': kw('fontSize'),
370 'fontSizeMultiplicator': kw('fontSizeMultiplicator'),
371 'forceDisplayFieldIcons': kw('forceDisplayFieldIcons'),
372 'forceDisplayIcons': kw('forceDisplayIcons'),
373 'forceTemplateParsing': kw('forceTemplateParsing'),
374 'forceTypeValue': kw('forceTypeValue'),
375 'FORM': kw('FORM'),
376 'format': kw('format'),
377 'ftu': kw('ftu'),
378 'function': kw('function'),
379 'Functions': A,
380 'gamma': kw('gamma'),
381 'gapBgCol': kw('gapBgCol'),
382 'gapLineCol': kw('gapLineCol'),
383 'gapLineThickness': kw('gapLineThickness'),
384 'gapWidth': kw('gapWidth'),
385 'get': kw('get'),
386 'getBorder': kw('getBorder'),
387 'getLeft': kw('getLeft'),
388 'getRight': kw('getRight'),
389 'GIFBUILDER': kw('GIFBUILDER'),
390 'global': kw('global'),
391 'globalNesting': kw('globalNesting'),
392 'globalString': kw('globalString'),
393 'globalVar': kw('globalVar'),
394 'GMENU': kw('GMENU'),
395 'GP': kw('GP'),
396 'gray': kw('gray'),
397 'group': kw('group'),
398 'groupBy': kw('groupBy'),
399 'groupid': kw('groupid'),
400 'header': B,
401 'header_layout': kw('header_layout'),
402 'headerComment': kw('headerComment'),
403 'headerData': kw('headerData'),
404 'headerSpace': kw('headerSpace'),
405 'headTag': kw('headTag'),
406 'height': kw('height'),
407 'helpText': kw('helpText'),
408 'hidden': kw('hidden'),
409 'hiddenFields': kw('hiddenFields'),
410 'hide': kw('hide'),
411 'hideButCreateMap': kw('hideButCreateMap'),
412 'hidePStyleItems': kw('hidePStyleItems'),
413 'hideRecords': kw('hideRecords'),
414 'highColor': kw('highColor'),
415 'history': kw('history'),
416 'HMENU': kw('HMENU'),
417 'hostname': A,
418 'hour': A,
419 'HTML': kw('HTML'),
420 'html': B,
421 'HTMLparser': kw('HTMLparser'),
422 'HTMLparser_tags': kw('HTMLparser_tags'),
423 'htmlSpecialChars': kw('htmlSpecialChars'),
424 'htmlTag_dir': kw('htmlTag_dir'),
425 'htmlTag_langKey': kw('htmlTag_langKey'),
426 'htmlTag_setParams': kw('htmlTag_setParams'),
427 'http': kw('http'),
428 'icon': kw('icon'),
429 'icon_image_ext_list': kw('icon_image_ext_list'),
430 'icon_link': kw('icon_link'),
431 'iconCObject': kw('iconCObject'),
432 'id': B,
433 'IENV': kw('IENV'),
434 'if': B,
435 'ifEmpty': B,
436 'IFSUB': B,
437 'IFSUBRO': B,
438 'IMAGE': kw('IMAGE'),
439 'image': B,
440 'image_frames': kw('image_frames'),
441 'imageLinkWrap': kw('imageLinkWrap'),
442 'imagePath': kw('imagePath'),
443 'images': kw('images'),
444 'imageWrapIfAny': kw('imageWrapIfAny'),
445 'IMG_RESOURCE': kw('IMG_RESOURCE'),
446 'imgList': A,
447 'imgMap': kw('imgMap'),
448 'imgMapExtras': kw('imgMapExtras'),
449 'imgMax': kw('imgMax'),
450 'IMGMENU': kw('IMGMENU'),
451 'IMGMENUITEM': kw('IMGMENUITEM'),
452 'imgNameNotRandom': kw('imgNameNotRandom'),
453 'imgNamePrefix': kw('imgNamePrefix'),
454 'imgObjNum': kw('imgObjNum'),
455 'imgParams': kw('imgParams'),
456 'imgPath': kw('imgPath'),
457 'imgResource': A,
458 'imgStart': kw('imgStart'),
459 'IMGTEXT': kw('IMGTEXT'),
460 'imgText': A,
461 'import': kw('import'),
462 'inBranch': B,
463 'inc': kw('inc'),
464 'INCLUDE_TYPOSCRIPT': kw('INCLUDE_TYPOSCRIPT'),
465 'includeCSS': kw('includeCSS'),
466 'includeLibrary': kw('includeLibrary'),
467 'includeNotInMenu': kw('includeNotInMenu'),
468 'index': kw('index'),
469 'index_descrLgd': kw('index_descrLgd'),
470 'index_enable': kw('index_enable'),
471 'index_externals': kw('index_externals'),
472 'info': A,
473 'inlineStyle2TempFile': kw('inlineStyle2TempFile'),
474 'innerStdWrap': kw('innerStdWrap'),
475 'innerStdWrap_all': kw('innerStdWrap_all'),
476 'innerWrap': kw('innerWrap'),
477 'innerWrap2': kw('innerWrap2'),
478 'input': kw('input'),
479 'inputLevels': kw('inputLevels'),
480 'insertData': kw('insertData'),
481 'intensity': kw('intensity'),
482 'intTarget': kw('intTarget'),
483 'intval': kw('intval'),
484 'invert': kw('invert'),
485 'IP': A,
486 'IProcFunc': kw('IProcFunc'),
487 'isFalse': B,
488 'isGreaterThan': B,
489 'isInList': B,
490 'isLessThan': B,
491 'isPositive': B,
492 'isTrue': B,
493 'itemArrayProcFunc': kw('itemArrayProcFunc'),
494 'itemH': kw('itemH'),
495 'items': kw('items'),
496 'itemsProcFunc': kw('itemsProcFunc'),
497 'iterations': kw('iterations'),
498 'join': kw('join'),
499 'JSwindow': A,
500 'JSWindow': kw('JSWindow'),
501 'JSwindow_params': kw('JSwindow_params'),
502 'keep': kw('keep'),
503 'keepEntries': kw('keepEntries'),
504 'keepNonMatchedTags': kw('keepNonMatchedTags'),
505 'key': kw('key'),
506 'keyword3': B,
507 'LABEL': A,
508 'label': kw('label'),
509 'labelStdWrap': kw('labelStdWrap'),
510 'labelWrap': kw('labelWrap'),
511 'lang': kw('lang'),
512 'language': B,
513 'language_alt': kw('language_alt'),
514 'languageField': kw('languageField'),
515 'layout': A,
516 'left': kw('left'),
517 'leftjoin': kw('leftjoin'),
518 'levels': kw('levels'),
519 'leveltitle': B,
520 'leveluid': kw('leveluid'),
521 'lib': A,
522 'limit': kw('limit'),
523 'line': kw('line'),
524 'lineColor': kw('lineColor'),
525 'lineThickness': kw('lineThickness'),
526 'linkPrefix': kw('linkPrefix'),
527 'linkTitleToSelf': kw('linkTitleToSelf'),
528 'linkVars': kw('linkVars'),
529 'linkWrap': kw('linkWrap'),
530 'list': B,
531 'listNum': kw('listNum'),
532 'listOnlyInSingleTableView': kw('listOnlyInSingleTableView'),
533 'LIT': kw('LIT'),
534 'lm': kw('lm'),
535 'LOAD_REGISTER': kw('LOAD_REGISTER'),
536 'locale_all': kw('locale_all'),
537 'localNesting': kw('localNesting'),
538 'locationData': kw('locationData'),
539 'lockToIP': kw('lockToIP'),
540 'login': B,
541 'loginUser': A,
542 'longdescURL': kw('longdescURL'),
543 'lowColor': kw('lowColor'),
544 'lower': kw('lower'),
545 'LR': kw('LR'),
546 'mailform': B,
547 'mailto': kw('mailto'),
548 'main': kw('main'),
549 'makelinks': kw('makelinks'),
550 'markerWrap': kw('markerWrap'),
551 'marks': A,
552 'mask': kw('mask'),
553 'max': kw('max'),
554 'maxAge': kw('maxAge'),
555 'maxChars': kw('maxChars'),
556 'maxH': kw('maxH'),
557 'maxHeight': kw('maxHeight'),
558 'maxItems': kw('maxItems'),
559 'maxW': kw('maxW'),
560 'maxWidth': kw('maxWidth'),
561 'maxWInText': kw('maxWInText'),
562 'media': B,
563 'menu': B,
564 'menu_type': kw('menu_type'),
565 'menuHeight': kw('menuHeight'),
566 'menuName': kw('menuName'),
567 'menuOffset': kw('menuOffset'),
568 'menuWidth': kw('menuWidth'),
569 'message_page_is_being_generated': kw('message_page_is_being_generated'),
570 'message_preview': kw('message_preview'),
571 'META': kw('META'),
572 'meta': kw('meta'),
573 'metaCharset': kw('metaCharset'),
574 'method': kw('method'),
575 'min': kw('min'),
576 'minH': kw('minH'),
577 'minItems': kw('minItems'),
578 'minute': A,
579 'minW': kw('minW'),
580 'mod': B,
581 'mode': kw('mode'),
582 'module': A,
583 'month': A,
584 'move_wizard': A,
585 'MP_defaults': kw('MP_defaults'),
586 'MP_disableTypolinkClosestMPvalue': kw('MP_disableTypolinkClosestMPvalue'),
587 'MP_mapRootPoints': kw('MP_mapRootPoints'),
588 'MULTIMEDIA': kw('MULTIMEDIA'),
589 'multimedia': B,
590 'name': kw('name'),
591 'negate': B,
592 'nesting': kw('nesting'),
593 'neverHideAtCopy': kw('neverHideAtCopy'),
594 'new': A,
595 'NEW': B,
596 'new_wizard': A,
597 'newPageWiz': kw('newPageWiz'),
598 'newRecordFromTable': kw('newRecordFromTable'),
599 'newWindow': kw('newWindow'),
600 'newWizards': kw('newWizards'),
601 'next': kw('next'),
602 'niceText': kw('niceText'),
603 'nicetext': kw('nicetext'),
604 'NO': B,
605 'no_cache': kw('no_cache'),
606 'no_search': kw('no_search'),
607 'noAttrib': kw('noAttrib'),
608 'noCache': kw('noCache'),
609 'noCreateRecordsLink': kw('noCreateRecordsLink'),
610 'noLink': kw('noLink'),
611 'noMatchingValue_label': kw('noMatchingValue_label'),
612 'nonCachedSubst': kw('nonCachedSubst'),
613 'none': B,
614 'nonTypoTagStdWrap': kw('nonTypoTagStdWrap'),
615 'nonTypoTagUserFunc': kw('nonTypoTagUserFunc'),
616 'nonWrappedTag': kw('nonWrappedTag'),
617 'noOrderBy': kw('noOrderBy'),
618 'noPageTitle': kw('noPageTitle'),
619 'noResultObj': A,
620 'noThumbsInEB': kw('noThumbsInEB'),
621 'noTrimWrap': kw('noTrimWrap'),
622 'noValueInsert': kw('noValueInsert'),
623 'numRows': A,
624 'obj': kw('obj'),
625 'offset': kw('offset'),
626 'onlineWorkspaceInfo': kw('onlineWorkspaceInfo'),
627 'onlyCurrentPid': kw('onlyCurrentPid'),
628 'opacity': kw('opacity'),
629 'options': A,
630 'orderBy': kw('orderBy'),
631 'outerWrap': kw('outerWrap'),
632 'outline': kw('outline'),
633 'outputLevels': kw('outputLevels'),
634 'override': kw('override'),
635 'overrideAttribs': kw('overrideAttribs'),
636 'overrideId': kw('overrideId'),
637 'overridePageModule': kw('overridePageModule'),
638 'overrideWithExtension': kw('overrideWithExtension'),
639 'PAGE': kw('PAGE'),
640 'page': A,
641 'PAGE_TARGET': kw('PAGE_TARGET'),
642 'PAGE_TSCONFIG_ID': kw('PAGE_TSCONFIG_ID'),
643 'PAGE_TSCONFIG_IDLIST': kw('PAGE_TSCONFIG_IDLIST'),
644 'PAGE_TSCONFIG_STR': kw('PAGE_TSCONFIG_STR'),
645 'pageFrameObj': kw('pageFrameObj'),
646 'pages': B,
647 'pages_language_overlay': B,
648 'pageTitleFirst': kw('pageTitleFirst'),
649 'pageTree': A,
650 'parameter': kw('parameter'),
651 'params': kw('params'),
652 'parseFunc': kw('parseFunc'),
653 'parseFunc_RTE': B,
654 'parser': kw('parser'),
655 'password': kw('password'),
656 'paste': A,
657 'path': kw('path'),
658 'permissions': kw('permissions'),
659 'perms': A,
660 'pid': B,
661 'pid_list': kw('pid_list'),
662 'pidInList': kw('pidInList'),
663 'PIDinRootline': A,
664 'PIDupinRootline': A,
665 'pixelSpaceFontSizeRef': kw('pixelSpaceFontSizeRef'),
666 'plaintextLib': kw('plaintextLib'),
667 'plainTextStdWrap': kw('plainTextStdWrap'),
668 'plugin': A,
669 'postCObject': kw('postCObject'),
670 'postLineBlanks': kw('postLineBlanks'),
671 'postLineChar': kw('postLineChar'),
672 'postLineLen': kw('postLineLen'),
673 'postUserFunc': kw('postUserFunc'),
674 'postUserFuncInt': kw('postUserFuncInt'),
675 'preBlanks': kw('preBlanks'),
676 'preCObject': kw('preCObject'),
677 'prefix': kw('prefix'),
678 'prefixComment': kw('prefixComment'),
679 'prefixLocalAnchors': kw('prefixLocalAnchors'),
680 'prefixRelPathWith': kw('prefixRelPathWith'),
681 'preIfEmptyListNum': kw('preIfEmptyListNum'),
682 'preLineBlanks': kw('preLineBlanks'),
683 'preLineChar': kw('preLineChar'),
684 'preLineLen': kw('preLineLen'),
685 'prepend': kw('prepend'),
686 'preserveEntities': kw('preserveEntities'),
687 'preUserFunc': kw('preUserFunc'),
688 'prev': kw('prev'),
689 'preview': A,
690 'previewBorder': kw('previewBorder'),
691 'prevnextToSection': kw('prevnextToSection'),
692 'prioriCalc': kw('prioriCalc'),
693 'proc': kw('proc'),
694 'processor_allowUpscaling': kw('processor_allowUpscaling'),
695 'properties': kw('properties'),
696 'protect': kw('protect'),
697 'protectLvar': kw('protectLvar'),
698 'publish': A,
699 'publish_levels': kw('publish_levels'),
700 'quality': kw('quality'),
701 'RADIO': A,
702 'radio': kw('radio'),
703 'radioWrap': kw('radioWrap'),
704 'range': kw('range'),
705 'rawUrlEncode': kw('rawUrlEncode'),
706 'recipient': kw('recipient'),
707 'RECORDS': kw('RECORDS'),
708 'recursive': kw('recursive'),
709 'recursiveDelete': kw('recursiveDelete'),
710 'redirect': kw('redirect'),
711 'redirectToURL': kw('redirectToURL'),
712 'reduceColors': kw('reduceColors'),
713 'references': kw('references'),
714 'register': kw('register'),
715 'relPathPrefix': kw('relPathPrefix'),
716 'remap': kw('remap'),
717 'remapTag': kw('remapTag'),
718 'REMOTE_ADDR': kw('REMOTE_ADDR'),
719 'removeDefaultJS': kw('removeDefaultJS'),
720 'removeIfEquals': kw('removeIfEquals'),
721 'removeIfFalse': kw('removeIfFalse'),
722 'removeItems': kw('removeItems'),
723 'removeObjectsOfDummy': kw('removeObjectsOfDummy'),
724 'removePrependedNumbers': kw('removePrependedNumbers'),
725 'removeTags': kw('removeTags'),
726 'removeWrapping': kw('removeWrapping'),
727 'renderObj': A,
728 'renderWrap': kw('renderWrap'),
729 'REQ': A,
730 'required': B,
731 'reset': kw('reset'),
732 'resources': kw('resources'),
733 'RESTORE_REGISTER': kw('RESTORE_REGISTER'),
734 'resultObj': kw('resultObj'),
735 'returnLast': kw('returnLast'),
736 'returnUrl': kw('returnUrl'),
737 'rightjoin': kw('rightjoin'),
738 'rm': kw('rm'),
739 'rmTagIfNoAttrib': kw('rmTagIfNoAttrib'),
740 'RO': B,
741 'rootline': B,
742 'rotate': kw('rotate'),
743 'rows': kw('rows'),
744 'rowSpace': kw('rowSpace'),
745 'RTE': A,
746 'RTE_compliant': A,
747 'rules': kw('rules'),
748 'sample': kw('sample'),
749 'saveClipboard': kw('saveClipboard'),
750 'saveDocNew': kw('saveDocNew'),
751 'script': B,
752 'search': B,
753 'SEARCHRESULT': kw('SEARCHRESULT'),
754 'secondRow': kw('secondRow'),
755 'section': kw('section'),
756 'sectionIndex': kw('sectionIndex'),
757 'select': A,
758 'selectFields': kw('selectFields'),
759 'separator': kw('separator'),
760 'set': kw('set'),
761 'setContentToCurrent': kw('setContentToCurrent'),
762 'setCurrent': kw('setCurrent'),
763 'setfixed': kw('setfixed'),
764 'setOnly': kw('setOnly'),
765 'setup': A,
766 'shadow': kw('shadow'),
767 'SHARED': kw('SHARED'),
768 'sharpen': kw('sharpen'),
769 'shear': kw('shear'),
770 'short': kw('short'),
771 'shortcut': B,
772 'shortcutFrame': kw('shortcutFrame'),
773 'shortcutIcon': kw('shortcutIcon'),
774 'show': kw('show'),
775 'showAccessRestrictedPages': kw('showAccessRestrictedPages'),
776 'showActive': kw('showActive'),
777 'showClipControlPanelsDespiteOfCMlayers': kw('showClipControlPanelsDespiteOfCMlayers'),
778 'showFirst': kw('showFirst'),
779 'showHiddenPages': kw('showHiddenPages'),
780 'showHiddenRecords': kw('showHiddenRecords'),
781 'showHistory': kw('showHistory'),
782 'showPageIdWithTitle': kw('showPageIdWithTitle'),
783 'showTagFreeClasses': kw('showTagFreeClasses'),
784 'simulateDate': kw('simulateDate'),
785 'simulateUserGroup': kw('simulateUserGroup'),
786 'singlePid': kw('singlePid'),
787 'site_author': kw('site_author'),
788 'site_reserved': kw('site_reserved'),
789 'sitemap': B,
790 'sitetitle': kw('sitetitle'),
791 'siteUrl': kw('siteUrl'),
792 'size': kw('size'),
793 'solarize': kw('solarize'),
794 'sorting': kw('sorting'),
795 'source': kw('source'),
796 'space': kw('space'),
797 'spaceAfter': kw('spaceAfter'),
798 'spaceBefore': kw('spaceBefore'),
799 'spaceBelowAbove': kw('spaceBelowAbove'),
800 'spaceLeft': kw('spaceLeft'),
801 'spaceRight': kw('spaceRight'),
802 'spacing': kw('spacing'),
803 'spamProtectEmailAddresses': kw('spamProtectEmailAddresses'),
804 'spamProtectEmailAddresses_atSubst': kw('spamProtectEmailAddresses_atSubst'),
805 'spamProtectEmailAddresses_lastDotSubst': kw('spamProtectEmailAddresses_lastDotSubst'),
806 'SPC': B,
807 'special': kw('special'),
808 'split': A,
809 'splitChar': kw('splitChar'),
810 'splitRendering': kw('splitRendering'),
811 'src': kw('src'),
812 'stdheader': kw('stdheader'),
813 'stdWrap': A,
814 'stdWrap2': kw('stdWrap2'),
815 'strftime': kw('strftime'),
816 'stripHtml': kw('stripHtml'),
817 'styles': kw('styles'),
818 'submenuObjSuffixes': kw('submenuObjSuffixes'),
819 'subMenuOffset': kw('subMenuOffset'),
820 'submit': kw('submit'),
821 'subparts': A,
822 'subst_elementUid': kw('subst_elementUid'),
823 'substMarksSeparately': kw('substMarksSeparately'),
824 'substring': kw('substring'),
825 'swirl': kw('swirl'),
826 'sword': kw('sword'),
827 'sword_noMixedCase': kw('sword_noMixedCase'),
828 'SWORD_PARAMS': kw('SWORD_PARAMS'),
829 'sword_standAlone': kw('sword_standAlone'),
830 'sys_dmail': B,
831 'sys_domain': B,
832 'sys_filemounts': B,
833 'sys_language_mode': kw('sys_language_mode'),
834 'sys_language_overlay': kw('sys_language_overlay'),
835 'sys_language_uid': kw('sys_language_uid'),
836 'sys_note': B,
837 'sys_template': B,
838 'system': A,
839 'table': B,
840 'tableCellColor': kw('tableCellColor'),
841 'tableParams': kw('tableParams'),
842 'tables': kw('tables'),
843 'tableStdWrap': kw('tableStdWrap'),
844 'tableWidth': kw('tableWidth'),
845 'tags': kw('tags'),
846 'target': kw('target'),
847 'TCAdefaults': kw('TCAdefaults'),
848 'TCEFORM': kw('TCEFORM'),
849 'TCEMAIN': kw('TCEMAIN'),
850 'TDparams': kw('TDparams'),
851 'temp': A,
852 'TEMPLATE': kw('TEMPLATE'),
853 'template': A,
854 'templateContent': kw('templateContent'),
855 'templateFile': kw('templateFile'),
856 'TEXT': kw('TEXT'),
857 'text': B,
858 'textarea': kw('textarea'),
859 'textMargin': kw('textMargin'),
860 'textMargin_outOfText': kw('textMargin_outOfText'),
861 'textMaxLength': kw('textMaxLength'),
862 'textObjNum': kw('textObjNum'),
863 'textpic': B,
864 'textPos': kw('textPos'),
865 'thickness': kw('thickness'),
866 'this': B,
867 'thumbnailsByDefault': kw('thumbnailsByDefault'),
868 'tile': kw('tile'),
869 'time_stdWrap': kw('time_stdWrap'),
870 'tipafriendLib': kw('tipafriendLib'),
871 'title': kw('title'),
872 'titleLen': kw('titleLen'),
873 'titleText': kw('titleText'),
874 'tm': kw('tm'),
875 'TMENU': kw('TMENU'),
876 'TMENUITEM': kw('TMENUITEM'),
877 'token': kw('token'),
878 'top': B,
879 'totalWidth': kw('totalWidth'),
880 'transparentBackground': kw('transparentBackground'),
881 'transparentColor': kw('transparentColor'),
882 'treeLevel': A,
883 'trim': kw('trim'),
884 'true': B,
885 'tsdebug': A,
886 'tsdebug_tree': kw('tsdebug_tree'),
887 'TSFE': kw('TSFE'),
888 'type': kw('type'),
889 'typeNum': kw('typeNum'),
890 'types': kw('types'),
891 'typolink': A,
892 'uid': B,
893 'uidInList': kw('uidInList'),
894 'uniqueGlobal': B,
895 'uniqueLocal': B,
896 'unset': kw('unset'),
897 'unsetEmpty': B,
898 'updated': B,
899 'uploads': B,
900 'upper': kw('upper'),
901 'url': A,
902 'us': B,
903 'useCacheHash': kw('useCacheHash'),
904 'useLargestItemX': kw('useLargestItemX'),
905 'useLargestItemY': kw('useLargestItemY'),
906 'USER': kw('USER'),
907 'user': kw('user'),
908 'USER_INT': kw('USER_INT'),
909 'user_task': B,
910 'useragent': A,
911 'USERDEF1': B,
912 'USERDEF1RO': B,
913 'USERDEF2': B,
914 'USERDEF2RO': B,
915 'userdefined': kw('userdefined'),
916 'userFunc': A,
917 'userfunction': kw('userfunction'),
918 'usergroup': B,
919 'userid': kw('userid'),
920 'userProc': kw('userProc'),
921 'USR': B,
922 'USRRO': B,
923 'value': kw('value'),
924 'valueArray': kw('valueArray'),
925 'version': A,
926 'view': A,
927 'wave': kw('wave'),
928 'web_func': B,
929 'web_info': B,
930 'web_layout': B,
931 'web_list': B,
932 'web_ts': kw('web_ts'),
933 'where': kw('where'),
934 'width': kw('width'),
935 'wiz': kw('wiz'),
936 'wordSpacing': kw('wordSpacing'),
937 'workArea': kw('workArea'),
938 'workOnSubpart': A,
939 'wrap': kw('wrap'),
940 'wrap1': kw('wrap1'),
941 'wrap2': kw('wrap2'),
942 'wrap3': kw('wrap3'),
943 'wrapAfterTags': kw('wrapAfterTags'),
944 'wrapAlign': kw('wrapAlign'),
945 'wrapFieldName': kw('wrapFieldName'),
946 'wrapItemAndSub': kw('wrapItemAndSub'),
947 'wrapNonWrappedLines': kw('wrapNonWrappedLines'),
948 'wraps': kw('wraps'),
949 'xhtml_cleaning': kw('xhtml_cleaning'),
950 'xhtml_strict': B,
951 'xhtml_trans': B,
952 'xmlprologue': kw('xmlprologue'),
953 'XY': B
954 };
955 }();
956
957 var isOperatorChar = /[\+\-\*\&\%\/=<>!\?]/;
958 var inValue = false;
959
960 function readRegexp(stream) {
961 var escaped = false, next, inSet = false;
962 while ((next = stream.next()) != null) {
963 if (!escaped) {
964 if (next === "/" && !inSet) return;
965 if (next === "[") inSet = true;
966 else if (inSet && next === "]") inSet = false;
967 }
968 escaped = !escaped && next === "\\";
969 }
970 }
971
972 // Used as scratch variables to communicate multiple values without
973 // consing up tons of objects.
974 var type, content;
975
976 function ret(tp, style, cont) {
977 type = tp;
978 content = cont;
979 return style;
980 }
981
982 function tokenBase(stream, state) {
983 var ch = stream.next();
984 if (ch === "\n") {
985 inValue = false;
986 }
987
988 if (ch === "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
989 return ret("number", "number");
990 }
991 if (ch === "." && stream.match("..")) {
992 return ret("spread", "meta");
993 }
994 if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
995 return ret(ch);
996 }
997 if ((ch === '<' || ch === '>' || ch === '.' || (ch === '=' && stream.peek() !== '<'))) {
998 inValue = true;
999 return ret(ch, 'operator')
1000 }
1001 if (!inValue && /[\[\]\(\),;\:\.\<\>\=]/.test(ch)) {
1002 return ret(ch, 'operator')
1003 }
1004 if (ch === "0" && stream.eat(/x/i)) {
1005 stream.eatWhile(/[\da-f]/i);
1006 return ret("number", "number");
1007 }
1008 if (ch === "0" && stream.eat(/o/i)) {
1009 stream.eatWhile(/[0-7]/i);
1010 return ret("number", "number");
1011 }
1012 if (ch === "0" && stream.eat(/b/i)) {
1013 stream.eatWhile(/[01]/i);
1014 return ret("number", "number");
1015 }
1016 if (/\d/.test(ch)) {
1017 stream.match(/^\d*(?:\.\d+)?(?:[eE][+\-]?\d+)?/);
1018 return ret("number", "number");
1019 }
1020 if (ch === "/") {
1021 if (stream.eat("*")) {
1022 state.tokenize = tokenComment;
1023 return tokenComment(stream, state);
1024 }
1025 if (stream.eat("/")) {
1026 stream.skipToEnd();
1027 return ret("comment", "comment");
1028 }
1029 if (expressionAllowed(stream, state, 1)) {
1030 readRegexp(stream);
1031 stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
1032 return ret("regexp", "string-2");
1033 }
1034
1035 stream.eatWhile(isOperatorChar);
1036 return ret("operator", "operator", stream.current());
1037 }
1038 if (ch === "`") {
1039 state.tokenize = tokenQuasi;
1040 return tokenQuasi(stream, state);
1041 }
1042 if (ch === "#") {
1043 stream.skipToEnd();
1044 return ret("comment", "comment");
1045 }
1046 if (isOperatorChar.test(ch)) {
1047 if (ch !== ">" || !state.lexical || state.lexical.type !== ">") {
1048 stream.eatWhile(isOperatorChar);
1049 }
1050 return ret("operator", "operator", stream.current());
1051 }
1052 if (wordRE.test(ch)) {
1053 stream.eatWhile(wordRE);
1054 var word = stream.current();
1055 if (keywords.propertyIsEnumerable(word)) {
1056 var kw = keywords[word];
1057 return ret(kw.type, kw.style, word);
1058 }
1059 if (word === "async" && stream.match(/^\s*[\(\w]/, false)) {
1060 return ret("async", "keyword", word);
1061 }
1062 if (inValue) {
1063 return ret('string', 'string', word);
1064 }
1065 return ret("variable", "other", word);
1066 }
1067 }
1068
1069 function tokenString(quote) {
1070 return function(stream, state) {
1071 var escaped = false, next;
1072 while ((next = stream.next()) != null) {
1073 if (next == quote && !escaped) break;
1074 escaped = !escaped && next === "\\";
1075 }
1076 if (!escaped) state.tokenize = tokenBase;
1077 return ret("string", "string");
1078 };
1079 }
1080
1081 function tokenComment(stream, state) {
1082 var maybeEnd = false, ch;
1083 while (ch = stream.next()) {
1084 if (ch === "/" && maybeEnd) {
1085 state.tokenize = tokenBase;
1086 break;
1087 }
1088 maybeEnd = (ch === "*");
1089 }
1090 return ret("comment", "comment");
1091 }
1092
1093 function tokenQuasi(stream, state) {
1094 var escaped = false, next;
1095 while ((next = stream.next()) != null) {
1096 if (!escaped && (next === "`" || next === "$" && stream.eat("{"))) {
1097 state.tokenize = tokenBase;
1098 break;
1099 }
1100 escaped = !escaped && next === "\\";
1101 }
1102 return ret("quasi", "string-2", stream.current());
1103 }
1104
1105 var brackets = "([{}])";
1106 // This is a crude lookahead trick to try and notice that we're
1107 // parsing the argument patterns for a fat-arrow function before we
1108 // actually hit the arrow token. It only works if the arrow is on
1109 // the same line as the arguments and there's no strange noise
1110 // (comments) in between. Fallback is to only notice when we hit the
1111 // arrow, and not declare the arguments as locals for the arrow
1112 // body.
1113 function findFatArrow(stream, state) {
1114 if (state.fatArrowAt) state.fatArrowAt = null;
1115 var arrow = stream.string.indexOf("=>", stream.start);
1116 if (arrow < 0) return;
1117
1118 var depth = 0, sawSomething = false;
1119 for (var pos = arrow - 1; pos >= 0; --pos) {
1120 var ch = stream.string.charAt(pos);
1121 var bracket = brackets.indexOf(ch);
1122 if (bracket >= 0 && bracket < 3) {
1123 if (!depth) {
1124 ++pos;
1125 break;
1126 }
1127 if (--depth == 0) {
1128 if (ch === "(") sawSomething = true;
1129 break;
1130 }
1131 } else if (bracket >= 3 && bracket < 6) {
1132 ++depth;
1133 } else if (wordRE.test(ch)) {
1134 sawSomething = true;
1135 } else if (/["'\/]/.test(ch)) {
1136 return;
1137 } else if (sawSomething && !depth) {
1138 ++pos;
1139 break;
1140 }
1141 }
1142 if (sawSomething && !depth) state.fatArrowAt = pos;
1143 }
1144
1145 // Parser
1146
1147 var atomicTypes = {
1148 "atom": true,
1149 "number": true,
1150 "variable": true,
1151 "string": true,
1152 "regexp": true
1153 };
1154
1155 function TSLexical(indented, column, type, align, prev, info) {
1156 this.indented = indented;
1157 this.column = column;
1158 this.type = type;
1159 this.prev = prev;
1160 this.info = info;
1161 if (align != null) this.align = align;
1162 }
1163
1164 function inScope(state, varname) {
1165 for (var v = state.localVars; v; v = v.next)
1166 if (v.name == varname) return true;
1167 for (var cx = state.context; cx; cx = cx.prev) {
1168 for (var v = cx.vars; v; v = v.next)
1169 if (v.name == varname) return true;
1170 }
1171 }
1172
1173 function parseTS(state, style, type, content, stream) {
1174 var cc = state.cc;
1175 // Communicate our context to the combinators.
1176 // (Less wasteful than consing up a hundred closures on every call.)
1177 cx.state = state;
1178 cx.stream = stream;
1179 cx.marked = null, cx.cc = cc;
1180 cx.style = style;
1181
1182 if (!state.lexical.hasOwnProperty("align"))
1183 state.lexical.align = true;
1184
1185 while (true) {
1186 var combinator = cc.length ? cc.pop() : statement;
1187 if (combinator(type, content)) {
1188 while (cc.length && cc[cc.length - 1].lex)
1189 cc.pop()();
1190 if (cx.marked) return cx.marked;
1191 if (type === "variable" && inScope(state, content)) return "variable-2";
1192 return style;
1193 }
1194 }
1195 }
1196
1197 // Combinator utils
1198
1199 var cx = {state: null, column: null, marked: null, cc: null};
1200
1201 function pass() {
1202 for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
1203 }
1204
1205 function cont() {
1206 pass.apply(null, arguments);
1207 return true;
1208 }
1209
1210 function register(varname) {
1211 function inList(list) {
1212 for (var v = list; v; v = v.next)
1213 if (v.name == varname) return true;
1214 return false;
1215 }
1216
1217 var state = cx.state;
1218 cx.marked = "def";
1219 if (state.context) {
1220 if (inList(state.localVars)) return;
1221 state.localVars = {name: varname, next: state.localVars};
1222 } else {
1223 if (inList(state.globalVars)) return;
1224 if (parserConfig.globalVars)
1225 state.globalVars = {name: varname, next: state.globalVars};
1226 }
1227 }
1228
1229 // Combinators
1230
1231 var defaultVars = {name: "this", next: {name: "arguments"}};
1232
1233 function pushcontext() {
1234 cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
1235 cx.state.localVars = defaultVars;
1236 }
1237
1238 function popcontext() {
1239 cx.state.localVars = cx.state.context.vars;
1240 cx.state.context = cx.state.context.prev;
1241 }
1242
1243 function pushlex(type, info) {
1244 var result = function() {
1245 var state = cx.state, indent = state.indented;
1246 if (state.lexical.type === "stat") indent = state.lexical.indented;
1247 else for (var outer = state.lexical; outer && outer.type === ")" && outer.align; outer = outer.prev)
1248 indent = outer.indented;
1249 state.lexical = new TSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
1250 };
1251 result.lex = true;
1252 return result;
1253 }
1254
1255 function poplex() {
1256 var state = cx.state;
1257 if (state.lexical.prev) {
1258 if (state.lexical.type === ")")
1259 state.indented = state.lexical.indented;
1260 state.lexical = state.lexical.prev;
1261 }
1262 }
1263
1264 poplex.lex = true;
1265
1266 function expect(wanted) {
1267 function exp(type) {
1268 if (type == wanted) return cont();
1269 else if (wanted === ";") return pass();
1270 else return cont(exp);
1271 };
1272 return exp;
1273 }
1274
1275 function statement(type, value) {
1276 if (type === "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
1277 if (type === "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex);
1278 if (type === "keyword b") return cont(pushlex("form"), statement, poplex);
1279 if (type === "{") return cont(pushlex("}"), block, poplex);
1280 if (type === ";") return cont();
1281 if (type === "if") {
1282 if (cx.state.lexical.info === "else" && cx.state.cc[cx.state.cc.length - 1] == poplex) {
1283 cx.state.cc.pop()();
1284 }
1285 return cont(pushlex("form"), parenExpr, statement, poplex, maybeelse);
1286 }
1287 if (type === "function") return cont(functiondef);
1288 if (type === "for") return cont(pushlex("form"), forspec, statement, poplex);
1289 if (type === "variable") {
1290 return cont(pushlex("stat"), maybelabel);
1291 }
1292 if (type === "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"),
1293 block, poplex, poplex);
1294 if (type === "case") return cont(expression, expect(":"));
1295 if (type === "default") return cont(expect(":"));
1296 if (type === "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
1297 statement, poplex, popcontext);
1298 if (type === "class") return cont(pushlex("form"), className, poplex);
1299 if (type === "export") return cont(pushlex("stat"), afterExport, poplex);
1300 if (type === "import") return cont(pushlex("stat"), afterImport, poplex);
1301 if (type === "module") return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex)
1302 if (type === "async") return cont(statement)
1303 if (value === "@") return cont(expression, statement)
1304 return pass(pushlex("stat"), expression, expect(";"), poplex);
1305 }
1306
1307 function expression(type) {
1308 return expressionInner(type, false);
1309 }
1310
1311 function expressionNoComma(type) {
1312 return expressionInner(type, true);
1313 }
1314
1315 function parenExpr(type) {
1316 if (type !== "(") return pass()
1317 return cont(pushlex(")"), expression, expect(")"), poplex)
1318 }
1319
1320 function expressionInner(type, noComma) {
1321 var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
1322 if (atomicTypes.hasOwnProperty(type)) {
1323 return cont(maybeop);
1324 }
1325 if (type === "keyword c") {
1326 return cont(noComma ? maybeexpressionNoComma : maybeexpression);
1327 }
1328 if (type === "(") {
1329 return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
1330 }
1331 if (type === "operator" || type === "spread") {
1332 return cont(noComma ? expressionNoComma : expression);
1333 }
1334 if (type === "[") {
1335 return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
1336 }
1337 if (type === "{") {
1338 return contCommasep(objprop, "}", null, maybeop);
1339 }
1340 return cont();
1341 }
1342
1343 function maybeexpression(type) {
1344 if (type.match(/[;\}\)\],]/)) return pass();
1345 return pass(expression);
1346 }
1347
1348 function maybeexpressionNoComma(type) {
1349 if (type.match(/[;\}\)\],]/)) return pass();
1350 return pass(expressionNoComma);
1351 }
1352
1353 function maybeoperatorComma(type, value) {
1354 if (type === ",") return cont(expression);
1355 return maybeoperatorNoComma(type, value, false);
1356 }
1357
1358 function maybeoperatorNoComma(type, value, noComma) {
1359 var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
1360 var expr = noComma == false ? expression : expressionNoComma;
1361 if (type === "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
1362 if (type === "operator") {
1363 if (/\+\+|--/.test(value)) return cont(me);
1364 if (value === "?") return cont(expression, expect(":"), expr);
1365 return cont(expr);
1366 }
1367 if (type === "quasi") {
1368 return pass(quasi, me);
1369 }
1370 if (type === ";") return;
1371 if (type === "(") return contCommasep(expressionNoComma, ")", "call", me);
1372 if (type === ".") return cont(property, me);
1373 if (type === "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
1374 }
1375
1376 function quasi(type, value) {
1377 if (type !== "quasi") return pass();
1378 if (value.slice(value.length - 2) !== "${") return cont(quasi);
1379 return cont(expression, continueQuasi);
1380 }
1381
1382 function continueQuasi(type) {
1383 if (type === "}") {
1384 cx.marked = "string-2";
1385 cx.state.tokenize = tokenQuasi;
1386 return cont(quasi);
1387 }
1388 }
1389
1390 function arrowBody(type) {
1391 findFatArrow(cx.stream, cx.state);
1392 return pass(type === "{" ? statement : expression);
1393 }
1394
1395 function arrowBodyNoComma(type) {
1396 findFatArrow(cx.stream, cx.state);
1397 return pass(type === "{" ? statement : expressionNoComma);
1398 }
1399
1400 function maybeTarget(noComma) {
1401 return function(type) {
1402 if (type === ".") return cont(noComma ? targetNoComma : target);
1403 else return pass(noComma ? expressionNoComma : expression);
1404 };
1405 }
1406
1407 function target(_, value) {
1408 if (value === "target") {
1409 cx.marked = "keyword";
1410 return cont(maybeoperatorComma);
1411 }
1412 }
1413
1414 function targetNoComma(_, value) {
1415 if (value === "target") {
1416 cx.marked = "keyword";
1417 return cont(maybeoperatorNoComma);
1418 }
1419 }
1420
1421 function maybelabel(type) {
1422 if (type === ":") return cont(poplex, statement);
1423 return pass(maybeoperatorComma, expect(";"), poplex);
1424 }
1425
1426 function property(type) {
1427 if (type === "variable") {
1428 cx.marked = "property";
1429 return cont();
1430 }
1431 }
1432
1433 function objprop(type, value) {
1434 if (type === "async") {
1435 cx.marked = "property";
1436 return cont(objprop);
1437 } else if (type === "variable" || cx.style === "keyword") {
1438 cx.marked = "property";
1439 if (value === "get" || value === "set") return cont(getterSetter);
1440 return cont(afterprop);
1441 } else if (type === "number" || type === "string") {
1442 cx.marked = cx.style + " property";
1443 return cont(afterprop);
1444 } else if (type === "jsonld-keyword") {
1445 return cont(afterprop);
1446 } else if (type === "modifier") {
1447 return cont(objprop)
1448 } else if (type === "[") {
1449 return cont(expression, expect("]"), afterprop);
1450 } else if (type === "spread") {
1451 return cont(expression, afterprop);
1452 } else if (type === ":") {
1453 return pass(afterprop)
1454 }
1455 }
1456
1457 function getterSetter(type) {
1458 if (type !== "variable") return pass(afterprop);
1459 cx.marked = "property";
1460 return cont(functiondef);
1461 }
1462
1463 function afterprop(type) {
1464 if (type === ":") return cont(expressionNoComma);
1465 if (type === "(") return pass(functiondef);
1466 }
1467
1468 function commasep(what, end, sep) {
1469 function proceed(type, value) {
1470 if (sep ? sep.indexOf(type) > -1 : type === ",") {
1471 var lex = cx.state.lexical;
1472 if (lex.info === "call") lex.pos = (lex.pos || 0) + 1;
1473 return cont(function(type, value) {
1474 if (type == end || value == end) return pass()
1475 return pass(what)
1476 }, proceed);
1477 }
1478 if (type == end || value == end) return cont();
1479 return cont(expect(end));
1480 }
1481
1482 return function(type, value) {
1483 if (type == end || value == end) return cont();
1484 return pass(what, proceed);
1485 };
1486 }
1487
1488 function contCommasep(what, end, info) {
1489 for (var i = 3; i < arguments.length; i++)
1490 cx.cc.push(arguments[i]);
1491 return cont(pushlex(end, info), commasep(what, end), poplex);
1492 }
1493
1494 function block(type) {
1495 if (type === "}") return cont();
1496 return pass(statement, block);
1497 }
1498
1499 function typeexpr(type) {
1500 if (type === "variable") {
1501 cx.marked = "type";
1502 return cont(afterType);
1503 }
1504 if (type === "string" || type === "number" || type === "atom") return cont(afterType);
1505 if (type === "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
1506 if (type === "(") return cont(commasep(typearg, ")"), maybeReturnType)
1507 }
1508
1509 function maybeReturnType(type) {
1510 if (type === "=>") return cont(typeexpr)
1511 }
1512
1513 function typeprop(type, value) {
1514 if (type === "variable" || cx.style === "keyword") {
1515 cx.marked = "property"
1516 return cont(typeprop)
1517 } else if (value === "?") {
1518 return cont(typeprop)
1519 } else if (type === ":") {
1520 return cont(typeexpr)
1521 } else if (type === "[") {
1522 return cont(expression, null, expect("]"), typeprop)
1523 }
1524 }
1525
1526 function typearg(type) {
1527 if (type === "variable") return cont(typearg)
1528 else if (type === ":") return cont(typeexpr)
1529 }
1530
1531 function afterType(type, value) {
1532 if (value === "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
1533 if (value === "|" || type === ".") return cont(typeexpr)
1534 if (type === "[") return cont(expect("]"), afterType)
1535 if (value === "extends") return cont(typeexpr)
1536 }
1537
1538 function vardef() {
1539 return pass(pattern, null, maybeAssign, vardefCont);
1540 }
1541
1542 function pattern(type, value) {
1543 if (type === "modifier") return cont(pattern)
1544 if (type === "variable") {
1545 register(value);
1546 return cont();
1547 }
1548 if (type === "spread") return cont(pattern);
1549 if (type === "[") return contCommasep(pattern, "]");
1550 if (type === "{") return contCommasep(proppattern, "}");
1551 }
1552
1553 function proppattern(type, value) {
1554 if (type === "variable" && !cx.stream.match(/^\s*:/, false)) {
1555 register(value);
1556 return cont(maybeAssign);
1557 }
1558 if (type === "variable") cx.marked = "property";
1559 if (type === "spread") return cont(pattern);
1560 if (type === "}") return pass();
1561 return cont(expect(":"), pattern, maybeAssign);
1562 }
1563
1564 function maybeAssign(_type, value) {
1565 if (value === "=") return cont(expressionNoComma);
1566 }
1567
1568 function vardefCont(type) {
1569 if (type === ",") return cont(vardef);
1570 }
1571
1572 function maybeelse(type, value) {
1573 if (type === "keyword b" && value === "else") return cont(pushlex("form", "else"), statement, poplex);
1574 }
1575
1576 function forspec(type) {
1577 if (type === "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
1578 }
1579
1580 function forspec1(type) {
1581 if (type === "var") return cont(vardef, expect(";"), forspec2);
1582 if (type === ";") return cont(forspec2);
1583 if (type === "variable") return cont(formaybeinof);
1584 return pass(expression, expect(";"), forspec2);
1585 }
1586
1587 function formaybeinof(_type, value) {
1588 if (value === "in" || value === "of") {
1589 cx.marked = "keyword";
1590 return cont(expression);
1591 }
1592 return cont(maybeoperatorComma, forspec2);
1593 }
1594
1595 function forspec2(type, value) {
1596 if (type === ";") return cont(forspec3);
1597 if (value === "in" || value === "of") {
1598 cx.marked = "keyword";
1599 return cont(expression);
1600 }
1601 return pass(expression, expect(";"), forspec3);
1602 }
1603
1604 function forspec3(type) {
1605 if (type !== ")") cont(expression);
1606 }
1607
1608 function functiondef(type, value) {
1609 if (value === "*") {
1610 cx.marked = "keyword";
1611 return cont(functiondef);
1612 }
1613 if (type === "variable") {
1614 register(value);
1615 return cont(functiondef);
1616 }
1617 if (type === "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, null, statement, popcontext);
1618 }
1619
1620 function funarg(type) {
1621 if (type === "spread") return cont(funarg);
1622 return pass(pattern, null, maybeAssign);
1623 }
1624
1625 function classExpression(type, value) {
1626 // Class expressions may have an optional name.
1627 if (type === "variable") return className(type, value);
1628 return classNameAfter(type, value);
1629 }
1630
1631 function className(type, value) {
1632 if (type === "variable") {
1633 register(value);
1634 return cont(classNameAfter);
1635 }
1636 }
1637
1638 function classNameAfter(type, value) {
1639 if (value === "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, classNameAfter)
1640 if (value === "extends" || value === "implements")
1641 return cont(expression, classNameAfter);
1642 if (type === "{") return cont(pushlex("}"), classBody, poplex);
1643 }
1644
1645 function classBody(type, value) {
1646 if (type === "variable" || cx.style === "keyword") {
1647 if ((value === "async" || value === "static" || value === "get" || value === "set") &&
1648 cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) {
1649 cx.marked = "keyword";
1650 return cont(classBody);
1651 }
1652 cx.marked = "property";
1653 return cont(functiondef, classBody);
1654 }
1655 if (type === "[")
1656 return cont(expression, expect("]"), functiondef, classBody)
1657 if (value === "*") {
1658 cx.marked = "keyword";
1659 return cont(classBody);
1660 }
1661 if (type === ";") return cont(classBody);
1662 if (type === "}") return cont();
1663 if (value === "@") return cont(expression, classBody)
1664 }
1665
1666 function classfield(type, value) {
1667 if (value === "?") return cont(classfield)
1668 if (type === ":") return cont(typeexpr, maybeAssign)
1669 if (value === "=") return cont(expressionNoComma)
1670 return pass(functiondef)
1671 }
1672
1673 function afterExport(type, value) {
1674 if (value === "*") {
1675 cx.marked = "keyword";
1676 return cont(maybeFrom, expect(";"));
1677 }
1678 if (value === "default") {
1679 cx.marked = "keyword";
1680 return cont(expression, expect(";"));
1681 }
1682 if (type === "{") return cont(commasep(exportField, "}"), maybeFrom, expect(";"));
1683 return pass(statement);
1684 }
1685
1686 function exportField(type, value) {
1687 if (value === "as") {
1688 cx.marked = "keyword";
1689 return cont(expect("variable"));
1690 }
1691 if (type === "variable") return pass(expressionNoComma, exportField);
1692 }
1693
1694 function afterImport(type) {
1695 if (type === "string") return cont();
1696 return pass(importSpec, maybeMoreImports, maybeFrom);
1697 }
1698
1699 function importSpec(type, value) {
1700 if (type === "{") return contCommasep(importSpec, "}");
1701 if (type === "variable") register(value);
1702 if (value === "*") cx.marked = "keyword";
1703 return cont(maybeAs);
1704 }
1705
1706 function maybeMoreImports(type) {
1707 if (type === ",") return cont(importSpec, maybeMoreImports)
1708 }
1709
1710 function maybeAs(_type, value) {
1711 if (value === "as") {
1712 cx.marked = "keyword";
1713 return cont(importSpec);
1714 }
1715 }
1716
1717 function maybeFrom(_type, value) {
1718 if (value === "from") {
1719 cx.marked = "keyword";
1720 return cont(expression);
1721 }
1722 }
1723
1724 function arrayLiteral(type) {
1725 if (type === "]") return cont();
1726 return pass(commasep(expressionNoComma, "]"));
1727 }
1728
1729 function isContinuedStatement(state, textAfter) {
1730 return state.lastType === "operator" || state.lastType === "," ||
1731 isOperatorChar.test(textAfter.charAt(0)) ||
1732 /[,.]/.test(textAfter.charAt(0));
1733 }
1734
1735 // Interface
1736
1737 return {
1738 startState: function(basecolumn) {
1739 var state = {
1740 tokenize: tokenBase,
1741 lastType: "sof",
1742 cc: [],
1743 lexical: new TSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
1744 localVars: parserConfig.localVars,
1745 context: parserConfig.localVars && {vars: parserConfig.localVars},
1746 indented: basecolumn || 0
1747 };
1748 if (parserConfig.globalVars && typeof parserConfig.globalVars === "object")
1749 state.globalVars = parserConfig.globalVars;
1750 return state;
1751 },
1752
1753 token: function(stream, state) {
1754 if (stream.sol()) {
1755 if (!state.lexical.hasOwnProperty("align"))
1756 state.lexical.align = false;
1757 state.indented = stream.indentation();
1758 findFatArrow(stream, state);
1759 }
1760 if (state.tokenize != tokenComment && stream.eatSpace()) return null;
1761 var style = state.tokenize(stream, state);
1762 if (type === "comment") return style;
1763 state.lastType = type === "operator" && (content === "++" || content === "--") ? "incdec" : type;
1764 return parseTS(state, style, type, content, stream);
1765 },
1766
1767 indent: function(state, textAfter) {
1768 if (state.tokenize == tokenComment) return CodeMirror.Pass;
1769 if (state.tokenize != tokenBase) return 0;
1770 var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical, top
1771 // Kludge to prevent 'maybelse' from blocking lexical scope pops
1772 if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
1773 var c = state.cc[i];
1774 if (c == poplex) lexical = lexical.prev;
1775 else if (c != maybeelse) break;
1776 }
1777 while ((lexical.type === "stat" || lexical.type === "form") &&
1778 (firstChar === "}" || ((top = state.cc[state.cc.length - 1]) &&
1779 (top == maybeoperatorComma || top == maybeoperatorNoComma) &&
1780 !/^[,\.=+\-*:?[\(]/.test(textAfter))))
1781 lexical = lexical.prev;
1782 if (statementIndent && lexical.type === ")" && lexical.prev.type === "stat")
1783 lexical = lexical.prev;
1784 var type = lexical.type, closing = firstChar == type;
1785
1786 if (type === "vardef") return lexical.indented + (state.lastType === "operator" || state.lastType === "," ? lexical.info + 1 : 0);
1787 else if (type === "form" && firstChar === "{") return lexical.indented;
1788 else if (type === "form") return lexical.indented + indentUnit;
1789 else if (type === "stat")
1790 return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
1791 else if (lexical.info === "switch" && !closing && parserConfig.doubleIndentSwitch != false)
1792 return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
1793 else if (lexical.align) return lexical.column + (closing ? 0 : 1);
1794 else return lexical.indented + (closing ? 0 : indentUnit);
1795 },
1796
1797 electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
1798 blockCommentStart: "/*",
1799 blockCommentEnd: "*/",
1800 lineComment: "#",
1801 fold: "brace",
1802 closeBrackets: "()[]{}''\"\"``",
1803
1804 helperType: "typoscript",
1805
1806 expressionAllowed: expressionAllowed,
1807 skipExpression: function(state) {
1808 var top = state.cc[state.cc.length - 1];
1809 if (top == expression || top == expressionNoComma) state.cc.pop()
1810 }
1811 };
1812 });
1813 });