Class: PlcUtil::Awl::AwlFile

Inherits:
Object
  • Object
show all
Defined in:
lib/plcutil/siemens/awl/awl_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, options = {}) ⇒ AwlFile

Returns a new instance of AwlFile.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/plcutil/siemens/awl/awl_file.rb', line 18

def initialize(filename, options = {})
  @symlist = options[:symlist] && SymlistFile.new(options[:symlist]) || {}
  # parse file
  parser = PlcUtil::Awl::AwlGrammarParser.new
  awl_nodes = parser.parse File.read(filename)
  @awl = awl_nodes && awl_nodes.visit
  if !@awl
    raise [
      "Unable to parse file: #{filename}",
      "Failure on line #{parser.failure_line} column #{parser.failure_column}",
      "Details:",
      parser.failure_reason.inspect,
    ].join("\n")
  end
end

Instance Attribute Details

#symlistObject (readonly)

Returns the value of attribute symlist.



16
17
18
# File 'lib/plcutil/siemens/awl/awl_file.rb', line 16

def symlist
  @symlist
end

Instance Method Details

#each_exploded(options = {}, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/plcutil/siemens/awl/awl_file.rb', line 38

def each_exploded(options = {}, &block)
  @awl[:dbs].each do |raw|
    db = create_struct raw
    name = if options[:no_block] 
             ''
           else 
             raw[:id]
           end

    a = DbAddress.new 0, db_address(raw[:name])
    db.each_exploded(a, name) do |addr, name, comment, type_name|
      yield addr, name, comment, type_name
    end
  end
end

#lookup_symlist(tag) ⇒ Object



34
35
36
# File 'lib/plcutil/siemens/awl/awl_file.rb', line 34

def lookup_symlist(tag)
  (options[:blocks] && options[:blocks][tag]) || (@symlist && @symlist[tag])
end