rgen 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/CHANGELOG +28 -0
  2. data/Rakefile +3 -4
  3. data/lib/ea_support/uml13_ea_metamodel.rb +3 -3
  4. data/lib/ea_support/uml13_ea_to_uml13.rb +33 -2
  5. data/lib/ea_support/uml13_to_uml13_ea.rb +7 -0
  6. data/lib/mmgen/mm_ext/ecore_mmgen_ext.rb +4 -4
  7. data/lib/mmgen/templates/metamodel_generator.tpl +143 -143
  8. data/lib/rgen/ecore/ecore.rb +11 -1
  9. data/lib/rgen/ecore/ecore_interface.rb +47 -0
  10. data/lib/rgen/ecore/ecore_to_ruby.rb +166 -0
  11. data/lib/rgen/ecore/{ecore_transformer.rb → ruby_to_ecore.rb} +11 -11
  12. data/lib/rgen/environment.rb +15 -2
  13. data/lib/rgen/fragment/dump_file_cache.rb +63 -0
  14. data/lib/rgen/fragment/fragmented_model.rb +139 -0
  15. data/lib/rgen/fragment/model_fragment.rb +268 -0
  16. data/lib/rgen/instantiator/abstract_xml_instantiator.rb +44 -72
  17. data/lib/rgen/instantiator/default_xml_instantiator.rb +2 -2
  18. data/lib/rgen/instantiator/ecore_xml_instantiator.rb +16 -1
  19. data/lib/rgen/instantiator/json_instantiator.rb +16 -2
  20. data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +118 -138
  21. data/lib/rgen/instantiator/qualified_name_resolver.rb +5 -1
  22. data/lib/rgen/instantiator/reference_resolver.rb +126 -24
  23. data/lib/rgen/instantiator/xmi11_instantiator.rb +6 -2
  24. data/lib/rgen/metamodel_builder.rb +18 -6
  25. data/lib/rgen/metamodel_builder/builder_extensions.rb +431 -407
  26. data/lib/rgen/metamodel_builder/builder_runtime.rb +8 -8
  27. data/lib/rgen/metamodel_builder/constant_order_helper.rb +4 -4
  28. data/lib/rgen/metamodel_builder/data_types.rb +5 -1
  29. data/lib/rgen/metamodel_builder/intermediate/feature.rb +167 -0
  30. data/lib/rgen/metamodel_builder/module_extension.rb +2 -2
  31. data/lib/rgen/model_builder.rb +10 -5
  32. data/lib/rgen/model_builder/builder_context.rb +17 -1
  33. data/lib/rgen/serializer/opposite_reference_filter.rb +18 -0
  34. data/lib/rgen/serializer/qualified_name_provider.rb +45 -0
  35. data/lib/rgen/template_language/template_container.rb +3 -1
  36. data/lib/rgen/{auto_class_creator.rb → util/auto_class_creator.rb} +6 -1
  37. data/lib/rgen/util/cached_glob.rb +67 -0
  38. data/lib/rgen/util/file_cache_map.rb +104 -0
  39. data/lib/rgen/util/file_change_detector.rb +78 -0
  40. data/lib/rgen/{method_delegation.rb → util/method_delegation.rb} +18 -3
  41. data/lib/rgen/{model_comparator.rb → util/model_comparator.rb} +17 -5
  42. data/lib/rgen/{model_comparator_base.rb → util/model_comparator_base.rb} +6 -1
  43. data/lib/rgen/{model_dumper.rb → util/model_dumper.rb} +6 -1
  44. data/lib/rgen/{name_helper.rb → util/name_helper.rb} +6 -1
  45. data/lib/rgen/util/pattern_matcher.rb +329 -0
  46. data/lib/transformers/uml13_to_ecore.rb +103 -60
  47. data/test/ecore_self_test.rb +43 -42
  48. data/test/json_test.rb +15 -0
  49. data/test/metamodel_builder_test.rb +361 -206
  50. data/test/metamodel_from_ecore_test.rb +45 -0
  51. data/test/metamodel_order_test.rb +10 -4
  52. data/test/metamodel_roundtrip_test.rb +2 -2
  53. data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +1 -1
  54. data/test/metamodel_roundtrip_test/houseMetamodel_Regenerated.ecore +50 -50
  55. data/test/method_delegation_test.rb +9 -9
  56. data/test/model_builder/ecore_internal.rb +19 -9
  57. data/test/model_builder/serializer_test.rb +1 -1
  58. data/test/reference_resolver_test.rb +79 -12
  59. data/test/rgen_test.rb +2 -0
  60. data/test/template_language_test.rb +7 -0
  61. data/test/template_language_test/templates/callback_indent_test/a.tpl +12 -0
  62. data/test/template_language_test/templates/callback_indent_test/b.tpl +5 -0
  63. data/test/testmodel/ea_testmodel_regenerated.xml +588 -583
  64. data/test/transformer_test.rb +3 -3
  65. data/test/util/file_cache_map_test.rb +91 -0
  66. data/test/util/file_cache_map_test/testdir/fileA +1 -0
  67. data/test/util_test.rb +4 -0
  68. data/test/xml_instantiator_test.rb +139 -135
  69. metadata +49 -104
  70. data/lib/rgen/ecore/ecore_instantiator.rb +0 -31
  71. data/lib/rgen/metamodel_builder/metamodel_description.rb +0 -232
  72. data/redist/xmlscan/ChangeLog +0 -1301
  73. data/redist/xmlscan/README +0 -34
  74. data/redist/xmlscan/THANKS +0 -11
  75. data/redist/xmlscan/doc/changes.html +0 -74
  76. data/redist/xmlscan/doc/changes.rd +0 -80
  77. data/redist/xmlscan/doc/en/conformance.html +0 -136
  78. data/redist/xmlscan/doc/en/conformance.rd +0 -152
  79. data/redist/xmlscan/doc/en/manual.html +0 -356
  80. data/redist/xmlscan/doc/en/manual.rd +0 -402
  81. data/redist/xmlscan/doc/ja/conformance.ja.html +0 -118
  82. data/redist/xmlscan/doc/ja/conformance.ja.rd +0 -134
  83. data/redist/xmlscan/doc/ja/manual.ja.html +0 -325
  84. data/redist/xmlscan/doc/ja/manual.ja.rd +0 -370
  85. data/redist/xmlscan/doc/src/Makefile +0 -41
  86. data/redist/xmlscan/doc/src/conformance.rd.src +0 -256
  87. data/redist/xmlscan/doc/src/langsplit.rb +0 -110
  88. data/redist/xmlscan/doc/src/manual.rd.src +0 -614
  89. data/redist/xmlscan/install.rb +0 -41
  90. data/redist/xmlscan/lib/xmlscan/encoding.rb +0 -311
  91. data/redist/xmlscan/lib/xmlscan/htmlscan.rb +0 -289
  92. data/redist/xmlscan/lib/xmlscan/namespace.rb +0 -352
  93. data/redist/xmlscan/lib/xmlscan/parser.rb +0 -299
  94. data/redist/xmlscan/lib/xmlscan/scanner.rb +0 -1109
  95. data/redist/xmlscan/lib/xmlscan/version.rb +0 -22
  96. data/redist/xmlscan/lib/xmlscan/visitor.rb +0 -158
  97. data/redist/xmlscan/lib/xmlscan/xmlchar.rb +0 -441
  98. data/redist/xmlscan/memo/CONFORMANCE +0 -1249
  99. data/redist/xmlscan/memo/PRODUCTIONS +0 -195
  100. data/redist/xmlscan/memo/contentspec.ry +0 -335
  101. data/redist/xmlscan/samples/chibixml.rb +0 -105
  102. data/redist/xmlscan/samples/getxmlchar.rb +0 -122
  103. data/redist/xmlscan/samples/rexml.rb +0 -159
  104. data/redist/xmlscan/samples/xmlbench.rb +0 -88
  105. data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +0 -22
  106. data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +0 -29
  107. data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +0 -62
  108. data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +0 -22
  109. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +0 -62
  110. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +0 -22
  111. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +0 -22
  112. data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +0 -99
  113. data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +0 -116
  114. data/redist/xmlscan/samples/xmlconftest.rb +0 -200
  115. data/redist/xmlscan/test.rb +0 -7
  116. data/redist/xmlscan/tests/deftestcase.rb +0 -73
  117. data/redist/xmlscan/tests/runtest.rb +0 -47
  118. data/redist/xmlscan/tests/testall.rb +0 -14
  119. data/redist/xmlscan/tests/testencoding.rb +0 -438
  120. data/redist/xmlscan/tests/testhtmlscan.rb +0 -752
  121. data/redist/xmlscan/tests/testnamespace.rb +0 -457
  122. data/redist/xmlscan/tests/testparser.rb +0 -591
  123. data/redist/xmlscan/tests/testscanner.rb +0 -1749
  124. data/redist/xmlscan/tests/testxmlchar.rb +0 -143
  125. data/redist/xmlscan/tests/visitor.rb +0 -34
@@ -1,105 +0,0 @@
1
- #
2
- # samples/chibixml.rb - xmlscan with ChibiXML
3
- #
4
- # Copyright (C) UENO Katsuhiro 2002
5
- #
6
- # $Id: chibixml.rb,v 1.1 2002/09/28 10:52:41 katsu Exp $
7
- #
8
-
9
- require 'xmlscan/parser'
10
- require 'chibixml'
11
-
12
-
13
- module XMLScan
14
-
15
- module ChibiXML
16
-
17
- class Visitor
18
-
19
- include XMLScan::Visitor
20
- include ::ChibiXML
21
-
22
- attr_reader :document
23
-
24
- def on_start_document
25
- @document = createDocument
26
- @current = @document
27
- end
28
-
29
- def on_doctype(root, pubid, sysid)
30
- @current.doctype = Node.new(DOCUMENT_TYPE_NODE, root)
31
- end
32
-
33
- def on_comment(str)
34
- @current.appendChild @document.createComment(str)
35
- end
36
-
37
- def on_pi(target, pi)
38
- @current.appendChild @document.createProcessingInstruction(target,pi)
39
- end
40
-
41
- def on_chardata(str)
42
- @current.appendChild @document.createTextNode(str)
43
- end
44
-
45
- def on_entityref(ref)
46
- @current.appendChild @document.createEntityReference(ref)
47
- end
48
-
49
- def on_stag(name)
50
- element = @document.createElement(name)
51
- @current.appendChild element
52
- @current = element
53
- end
54
-
55
- def on_attribute(*)
56
- @attr = ''
57
- end
58
-
59
- def on_attr_value(str)
60
- @attr << str
61
- end
62
-
63
- def on_attr_charref(str)
64
- @attr << [str].pack('U')
65
- end
66
-
67
- def on_attribute_end(name)
68
- @current.setAttribute name, @attr
69
- end
70
-
71
- def on_etag(*)
72
- @current = @current.parentNode
73
- end
74
-
75
- end
76
-
77
-
78
- def self.parse(src)
79
- visitor = Visitor.new
80
- XMLScan::XMLParser.new(visitor).parse src
81
- visitor.document
82
- end
83
-
84
- def self.scan(src)
85
- visitor = Visitor.new
86
- XMLScan::XMLScanner.new(visitor).parse src
87
- visitor.document
88
- end
89
-
90
- end
91
-
92
- end
93
-
94
-
95
-
96
-
97
-
98
- if $0 == __FILE__ then
99
- src = ARGF
100
- def src.path; filename; end
101
- t1 = Time.times.utime
102
- XMLScan::ChibiXML.parse src
103
- t2 = Time.times.utime
104
- STDERR.printf "%2.3f sec\n", t2 - t1
105
- end
@@ -1,122 +0,0 @@
1
- #!/usr/bin/ruby
2
- #
3
- # getxmlchar.rb - get XML-valid characters from XML 1.0 Specification.
4
- #
5
- # Copyright (C) UENO Katsuhiro 2002
6
- #
7
- # $Id: getxmlchar.rb,v 1.2 2002/09/27 02:33:40 katsu Exp $
8
- #
9
-
10
- require 'xmlscan/parser'
11
-
12
-
13
- class String
14
-
15
- def decamel
16
- gsub(/[a-z](?=[A-Z])|[A-Z](?=([A-Z][a-z])|((?=[a-z])))/){ |s|
17
- ($1 ? s : s.downcase) + ($2 || '_')
18
- }
19
- end
20
-
21
- end
22
-
23
-
24
-
25
- class ProductionGetter
26
-
27
- include XMLScan::Visitor
28
-
29
- def initialize(targets)
30
- @targets = targets
31
- @parser = XMLScan::XMLParser.new(self)
32
- @elem = nil
33
- @content = nil
34
- @current = nil
35
- @production = {}
36
- end
37
-
38
- attr_reader :production
39
-
40
- def parse(src)
41
- @parser.parse src
42
- end
43
-
44
- def on_stag(name)
45
- if name == 'lhs' or name == 'rhs' then
46
- @elem = name
47
- @content = ''
48
- end
49
- end
50
-
51
- def on_chardata(str)
52
- if @content then
53
- @content << str
54
- end
55
- end
56
-
57
- def on_cdata(str)
58
- on_chardata str
59
- end
60
-
61
- def on_etag(name)
62
- case name
63
- when 'lhs' then
64
- if @targets.include? @content then
65
- if $VERBOSE then
66
- STDERR.puts "`#{@content}' is found at line #{@parser.lineno}."
67
- end
68
- @current = @content
69
- end
70
- when 'rhs' then
71
- if @current then
72
- @production[@current] = @content
73
- end
74
- @current = nil
75
- end
76
- @elem = nil
77
- @content = nil
78
- end
79
-
80
- end
81
-
82
-
83
-
84
-
85
-
86
- def ARGF.path
87
- filename
88
- end
89
-
90
- Productions = %w(Char BaseChar Ideographic CombiningChar Digit Extender)
91
-
92
- p = ProductionGetter.new(Productions)
93
- p.parse ARGF
94
-
95
- # 0x0041..0x005A, 0x0061..0x007A, 0x00C0..0x00D6, 0x00D8..0x00F6,
96
- # |-^--+----|----+---^|----+----|----+^---|----+----|--^-+----|----+----|
97
- # 0 2 19 36 53
98
-
99
- Productions.each { |name|
100
- prod = p.production[name]
101
- unless prod then
102
- print "#{name} = [] # not found\n"
103
- else
104
- ranges = []
105
- prod.scan(/\#x([0-9A-Fa-f]+)(?:-\#x([0-9A-Fa-f]+))?/) { |rstart,rend|
106
- rend = rend || rstart
107
- ranges.push Range.new(rstart.hex, rend.hex)
108
- }
109
- ranges.sort! { |a,b| a.begin <=> b.begin }
110
- print "#{name.decamel} = ["
111
- column = 0
112
- ranges.each { |i|
113
- column += 1
114
- print "\n " if column == 1
115
- s = sprintf("0x%04X..0x%04X,", i.begin, i.end)
116
- s = s.ljust(17) if column < 4
117
- print s
118
- column = 0 if column >= 4
119
- }
120
- print "\n]\n"
121
- end
122
- }
@@ -1,159 +0,0 @@
1
- #
2
- # samples/rexml.rb - xmlscan with REXML
3
- #
4
- # Copyright (C) UENO Katsuhiro 2002
5
- #
6
- # $Id: rexml.rb,v 1.1 2002/09/29 15:55:31 katsu Exp $
7
- #
8
-
9
- require 'xmlscan/parser'
10
- require 'rexml/document'
11
-
12
-
13
- module XMLScan
14
-
15
- module REXML
16
-
17
- class Visitor
18
-
19
- include XMLScan::Visitor
20
- include ::REXML
21
-
22
- def initialize(context = {})
23
- @document = Document.new(nil, context)
24
- end
25
-
26
- attr_reader :document
27
-
28
-
29
- def on_start_document
30
- @current = @document
31
- end
32
-
33
-
34
- def on_xmldecl
35
- @version = nil
36
- @encoding = nil
37
- @standalone = nil
38
- end
39
-
40
- def on_xmldecl_version(str)
41
- @version = str
42
- end
43
-
44
- def on_xmldecl_encoding(str)
45
- @encoding = str
46
- end
47
-
48
- def on_xmldecl_standalone(str)
49
- @standalone = str
50
- end
51
-
52
- def on_xmldecl_end
53
- @document.add XMLDecl.new(@version, @encoding, @standalone)
54
- end
55
-
56
-
57
- def on_doctype(root, pubid, sysid)
58
- if pubid then
59
- external_id = 'PUBLIC'
60
- else
61
- external_id = 'SYSTEM'
62
- end
63
- if pubid then
64
- if /"/ =~ pubid then
65
- external_id << " '#{pubid}'"
66
- else
67
- external_id << %' "#{pubid}"'
68
- end
69
- end
70
- if sysid then
71
- if /"/ =~ sysid then
72
- external_id << " '#{sysid}'"
73
- else
74
- external_id << %' "#{sysid}"'
75
- end
76
- end
77
- @current.add DocType.new(root, external_id)
78
- end
79
-
80
-
81
- def on_comment(str)
82
- @current.add Comment.new(str)
83
- end
84
-
85
- def on_pi(target, pi)
86
- @current.add Instruction.new(target, pi)
87
- end
88
-
89
-
90
- def on_stag(name)
91
- @current = Element.new(name, @current, @current.context)
92
- end
93
-
94
- def on_attribute(name)
95
- @attr = ''
96
- end
97
-
98
- def on_attr_value(str)
99
- @attr << str
100
- end
101
-
102
- def on_attr_entityref(ref)
103
- @attr << "&#{ref};"
104
- end
105
-
106
- def on_attr_charref(code)
107
- @attr << [code].pack('U')
108
- end
109
-
110
- def on_attribute_end(name)
111
- @current.add_attribute name, @attr
112
- end
113
-
114
- def on_etag(name)
115
- @current = @current.parent
116
- end
117
-
118
-
119
- def on_chardata(str)
120
- @current.add_text str
121
- end
122
-
123
- def on_cdata(str)
124
- @current.add CData.new(str)
125
- end
126
-
127
- def on_entityref(ref)
128
- @current.add_text "&#{ref};"
129
- end
130
-
131
- def on_charref(code)
132
- @current.add_text "&#{code};"
133
- end
134
-
135
- end
136
-
137
-
138
- def self.parse(src)
139
- visitor = Visitor.new
140
- XMLScan::XMLParser.new(visitor).parse src
141
- visitor.document
142
- end
143
-
144
- end
145
-
146
- end
147
-
148
-
149
-
150
-
151
-
152
- if $0 == __FILE__ then
153
- src = ARGF
154
- def src.path; filename; end
155
- t1 = Time.times.utime
156
- XMLScan::REXML.parse src
157
- t2 = Time.times.utime
158
- STDERR.printf "%2.3f sec\n", t2 - t1
159
- end
@@ -1,88 +0,0 @@
1
- #!/usr/bin/ruby
2
- #
3
- # samples/xmlbench.rb
4
- #
5
- # Copyright (C) UENO Katsuhiro 2002
6
- #
7
- # $Id: xmlbench.rb,v 1.6 2003/03/16 02:34:53 katsu Exp $
8
- #
9
-
10
- require 'samples/xmlbench/xmlbench-lib'
11
- require 'benchmark'
12
-
13
- $KCODE = 'U'
14
-
15
-
16
- source = ARGV.shift
17
-
18
- unless source then
19
- STDERR.print "#$0: no source document is given.\n"
20
- exit 1
21
- end
22
-
23
- #XMLBench.weight_limit = 1000
24
- if ARGV.empty? then
25
- subjects = XMLBench.setup_all
26
- else
27
- subjects = XMLBench.setup(*ARGV)
28
- end
29
-
30
-
31
-
32
- class BenchmarkRunner
33
-
34
- def initialize(source)
35
- @source = source
36
- @bench = []
37
- end
38
-
39
- def add_bench(*subjects)
40
- @bench.concat subjects
41
- end
42
-
43
- BenchTitles = [
44
- [ '** File **', proc { |f| f }, ],
45
- [ '** Array **', proc { |f| f.readlines } ],
46
- [ '** String **', proc { |f| f.read } ],
47
- ]
48
-
49
- def run
50
- file = File.open(@source)
51
- source = nil
52
- pid = nil
53
- begin
54
- Benchmark.bm(30) { |x|
55
- BenchTitles.each { |title,sourcemaker|
56
- puts title
57
- @bench.each { |i|
58
- file.rewind
59
- pid = fork {
60
- begin
61
- source = sourcemaker.call(file)
62
- GC.start
63
- x.report(i.name, '') { i.parse source }
64
- rescue Exception => e
65
- puts " #{e.class.name}"
66
- ensure
67
- file.close
68
- end
69
- }
70
- Process.waitpid(pid)
71
- pid = nil
72
- puts " killed at status #{$?}" unless $? == 0
73
- }
74
- }
75
- }
76
- ensure
77
- Process.waitpid pid if pid rescue nil
78
- file.close
79
- end
80
- self
81
- end
82
-
83
- end
84
-
85
-
86
- bench = BenchmarkRunner.new(source)
87
- bench.add_bench(*subjects)
88
- bench.run