sfp 0.4.2 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +0 -2
- data/VERSION +1 -1
- data/lib/sfp/SfpLangLexer.rb +51 -51
- data/lib/sfp/SfpLangParser.rb +1114 -1106
- data/lib/sfp/Sfplib.rb +5 -5
- data/lib/sfp/parser.rb +13 -4
- data/lib/sfp/visitors.rb +7 -0
- data/src/SfpLang.g +6 -1
- metadata +3 -3
data/lib/sfp/Sfplib.rb
CHANGED
@@ -14,10 +14,10 @@ module Sfp
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def finalize
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
17
|
+
#@root.keys.each { |k|
|
18
|
+
# next if k[0,1] == '_' or !@root[k].is_a?(Hash)
|
19
|
+
# @root.delete(k) if @root[k]['_context'] == 'abstract'
|
20
|
+
#}
|
21
21
|
end
|
22
22
|
|
23
23
|
def next_id
|
@@ -57,7 +57,7 @@ module Sfp
|
|
57
57
|
parser = Sfp::Parser.new({ :root_dir => @root_dir,
|
58
58
|
:home_dir => File.expand_path(File.dirname(filepath)),
|
59
59
|
:constraint_next_id => @constraint_next_id })
|
60
|
-
parser.parse(File.read(filepath))
|
60
|
+
parser.parse(File.read(filepath), {:keep_abstract => true})
|
61
61
|
parser.root.each_pair do |key,val|
|
62
62
|
if val.is_a?(Hash)
|
63
63
|
if val['_context'] == 'state' and @root.has_key?(key) and @root[key]['_context'] == 'state'
|
data/lib/sfp/parser.rb
CHANGED
@@ -4,6 +4,8 @@ class Sfp::Parser
|
|
4
4
|
# enable this class to process SFP into FDR (SAS+)
|
5
5
|
include Sfp::SasTranslator
|
6
6
|
|
7
|
+
AbstractEliminator = Sfp::Visitor::AbstractEliminator.new
|
8
|
+
|
7
9
|
attr_accessor :root_dir, :home_dir, :conformant
|
8
10
|
attr_reader :root, :constraint_next_id
|
9
11
|
|
@@ -19,7 +21,14 @@ class Sfp::Parser
|
|
19
21
|
@constraint_next_id = (params[:constraint_next_id] ? params[:constraint_next_id] : 0)
|
20
22
|
end
|
21
23
|
|
22
|
-
|
24
|
+
#####
|
25
|
+
#
|
26
|
+
# @param [String] : a string of specification in SFP language
|
27
|
+
# @options [Hash]
|
28
|
+
#
|
29
|
+
# @return [Hash] : the result Hash
|
30
|
+
#
|
31
|
+
#####
|
23
32
|
def parse(string, options={})
|
24
33
|
lexer = SfpLang::Lexer.new(string)
|
25
34
|
tokens = ANTLR3::CommonTokenStream.new(lexer)
|
@@ -30,8 +39,10 @@ class Sfp::Parser
|
|
30
39
|
parser.sfp
|
31
40
|
@constraint_next_id = parser.constraint_next_id
|
32
41
|
@root = parser.root
|
42
|
+
parser.root.accept(AbstractEliminator) if not options[:keep_abstract]
|
33
43
|
@conformant = parser.conformant
|
34
44
|
@parser_arrays = parser.arrays
|
45
|
+
parser.root
|
35
46
|
end
|
36
47
|
|
37
48
|
def to_json(params={})
|
@@ -41,10 +52,8 @@ class Sfp::Parser
|
|
41
52
|
end
|
42
53
|
|
43
54
|
def self.parse_file(filepath, options={})
|
44
|
-
#homedir = File.expand_path(File.dirname(filepath))
|
45
55
|
options[:home_dir] = File.expand_path(File.dirname(filepath)) if !options[:home_dir]
|
46
|
-
parser = Sfp::Parser.new(options)
|
56
|
+
parser = Sfp::Parser.new(options)
|
47
57
|
parser.parse(File.read(filepath))
|
48
|
-
parser.root
|
49
58
|
end
|
50
59
|
end
|
data/lib/sfp/visitors.rb
CHANGED
@@ -30,6 +30,13 @@ module Sfp
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
class AbstractEliminator
|
34
|
+
def visit(name, value, parent)
|
35
|
+
parent.delete(name) if value.is_a?(Hash) and value['_context'] == 'abstract'
|
36
|
+
true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
33
40
|
class ParentGenerator
|
34
41
|
def visit(name, value, parent)
|
35
42
|
value['_parent'] = parent if value.is_a?(Hash)
|
data/src/SfpLang.g
CHANGED
@@ -189,7 +189,11 @@ object_schemata
|
|
189
189
|
;
|
190
190
|
|
191
191
|
abstract_object
|
192
|
-
:
|
192
|
+
: {
|
193
|
+
@is_final = false
|
194
|
+
@now['_finals'] = [] if !@now.has_key? '_finals'
|
195
|
+
}
|
196
|
+
'abstract' object_def
|
193
197
|
{ @root[$object_def.id]['_context'] = 'abstract' }
|
194
198
|
;
|
195
199
|
|
@@ -197,6 +201,7 @@ object_def returns [id]
|
|
197
201
|
: ID { $id = $ID.text }
|
198
202
|
{
|
199
203
|
@use_template = false
|
204
|
+
@now['_finals'] = [] if !@now.has_key? '_finals'
|
200
205
|
@now['_finals'] << $ID.text if @is_final
|
201
206
|
}
|
202
207
|
('extends' path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Herry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: antlr3
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project: sfp
|
92
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.1.10
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: SFP Parser
|