rtext 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGELOG +20 -0
  2. data/{README → README.rdoc} +5 -1
  3. data/RText_Protocol +444 -0
  4. data/Rakefile +10 -10
  5. data/lib/rtext/completer.rb +32 -26
  6. data/lib/rtext/context_builder.rb +113 -59
  7. data/lib/rtext/default_loader.rb +73 -8
  8. data/lib/rtext/default_service_provider.rb +30 -14
  9. data/lib/rtext/frontend/config.rb +58 -0
  10. data/lib/rtext/frontend/connector.rb +233 -0
  11. data/lib/rtext/frontend/connector_manager.rb +81 -0
  12. data/lib/rtext/frontend/context.rb +56 -0
  13. data/lib/rtext/generic.rb +13 -0
  14. data/lib/rtext/instantiator.rb +30 -7
  15. data/lib/rtext/language.rb +54 -27
  16. data/lib/rtext/link_detector.rb +57 -0
  17. data/lib/rtext/message_helper.rb +77 -0
  18. data/lib/rtext/parser.rb +19 -68
  19. data/lib/rtext/serializer.rb +18 -3
  20. data/lib/rtext/service.rb +182 -118
  21. data/lib/rtext/tokenizer.rb +102 -0
  22. data/test/completer_test.rb +327 -70
  23. data/test/context_builder_test.rb +671 -91
  24. data/test/instantiator_test.rb +153 -0
  25. data/test/integration/backend.out +10 -0
  26. data/test/integration/crash_on_request_editor.rb +12 -0
  27. data/test/integration/ecore_editor.rb +50 -0
  28. data/test/integration/frontend.log +25138 -0
  29. data/test/integration/model/invalid_encoding.invenc +2 -0
  30. data/test/integration/model/test.crash_on_request +18 -0
  31. data/test/integration/model/test.crashing_backend +18 -0
  32. data/test/integration/model/test.dont_open_socket +0 -0
  33. data/test/integration/model/test.invalid_cmd_line +0 -0
  34. data/test/integration/model/test.not_in_rtext +0 -0
  35. data/test/integration/model/test_large_with_errors.ect3 +43523 -0
  36. data/test/integration/model/test_metamodel.ect +18 -0
  37. data/test/integration/model/test_metamodel2.ect +5 -0
  38. data/test/integration/model/test_metamodel_error.ect2 +3 -0
  39. data/test/integration/model/test_metamodel_ok.ect2 +18 -0
  40. data/test/integration/test.rb +684 -0
  41. data/test/link_detector_test.rb +276 -0
  42. data/test/message_helper_test.rb +118 -0
  43. data/test/rtext_test.rb +4 -1
  44. data/test/serializer_test.rb +96 -1
  45. data/test/tokenizer_test.rb +125 -0
  46. metadata +36 -10
  47. data/RText_Plugin_Implementation_Guide +0 -268
  48. data/lib/rtext_plugin/connection_manager.rb +0 -59
@@ -12,6 +12,7 @@ module TestMM
12
12
  extend RGen::MetamodelBuilder::ModuleExtension
13
13
  class TestNode2 < RGen::MetamodelBuilder::MMBase
14
14
  has_attr 'text', String
15
+ has_attr 'unlabled', String
15
16
  end
16
17
  class TestNode < RGen::MetamodelBuilder::MMBase
17
18
  has_attr 'text', String
@@ -37,10 +38,10 @@ end
37
38
 
38
39
  def test_after_command
39
40
  options = complete TestMM, <<-END
40
- TestNode |
41
+ TestNode |
41
42
  END
42
43
  assert_options([
43
- ["<unlabled1>", "<EString>"],
44
+ ["\"\"", "[unlabled1] <EString>"],
44
45
  ["text:", "<EString>"],
45
46
  ["nums:", "<EInt>"],
46
47
  ["related:", "<TestNode>"],
@@ -50,25 +51,46 @@ end
50
51
 
51
52
  def test_lable_prefix
52
53
  options = complete TestMM, <<-END
53
- TestNode t|
54
+ TestNode t|
54
55
  END
55
56
  assert_options([
56
- ["text:", "<EString>"]
57
+ ["\"\"", "[unlabled1] <EString>"],
58
+ ["text:", "<EString>"],
59
+ ["nums:", "<EInt>"],
60
+ ["related:", "<TestNode>"],
61
+ ["others:", "<TestNode>"]
62
+ ], options)
63
+ end
64
+
65
+ def test_lable_within
66
+ options = complete TestMM, <<-END
67
+ TestNode t|ext
68
+ END
69
+ assert_options([
70
+ ["\"\"", "[unlabled1] <EString>"],
71
+ ["text:", "<EString>"],
72
+ ["nums:", "<EInt>"],
73
+ ["related:", "<TestNode>"],
74
+ ["others:", "<TestNode>"]
57
75
  ], options)
58
76
  end
59
77
 
60
78
  def test_unlabled_prefix
61
79
  options = complete TestMM, <<-END
62
- TestNode u|
80
+ TestNode u|
63
81
  END
64
82
  assert_options([
65
- ["<unlabled1>", "<EString>"]
83
+ ["\"\"", "[unlabled1] <EString>"],
84
+ ["text:", "<EString>"],
85
+ ["nums:", "<EInt>"],
86
+ ["related:", "<TestNode>"],
87
+ ["others:", "<TestNode>"]
66
88
  ], options)
67
89
  end
68
90
 
69
91
  def test_after_labled_value
70
92
  options = complete TestMM, <<-END
71
- TestNode nums: 1, |
93
+ TestNode nums: 1, |
72
94
  END
73
95
  assert_options([
74
96
  ["text:", "<EString>"],
@@ -77,12 +99,46 @@ def test_after_labled_value
77
99
  ], options)
78
100
  end
79
101
 
102
+ def test_after_labled_value_directly_after_comma
103
+ options = complete TestMM, <<-END
104
+ TestNode nums: 1,|
105
+ END
106
+ assert_options([
107
+ ["text:", "<EString>"],
108
+ ["related:", "<TestNode>"],
109
+ ["others:", "<TestNode>"]
110
+ ], options)
111
+ end
112
+
113
+ def test_after_second_labled_value_directly_after_comma
114
+ options = complete TestMM, <<-END
115
+ TestNode nums: 1, text: "a",|
116
+ END
117
+ assert_options([
118
+ ["related:", "<TestNode>"],
119
+ ["others:", "<TestNode>"]
120
+ ], options)
121
+ end
122
+
80
123
  def test_after_unlabled_value
81
124
  options = complete TestMM, <<-END
82
- TestNode "bla", |
125
+ TestNode "bla", |
126
+ END
127
+ assert_options([
128
+ ["0", "[unlabled2] <EInt>"],
129
+ ["text:", "<EString>"],
130
+ ["nums:", "<EInt>"],
131
+ ["related:", "<TestNode>"],
132
+ ["others:", "<TestNode>"]
133
+ ], options)
134
+ end
135
+
136
+ def test_after_unlabled_value_directly_after_comma
137
+ options = complete TestMM, <<-END
138
+ TestNode "bla",|
83
139
  END
84
140
  assert_options([
85
- ["<unlabled2>", "<EInt>"],
141
+ ["0", "[unlabled2] <EInt>"],
86
142
  ["text:", "<EString>"],
87
143
  ["nums:", "<EInt>"],
88
144
  ["related:", "<TestNode>"],
@@ -92,7 +148,19 @@ end
92
148
 
93
149
  def test_after_unlabled_value2
94
150
  options = complete TestMM, <<-END
95
- TestNode "bla", 1, |
151
+ TestNode "bla", 1, |
152
+ END
153
+ assert_options([
154
+ ["text:", "<EString>"],
155
+ ["nums:", "<EInt>"],
156
+ ["related:", "<TestNode>"],
157
+ ["others:", "<TestNode>"]
158
+ ], options)
159
+ end
160
+
161
+ def test_after_unlabled_value3
162
+ options = complete TestMM, <<-END
163
+ TestNode "bla", 1,|
96
164
  END
97
165
  assert_options([
98
166
  ["text:", "<EString>"],
@@ -104,7 +172,7 @@ end
104
172
 
105
173
  def test_after_array
106
174
  options = complete TestMM, <<-END
107
- TestNode nums: [1, 2], |
175
+ TestNode nums: [1, 2], |
108
176
  END
109
177
  assert_options([
110
178
  ["text:", "<EString>"],
@@ -115,7 +183,7 @@ end
115
183
 
116
184
  def test_after_array_direct
117
185
  options = complete TestMM, <<-END
118
- TestNode nums: [1, 2]|
186
+ TestNode nums: [1, 2]|
119
187
  END
120
188
  assert_options([
121
189
  ], options)
@@ -123,80 +191,122 @@ end
123
191
 
124
192
  def test_value_int
125
193
  options = complete TestMM, <<-END
126
- TestNode nums: |
194
+ TestNode nums: |
195
+ END
196
+ assert_options([
197
+ ["0", "<EInt>"],
198
+ ], options)
199
+ end
200
+
201
+ def test_value_int_part
202
+ options = complete TestMM, <<-END
203
+ TestNode nums: 0|
127
204
  END
128
205
  assert_options([
129
- ["0", nil],
130
- ["1", nil],
131
- ["2", nil],
132
- ["3", nil],
133
- ["4", nil]
206
+ ["0", "<EInt>"]
134
207
  ], options)
135
208
  end
136
209
 
137
210
  def test_value_boolean
138
211
  options = complete TestMM, <<-END
139
- TestNode3 bool: |
212
+ TestNode3 bool: |
213
+ END
214
+ assert_options([
215
+ ["true", "<EBoolean>"],
216
+ ["false", "<EBoolean>"],
217
+ ], options)
218
+ end
219
+
220
+ def test_value_boolean_part
221
+ options = complete TestMM, <<-END
222
+ TestNode3 bool: t|
223
+ END
224
+ assert_options([
225
+ ["true", "<EBoolean>"],
226
+ ["false", "<EBoolean>"],
227
+ ], options)
228
+ end
229
+
230
+ def test_value_boolean_full
231
+ options = complete TestMM, <<-END
232
+ TestNode3 bool: true|
140
233
  END
141
234
  assert_options([
142
- ["true", nil],
143
- ["false", nil],
235
+ ["true", "<EBoolean>"],
236
+ ["false", "<EBoolean>"],
144
237
  ], options)
145
238
  end
146
239
 
147
240
  def test_value_float
148
241
  options = complete TestMM, <<-END
149
- TestNode3 float: |
242
+ TestNode3 float: |
243
+ END
244
+ assert_options([
245
+ ["0.0", "<EFloat>"],
246
+ ], options)
247
+ end
248
+
249
+ def test_value_float_part
250
+ options = complete TestMM, <<-END
251
+ TestNode3 float: 0|
252
+ END
253
+ assert_options([
254
+ ["0.0", "<EFloat>"],
255
+ ], options)
256
+ end
257
+
258
+ def test_value_float_full
259
+ options = complete TestMM, <<-END
260
+ TestNode3 float: 0.0|
150
261
  END
151
262
  assert_options([
152
- ["0.0", nil],
153
- ["1.0", nil],
154
- ["2.0", nil],
155
- ["3.0", nil],
156
- ["4.0", nil]
263
+ ["0.0", "<EFloat>"],
157
264
  ], options)
158
265
  end
159
266
 
160
267
  def test_value_enum
161
268
  options = complete TestMM, <<-END
162
- TestNode3 enum: |
269
+ TestNode3 enum: |
270
+ END
271
+ assert_options([
272
+ ["A", "<SomeEnum>"],
273
+ ["B", "<SomeEnum>"],
274
+ ["non-word*chars", "<SomeEnum>"]
275
+ ], options)
276
+ end
277
+
278
+ def test_value_enum_part
279
+ options = complete TestMM, <<-END
280
+ TestNode3 enum: A|
163
281
  END
164
282
  assert_options([
165
- ["A", nil],
166
- ["B", nil],
167
- ["non-word*chars", nil]
283
+ ["A", "<SomeEnum>"],
284
+ ["B", "<SomeEnum>"],
285
+ ["non-word*chars", "<SomeEnum>"]
168
286
  ], options)
169
287
  end
170
288
 
171
289
  def test_array_value
172
290
  options = complete TestMM, <<-END
173
- TestNode nums: [|
291
+ TestNode nums: [|
174
292
  END
175
293
  assert_options([
176
- ["0", nil],
177
- ["1", nil],
178
- ["2", nil],
179
- ["3", nil],
180
- ["4", nil]
294
+ ["0", "<EInt>"],
181
295
  ], options)
182
296
  end
183
297
 
184
298
  def test_array_value2
185
299
  options = complete TestMM, <<-END
186
- TestNode nums: [1,|
300
+ TestNode nums: [1,|
187
301
  END
188
302
  assert_options([
189
- ["0", nil],
190
- ["1", nil],
191
- ["2", nil],
192
- ["3", nil],
193
- ["4", nil]
303
+ ["0", "<EInt>"],
194
304
  ], options)
195
305
  end
196
306
 
197
307
  def test_reference_value
198
308
  options = complete(TestMM, %Q(\
199
- TestNode related: |\
309
+ TestNode related: |\
200
310
  ), lambda { |r| [
201
311
  RText::Completer::CompletionOption.new("A", "a"),
202
312
  RText::Completer::CompletionOption.new("B", "b") ] })
@@ -206,9 +316,78 @@ def test_reference_value
206
316
  ], options)
207
317
  end
208
318
 
319
+ def test_reference_value_part
320
+ options = complete(TestMM, %Q(\
321
+ TestNode related: /My/|\
322
+ ), lambda { |r| [
323
+ RText::Completer::CompletionOption.new("/My/Target", "a"),
324
+ RText::Completer::CompletionOption.new("/MyOther/Target", "b") ] })
325
+ assert_options([
326
+ ["/My/Target", "a"],
327
+ ["/MyOther/Target", "b"]
328
+ ], options)
329
+ end
330
+
209
331
  def test_reference_value_no_ref_completion_provider
210
332
  options = complete TestMM, <<-END
211
- TestNode related: |
333
+ TestNode related: |
334
+ END
335
+ assert_options([
336
+ ], options)
337
+ end
338
+
339
+ def test_reference_value_in_array
340
+ options = complete(TestMM, %Q(\
341
+ TestNode others: |
342
+ ), lambda { |r| [
343
+ RText::Completer::CompletionOption.new("A", "a"),
344
+ RText::Completer::CompletionOption.new("B", "b") ] })
345
+ assert_options([
346
+ ["A", "a"],
347
+ ["B", "b"],
348
+ ], options)
349
+ end
350
+
351
+ def test_reference_value_in_array_after_bracket
352
+ options = complete(TestMM, %Q(\
353
+ TestNode others: [|
354
+ ), lambda { |r| [
355
+ RText::Completer::CompletionOption.new("A", "a"),
356
+ RText::Completer::CompletionOption.new("B", "b") ] })
357
+ assert_options([
358
+ ["A", "a"],
359
+ ["B", "b"],
360
+ ], options)
361
+ end
362
+
363
+ def test_reference_value_in_array_second_value
364
+ options = complete(TestMM, %Q(\
365
+ TestNode others: [xxx, |
366
+ ), lambda { |r| [
367
+ RText::Completer::CompletionOption.new("A", "a"),
368
+ RText::Completer::CompletionOption.new("B", "b") ] })
369
+ assert_options([
370
+ ["A", "a"],
371
+ ["B", "b"],
372
+ ], options)
373
+ end
374
+
375
+ def test_reference_value_nested
376
+ options = complete(TestMM, %Q(\
377
+ TestNode {
378
+ TestNode SimpleState, others: [|/StatemachineMM/State]
379
+ ), lambda { |r| [
380
+ RText::Completer::CompletionOption.new("A", "a"),
381
+ RText::Completer::CompletionOption.new("B", "b") ] })
382
+ assert_options([
383
+ ["A", "a"],
384
+ ["B", "b"],
385
+ ], options)
386
+ end
387
+
388
+ def test_after_curly
389
+ options = complete TestMM, <<-END
390
+ TestNode {|
212
391
  END
213
392
  assert_options([
214
393
  ], options)
@@ -216,8 +395,8 @@ end
216
395
 
217
396
  def test_children
218
397
  options = complete TestMM, <<-END
219
- TestNode {
220
- |
398
+ TestNode {
399
+ |
221
400
  END
222
401
  assert_options([
223
402
  ["TestNode", "<unlabled1>, <unlabled2>"],
@@ -228,65 +407,115 @@ end
228
407
 
229
408
  def test_children_with_role
230
409
  options = complete TestMM, <<-END
231
- TestNode {
232
- child2RoleA:
233
- |
410
+ TestNode {
411
+ child2RoleA:
412
+ |
413
+ END
414
+ assert_options([
415
+ ["TestNode2", "<unlabled>"],
416
+ ], options)
417
+ end
418
+
419
+ def test_after_child_role
420
+ options = complete TestMM, <<-END
421
+ TestNode {
422
+ child2RoleA:|
423
+ END
424
+ assert_options([
425
+ ], options)
426
+ end
427
+
428
+ def test_after_child_role2
429
+ options = complete TestMM, <<-END
430
+ TestNode {
431
+ child2RoleA: |
432
+ END
433
+ assert_options([
434
+ ], options)
435
+ end
436
+
437
+ def test_after_child_role3
438
+ options = complete TestMM, <<-END
439
+ TestNode {
440
+ child2RoleA: [|
441
+ END
442
+ assert_options([
443
+ ], options)
444
+ end
445
+
446
+ def test_after_child_role4
447
+ options = complete TestMM, <<-END
448
+ TestNode {
449
+ child2RoleA: [ |
234
450
  END
235
451
  assert_options([
236
- ["TestNode2", ""],
237
452
  ], options)
238
453
  end
239
454
 
240
455
  def test_children_with_role_array
241
456
  options = complete TestMM, <<-END
242
- TestNode {
243
- child2RoleB: [
244
- |
457
+ TestNode {
458
+ child2RoleB: [
459
+ |
245
460
  END
246
461
  assert_options([
247
- ["TestNode2", ""],
462
+ ["TestNode2", "<unlabled>"],
248
463
  ], options)
249
464
  end
250
465
 
251
466
  def test_children_prefix
252
467
  options = complete TestMM, <<-END
253
- TestNode {
254
- child2RoleB: [
255
- X|
468
+ TestNode {
469
+ child2RoleB: [
470
+ X|
256
471
  END
257
472
  assert_options([
473
+ ["TestNode2", "<unlabled>"],
258
474
  ], options)
259
475
  end
260
476
 
261
477
  def test_children_inside_childrole
262
478
  options = complete TestMM, <<-END
263
- TestNode {
264
- child2RoleA:
265
- TestNode2 |
479
+ TestNode {
480
+ child2RoleA:
481
+ TestNode2 |
266
482
  END
267
483
  assert_options([
484
+ ["unlabled", "[unlabled] <EString>"],
268
485
  ["text:", "<EString>"]
269
486
  ], options)
270
487
  end
271
488
 
272
489
  def test_children_inside_childrole_array
273
490
  options = complete TestMM, <<-END
274
- TestNode {
275
- child2RoleB: [
276
- TestNode2 |
491
+ TestNode {
492
+ child2RoleB: [
493
+ TestNode2 |
277
494
  END
278
495
  assert_options([
496
+ ["unlabled", "[unlabled] <EString>"],
279
497
  ["text:", "<EString>"]
280
498
  ], options)
281
499
  end
282
500
 
501
+ def test_unquoted_argument
502
+ options = complete TestMM, <<-END
503
+ TestNode {
504
+ child2RoleB: [
505
+ TestNode2 text: |
506
+ END
507
+ assert_options([
508
+ ["text", "<EString>"]
509
+ ], options)
510
+ end
511
+
283
512
  def test_root
284
513
  options = complete TestMM, <<-END
285
- |
514
+ |
286
515
  END
287
516
  assert_options([
288
517
  ["TestNode", "<unlabled1>, <unlabled2>"],
289
- ["TestNode2", ""],
518
+ ["TestNode2", "<unlabled>"],
290
519
  ["TestNode3", ""],
291
520
  ["TextNode", ""]
292
521
  ], options)
@@ -296,7 +525,7 @@ def test_root_no_context_lines
296
525
  options = complete TestMM, ""
297
526
  assert_options([
298
527
  ["TestNode", "<unlabled1>, <unlabled2>"],
299
- ["TestNode2", ""],
528
+ ["TestNode2", "<unlabled>"],
300
529
  ["TestNode3", ""],
301
530
  ["TextNode", ""]
302
531
  ], options)
@@ -304,9 +533,36 @@ end
304
533
 
305
534
  def test_root_prefix
306
535
  options = complete TestMM, <<-END
307
- Text|
308
- END
536
+ Text|
537
+ END
538
+ assert_options([
539
+ ["TestNode", "<unlabled1>, <unlabled2>"],
540
+ ["TestNode2", "<unlabled>"],
541
+ ["TestNode3", ""],
542
+ ["TextNode", ""]
543
+ ], options)
544
+ end
545
+
546
+ def test_within_command
547
+ options = complete TestMM, <<-END
548
+ Text|Node
549
+ END
550
+ assert_options([
551
+ ["TestNode", "<unlabled1>, <unlabled2>"],
552
+ ["TestNode2", "<unlabled>"],
553
+ ["TestNode3", ""],
554
+ ["TextNode", ""]
555
+ ], options)
556
+ end
557
+
558
+ def test_within_command2
559
+ options = complete TestMM, <<-END
560
+ |TextNode
561
+ END
309
562
  assert_options([
563
+ ["TestNode", "<unlabled1>, <unlabled2>"],
564
+ ["TestNode2", "<unlabled>"],
565
+ ["TestNode3", ""],
310
566
  ["TextNode", ""]
311
567
  ], options)
312
568
  end
@@ -323,7 +579,8 @@ def complete(mm, text, ref_comp_option_provider=nil)
323
579
  end
324
580
  lang = RText::Language.new(mm.ecore,
325
581
  :root_classes => mm.ecore.eAllClasses,
326
- :unlabled_arguments => lambda {|c| ["unlabled1", "unlabled2"]})
582
+ :unlabled_arguments => lambda {|c| ["unlabled1", "unlabled2", "unlabled"]},
583
+ :unquoted_arguments => lambda {|c| c.name == "TestNode2" ? ["text", "unlabled"] : []})
327
584
  context = RText::ContextBuilder.build_context(lang, context_lines, pos_in_line)
328
585
  RText::Completer.new(lang).complete(context, ref_comp_option_provider)
329
586
  end