Jump to content

parse comments #cs


Will66
 Share

Recommended Posts

is it possible to parse comments somehow within a function or script?

eg:(Obviously this will fail)

Func test()

$mycomm=("" & _

#cs

hello

how are you

#ce

)

;is there a way to read the above comments (#cs->#ce)at runtime

MsgBox(0,"comments parsed", $mycomm)

EndFunc

Link to comment
Share on other sites

Hello,

you could try it with regular expression:

#cs
hello
how are you
#ce
$f = @ScriptFullPath
#cs
read in script file
#ce
$txt = FileRead($f)
#cs
regular expressions are very effective
#ce
$aRes = StringRegExp($txt,"(?s)(?U)(#cs.*#ce)",3)
If @error Then 
    Cons("err:"&@error)
    Exit
EndIf
#cs 
show result
#ce
For $i = 0 To UBound($aRes) -1
    Cons("- comment number " & $i+1 & ": " & $aRes[$i])
Next
#cs 
screen output helper
#ce
Func cons($t)
    ConsoleWrite($t & @LF)
EndFunc

The interesting part is the StringRegExp() function:

(?s) ... enables newlines to be matched by '.'

(?U) ... inverts greediness, we dont want it to be greedy here

(#cs.*#ce) ... selects an returns parts between start and end marks

Really, I recommend any programmer to take a deep look into regular expressions.

It's hard at start, but if you get some feeling for it, you will find out that regexp can

help you in many various cases, often making code less complex.

Last but not least, you can use regular expressions in many programming languages,

so its absolutely no waste to know how to use them.

ciao

Xandl

Link to comment
Share on other sites

Thankyou Xandl, Very nice.

Do you think there's any way this can be done from a compiled script and for arguments sake output to msgbox(0,"comments",$t):

Func cons($t)

msgbox(0,"",$t)

EndFunc

The option to de-compile a script has been removed from the current version of AutoIt. I think one of the reason for doing this was so the text source of the script could be stripped down and encoded efficiently. I'm not sure, but I don't think comments survive that optimization process.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The option to de-compile a script has been removed from the current version of AutoIt. I think one of the reason for doing this was so the text source of the script could be stripped down and encoded efficiently. I'm not sure, but I don't think comments survive that optimization process.

:)

It was a longshot request.

Basically i'm looking for a way to include blocks of text in my compiled script that i can read without the hassle of variablizing each line of text.

Naturally, there are a couple of ways:

1 $somevariable ="jwhgdjwe" & _

or

$somevariable &="jwhgdjwe" etc

2. #including the text block as a file install, then extracting temporarily to the hard disk for reading, then delete the temp file.

Ideally it would be great if autoit offered a way of including blocks of text that could be read at runtime of a compiled exe?

Link to comment
Share on other sites

for example in php you can do something like this:

<?php

echo "<table width=\"90%\" border=\"0\" align=\"center\" class=\"\">

<tr>

<td width=\"526\" class=\"\" align=\"left\"><strong><font color=\"#E17100\">Thank you for contacting us.</font></strong> <br>We will respond to all inquiries in the order as they are received, as soon as it is possible.</span></td>

</tr>

<tr>

<td width=\"526\" class=\"\" align=\"left\">Name: $name</span></td>

</tr>

<tr>

<tr>

<td width=\"526\" class=\"\" align=\"left\">Email Address: $email</span></td>

</tr>

<tr>

<tr>

<td width=\"526\" class=\"\" align=\"left\">Web Site: $phone</span></td>

</tr>

<tr>

<tr>

<td width=\"526\" class=\"\" align=\"left\">Message: $comments</span></td>

</tr>

<tr>

</table>";

?>

Link to comment
Share on other sites

Somebody, I think it might have been Zedna, did something with reshack that would put resources (like a text file) into a compiled file and then get it out again.

Didn't need it at the time, so I didn't look too closely... :)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...