CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Removing comments from LUA scripts

 



sjcomp
New User


Feb 1, 2008, 2:38 PM

Post #1 of 3 (2732 views)
Removing comments from LUA scripts Can't Post

I'd like to remove all the comments from a lua script. There are one line comments marked with double dashes. And block comments that start with double dashes followed by double left square brackets and end with double right square brackets.

Code
-- This is a comment. 
a = 3; -- This is a comment.
a = 4; --[[ This is
a
block
comment
]]

I can remove single line comments by doing:

Code
$_ =~ s/--[^\n]*\n//;

How do I detect beginning of the block comment though?

Thanks.
Regards, Alexander. http://sjcomp.com


KevinR
Veteran


Feb 1, 2008, 3:01 PM

Post #2 of 3 (2728 views)
Re: [sjcomp] Removing comments from LUA scripts [In reply to] Can't Post

do you have it all in one string or are you processing a file line by line?
-------------------------------------------------


sjcomp
New User


Feb 1, 2008, 3:08 PM

Post #3 of 3 (2727 views)
Re: [KevinR] Removing comments from LUA scripts [In reply to] Can't Post


In Reply To
do you have it all in one string or are you processing a file line by line?

A the moment I read file line by line:

Code
while(<>) 
{
$_ =~ s/--[^\n]*\n//;
}

I can change how it's done. I suppose it should be easier to get rid of the block comments if I put all the lines into one string and then process it:

Code
str = ""; 
while(<>)
{
str = str + $_;
}
str =~ s/--[^\n]*\n//g;
print str;

Thanks.
Regards, Alexander. http://sjcomp.com

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives