rgen 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +20 -1
- data/MIT-LICENSE +1 -1
- data/README +12 -9
- data/lib/instantiators/ea_instantiator.rb +36 -0
- data/lib/metamodels/uml13_metamodel.rb +559 -0
- data/lib/metamodels/uml13_metamodel_ext.rb +26 -0
- data/lib/mmgen/metamodel_generator.rb +5 -5
- data/lib/mmgen/mm_ext/ecore_ext.rb +95 -0
- data/lib/mmgen/mmgen.rb +6 -4
- data/lib/mmgen/templates/annotations.tpl +37 -0
- data/lib/mmgen/templates/metamodel_generator.tpl +171 -0
- data/lib/rgen/ecore/ecore.rb +190 -0
- data/lib/rgen/ecore/ecore_instantiator.rb +25 -0
- data/lib/rgen/ecore/ecore_transformer.rb +85 -0
- data/lib/rgen/environment.rb +9 -24
- data/lib/rgen/find_helper.rb +68 -0
- data/lib/rgen/{instantiator.rb → instantiator/abstract_instantiator.rb} +6 -2
- data/lib/rgen/instantiator/abstract_xml_instantiator.rb +59 -0
- data/lib/rgen/instantiator/default_xml_instantiator.rb +117 -0
- data/lib/rgen/instantiator/ecore_xml_instantiator.rb +144 -0
- data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +157 -0
- data/lib/rgen/instantiator/xmi11_instantiator.rb +164 -0
- data/lib/rgen/metamodel_builder.rb +103 -9
- data/lib/rgen/metamodel_builder/build_helper.rb +26 -4
- data/lib/rgen/metamodel_builder/builder_extensions.rb +285 -88
- data/lib/rgen/metamodel_builder/builder_runtime.rb +7 -1
- data/lib/rgen/metamodel_builder/data_types.rb +67 -0
- data/lib/rgen/metamodel_builder/intermediate/annotation.rb +30 -0
- data/lib/rgen/metamodel_builder/metamodel_description.rb +232 -0
- data/lib/rgen/metamodel_builder/mm_multiple.rb +23 -0
- data/lib/rgen/metamodel_builder/module_extension.rb +33 -0
- data/lib/rgen/model_comparator.rb +56 -0
- data/lib/rgen/model_dumper.rb +5 -5
- data/lib/rgen/name_helper.rb +17 -1
- data/lib/rgen/template_language.rb +148 -28
- data/lib/rgen/template_language/directory_template_container.rb +56 -38
- data/lib/rgen/template_language/output_handler.rb +93 -77
- data/lib/rgen/template_language/template_container.rb +186 -143
- data/lib/rgen/transformer.rb +19 -14
- data/lib/transformers/uml13_to_ecore.rb +75 -0
- data/redist/xmlscan/ChangeLog +1301 -0
- data/redist/xmlscan/README +34 -0
- data/redist/xmlscan/THANKS +11 -0
- data/redist/xmlscan/doc/changes.html +74 -0
- data/redist/xmlscan/doc/changes.rd +80 -0
- data/redist/xmlscan/doc/en/conformance.html +136 -0
- data/redist/xmlscan/doc/en/conformance.rd +152 -0
- data/redist/xmlscan/doc/en/manual.html +356 -0
- data/redist/xmlscan/doc/en/manual.rd +402 -0
- data/redist/xmlscan/doc/ja/conformance.ja.html +118 -0
- data/redist/xmlscan/doc/ja/conformance.ja.rd +134 -0
- data/redist/xmlscan/doc/ja/manual.ja.html +325 -0
- data/redist/xmlscan/doc/ja/manual.ja.rd +370 -0
- data/redist/xmlscan/doc/src/Makefile +41 -0
- data/redist/xmlscan/doc/src/conformance.rd.src +256 -0
- data/redist/xmlscan/doc/src/langsplit.rb +110 -0
- data/redist/xmlscan/doc/src/manual.rd.src +614 -0
- data/redist/xmlscan/install.rb +41 -0
- data/redist/xmlscan/lib/xmlscan/encoding.rb +311 -0
- data/redist/xmlscan/lib/xmlscan/htmlscan.rb +289 -0
- data/redist/xmlscan/lib/xmlscan/namespace.rb +352 -0
- data/redist/xmlscan/lib/xmlscan/parser.rb +299 -0
- data/redist/xmlscan/lib/xmlscan/scanner.rb +1109 -0
- data/redist/xmlscan/lib/xmlscan/version.rb +22 -0
- data/redist/xmlscan/lib/xmlscan/visitor.rb +158 -0
- data/redist/xmlscan/lib/xmlscan/xmlchar.rb +441 -0
- data/redist/xmlscan/memo/CONFORMANCE +1249 -0
- data/redist/xmlscan/memo/PRODUCTIONS +195 -0
- data/redist/xmlscan/memo/contentspec.ry +335 -0
- data/redist/xmlscan/samples/chibixml.rb +105 -0
- data/redist/xmlscan/samples/getxmlchar.rb +122 -0
- data/redist/xmlscan/samples/rexml.rb +159 -0
- data/redist/xmlscan/samples/xmlbench.rb +88 -0
- data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +29 -0
- data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +62 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +62 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +99 -0
- data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +116 -0
- data/redist/xmlscan/samples/xmlconftest.rb +200 -0
- data/redist/xmlscan/test.rb +7 -0
- data/redist/xmlscan/tests/deftestcase.rb +73 -0
- data/redist/xmlscan/tests/runtest.rb +47 -0
- data/redist/xmlscan/tests/testall.rb +14 -0
- data/redist/xmlscan/tests/testencoding.rb +438 -0
- data/redist/xmlscan/tests/testhtmlscan.rb +752 -0
- data/redist/xmlscan/tests/testnamespace.rb +457 -0
- data/redist/xmlscan/tests/testparser.rb +591 -0
- data/redist/xmlscan/tests/testscanner.rb +1749 -0
- data/redist/xmlscan/tests/testxmlchar.rb +143 -0
- data/redist/xmlscan/tests/visitor.rb +34 -0
- data/test/array_extensions_test.rb +2 -2
- data/test/ea_instantiator_test.rb +41 -0
- data/test/ecore_self_test.rb +53 -0
- data/test/environment_test.rb +11 -6
- data/test/metamodel_builder_test.rb +404 -245
- data/test/metamodel_roundtrip_test.rb +52 -0
- data/test/metamodel_roundtrip_test/TestModel.rb +65 -0
- data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +64 -0
- data/test/metamodel_roundtrip_test/houseMetamodel.ecore +32 -0
- data/test/metamodel_roundtrip_test/houseMetamodel_from_ecore.rb +39 -0
- data/test/rgen_test.rb +3 -3
- data/test/template_language_test.rb +65 -39
- data/test/template_language_test/expected_result.txt +24 -3
- data/test/template_language_test/templates/code/array.tpl +11 -0
- data/test/template_language_test/templates/content/author.tpl +7 -0
- data/test/template_language_test/templates/content/chapter.tpl +1 -1
- data/test/template_language_test/templates/root.tpl +17 -8
- data/test/template_language_test/testout.txt +24 -3
- data/test/testmodel/class_model_checker.rb +119 -0
- data/test/{xmi_instantiator_test/testmodel.eap → testmodel/ea_testmodel.eap} +0 -0
- data/test/{xmi_instantiator_test/testmodel.xml → testmodel/ea_testmodel.xml} +81 -14
- data/test/testmodel/ea_testmodel_partial.xml +317 -0
- data/test/testmodel/ecore_model_checker.rb +101 -0
- data/test/testmodel/manual_testmodel.xml +22 -0
- data/test/testmodel/object_model_checker.rb +67 -0
- data/test/transformer_test.rb +18 -10
- data/test/xml_instantiator_test.rb +81 -8
- data/test/xml_instantiator_test/simple_ecore_model_checker.rb +94 -0
- data/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb +53 -0
- data/test/xml_instantiator_test/simple_xmi_metamodel.rb +49 -0
- data/test/xml_instantiator_test/simple_xmi_to_ecore.rb +75 -0
- metadata +126 -28
- data/lib/ea/xmi_class_instantiator.rb +0 -46
- data/lib/ea/xmi_helper.rb +0 -26
- data/lib/ea/xmi_metamodel.rb +0 -34
- data/lib/ea/xmi_object_instantiator.rb +0 -46
- data/lib/ea/xmi_to_classmodel.rb +0 -78
- data/lib/ea/xmi_to_objectmodel.rb +0 -92
- data/lib/mmgen/mm_ext/uml_classmodel_ext.rb +0 -71
- data/lib/mmgen/templates/uml_classmodel.tpl +0 -63
- data/lib/rgen/xml_instantiator.rb +0 -132
- data/lib/uml/objectmodel_instantiator.rb +0 -53
- data/lib/uml/uml_classmodel.rb +0 -92
- data/lib/uml/uml_objectmodel.rb +0 -65
- data/test/metamodel_generator_test.rb +0 -44
- data/test/metamodel_generator_test/TestModel.rb +0 -40
- data/test/metamodel_generator_test/expected_result.txt +0 -40
- data/test/xmi_class_instantiator_test.rb +0 -24
- data/test/xmi_instantiator_test/class_model_checker.rb +0 -97
- data/test/xmi_object_instantiator_test.rb +0 -65
- data/test/xml_instantiator_test/testmodel.xml +0 -7
@@ -0,0 +1,105 @@
|
|
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
|
@@ -0,0 +1,122 @@
|
|
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
|
+
}
|
@@ -0,0 +1,159 @@
|
|
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
|
@@ -0,0 +1,88 @@
|
|
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
|