rtext 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -2
- data/Rakefile +1 -1
- data/lib/rtext/completer.rb +84 -111
- data/lib/rtext/context_builder.rb +188 -0
- data/lib/rtext/default_loader.rb +8 -0
- data/lib/rtext/default_service_provider.rb +21 -18
- data/lib/rtext/instantiator.rb +28 -9
- data/lib/rtext/language.rb +51 -21
- data/lib/rtext/parser.rb +6 -4
- data/lib/rtext/serializer.rb +3 -2
- data/lib/rtext/service.rb +7 -9
- data/test/completer_test.rb +332 -0
- data/test/context_builder_test.rb +360 -0
- data/test/instantiator_test.rb +95 -13
- data/test/rtext_test.rb +2 -0
- data/test/serializer_test.rb +9 -8
- metadata +8 -11
- data/lib/rtext/context_element_builder.rb +0 -112
data/test/rtext_test.rb
CHANGED
data/test/serializer_test.rb
CHANGED
@@ -6,7 +6,7 @@ require 'rgen/metamodel_builder'
|
|
6
6
|
require 'rtext/serializer'
|
7
7
|
require 'rtext/language'
|
8
8
|
|
9
|
-
class
|
9
|
+
class SerializerTest < Test::Unit::TestCase
|
10
10
|
|
11
11
|
class StringWriter < String
|
12
12
|
alias write concat
|
@@ -15,7 +15,7 @@ class RTextSerializerTest < Test::Unit::TestCase
|
|
15
15
|
module TestMM
|
16
16
|
extend RGen::MetamodelBuilder::ModuleExtension
|
17
17
|
SomeEnum = RGen::MetamodelBuilder::DataTypes::Enum.new(
|
18
|
-
:name => "SomeEnum", :literals => [:A, :B, :'non-word*chars'
|
18
|
+
:name => "SomeEnum", :literals => [:A, :B, :'non-word*chars'])
|
19
19
|
class TestNode < RGen::MetamodelBuilder::MMBase
|
20
20
|
has_attr 'text', String
|
21
21
|
has_attr 'integer', Integer
|
@@ -243,7 +243,7 @@ TestNode name: "Target" {
|
|
243
243
|
has_attr 'text', String
|
244
244
|
end
|
245
245
|
class TestNodeD < RGen::MetamodelBuilder::MMBase
|
246
|
-
has_attr '
|
246
|
+
has_attr 'text3', String
|
247
247
|
end
|
248
248
|
class TestNodeE < RGen::MetamodelBuilder::MMMultiple(TestNodeC, TestNodeD)
|
249
249
|
has_attr 'text2', String
|
@@ -270,7 +270,7 @@ TestNode name: "Target" {
|
|
270
270
|
:child3 => TestMMChildRole::TestNodeA.new(:text => "child3"),
|
271
271
|
:childs4 => [TestMMChildRole::TestNodeB.new(:text => "child4")],
|
272
272
|
:child5 => TestMMChildRole::TestNodeC.new(:text => "child5"),
|
273
|
-
:childs6 => [TestMMChildRole::TestNodeD.new(:text => "child6")],
|
273
|
+
:childs6 => [TestMMChildRole::TestNodeD.new(:text3 => "child6"), TestMMChildRole::TestNodeE.new(:text => "child6.1")],
|
274
274
|
:child7 => TestMMChildRole::TestNodeE.new(:text2 => "child7")
|
275
275
|
)
|
276
276
|
|
@@ -288,7 +288,10 @@ TestNode {
|
|
288
288
|
TestNodeA text: "child3"
|
289
289
|
TestNodeB text: "child4"
|
290
290
|
TestNodeC text: "child5"
|
291
|
-
|
291
|
+
childs6: [
|
292
|
+
TestNodeD text3: "child6"
|
293
|
+
TestNodeE text: "child6.1"
|
294
|
+
]
|
292
295
|
child7:
|
293
296
|
TestNodeE text2: "child7"
|
294
297
|
}
|
@@ -352,8 +355,7 @@ TestNode {
|
|
352
355
|
testModel = [
|
353
356
|
TestMM::TestNode.new(:enum => :A),
|
354
357
|
TestMM::TestNode.new(:enum => :B),
|
355
|
-
TestMM::TestNode.new(:enum => :'non-word*chars')
|
356
|
-
TestMM::TestNode.new(:enum => :'2you')
|
358
|
+
TestMM::TestNode.new(:enum => :'non-word*chars')
|
357
359
|
]
|
358
360
|
output = StringWriter.new
|
359
361
|
serialize(testModel, TestMM, output)
|
@@ -361,7 +363,6 @@ TestNode {
|
|
361
363
|
TestNode enum: A
|
362
364
|
TestNode enum: B
|
363
365
|
TestNode enum: "non-word*chars"
|
364
|
-
TestNode enum: "2you"
|
365
366
|
), output
|
366
367
|
end
|
367
368
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rgen
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &22687308 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,12 +21,7 @@ dependencies:
|
|
21
21
|
version: 0.6.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.6.0
|
24
|
+
version_requirements: *22687308
|
30
25
|
description: RText can be used to derive textual languages from an RGen metamodel
|
31
26
|
with very little effort.
|
32
27
|
email: martin dot thiede at gmx de
|
@@ -40,7 +35,7 @@ extra_rdoc_files:
|
|
40
35
|
- RText_Plugin_Implementation_Guide
|
41
36
|
files:
|
42
37
|
- lib/rtext/completer.rb
|
43
|
-
- lib/rtext/
|
38
|
+
- lib/rtext/context_builder.rb
|
44
39
|
- lib/rtext/default_loader.rb
|
45
40
|
- lib/rtext/default_service_provider.rb
|
46
41
|
- lib/rtext/instantiator.rb
|
@@ -49,6 +44,8 @@ files:
|
|
49
44
|
- lib/rtext/serializer.rb
|
50
45
|
- lib/rtext/service.rb
|
51
46
|
- lib/rtext_plugin/connection_manager.rb
|
47
|
+
- test/completer_test.rb
|
48
|
+
- test/context_builder_test.rb
|
52
49
|
- test/instantiator_test.rb
|
53
50
|
- test/rtext_test.rb
|
54
51
|
- test/serializer_test.rb
|
@@ -82,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
79
|
version: '0'
|
83
80
|
requirements: []
|
84
81
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.7.2
|
86
83
|
signing_key:
|
87
84
|
specification_version: 3
|
88
85
|
summary: Ruby Textual Modelling
|
@@ -1,112 +0,0 @@
|
|
1
|
-
module RText
|
2
|
-
|
3
|
-
# ContextElementBuilder build a partial model from a set of context lines.
|
4
|
-
#
|
5
|
-
# Context lines are lines from an RText file which contain a (context) command and all
|
6
|
-
# the parent commands wrapped around it. Any sibling commands can be omitted as well as
|
7
|
-
# any lines containing closing braces and brackets.
|
8
|
-
#
|
9
|
-
# The resulting partial model contains a (context) model element and all its parent
|
10
|
-
# elements. Further references are not resolved.
|
11
|
-
#
|
12
|
-
module ContextElementBuilder
|
13
|
-
|
14
|
-
class << self
|
15
|
-
|
16
|
-
# Instantiates the context element based on a set of +content_lines+. Content lines
|
17
|
-
# are the RText lines containing the nested command headers in the original order.
|
18
|
-
# The last line of +context_lines+ is the one which will create the context element.
|
19
|
-
# +position_in_line+ is the cursor column position within the last line
|
20
|
-
def build_context_element(language, context_lines, position_in_line)
|
21
|
-
context_info = fix_context(context_lines)
|
22
|
-
return nil unless context_info
|
23
|
-
element = instantiate_context_element(language, context_info)
|
24
|
-
unless element
|
25
|
-
fix_current_line(context_info, position_in_line)
|
26
|
-
element = instantiate_context_element(language, context_info)
|
27
|
-
end
|
28
|
-
element
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def instantiate_context_element(language, context_info)
|
34
|
-
root_elements = []
|
35
|
-
problems = []
|
36
|
-
Instantiator.new(language).instantiate(context_info.lines.join("\n"),
|
37
|
-
:root_elements => root_elements, :problems => problems)
|
38
|
-
if root_elements.size > 0
|
39
|
-
find_leaf_child(root_elements.first, context_info.num_elements-1)
|
40
|
-
else
|
41
|
-
nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def find_leaf_child(element, num_required_children)
|
46
|
-
childs = element.class.ecore.eAllReferences.select{|r| r.containment}.collect{|r|
|
47
|
-
element.getGenericAsArray(r.name)}.flatten
|
48
|
-
if childs.size > 0
|
49
|
-
find_leaf_child(childs.first, num_required_children-1)
|
50
|
-
elsif num_required_children == 0
|
51
|
-
element
|
52
|
-
else
|
53
|
-
nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
ContextInfo = Struct.new(:lines, :num_elements, :pos_leaf_element)
|
58
|
-
|
59
|
-
# extend +context_lines+ into a set of lines which can be processed by the RText
|
60
|
-
# instantiator: cut of curly brace from current line if present and add missing
|
61
|
-
# closing curly braces and square brackets
|
62
|
-
# returns a ContextInfo containing the new set of lines, the number of model elements
|
63
|
-
# contained in this model snipped and the number of the line containing the leaf element
|
64
|
-
def fix_context(context_lines)
|
65
|
-
context_lines = context_lines.dup
|
66
|
-
line = context_lines.last
|
67
|
-
return nil if line.nil? || is_non_element_line(line)
|
68
|
-
context_lines << strip_curly_brace(context_lines.pop)
|
69
|
-
pos_leaf_element = context_lines.size-1
|
70
|
-
num_elements = 1
|
71
|
-
context_lines.reverse.each do |l|
|
72
|
-
if l =~ /\{\s*$/
|
73
|
-
context_lines << "}"
|
74
|
-
num_elements += 1
|
75
|
-
elsif l =~ /\[\s*$/
|
76
|
-
context_lines << "]"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
ContextInfo.new(context_lines, num_elements, pos_leaf_element)
|
80
|
-
end
|
81
|
-
|
82
|
-
def is_non_element_line(line)
|
83
|
-
line = line.strip
|
84
|
-
line == "" || line == "}" || line == "]" || line =~ /^#/ || line =~ /^\w+:$/
|
85
|
-
end
|
86
|
-
|
87
|
-
def strip_curly_brace(line)
|
88
|
-
line.sub(/\{\s*$/,'')
|
89
|
-
end
|
90
|
-
|
91
|
-
def fix_current_line(context_info, pos_in_line)
|
92
|
-
context_info.lines[context_info.pos_leaf_element] =
|
93
|
-
cut_current_argument(context_info.lines[context_info.pos_leaf_element], pos_in_line)
|
94
|
-
end
|
95
|
-
|
96
|
-
def cut_current_argument(line, pos_in_line)
|
97
|
-
left_comma_pos = line.rindex(",", pos_in_line-1)
|
98
|
-
if left_comma_pos
|
99
|
-
line[0..left_comma_pos-1]
|
100
|
-
elsif line =~ /^\s*\w+/
|
101
|
-
$&
|
102
|
-
else
|
103
|
-
""
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|