Module: VHDL_Parser
- Defined in:
- lib/vhdl_parser.rb,
lib/vhdl_parser/port.rb,
lib/vhdl_parser/entity.rb,
lib/vhdl_parser/generic.rb,
lib/vhdl_parser/package.rb,
lib/vhdl_parser/utility.rb,
lib/vhdl_parser/extractor.rb
Overview
VHDL Parser Module. It parses a given VHDL entity into Ruby objects that can then be used further in code, e.g. for visualization or automation.
Defined Under Namespace
Classes: Entity, Extractor, Generic, Package, Port, Utility
Class Method Summary collapse
-
.parse(vhdl_string) ⇒ Entity
Parses the given string and returns an Entity object.
-
.parse_file(filename) ⇒ Entity
Parses the given file and returns an Entity object.
-
.parse_package(string) ⇒ Package
Parses the given VHDL package string and returns a Package object.
-
.parse_package_file(filename) ⇒ Package
Parses the given VHDL package file and returns a Package object.
Class Method Details
.parse(vhdl_string) ⇒ Entity
Parses the given string and returns an Entity object.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vhdl_parser.rb', line 28 def self.parse(vhdl_string) info = vhdl_string.match /entity\s+(.*)\s+is\s+(?:generic\s*\((.*)\);)?\s*port\s*\((.*)\);\s*end\s*\1;/im unless info[2].nil? generics = info[2].split("\n").compact.delete_if { |s| s.strip.empty? } generics.map! { |s| s.strip} generics.delete_if { |l| l.match /^--/} end ports = info[3].split("\n").compact.delete_if { |s| s.strip.empty? } ports.map! { |s| s.strip} ports.delete_if { |l| l.match /^\s*--/} @entity = Entity.new(info[1]) self.parse_generics(generics) self.parse_ports(ports) @entity.process_generics return @entity end |
.parse_file(filename) ⇒ Entity
Parses the given file and returns an Entity object.
20 21 22 23 |
# File 'lib/vhdl_parser.rb', line 20 def self.parse_file(filename) string = File.read(filename) self.parse(string) end |
.parse_package(string) ⇒ Package
Parses the given VHDL package string and returns a Package object.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vhdl_parser.rb', line 63 def self.parse_package(string) package = Package.new constants = Extractor.extract_package_constants(string) constants.each do |c| package.constants[c[0]] = c[2] end package.process package end |
.parse_package_file(filename) ⇒ Package
Parses the given VHDL package file and returns a Package object.
55 56 57 58 |
# File 'lib/vhdl_parser.rb', line 55 def self.parse_package_file(filename) string = File.read(filename) self.parse_package(string) end |