summaryrefslogtreecommitdiffstats
path: root/kate/data/matlab.xml
blob: b4b6fbc0bd90e6468a2be738fb47be5ec1fed284 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?xml version="1.0" encoding="UTF-8"?>
<!--
  ====================================================================
  MATLAB syntax highlighting file for the KDE editors Kate and Kwrite
  ====================================================================
      works (at least) for MATLAB versions 5.3, 6.0, 6.1, 6.5, 6.5sp1
      works with Kate 2.2 and with Kwrite 4.2 (KDE 3.2)

  This file works only for syntactically correct MATLAB code. For incorrect
  code, the behaviour is undefined. One exception is made: Incomplete strings
  with missing closing delimiter are highlighted separately, just as in the
  native editor of MATLAB does.

  Highlighting errors never propagate across line breaks.

  Most of this XML file is straight and simple. Only the character ' (&apos;)
  needs nontrivial treatment, since it is both a postfix operator indicating
  complex conjugate transpose (adjoint) and a string delimiter. It is an
  adjoint operator in the following positions:
  1) immediately after an identifier (variable, function, but not keyword)
  2) immediately after a number literal
  3) immediately after the closing parenthesis ), ] and }
  4) immediately after a simple transpose operator .'
  5) immediately after another adjoint operator '
  In all other cases it is a string delimiter.

  This is implemented using look-ahead regexps. If one of the entities in the
  above cases 1-4 (identifier, number literal, ...) matches and look-ahead
  shows that it is followed by a ', the entity is highlighted and control is
  passed to the special context _adjoint, whose sole purpose is to correctly
  highlight a series of ' (thus covering case 5 as well). _adjoint immediately
  returns to the default context _normal.

  MATLAB number literals are different from those in C and similar languages:
  a) All numbers literals are doubles. There is no distinction between float and int.
  b) There is no notation of hex or oct base integers.
  c) The symbols i or j may be attached to a number to indicate a multiplication
     with the imaginary unit.

  MATLAB identifiers have to start with a letter followed by any number of letters,
  digits and underscores.

  There is a small number of reserved keywords, which cannot be the target of an
  assignment. All other identifiers (including all of the many 100s of MATLAB commands)
  can be redefined. Consequently, only the reserved keywords are highlighted.

  At the end of the XML file, there is MATLAB testing code for developers.

  Change log:
  19-Nov-03  Created from scratch.
  08-Mar-04  Small corrections. Added default colors of MATLAB editor.

  Author: Stefan Stoll, Swiss Federal Institute of Technology, Zurich
-->

<!DOCTYPE language SYSTEM "language.dtd">

<language name="Matlab" version="1.20" kateversion="2.2" section="Scientific" extensions="*.m;*.M" mimetype="text/mfile" casesensitive="1">
  <highlighting>

    <!-- Reserved keywords in MATLAB -->
    <list name="KeywordsList">
      <item> break </item>
      <item> case </item>
      <item> catch </item>
      <item> continue </item>
      <item> else </item>
      <item> elseif </item>
      <item> end </item>
      <item> for </item>
      <item> function </item>
      <item> global </item>
      <item> if </item>
      <item> otherwise </item>
      <item> persistent </item>
      <item> return </item>
      <item> switch </item>
      <item> try </item>
      <item> while </item>
    </list>

    <contexts>

      <context name="_normal" attribute="Normal Text" lineEndContext="#pop">

        <!-- Look-ahead for adjoint ' after variable, number literal, closing braces and .' -->
        <RegExpr context="_adjoint" attribute="Variable" String="[a-zA-Z]\w*(?=')" />
        <RegExpr context="_adjoint" attribute="Number" String="(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?[ij]?(?=')" />
        <RegExpr context="_adjoint" attribute="Delimiter" String="[\)\]}](?=')" />
        <RegExpr context="_adjoint" attribute="Operator" String="\.'(?=')" />

        <!-- If ' is not the adjoint operator, it starts a string or an unterminated string -->
        <RegExpr context="#stay" attribute="String" String="'[^']*(''[^']*)*'(?=[^']|$)" />
        <RegExpr context="#stay" attribute="Incomplete String" String="'[^']*(''[^']*)*" />

        <!-- Handling of keywords, comments, system commands, identifiers, numbers and braces -->
        <keyword context="#stay" attribute="Keyword" String="KeywordsList" />
        <RegExpr context="#stay" attribute="Comment" String="%.*$" />
        <RegExpr context="#stay" attribute="System" String="!.*$" />
        <RegExpr context="#stay" attribute="Variable" String="[a-zA-Z]\w*" />
        <RegExpr context="#stay" attribute="Number" String="(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?[ij]?" />
        <AnyChar context="#stay" attribute="Delimiter" String="()[]{}"/>

        <!-- Three and two-character operators -->
        <StringDetect context="#stay" attribute="Operator" String="..."/>
        <StringDetect context="#stay" attribute="Operator" String="=="/>
        <StringDetect context="#stay" attribute="Operator" String="~="/>
        <StringDetect context="#stay" attribute="Operator" String="&lt;="/>
        <StringDetect context="#stay" attribute="Operator" String="&gt;="/>
        <StringDetect context="#stay" attribute="Operator" String="&amp;&amp;"/>
        <StringDetect context="#stay" attribute="Operator" String="||"/>
        <StringDetect context="#stay" attribute="Operator" String=".*"/>
        <StringDetect context="#stay" attribute="Operator" String=".^"/>
        <StringDetect context="#stay" attribute="Operator" String="./"/>
        <StringDetect context="#stay" attribute="Operator" String=".'"/>

        <!-- Single-character operators -->
        <AnyChar context="#stay" attribute="Operator" String="*+-/\&amp;|&lt;&gt;~^=,;:@"/>

      </context>

      <!-- Context entered after encountering an ' adjoint operator -->
      <context name="_adjoint" attribute="Operator" lineEndContext="#pop">
        <RegExpr context="#pop" attribute="Operator" String="'+" />
      </context>

    </contexts>

    <itemDatas>
      <itemData name="Normal Text" defStyleNum="dsNormal" />
      <itemData name="Variable" defStyleNum="dsNormal" />
      <itemData name="Operator" defStyleNum="dsNormal"/>
      <itemData name="Number" defStyleNum="dsFloat" />
      <itemData name="Delimiter" defStyleNum="dsNormal" />
      <itemData name="String" defStyleNum="dsString" color="#b20000"/>
      <itemData name="System" defStyleNum="dsBaseN" color="#b28c00"/>
      <itemData name="Incomplete String" defStyleNum="dsChar" color="#a020f0"/>
      <itemData name="Keyword"  defStyleNum="dsNormal" color="#0000ff"/>
      <itemData name="Comment" defStyleNum="dsComment" color="#009900"/>
    </itemDatas>
    <!-- MATLAB 6.5 default color scheme
          keywords             #0000ff
          comments             #228b22
          strings              #b20000
          unterminated strings #a020f0
          system commands      #b28c00
          errors               #ff0000
          all others           #000000
    -->

  </highlighting>

  <general>
    <comments>
      <comment name="singleLine" start="% " />
    </comments>
    <keywords casesensitive="1" weakDeliminator=""/>
  </general>

</language>
<!--
%%=====================================================
% MATLAB test code for Kate/Kwrite syntax highlighting
%%=====================================================

% Numbers _____________________________________________
5, 5.5, .1, 0.1, 0.4e5, 1.2e-5, 5i, 5.3i, 6j, .345+3i
5', 5.5', .1', 0.1', 0.4e5', 1.2e-5', 5i', 5.3i', 6j', .345+3i'

% Operators ___________________________________________
% relational operators
'asdf'~=4, c<=4, d>=4, a<b, a>b, a==b, b||c, b&&c
% elementwise arithmetic operators
a.^b, a.*b a./b, 1:4:5
% single-character binary arithmetic
a+3, a-3, a*2, a^3, a/3, a\3, a|b, a&b
% unary operators
a = ~g; g = @sfdgdsf(sdfsd,345); g.' + 1i.' - ('asdf').'
% separators and delimiter
(asd),[sadf];{asdf},;;,;;;()
% continuation
a = 1+ ...
  2;

% Strings and adjoint _________________________________
% incomplete strings
'string
'str''
'str''ing
% complete strings
'string' % simple string
'''' % string containing '
'str''ing' % one string containing '
'string' 'string'  % two strings
'asdf'  'asdf''' variable  % two strings and a variable
'asdf''asdf''   fsgdfg' + (asdf)' - 'asdf'.' + []''''.';''
'sadf'.' % string transpose
% adjoint
{'asdf'}' + 1
('asdf')' + 1
['asdf']' + 1
'' var''' % empty string, var with >1 adjoints
[5]'*{5}'*('asd')'.'+(5)'*6'*asdf'*asdf'.'  % many adjoints
A'*B + 1      % adjoint
A.'*B + 1     % transpose
A.'.'*B + 1   % double transpose
A'.' + 1      % adjoint, then transpose
A.''          % transpose, then adjoint

% System command ______________________________________
!hostname
!cp * /tmp

% Reserved keywords ___________________________________
function, persistent, global
switch, case, otherwise
if, else, elseif
try, catch
for, while, break, continue
end, return
function, FUNCTION, Function  % case sensitive!
-->