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.
- data/Gemfile +4 -0
- data/History.txt +12 -2
- data/LICENSE +58 -0
- data/README.rdoc +1 -8
- data/README.rdoc~ +57 -0
- data/Rakefile +3 -27
- data/bin/moflint +5 -0
- data/lib/include/sblim-qualifiers.mof +7 -0
- data/lib/include/wmi-qualifiers.mof +213 -0
- data/lib/mof.rb +1 -1
- data/lib/mof/helper.rb +7 -5
- data/lib/mof/parser.rb +422 -431
- data/lib/mof/parser.y +661 -0
- data/lib/mof/result.rb +2 -1
- data/lib/mof/scanner.rb +13 -13
- data/mof.gemspec +29 -0
- data/parser/doc/mof.bnf +208 -0
- data/tasks/clean.rake +2 -0
- data/tasks/doc.rake +14 -0
- data/tasks/racc.rake +7 -0
- data/tasks/test.rake +6 -0
- data/test/mof/array_initializer.mof +8 -0
- data/test/mof/association_qualifier.mof +4 -0
- data/test/mof/class_qualifier_fail.mof +4 -0
- data/test/mof/class_qualifiers.mof +7 -0
- data/test/mof/derived.mof +3 -0
- data/test/mof/property_qualifier.mof +8 -0
- data/test/mof/qualifier.mof +3 -0
- data/test/mof/simple.mof +2 -0
- data/test/test_array_initializer.rb +39 -0
- data/test/test_association_qualifier.rb +37 -0
- data/test/test_qualifier.rb +12 -7
- metadata +54 -57
- data/Manifest.txt +0 -10
data/lib/mof/result.rb
CHANGED
data/lib/mof/scanner.rb
CHANGED
@@ -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,
|
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,
|
124
|
+
when "association": @q.push [:ASSOCIATION, m]
|
125
125
|
when "class": @q.push( [:CLASS, m] )
|
126
|
-
when "disableoverride": @q.push [:DISABLEOVERRIDE,
|
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,
|
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,
|
147
|
-
when "instance": @q.push [:INSTANCE, m
|
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,
|
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,
|
161
|
-
when "tosubclass": @q.push [:TOSUBCLASS,
|
162
|
-
when "translatable": @q.push [:TRANSLATABLE,
|
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
|
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__), '
|
202
|
-
raise
|
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
|
data/mof.gemspec
ADDED
@@ -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
|
data/parser/doc/mof.bnf
ADDED
@@ -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"
|
data/tasks/clean.rake
ADDED
data/tasks/doc.rake
ADDED
@@ -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
|
data/tasks/racc.rake
ADDED
data/tasks/test.rake
ADDED
data/test/mof/simple.mof
ADDED
@@ -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
|