Class: VHDL_Parser::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/vhdl_parser/extractor.rb

Overview

Helper class with methods that extract a portion of interest from a given String.

Class Method Summary collapse

Class Method Details

.extract_comment(string) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/vhdl_parser/extractor.rb', line 44

def self.extract_comment(string)
  res = string.match(/--(.*)$/)
  if res && res[0]
    return res[0]
  end
  ""
end

.extract_direction(string) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/vhdl_parser/extractor.rb', line 12

def self.extract_direction(string)
  res = string.match(/:\s*(in|out|inout)/)
  if res[1]
    return res[1]
  end
  ""
end

.extract_name(string) ⇒ Object



7
8
9
10
# File 'lib/vhdl_parser/extractor.rb', line 7

def self.extract_name(string)
  names = string.split(":").map! { |e| e.strip}
  names[0].split(/\s*,\s*/)
end

.extract_package_constants(string) ⇒ Object



52
53
54
55
56
57
# File 'lib/vhdl_parser/extractor.rb', line 52

def self.extract_package_constants(string)
  body = string.match(/package\s+(.*)\s+is\s+(.*)\s*end\s*\1;/im)
  name = body[1]
  constants = body[2]
  constants.scan /constant\s+(\w+)\s*:\s*(\w+)\s*:=\s*(.*);/i
end

.extract_range(string) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/vhdl_parser/extractor.rb', line 36

def self.extract_range(string)
  res = string.match(/range\s+(.*?)\s+(downto|to)\s+([-a-z0-9_]*)/i)
  if res 
    return res
  end
  ""
end

.extract_size(string) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/vhdl_parser/extractor.rb', line 28

def self.extract_size(string)
  res = string.match(/\((.*?)\s+(downto|to)\s+(.+?)\)/i)
  if res 
    return res
  end
  ""
end

.extract_type(string) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/vhdl_parser/extractor.rb', line 20

def self.extract_type(string)
  res =  string.match(/:\s*(?:in|out|inout)?\s+(\w+)/i)
  if res[1]
    return res[1]
  end
  ""
end

.extract_value(string) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/vhdl_parser/extractor.rb', line 59

def self.extract_value(string)
  res = string.match /:=\s*([xo"0-9a-z_]*)/i
  if res && res[1]
    return res[1]
  end
  ""
end