NAME
Verilog::Parse - parse Verilog language files
WARNING
This module is no longer supported. Use Verilog::Parser instead.
SYNOPSIS
use Verilog::Parse;
$parser = new Verilog::Parse;
sub function {my ($parser, $what, $info) = @_; ...}
$parser->callback ("xxx", \&function)
$string = $parser->unreadback ();
$parser->Verilog::Parse::parse ($FileHandle)
DESCRIPTION
This package implements parsing of the Verilog language. A file is parsed and callbacks are called for various entities in the file, as they occur.
WARNING
This module is no longer supported. Use Verilog::Parser instead.
- $parser->new
-
Create a new parser.
- $parser->callback ("token", \&function)
-
Request that when the parser hits the given token, function will be called. The tokens that may be parsed are:
"COMMENT" Any text in // or /**/ comments. "STRING" Any quoted string, including the quotes. "KEYWORD" A Verilog keyword. (See C<Verilog::Language>) "SYMBOL" A textual non-keyword "OPERATOR" A non-alphanumeric operator. "NUMBER" A number.
The callback will get three arguments. The first is the parser (self). The second is the exact type of token, one of those listed above. Third is a string with the symbol, number, etc.
- $parser->parse ($FileHandle)
-
Read input from the filehandle, and perform callbacks as needed.
- $parser->unreadback ()
-
Return any input string from the file that has not been sent to the callback. This will include whitespace and tokens which did not have a callback. (For example comments, if there is no comment callback.) This is useful for recording the entire contents of the input, for preprocessors, pretty-printers, and such.
EXAMPLE
Here\'s a simple example which will print every symbol in a verilog file. We also remember what line it occured on, just for the heck of it.
sub symbol_cb { # Callback from parser when a symbol occurs sub function (my ($parser, $what, $info) = @_; ...) $signals_and_symbols{$info} = $.; }
sub verilog_read_symbols { my $filename = shift;
local %signals_and_symbols = (); # Signals already found in module
my $fh = new FileHandle;
my $parser = new Verilog::Parse;
$parser->callback ("SYMBOL", \&symbol_cb);
$fh->open("<$filename") or die "Can't read $filename.";
$parser->Verilog::Parse::parse ($fh);
$fh->close;
foreach $sym (sort (keys %signals_and_symbols)) {
print "Symbol $sym\n";
}
}
SEE ALSO
Verilog::ParseSig
, Verilog::Language
, FileHandle
,
BUGS
This is being distributed as a baseline for future contributions. Don\'t expect a lot, the parser is still nieve, and there are many awkward cases that aren\'t covered.
DISTRIBUTION
The latest version is available from http://veripool.com/verilog-perl
.
AUTHORS
Wilson Snyder <wsnyder@wsnyder.org>