summaryrefslogtreecommitdiff
path: root/eo.sublime-syntax
blob: df7e42c325670b715fd69cd358894c44bd7bc862 (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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
%YAML 1.2
---
name: Eo / Eot files
file_extensions: [eo, eot]
scope: eo

contexts:
  main:
    - include: struct
    - include: function
    - include: enum
    - include: class
    - include: import
    - include: comments
  import:
    - match: "import"
      scope: keyword.other
      set: [semicolon, file_name]

#class matcher
  class:
    - match: "(class|interface|abstract|mixin) "
      scope: keyword.other
      set: [class.inheritence ,typename]
  class.inheritence:
    #case for no inheritence definition
    - match: "\\{"
      set: class.body
    - match: "\\("
      set:
        - match: "[A-Za-z0-9_]+"
          scope: entity.name
          push:
            - match: ","
              pop: true
            - match: ""
              pop: true
        - match: "\\)"
          set:
            - match: "\\{"
              set: class.body

  class.body:
    - include: comments
    - include: close_rule
    - include: eo_prefix_define
    - include: event_prefix_define
    - include: legacy_prefix_define
    - include: data_define
    - match: "methods"
      scope: keyword.other
      push:
         - match: "\\{"
           set: class.methods

    - match: "implements"
      scope: keyword.other
      push:
         - match: "\\{"
           set: class.implements

    - match: "events"
      scope: keyword.other
      push:
         - match: "\\{"
           set: class.events
    - match: "constructors"
      scope: keyword.other
      push:
         - match: "\\{"
           set: class.constructors
    - match: "parts"
      scope: keyword.other
      push:
         - match: "\\{"
           set: class.parts

  class.constructors:
    - include: close_rule


  class.methods:
    - include: comments
    - include: close_rule
    - match: "\\@property"
      scope: storage.type
      push: [class.method.property.define, class.method.property.mods, func_name]
    - match: "[\\.]?[A-Za-z0-9_]+"
      push: [class.method.define, class.method.mods]

  class.method.property.define:
    - include: close_rule
    - include: comments
    - match: "values"
      scope: keyword.other
      push: [class.method.property.values]
    - match: "(get|set)"
      scope: keyword.other
      push: [class.method.property.getset]
    - match: "keys"
      scope: keyword.other
      push: [class.method.property.keys]

  class.method.property.keys:
    - include: comments
    - include: close_rule
    - match: "[A-Za-z0-9_]+"
      scope: entity.name
      push: [semicolon, type.definition, colon]

  class.method.property.getset:
    - include: comments
    - include: close_rule
    - include: legacy_define
    - include: return_define
    - match: "values"
      scope: storage.type
      push: [class.method.property.values]

  class.method.property.values:
    - include: comments
    - include: close_rule
    - match: "[A-Za-z0-9_]+"
      scope: entity.name
      push: [semicolon, type.definition, colon]

  class.method.property.mods:
    - match: "(@protected|@class)"
      scope: storage.type
    - match: "\\{"
      pop: true

  class.method.define:
    - include: comments
    - include: close_rule
    - include: legacy_define
    - include: return_define
    - match: "params"
      scope: keyword.other
      push: [class.method.params]

  class.method.params:
    - include: comments
    - include: close_rule
    - match: "(@in|@out|@inout|@cref)"
      scope: storage.type
    - match: "[A-Za-z0-9_]+"
      scope: entity.name
      push: [semicolon, type.definition, colon]

  class.method.mods:
    - match: "(@protected|@const|@class)"
      scope: storage.type
    - match: "\\{"
      pop: true



  class.implements:
    - include: close_rule
    - include: comments
    - match: "[A-Za-z0-9_]+"
      scope: entity.name
      push: class.implements.rule

  class.implements.rule:
    - match: "[A-Za-z0-9_]+"
      scope: entity.name
    - match: "{"
      set: class.implements.property
    - match: ";"
      pop: true

  class.implements.property:
    - include: close_rule
    - include: comments
    - match: "(get;|set;)"
      scope: keyword.other

  class.parts:
    - include: close_rule
    - include: comments
    - match: "[A-Za-z0-9_]"
      push: [semicolon, typename, colon]

  class.events:
    - include: close_rule
    - include: comments
    - match: "[A-Za-z0-9_,]+"
      scope: variable.name
      push: [semicolon, type.definition, class.events.modifier_or_colon]

  class.events.modifier_or_colon:
    - include: "colon"
    - match: "(@hot|@restart)"
      scope: keyword.other
      pop: true

  func_name:
    - match: "[.]?[A-Za-z0-9_]*"
      pop: true


#enum matcher
  enum:
    - match: "enum "
      scope: keyword.other
      set: [enum.body, curly_brace_open, typename]

  enum.body:
    - include: close_rule
    - include: comments
    - include: legacy_define
    #TODO make a real and usefull formular parser
    - match: "[A-Za-z0-9_]+"
      scope: entity.name
    - match: "="
    - match: "(\\+|\\-|\\/|\\*|\\<<|\\>>|\\(|\\))"
    - match: ","
#function
  function:
    - match: "function "
      scope: keyword.other
      set: [function.body, curly_brace_open, typename]
  function.body:
    - include: "comments"
    - match : "params"
      scope: keyword.other
      pop: true

#struct matcher
  struct:
    - match: "struct "
      scope: keyword.other
      set: [struct.def, typename]

  struct.def:
    - match: ";"
      pop: true
    - match: '{'
      set: [struct.body]

  struct.body:
    - include: comments
    - include: close_rule
    - match: "[A-Za-z0-9_]+"
      scope: entity.name
      push: [semicolon, type.definition, colon]

#typedefinitions according to eolian
  type.definition:
    - match: "void_ptr"
      scope: storage.type
      pop: true
    - match: "(list|array|accessor|iterator|hash)"
      scope: storage.type
      set: [tag_close, type.definition, tag_open]
    - match: "free"
      scope: storage.type
      set: [brace_close, c_type_name, comma, type.definition, brace_open]
    - match: "(own|const|ptr)"
      scope: storage.type
      set: [brace_close, type.definition, brace_open]
    - match: "[A-Za-z0-9_]+[.]"
      scope: entity.name.type
      set: [typename]
    - match: "[A-Za-z0-9_]+"
      scope: entity.name.type
      pop: true


  comments:
    - match: "\\[\\["
      scope: comment.block
      push:
         - match: "[[:alnum:]]*"
           scope: comment.block
         - match: "\\]\\]"
           scope: comment.block
           pop: true
    - match: "\\/\\*"
      scope: comment.block
      push:
          - match: "\\*\\/"
            scope: comment.block
            pop: true
          - match: "[[:alnum:]]*"
            scope: comment.block
    - match: "//"
      scope: comment.block
      push:
         - match: "[[:alnum:]]*"
           scope: comment.block
         - match: "\n"
           pop: true

# include helpers

  legacy_define:
    - match: "legacy"
      scope: keyword.other
      push: [semicolon, c_type_name, colon]

  return_define:
    - match: "return"
      scope: keyword.other
      push: [semicolon,type.definition,colon]

  eo_prefix_define:
    - match: "eo_prefix"
      scope: keyword.other
      push: [semicolon, c_type_name, colon]
  legacy_prefix_define:
    - match: "legacy_prefix"
      scope: keyword.other
      push: [semicolon, c_type_name, colon]
  event_prefix_define:
    - match: "event_prefix"
      scope: keyword.other
      push: [semicolon, c_type_name, colon]
  data_define:
    - match: "data"
      scope: keyword.other
      push: [semicolon, c_type_name, colon]

# some little helpers
  file_name:
    - match: "[A-Za-z0-9_]+"
      scope: storage.type
      pop: true

# matches a typename according to the eo typenames
  typename:
    - match: "([A-Za-z0-9_]+)[.]"
      #pop: true
      #push : typename
      captures:
        1: entity.name
    - match: "([A-Za-z0-9_]+)"
      scope: entity.name
      pop: true

# matches a typename according to c
  c_type_name:
    - match: "[A-Za-z0-9_]+"
      scope: entity.name
      pop: true

  close_rule:
    - match: "\\}"
      pop: true

  tag_open:
    - match: "<"
      pop: true

  tag_close:
    - match: ">"
      pop: true

  brace_open:
    - match: "\\("
      pop: true

  brace_close:
    - match: "\\)"
      pop: true

  semicolon:
    - match: "\\;"
      pop: true

  colon:
    - match: "\\:"
      pop: true

  curly_brace_open:
    - match: "\\{"
      pop: true

  equal:
    - match: "="
      pop: true

  comma:
    - match: ","
      pop: true