1/**
2 * @license
3 * Copyright (C) 2011 Kitware Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *    http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @fileoverview
20 * Registers a language handler for MUMPS.
21 *
22 *
23 * To use, include prettify.js and this file in your HTML page.
24 * Then put your code in an HTML tag like
25 *      <pre class="prettyprint lang-mumps">(my SQL code)</pre>
26 *
27 * Commands, intrinsic functions and variables taken from ISO/IEC 11756:1999(E)
28 *
29 * @author chris.harris@kitware.com
30 *
31 * Known issues:
32 *
33 * - Currently can't distinguish between keywords and local or global variables having the same name
34 *   for exampe SET IF="IF?"
35 * - m file are already used for MatLab hence using mumps.
36 */
37
38(function () {
39
40
41var commands = 'B|BREAK|'       +
42               'C|CLOSE|'       +
43               'D|DO|'          +
44               'E|ELSE|'        +
45               'F|FOR|'         +
46               'G|GOTO|'        +
47               'H|HALT|'        +
48               'H|HANG|'        +
49               'I|IF|'          +
50               'J|JOB|'         +
51               'K|KILL|'        +
52               'L|LOCK|'        +
53               'M|MERGE|'       +
54               'N|NEW|'         +
55               'O|OPEN|'        +
56               'Q|QUIT|'        +
57               'R|READ|'        +
58               'S|SET|'         +
59               'TC|TCOMMIT|'    +
60               'TRE|TRESTART|'  +
61               'TRO|TROLLBACK|' +
62               'TS|TSTART|'     +
63               'U|USE|'         +
64               'V|VIEW|'        +
65               'W|WRITE|'       +
66               'X|XECUTE';
67
68var intrinsicVariables = 'D|DEVICE|'       +
69                         'EC|ECODE|'       +
70                         'ES|ESTACK|'      +
71                         'ET|ETRAP|'       +
72                         'H|HOROLOG|'      +
73                         'I|IO|'           +
74                         'J|JOB|'          +
75                         'K|KEY|'          +
76                         'P|PRINCIPAL|'    +
77                         'Q|QUIT|'         +
78                         'ST|STACK|'       +
79                         'S|STORAGE|'      +
80                         'SY|SYSTEM|'      +
81                         'T|TEST|'         +
82                         'TL|TLEVEL|'      +
83                         'TR|TRESTART|'    +
84                         'X|'              +
85                         'Y|'              +
86                         'Z[A-Z]*|';
87
88var intrinsicFunctions = 'A|ASCII|'        +
89                         'C|CHAR|'         +
90                         'D|DATA|'         +
91                         'E|EXTRACT|'      +
92                         'F|FIND|'         +
93                         'FN|FNUMBER|'     +
94                         'G|GET|'          +
95                         'J|JUSTIFY|'      +
96                         'L|LENGTH|'       +
97                         'NA|NAME|'        +
98                         'O|ORDER|'        +
99                         'P|PIECE|'        +
100                         'QL|QLENGTH|'     +
101                         'QS|QSUBSCRIPT|'  +
102                         'Q|QUERY|'        +
103                         'R|RANDOM|'       +
104                         'RE|REVERSE|'     +
105                         'S|SELECT|'       +
106                         'ST|STACK|'       +
107                         'T|TEXT|'         +
108                         'TR|TRANSLATE|'   +
109                         'V|VIEW|'         *
110                         'Z[A-Z]*|';
111
112var intrinsic = intrinsicVariables + intrinsicFunctions;
113
114
115var shortcutStylePatterns = [
116         // Whitespace
117         [PR['PR_PLAIN'],       /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
118         // A double or single quoted, possibly multi-line, string.
119         [PR['PR_STRING'],      /^(?:"(?:[^"]|\\.)*")/, null, '"']
120  ];
121
122var fallthroughStylePatterns = [
123         // A line comment that starts with ;
124         [PR['PR_COMMENT'],     /^;[^\r\n]*/, null, ';'],
125         // Add intrinsic variables and functions as declarations, there not really but it mean
126         // they will hilighted differently from commands.
127         [PR['PR_DECLARATION'], new RegExp('^(?:\\$(?:' + intrinsic + '))\\b', 'i'), null],
128         // Add commands as keywords
129         [PR['PR_KEYWORD'], new RegExp('^(?:[^\\$]' + commands + ')\\b', 'i'), null],
130         // A number is a decimal real literal or in scientific notation.
131         [PR['PR_LITERAL'],
132          /^[+-]?(?:(?:\.\d+|\d+(?:\.\d*)?)(?:E[+\-]?\d+)?)/i],
133         // An identifier
134         [PR['PR_PLAIN'], /^[a-z][a-zA-Z0-9]*/i],
135         // Exclude $ % and ^
136         [PR['PR_PUNCTUATION'], /^[^\w\t\n\r\xA0\"\$;%\^]|_/]
137  ];
138// Can't use m as its already used for MatLab
139PR.registerLangHandler(PR.createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns), ['mumps']);
140})();
141