mof 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/mof/result.rb ADDED
@@ -0,0 +1,35 @@
1
+ module MOF
2
+ class Result
3
+ attr_reader :classes, :associations, :indications, :qualifiers, :instances
4
+
5
+ def initialize
6
+ @qualifiers = []
7
+ @classes = []
8
+ @associations = []
9
+ @indications = []
10
+ @instances = []
11
+ end
12
+
13
+ def is_qualifier? name
14
+ !qualifier(name).nil?
15
+ end
16
+ private
17
+ def join_to_s title, array
18
+ s = ""
19
+ if array.size > 0
20
+ s << "\n// #{title} [#{array.size}]\n"
21
+ s << array.join("\n")
22
+ end
23
+ s
24
+ end
25
+ public
26
+ def to_s
27
+ s = join_to_s( "Qualifiers", @qualifiers )
28
+ s << join_to_s( "Classes", @classes )
29
+ s << join_to_s( "Associations", @associations )
30
+ s << join_to_s( "Indications", @indications )
31
+ s << join_to_s( "Instances", @instances )
32
+ s
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,206 @@
1
+ #
2
+ # scanner.rb
3
+ #
4
+ # A scanner module for MOF files
5
+ # to extend the Scanner class (via include)
6
+ #
7
+ # functions offered:
8
+ # parse( file ) : start parsing of file
9
+ # next_token : return next [token,value] pair
10
+ # on_error : report error
11
+ #
12
+ # Class variables:
13
+ #
14
+ # @file: file being scanned
15
+ # @name: name of file
16
+ # @lineno: current line number in file (for error reports)
17
+ # @iconv: non-nil if iconv needed (i.e. Windows utf-16 mof files)
18
+ # @fstack: stack of [ @file, @name, @lineno, @iconv ] for open files (to handle includes)
19
+ # @q: Queue of [token,value] pairs, [false,false] denotes EOF
20
+ #
21
+
22
+ require 'iconv'
23
+
24
+ module MOF
25
+ module Scanner
26
+ def fill_queue
27
+ if @file.eof?
28
+ # $stderr.puts "eof ! #{@fstack.size}"
29
+ @file.close unless @file == $stdin
30
+ unless @fstack.empty?
31
+ @file, @name, @lineno, @iconv, $/, @result = @fstack.pop
32
+ # $stderr.puts "fill! #{@fstack.size}, #{@name}@#{@lineno}"
33
+ return fill_queue
34
+ end
35
+ @q.push [false, false]
36
+ return false
37
+ end
38
+ @line = @file.gets
39
+ return true unless @line
40
+ @lineno += 1
41
+
42
+ # $stderr.puts "fill_queue(#{@line.split('').inspect})"
43
+ @line.chomp! # remove $/
44
+ @line = Iconv.conv( "ISO-8859-1", @iconv, @line ) if @iconv
45
+ # $stderr.puts "scan(#{@line})" unless @quiet
46
+ scanner = StringScanner.new(@line)
47
+
48
+ until scanner.eos?
49
+ # $stderr.puts "#{@q.size}:\"#{scanner.rest}\""
50
+ if @in_comment
51
+ if scanner.scan(%r{.*\*/})
52
+ @in_comment = false
53
+ else
54
+ break
55
+ end
56
+ end
57
+
58
+ case
59
+ when scanner.scan(/\s+/)
60
+ next # ignore space
61
+
62
+ when m = scanner.scan(/\n+/)
63
+ @lineno += m.size
64
+ next # ignore newlines
65
+
66
+ when m = scanner.scan(%r{/\*})
67
+ @in_comment = true
68
+
69
+ when m = scanner.scan(%r{//.*})
70
+ next # c++ style comment
71
+
72
+ when m = scanner.scan(%r{[(){}\[\],;\$#:=]})
73
+ @q.push [m, m]
74
+
75
+ # hexValue = [ "+" | "-" ] [ "0x" | "0X"] 1*hexDigit
76
+ # hexDigit = decimalDigit | "a" | "A" | "b" | "B" | "c" | "C" | "d" | "D" | "e" | "E" | "f" | "F"
77
+ when m = scanner.scan(%r{(\+|-)?(0x|0X)([0123456789]|[abcdef]|[ABCDEF])+})
78
+ @q.push [:hexValue, m.to_i]
79
+
80
+ # octalValue = [ "+" | "-" ] "0" 1*octalDigit
81
+ when m = scanner.scan(%r{(\+|-)?0[01234567]+})
82
+ @q.push [:octalValue, m.to_i]
83
+
84
+ # binaryValue = [ "+" | "-" ] 1*binaryDigit ( "b" | "B" )
85
+ when m = scanner.scan(%r{(\+|-)?(0|1)(b|B)})
86
+ @q.push [:binaryValue, m.to_i]
87
+
88
+ # realValue = [ "+" | "-" ] *decimalDigit "." 1*decimalDigit
89
+ # [ ( "e" | "E" ) [ "+" | "-" ] 1*decimalDigit ]
90
+
91
+ when m = scanner.scan(%r{(\+|-)?\d*\.\d+})
92
+ @q.push [:realValue, m.to_f]
93
+
94
+ when m = scanner.scan(%r{[123456789]\d*})
95
+ @q.push [:positiveDecimalValue, m.to_i]
96
+
97
+ # decimalValue = [ "+" | "-" ] ( positiveDecimalDigit *decimalDigit | "0" )
98
+ # decimalDigit = "0" | positiveDecimalDigit
99
+ when m = scanner.scan(%r{(\+|-)?\d+})
100
+ @q.push [:decimalValue, m.to_i]
101
+
102
+ # charValue = // any single-quoted Unicode-character, except single quotes
103
+
104
+ when m = scanner.scan(%r{\'([^\'])\'})
105
+ @q.push [:charValue, scanner[1]]
106
+
107
+ # stringValue = 1*( """ *ucs2Character """ )
108
+ # ucs2Character = // any valid UCS-2-character
109
+
110
+ # when m = scanner.scan(%r{\"([^\\\"]*)\"})
111
+ # @q.push [:stringValue, scanner[1]]
112
+
113
+ # string with embedded backslash
114
+ when m = scanner.scan(%r{\"(([^\\\"]|(\\[nrt\(\)/\"\'\\]))*)\"})
115
+ # $stderr.puts "scan(#{@line})" unless @quiet
116
+ # $stderr.puts ":string(#{scanner[1]})"
117
+ @q.push [:stringValue, scanner[1]]
118
+
119
+ when m = scanner.scan(%r{\w+})
120
+ case m.downcase
121
+ when "amended": @q.push [:AMENDED, CIM::QualifierFlavors.new(m)]
122
+ when "any": @q.push [:ANY, m]
123
+ when "as": @q.push [:AS, nil]
124
+ when "association": @q.push [:ASSOCIATION, CIM::QualifierDeclaration.new(m.downcase)]
125
+ when "class": @q.push( [:CLASS, m] )
126
+ when "disableoverride": @q.push [:DISABLEOVERRIDE, CIM::QualifierFlavors.new(m)]
127
+ when "void": @q.push [:DT_VOID, CIM::Type.new(:void)]
128
+ when "boolean": @q.push [:DT_BOOL, CIM::Type.new(:bool)]
129
+ when "char16": @q.push [:DT_CHAR16, CIM::Type.new(m)]
130
+ when "datetime": @q.push [:DT_DATETIME, CIM::Type.new(m)]
131
+ when "real32": @q.push [:DT_REAL32, CIM::Type.new(m)]
132
+ when "real64": @q.push [:DT_REAL64, CIM::Type.new(m)]
133
+ when "sint16": @q.push [:DT_SINT16, CIM::Type.new(m)]
134
+ when "sint32": @q.push [:DT_SINT32, CIM::Type.new(m)]
135
+ when "sint64": @q.push [:DT_SINT64, CIM::Type.new(m)]
136
+ when "sint8": @q.push [:DT_SINT8, CIM::Type.new(m)]
137
+ when "string": @q.push [:DT_STR, CIM::Type.new(m)]
138
+ when "uint16": @q.push [:DT_UINT16, CIM::Type.new(m)]
139
+ when "uint32": @q.push [:DT_UINT32, CIM::Type.new(m)]
140
+ when "uint64": @q.push [:DT_UINT64, CIM::Type.new(m)]
141
+ when "uint8": @q.push [:DT_UINT8, CIM::Type.new(m)]
142
+ when "enableoverride": @q.push [:ENABLEOVERRIDE, CIM::QualifierFlavors.new(m)]
143
+ when "false": @q.push [:booleanValue, false]
144
+ when "flavor": @q.push [:FLAVOR, nil]
145
+ when "include": @q.push [:INCLUDE, nil]
146
+ when "indication": @q.push [:INDICATION, CIM::QualifierDeclaration.new(m.downcase)]
147
+ when "instance": @q.push [:INSTANCE, m.to_sym]
148
+ when "method": @q.push [:METHOD, m]
149
+ when "null": @q.push [:nullValue, CIM::Variant.new(:null,nil)]
150
+ when "of": @q.push [:OF, nil]
151
+ when "parameter": @q.push [:PARAMETER, m]
152
+ when "pragma": @q.push [:PRAGMA, nil]
153
+ when "property": @q.push [:PROPERTY, m]
154
+ when "qualifier": @q.push [:QUALIFIER, m]
155
+ when "ref": @q.push [:REF, nil]
156
+ when "reference": @q.push [:REFERENCE, m]
157
+ when "restricted": @q.push [:RESTRICTED, CIM::QualifierFlavors.new(m)]
158
+ when "schema": @q.push [:SCHEMA, m]
159
+ when "scope": @q.push [:SCOPE, nil]
160
+ when "toinstance": @q.push [:TOINSTANCE, CIM::QualifierFlavors.new(m)]
161
+ when "tosubclass": @q.push [:TOSUBCLASS, CIM::QualifierFlavors.new(m)]
162
+ when "translatable": @q.push [:TRANSLATABLE, CIM::QualifierFlavors.new(m)]
163
+ when "true": @q.push [:booleanValue, true]
164
+ else
165
+ @q.push( [:IDENTIFIER, m] )
166
+ end # case m.downcase
167
+
168
+ else
169
+ require File.join(File.dirname(__FILE__), 'helper')
170
+ raise ParseHelper::ScannerError.new( @name, @lineno, @line, scanner.rest ) unless scanner.rest.empty?
171
+ end # case
172
+ end # until scanner.eos?
173
+ # $stderr.puts "scan done, @q #{@q.size} entries"
174
+ true
175
+ end
176
+
177
+ def parse files
178
+ return unless files
179
+ return if files.empty?
180
+ # open files in reverse order
181
+ # open() will stack them and parse starts in right order
182
+ files.reverse_each do |file|
183
+ open file, :argv
184
+ # puts "Opened #{file} as #{@file} @ #{@fstack.size}"
185
+ end
186
+ @q = [] # init the token queue
187
+ do_parse
188
+ end
189
+
190
+ def next_token
191
+ while @q.empty?
192
+ break unless fill_queue
193
+ end
194
+ # $stderr.puts "next_token #{@q.first.inspect}"
195
+ @q.shift
196
+ end
197
+
198
+ # stack_size, last_token, value_stack
199
+ # stack[0] == Result
200
+ def on_error token, token_value, value_stack
201
+ require File.join(File.dirname(__FILE__), 'parse_helper')
202
+ raise ParseHelper::ParserError.new @name,@lineno, @line, token,token_value,value_stack
203
+ end
204
+
205
+ end # module Scanner
206
+ end # module MOF
@@ -0,0 +1,2 @@
1
+ # test loading
2
+ require File.join(File.dirname(__FILE__), "..", "lib", "mof")
@@ -0,0 +1,28 @@
1
+ D = File.expand_path(File.dirname(__FILE__))
2
+ require "test/unit"
3
+ require File.join(D,'..','lib','mof')
4
+
5
+ class TestQualifiers < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @moffiles, @options = MOF::Parser.argv_handler "test_qualifier", ["qualifier.mof"]
9
+ @options[:style] ||= :cim
10
+ @options[:includes] ||= [ D, File.join(D,"mof")]
11
+
12
+ @parser = MOF::Parser.new @options
13
+ end
14
+
15
+ def test_parse
16
+ result = @parser.parse @moffiles
17
+ assert result
18
+ # parsed one file
19
+ assert_equal 1, result.size
20
+
21
+ name,res = result.shift
22
+ assert !res.qualifiers.empty?
23
+ res.qualifiers.each do |q|
24
+ puts "#{q.class}"
25
+ assert q.is_a? CIM::QualifierDeclaration
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mof
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
+ platform: ruby
12
+ authors:
13
+ - "Klaus K\xC3\xA4mpf"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-04 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: cim
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 0
32
+ - 2
33
+ - 7
34
+ version: 0.2.7
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rubyforge
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 4
50
+ version: 2.0.4
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: hoe
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 21
62
+ segments:
63
+ - 2
64
+ - 6
65
+ - 1
66
+ version: 2.6.1
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: |-
70
+ A parser for the Managed Object Format (MOF) language used to describe
71
+ classes and instances of the Common Information Model (CIM)
72
+
73
+ See http://www.dmtf.org/education/mof
74
+ email:
75
+ - kkaempf@suse.de
76
+ executables:
77
+ - moflint
78
+ extensions: []
79
+
80
+ extra_rdoc_files:
81
+ - History.txt
82
+ - Manifest.txt
83
+ files:
84
+ - History.txt
85
+ - Manifest.txt
86
+ - README.rdoc
87
+ - Rakefile
88
+ - bin/moflint
89
+ - lib/mof.rb
90
+ - lib/mof/helper.rb
91
+ - lib/mof/parser.rb
92
+ - lib/mof/result.rb
93
+ - lib/mof/scanner.rb
94
+ - test/test_qualifier.rb
95
+ - test/test_loading.rb
96
+ has_rdoc: true
97
+ homepage: http://github.com/kkaempf/mof
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options:
102
+ - --main
103
+ - README.rdoc
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirements: []
125
+
126
+ rubyforge_project: mof
127
+ rubygems_version: 1.3.7
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: A parser for the Managed Object Format (MOF) language used to describe classes and instances of the Common Information Model (CIM) See http://www.dmtf.org/education/mof
131
+ test_files:
132
+ - test/test_qualifier.rb
133
+ - test/test_loading.rb