mof 0.3.0 → 0.3.2

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.
@@ -18,7 +18,8 @@ class Result
18
18
  s = ""
19
19
  if array.size > 0
20
20
  s << "\n// #{title} [#{array.size}]\n"
21
- s << array.join("\n")
21
+ s << array.join(";\n")
22
+ s << ";"
22
23
  end
23
24
  s
24
25
  end
@@ -118,12 +118,12 @@ module Scanner
118
118
 
119
119
  when m = scanner.scan(%r{\w+})
120
120
  case m.downcase
121
- when "amended": @q.push [:AMENDED, CIM::QualifierFlavors.new(m)]
121
+ when "amended": @q.push [:AMENDED, m]
122
122
  when "any": @q.push [:ANY, m]
123
123
  when "as": @q.push [:AS, nil]
124
- when "association": @q.push [:ASSOCIATION, CIM::QualifierDeclaration.new(m.downcase)]
124
+ when "association": @q.push [:ASSOCIATION, m]
125
125
  when "class": @q.push( [:CLASS, m] )
126
- when "disableoverride": @q.push [:DISABLEOVERRIDE, CIM::QualifierFlavors.new(m)]
126
+ when "disableoverride": @q.push [:DISABLEOVERRIDE, m]
127
127
  when "void": @q.push [:DT_VOID, CIM::Type.new(:void)]
128
128
  when "boolean": @q.push [:DT_BOOL, CIM::Type.new(:bool)]
129
129
  when "char16": @q.push [:DT_CHAR16, CIM::Type.new(m)]
@@ -139,12 +139,12 @@ module Scanner
139
139
  when "uint32": @q.push [:DT_UINT32, CIM::Type.new(m)]
140
140
  when "uint64": @q.push [:DT_UINT64, CIM::Type.new(m)]
141
141
  when "uint8": @q.push [:DT_UINT8, CIM::Type.new(m)]
142
- when "enableoverride": @q.push [:ENABLEOVERRIDE, CIM::QualifierFlavors.new(m)]
142
+ when "enableoverride": @q.push [:ENABLEOVERRIDE, m]
143
143
  when "false": @q.push [:booleanValue, false]
144
144
  when "flavor": @q.push [:FLAVOR, nil]
145
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]
146
+ when "indication": @q.push [:INDICATION, m]
147
+ when "instance": @q.push [:INSTANCE, m]
148
148
  when "method": @q.push [:METHOD, m]
149
149
  when "null": @q.push [:nullValue, CIM::Variant.new(:null,nil)]
150
150
  when "of": @q.push [:OF, nil]
@@ -154,12 +154,12 @@ module Scanner
154
154
  when "qualifier": @q.push [:QUALIFIER, m]
155
155
  when "ref": @q.push [:REF, nil]
156
156
  when "reference": @q.push [:REFERENCE, m]
157
- when "restricted": @q.push [:RESTRICTED, CIM::QualifierFlavors.new(m)]
157
+ when "restricted": @q.push [:RESTRICTED, m]
158
158
  when "schema": @q.push [:SCHEMA, m]
159
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)]
160
+ when "toinstance": @q.push [:TOINSTANCE, m]
161
+ when "tosubclass": @q.push [:TOSUBCLASS, m]
162
+ when "translatable": @q.push [:TRANSLATABLE, m]
163
163
  when "true": @q.push [:booleanValue, true]
164
164
  else
165
165
  @q.push( [:IDENTIFIER, m] )
@@ -167,7 +167,7 @@ module Scanner
167
167
 
168
168
  else
169
169
  require File.join(File.dirname(__FILE__), 'helper')
170
- raise ParseHelper::ScannerError.new( @name, @lineno, @line, scanner.rest ) unless scanner.rest.empty?
170
+ raise MOF::Helper::ScannerError.new( @name, @lineno, @line, scanner.rest ) unless scanner.rest.empty?
171
171
  end # case
172
172
  end # until scanner.eos?
173
173
  # $stderr.puts "scan done, @q #{@q.size} entries"
@@ -198,8 +198,8 @@ module Scanner
198
198
  # stack_size, last_token, value_stack
199
199
  # stack[0] == Result
200
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
201
+ require File.join(File.dirname(__FILE__), 'helper')
202
+ raise MOF::Helper::ParserError.new @name,@lineno, @line, token,token_value,value_stack
203
203
  end
204
204
 
205
205
  end # module Scanner
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mof"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mof"
7
+ s.version = MOF::VERSION
8
+
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Klaus Kämpf"]
11
+ s.email = ["kkaempf@suse.de"]
12
+ s.homepage = "https://github.com/kkaempf/mof"
13
+ s.summary = %q{A pure Ruby parser for MOF (Managed Object Format) files}
14
+ s.description = %q{The Managed Object Format (MOF) language used to
15
+ describe classes and instances of the Common Information Model (CIM).
16
+ See http://www.dmtf.org/education/mof}
17
+
18
+ s.rubyforge_project = "mof"
19
+
20
+ # CIM metamodel
21
+ s.add_dependency("cim", ["~> 0.5"])
22
+
23
+ s.files = `git ls-files`.split("\n") << "lib/mof/parser.rb"
24
+ s.files.reject! { |fn| fn == '.gitignore' }
25
+ s.extra_rdoc_files = Dir['README*', 'TODO*', 'CHANGELOG*', 'LICENSE']
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,208 @@
1
+ //
2
+ // Managed Object Format
3
+ // BNF syntax as of CIM 2.2
4
+ //
5
+
6
+ mofSpecification = *mofProduction
7
+
8
+ mofProduction = compilerDirective |
9
+
10
+ classDeclaration |
11
+
12
+ assocDeclaration |
13
+
14
+ indicDeclaration |
15
+
16
+ qualifierDeclaration |
17
+
18
+ instanceDeclaration
19
+
20
+ compilerDirective = PRAGMA pragmaName "(" pragmaParameter ")"
21
+
22
+ pragmaName = IDENTIFIER
23
+
24
+ pragmaParameter = stringValue
25
+
26
+ classDeclaration = [ qualifierList ] CLASS className [ alias ] [ superClass ] "{" *classFeature "}" ";"
27
+
28
+ assocDeclaration = "[" ASSOCIATION *( "," qualifier ) "]" CLASS className [ alias ] [ superClass ] "{" *associationFeature "}" ";"
29
+
30
+
31
+ // Context:
32
+
33
+ // The remaining qualifier list must not include
34
+ // the ASSOCIATION qualifier again. If the
35
+ // association has no super association, then at
36
+ // least two references must be specified! The
37
+ // ASSOCIATION qualifier may be omitted in
38
+ // sub associations.
39
+
40
+ indicDeclaration = "[" INDICATION *( "," qualifier ) "]" CLASS className [ alias ] [ superClass ] "{" *classFeature "}" ";"
41
+
42
+ className = schemaName "_" IDENTIFIER // NO whitespace !
43
+
44
+ // Context:
45
+
46
+ // Schema name must not include "_" !
47
+
48
+ alias = AS aliasIdentifer
49
+
50
+ aliasIdentifer = "$" IDENTIFIER // NO whitespace !
51
+
52
+ superClass = ":" className
53
+
54
+ classFeature = propertyDeclaration | methodDeclaration
55
+
56
+ associationFeature = classFeature | referenceDeclaration
57
+
58
+ qualifierList = "[" qualifier *( "," qualifier ) "]"
59
+
60
+ qualifier = qualifierName [ qualifierParameter ] [ ":" 1*flavor ]
61
+
62
+ qualifierParameter = "(" constantValue ")" | arrayInitializer
63
+
64
+ flavor = ENABLEOVERRIDE | DISABLEOVERRIDE | RESTRICTED | TOSUBCLASS | TRANSLATABLE
65
+
66
+ propertyDeclaration = [ qualifierList ] dataType propertyName [ array ] [ defaultValue ] ";"
67
+
68
+ referenceDeclaration = [ qualifierList ] objectRef referenceName [ defaultValue ] ";"
69
+
70
+ methodDeclaration = [ qualifierList ] dataType methodName "(" [ parameterList ] ")" ";"
71
+
72
+ propertyName = IDENTIFIER
73
+
74
+ referenceName = IDENTIFIER
75
+
76
+ methodName = IDENTIFIER
77
+
78
+ dataType = DT_UINT8 | DT_SINT8 | DT_UINT16 | DT_SINT16 | DT_UINT32 | DT_SINT32 | DT_UINT64 | DT_SINT64 | DT_REAL32 | DT_REAL64 | DT_CHAR16 | DT_STR | DT_BOOL | DT_DATETIME
79
+
80
+ objectRef = className REF
81
+
82
+ parameterList = parameter *( "," parameter )
83
+
84
+ parameter = [ qualifierList ] (dataType|objectRef) parameterName [ array ]
85
+ parameterName = IDENTIFIER
86
+
87
+ array = "[" [positiveDecimalValue] "]"
88
+
89
+ positiveDecimalValue = positiveDecimalDigit *decimalDigit
90
+
91
+ defaultValue = "=" initializer
92
+
93
+ initializer = ConstantValue | arrayInitializer | referenceInitializer
94
+
95
+ arrayInitializer = "{" constantValue*( "," constantValue)"}"
96
+
97
+ constantValue = integerValue | realValue | charValue | stringValue | booleanValue | nullValue
98
+
99
+ integerValue = binaryValue | octalValue | decimalValue | hexValue
100
+
101
+ referenceInitializer = objectHandle | aliasIdentifier
102
+
103
+ objectHandle = """ [ namespaceHandle ":" ] modelPath """
104
+
105
+ namespaceHandle = *ucs2Character
106
+ // Note: structure depends on type of namespace
107
+
108
+ modelPath = className "." keyValuePairList
109
+
110
+ keyValuePairList = keyValuePair *( "," keyValuePair )
111
+
112
+ keyValuePair = ( propertyname | referenceName ) "=" initializer
113
+
114
+ qualifierDeclaration = QUALIFIER qualifierName qualifierType scope [ defaultFlavor ] ";"
115
+
116
+ qualifierName = IDENTIFIER
117
+
118
+ qualifierType = ":" dataType [ array ] [ defaultValue ]
119
+
120
+ scope = "," SCOPE "(" metaElement *( "," metaElement ) ")"
121
+
122
+ metaElement = SCHEMA | CLASS | ASSOCIATION | INDICATION | QUALIFIER PROPERTY | REFERENCE | METHOD | PARAMETER | ANY
123
+
124
+ defaultFlavor = "," FLAVOR "(" flavor *( "," flavor ) ")"
125
+
126
+ instanceDeclaration = [ qualifierList ] INSTANCE OF className [ alias ] "{" 1*valueInitializer "}" ";"
127
+
128
+ valueInitializer = [ qualifierList ]
129
+
130
+ ( propertyName | referenceName ) "=" initializer ";"
131
+ These productions do not allow whitespace between the terms:
132
+ schemaName = IDENTIFIER
133
+
134
+ // Context:
135
+
136
+ // Schema name must not include "_" !
137
+ fileName = stringValue
138
+
139
+ binaryValue = [ "+" | "-" ] 1*binaryDigit ( "b" | "B" )
140
+
141
+ binaryDigit = "0" | "1"
142
+
143
+ octalValue = [ "+" | "-" ] "0" 1*octalDigit
144
+
145
+ octalDigit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"
146
+
147
+ decimalValue = [ "+" | "-" ] ( positiveDecimalDigit *decimalDigit | "0" )
148
+
149
+ decimalDigit = "0" | positiveDecimalDigit
150
+
151
+ positiveDecimalDigit = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
152
+
153
+ hexValue = [ "+" | "-" ] ( "0x" | "0X" ) 1*hexDigit
154
+
155
+ hexDigit = decimalDigit | "a" | "A" | "b" | "B" | "c" | "C" | "d" | "D" | "e" | "E" | "f" | "F"
156
+
157
+ realValue = [ "+" | "-" ] *decimalDigit "." 1*decimalDigit [ ( "e" | "E" ) [ "+" | "-" ] 1*decimalDigit ]
158
+
159
+ charValue = // any single-quoted Unicode-character, except
160
+ // single quotes
161
+
162
+ stringValue = 1*( """ *ucs2Character """ )
163
+
164
+ ucs2Character = // any valid UCS-2-character
165
+
166
+ booleanValue = TRUE | FALSE
167
+
168
+ nullValue = NULL
169
+ The remaining productions are case-insensitive keywords:
170
+ ANY = "any"
171
+ AS = "as"
172
+ ASSOCIATION = "association"
173
+ CLASS = "class"
174
+ DISABLEOVERRIDE = "disableOverride"
175
+ DT_BOOL = "boolean"
176
+ DT_CHAR16 = "char16"
177
+ DT_DATETIME = "datetime"
178
+ DT_REAL32 = "real32"
179
+ DT_REAL64 = "real64"
180
+ DT_SINT16 = "sint16"
181
+ DT_SINT32 = "sint32"
182
+ DT_SINT64 = "sint64"
183
+ DT_SINT8 = "sint8"
184
+ DT_STR = "string"
185
+ DT_UINT16 = "uint16"
186
+ DT_UINT32 = "uint32"
187
+ DT_UINT64 = "uint64"
188
+ DT_UINT8 = "uint8"
189
+ ENABLEOVERRIDE = "enableoverride"
190
+ FALSE = "false"
191
+ FLAVOR = "flavor"
192
+ INDICATION = "indication"
193
+ INSTANCE = "instance"
194
+ METHOD = "method"
195
+ NULL = "null"
196
+ OF = "of"
197
+ PARAMETER = "parameter"
198
+ PRAGMA = "#pragma"
199
+ PROPERTY = "property"
200
+ QUALIFIER = "qualifier"
201
+ REF = "ref"
202
+ REFERENCE = "reference"
203
+ RESTRICTED = "restricted"
204
+ SCHEMA = "schema"
205
+ SCOPE = "scope"
206
+ TOSUBCLASS = "tosubclass"
207
+ TRANSLATABLE = "translatable"
208
+ TRUE = "true"
@@ -0,0 +1,2 @@
1
+ require 'rake/clean'
2
+ CLEAN.include("**/*~", "Gemfile.lock", "doc", ".yardoc", "pkg", "lib/mof/parser.rb", "lib/mof/parser.output")
@@ -0,0 +1,14 @@
1
+ begin
2
+ require 'yard'
3
+ YARD::Rake::YardocTask.new(:doc) do |t|
4
+ t.files = ['lib/**/*.rb']
5
+ t.options = ['--no-private']
6
+ end
7
+ rescue LoadError
8
+ STDERR.puts "Install yard if you want prettier docs"
9
+ require 'rdoc/task'
10
+ Rake::RDocTask.new(:doc) do |rdoc|
11
+ rdoc.rdoc_dir = "doc"
12
+ rdoc.title = "dm-keeper-adapter #{CIM::VERSION}"
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ rule '.rb' => '.y' do |t|
2
+ sh "racc -g -v -o #{t.name} #{t.source}"
3
+ end
4
+
5
+ task :test => [:racc]
6
+
7
+ task :racc => ["lib/mof/parser.rb"]
@@ -0,0 +1,6 @@
1
+ Rake::TestTask.new do |t|
2
+ t.libs << File.expand_path('../test', __FILE__)
3
+ t.libs << File.expand_path('../', __FILE__)
4
+ t.test_files = FileList['test/test*.rb']
5
+ t.verbose = true
6
+ end
@@ -0,0 +1,8 @@
1
+ qualifier Array : string[],
2
+ Scope(property);
3
+
4
+ class MOF_Test : Parent_Class
5
+ {
6
+ [ Array { "One", "Two", "Three" } ]
7
+ string text;
8
+ };
@@ -0,0 +1,4 @@
1
+ // association qualifier declaration
2
+ Qualifier Association : boolean = false,
3
+ Scope(association),
4
+ Flavor(DisableOverride, ToSubclass);
@@ -0,0 +1,4 @@
1
+ [ Description("This should fail with: 'Description' is not a valid qualifier") ]
2
+ class MOF_Test : Parent_Class
3
+ {
4
+ };
@@ -0,0 +1,7 @@
1
+ qualifier Description : string,
2
+ Scope(class);
3
+
4
+ [ Description("This is a class with a Description qualifier") ]
5
+ class MOF_Test : Parent_Class
6
+ {
7
+ };
@@ -0,0 +1,3 @@
1
+ class MOF_Test : Parent_Class
2
+ {
3
+ };
@@ -0,0 +1,8 @@
1
+ qualifier Description : string,
2
+ Scope(property);
3
+
4
+ class MOF_Test : Parent_Class
5
+ {
6
+ [ Description("This is a property with a Description qualifier") ]
7
+ string text;
8
+ };
@@ -0,0 +1,3 @@
1
+ // simple qualifier declaration
2
+ qualifier Description : string,
3
+ Scope(class, property);
@@ -0,0 +1,2 @@
1
+ class MOF_Test {
2
+ };
@@ -0,0 +1,39 @@
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", ["array_initializer.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
+ name,res = result.shift
19
+ # parsed one class
20
+ assert_equal 1, res.classes.size
21
+ c = res.classes.shift
22
+ assert c.is_a? CIM::Class
23
+ assert_equal "MOF_Test", c.name
24
+ assert_equal "Parent_Class", c.superclass
25
+ # one (property) feature
26
+ assert_equal 1, c.features.size
27
+ c.features.each do |f|
28
+ next unless f.is_a? CIM::Property
29
+ assert f.property?
30
+ assert !f.method?
31
+ assert_equal "text", f.name
32
+ assert f.type == :string
33
+ assert_equal 1, f.qualifiers.size
34
+ q = f.qualifiers.shift
35
+ assert_equal "Array", q.name
36
+ assert q.type == :array
37
+ end
38
+ end
39
+ end