in reply to Bash Parser
undef my %functions;What's the point of using an explicite undef here? What's wrong with my %functions;?
I don't get this. Why not just $file =~ s/\$$variable/$path/g;, or, if you're worried the substitution has a fatal syntax: eval {$file =~ s/\$$variable/$path/g;}? But you aren't checking the result of the eval, so you must be confident that it won't fail.my $regex = "\$file =~ s/\\\$$variable/$path/g;"; eval "$regex";
open FH2, "<$file";Remember what one of the creators of Unix (Thompson?) said: not being able to open a file is not exceptional. Always check if opening a file succeeded.
if(/^[ \t]*source +([\w\-\/\.\_\$]+)/)Hmmm. So, I can have tabs before the source keyword, but not after them? And I cannot surround the filenames with quotes? Or have non-word characters other than '-', '/', '.', '_' or '$' in them?
if($check_if_bash == 1 && $line_number == 1 && ! /bash/) { return }A bash script doesn't have to start with a line saying "bash". Just like a Perl program doesn't have to start with a line saying "perl". And even if such a script starts with a she-bang line, it may says #!/usr/bin/sh, where /usr/bin/sh and /usr/bin/bash are links to the same file.
What makes you think that %% ... %% on a single line is a comment block in bash? My bash manual mentions various meanings for %% depending on context, but none of them have anything to do with comments.# Count comments and empty lines elsif(/(\%\%.*\%\%)/) {
You also seem to assume bash programs use only newlines as statement separators, and all newlines separate statements. Neither statement is true.
You don't seem to deal with any of the many quoting and grouping mechanisms of a bash program. Nor does your program seem to be able to deal with here documents.
There's quite some duplication of code between 'match' and 'get_sources', but there are also differences. It's totally unclear to me why there need to be any differences.
It looks to me there's no guards against infinite recursion. If file 'A' contains source A, then your program will never stop by itself.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bash Parser
by mickep76 (Beadle) on Sep 30, 2009 at 11:30 UTC | |
by jakobi (Pilgrim) on Sep 30, 2009 at 19:22 UTC | |
|
Re^2: Bash Parser
by mickep76 (Beadle) on Sep 30, 2009 at 09:59 UTC | |
by Anonymous Monk on Sep 30, 2009 at 10:12 UTC |