Sign in to follow this  
Followers 0
dragonlord

String parsing Help needed

12 posts in this topic

Class myclass Subclass Of ::rootIMExpress

Static gAccCommBaseTotal As Integer

Static gTotCurr As Variant

Static gTotCurrency As Integer

Static gUnitsSold As Double

Dim TotalUnitsCurrencyLevel As Integer

End Class

#Location Myreport::ConditionalSection1%ConditionIsTrue%AcDataRow

Function ConditionIsTrue( row As AcDataRow ) As Boolean

If gUnitsSold >100 then

ConditionIsTrue = True

Else

ConditionIsTrue = False

End If

End Function

#Pop

#Location Myreport::ConditionalSection2%ConditionIsFalse%AcDataRow

Function ConditionIsFalse( row As AcDataRow ) As Boolean

If gTotCurr >100 then

ConditionIsFalse = True

Else

ConditionIsFalse = False

End If

End Function

#Pop

the #location and #Pop stuff repeats hundreds of times.

I have a file with the above contents. What i need is to find if the variables that are declared in the Class section appear in any of the code that follows the class declaration. Once the variables are found, i need to the #location LINE in whose body the variable appears.

[For E.g : the output would be two arrays.

First Array : UnusedVariables[]={gAccCommBaseTotal,gTotCurrency,TotalUnitsCurrencyLevel}

Second Array : UsedVariables[]={{gUnitsSold,#Location Myreport::ConditionalSection1%ConditionIsTrue%AcDataRow},

{gTotCurr,#Location Myreport::ConditionalSection2%ConditionIsFalse%AcDataRow}}

]

I have succesfully read the variables in the Class section into an array. But, to search for variable in the code below, i tried a stupid way a looping through the file array and checkin using StringInStr(fileline,Variable array[1]), StringInStr(fileline,Variablearray[2])....till StringInStr(fileline,Variablearray[ubound]).

As you guys mite have guessed by now, each line doing a stringinStr with the whole array, is taking way too much time, coz the file is huge.(as i mentioned, the #location and #Pop stuff will repeat many times, with different body].

Anybody has a suggestion or workaround for this ?

[RegExp any good for this ? i have no clue abt it.]

Share this post


Link to post
Share on other sites



no suggestions ?

Share this post


Link to post
Share on other sites

You haven't given a good example of what you are trying to do.

1. Show exactly how you want to obtain the variables.. The code you are using to do that... and what you would like to have the output as.

2. Show exactly how you would like to obtain the variables (used ... that's what I'm assuming) and how you would like to see the output.

I have no clue on what you are trying to achieve, are you just trying to find the number of times a variable is used, what line it is used on, what... ?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You haven't given a good example of what you are trying to do.

1. Show exactly how you want to obtain the variables.. The code you are using to do that... and what you would like to have the output as.

2. Show exactly how you would like to obtain the variables (used ... that's what I'm assuming) and how you would like to see the output.

I have no clue on what you are trying to achieve, are you just trying to find the number of times a variable is used, what line it is used on, what... ?

my sentiments exactly

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

ooops, i missed out on that.

For the above file, the output should be something like.

UnusedVars[]={gAccCommBaseTotal,gTotCurrency,TotalUnitsCurrencyLevel}

since these are not used in any method.

and

UsedVars[][]={{gUnitsSold,ConditionIsTrue},{gTotCurr,ConditionIsFalse}}

since the variables gUnitsSold and gTotCurr appear in the methods ConditionIsTrue and ConditionIsFalse.

Will post the code i have to currently get the variable names into an array after i get back home 2nite. But i guess that would not be the challenging part.

Hope this is enough to spark your thoughts.

Edited by dragonlord

Share this post


Link to post
Share on other sites

any progress guys ?

Share this post


Link to post
Share on other sites

any progress guys ?

As much as you (considering this is the first I've even looked at it since my reply... any progress... pfft ;) )

You've still not provided anything to work with... no text to parse (like a txt file) none of your script (that you said you would in fact show). So you get what you offer in this case I suppose.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

..what language is this even in? that doesn't look like autoit code to me...actually it looks like VBS

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

K guys, attaching the code i have 2 get the variable declaration.

$FoundAllVars=0
            $FoundGlobalVars=0
            $GlobalsHaveStarted=0
            For $z = 1 To $filelines[0]
                If $FoundGlobalVars=1 Then ExitLoop
                If StringInStr ($filelines[$z] ,"Subclass Of ::rootIMExpress") Then
                    $p=$z+1
                        While $foundAllvars=0
                            If StringInStr($filelines[$p],"Static") or StringInStr($filelines[$p],"Dim") Then
                                        If StringInStr($filelines[$p],"Static") Then
                                        $GlobalVarEndPos=StringInStr($filelines[$p]," As")
                                        $GlobalVarStartPos=StringInStr($filelines[$p],"Static")+7
                                        $Gvarname=StringMid($filelines[$p],$GlobalVarStartPos,$GlobalVarEndPos-$GlobalVarStartPos)
                                        
                                    EndIf
                                    If StringInStr($filelines[$p],"Dim") Then
                                        $GlobalVarEndPos=StringInStr($filelines[$p]," As")
                                        $GlobalVarStartPos=StringInStr($filelines[$p],"Dim")+3
                                        $Gvarname=StringMid($filelines[$p],$GlobalVarStartPos,$GlobalVarEndPos-$GlobalVarStartPos)
                                    Endif
                            $GlobalVarsArray[$GlobalVarsArrayIndex]=$Gvarname
                            $GlobalVarsArrayIndex=$GlobalVarsArrayIndex+1
                            If $GlobalVarsArrayIndex >= 100 Then Redim $GlobalVarsArray[$GlobalVarsArrayIndex]
                            $GlobalsHaveStarted=1
                        Endif
                        If $GlobalsHaveStarted=1 and Stringlen($filelines[$p])=0 Then
                            $FoundGlobalVars=1
                            $foundAllvars=1
                        EndIf
                        $p=$p+1
                        Wend
                EndIf
                
            Next

Any the file to be parsed would be something like..

Class frmGetAsss Subclass Of AcFrame

    Dim accountNameValue As String
    Dim AccountNumberTempTable As String
    Dim accountNumberValue As String
    Dim creatorValue As String
    Dim dateCreatedValue As String
    Dim descriptionValue As String
    Dim detailValue As String
    Dim entriesValue As String
    Dim idListValue As String
    Dim lastModifiedDateValue As String
    Dim lastModifingUserValue As String
    Dim nameValue As String

    Sub SetProperties( )
        Super::SetProperties( )
        Size.Height = 0
        Size.Width = 0
    End Sub
    
    '----------------------------------------
    ' User-defined methods
    '----------------------------------------
    
#Location "frmGetAsss%getAsssInfo%String"
    Function getAsssInfo(acctNumber As String) As String
    creatorValue =creatorValue +1
    End Function
#Pop

#Location "frmGetAsss%parseSSSInfo%String"
    Function parseSSSInfo(sssString As String) As Boolean
    lastModifingUserValue="ABB"
    End Function
#Pop

#Location "frmGetAsss%parseSSSKey%String"
    Function parseSSSKey(FullKey As String) As Boolean
        ShowFactoryStatus("result str" + nameValue)
    
    End Function
#Pop

End Class

FYI, this is actually a language called Actuate basic, used in a reporting tool called Actuate.

I just made the file myself. it's not big as i mentioned in my first post. just imagine the #Location to #Pop code repeats some 1000 times.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Generally... when people post code, it works (or attempts to work). You've still not provided an "Exact" layout file example of what you want.

Get all Vars? What's a var in this language Dim <var name here>? Are they always declared? Do you need to know if it is declared as a string or whatever?

Your code and your text example doesn't even match up ;)

I enjoy using the string functions and want to help, but I can't stand it when I have no idea where to start, what I need to get, and what the exact output needs to be... if that out put is stored in an array, if it's written to a file, if it's just for shits and giggles.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Just to show you I wasn't kidding, this is how I would get the declared vars

;Dim $sString = FileRead('FileLocation')
Dim $sString = "    Dim accountNameValue As String" & @CRLF & _
    "   Dim AccountNumberTempTable As String" & @CRLF & _
    "   Dim accountNumberValue As String" & @CRLF & _
    "   Dim creatorValue As String" & @CRLF & _
    "   Dim dateCreatedValue As String" & @CRLF & _
    "   Dim descriptionValue As String" & @CRLF & _
    "   Dim detailValue As String" & @CRLF & _
    "   Dim entriesValue As String" & @CRLF & _
    "   Dim idListValue As String" & @CRLF & _
    "   Dim lastModifiedDateValue As String" & @CRLF & _
    "   Dim lastModifingUserValue As String" & @CRLF & _
    "   Dim nameValue As String" & @CRLF & @CRLF & _
    "   Sub SetProperties( )";

Dim $aAllVarsAndDeclarations = StringRegExp($sString, '(?s)(?i)Dim\s(.*?)\sAs\s(.*?)\n', 3);
If Not IsArray($aAllVarsAndDeclarations) Then;
    MsgBox(16, 'Error', 'Not an array.');
    Exit;
EndIf;

Dim $aAVAD[UBound($aAllVarsAndDeclarations)][2], $iAdd;
For $iCC = 0 To UBound($aAllVarsAndDeclarations) - 1 Step 2;
    $iAdd += 1;
    $aAVAD[$iAdd][0] = $aAllVarsAndDeclarations[$iCC];
    $aAVAD[$iAdd][1] = $aAllVarsAndDeclarations[$iCC + 1];
Next;
ReDim $aAVAD[$iAdd + 1][2];
_ArrayDisplay2D($aAVAD);
    

Func _ArrayDisplay2D($aArray, $sTitle = 'Array Display 2Dim', $iBase = 1, $sToConsole = 0);
    If Not IsArray($aArray) Then Return SetError(1, 0, 0);
    Local $sHold = 'Dimension 1 Has:  ' & UBound($aArray, 1) -1 & ' Element(s)' & @LF & _
            'Dimension 2 Has:  ' & UBound($aArray, 2) - 1 & ' Element(s)' & @LF & @LF;
    For $iCC = $iBase To UBound($aArray, 1) - 1;
        For $xCC = 0 To UBound($aArray, 2) - 1;
            $sHold &= '[' & $iCC & '][' & $xCC & ']  = ' & $aArray[$iCC][$xCC] & @LF;
        Next;
    Next;
    If $sToConsole Then Return ConsoleWrite(@LF & $sHold);
    Return MsgBox(262144, $sTitle, StringTrimRight($sHold, 1));
EndFunc;oÝ÷ Øg­¶¦v¬x%{FÚ±çZ®¶²ºÈ§+kxz1¦Ø^«±ëazh§¶¶v)Ȩ©Z®¶²Ò%v)දj¸nWÝa¢Wbayתڶ*'Ø­ËnjYr¶¡×¢²«¢µë!¢»HºÇºÚÈ8¬¦V²Ø6ºËhç_¡ù¢ëh²0Ê+"±§-¹©eÉ©e¶­Â¥u·§yç^u«­¢+Ù¥´ÀÌØíÍMÑÉ¥¹ô¥±I Ìäí¥±1½Ñ¥½¸Ìäì¤)¥´ÀÌØí±±YÉ͹±ÉÑ¥½¹ÌôMÑÉ¥¹IáÀ ÀÌØíÍMÑÉ¥¹°Ìäì ý̤ ý¤¥¥´ÀäÈíÌ ¸¨ü¤ÀäÈíÍÌÀäÈíÌ ¸¨ü¤ÀäÈí¸Ìäì°Ì¤ì)%9½Ð%ÍÉÉä ÀÌØí±±YÉ͹±ÉÑ¥½¹Ì¤Q¡¸ì(%5Í ½à ÄØ°ÌäíÉɽÈÌäì°Ìäí9½Ð¸ÉÉä¸Ìäì¤ì(%á¥Ðì)¹%ì()¥´ÀÌØíYmU   ½Õ¹ ÀÌØí±±YÉ͹±ÉÑ¥½¹Ì¥ulÉt°ÀÌØí¥ì)½ÈÀÌØí¥
ôÀQ¼U    ½Õ¹ ÀÌØí±±YÉ͹±ÉÑ¥½¹Ì¤´ÄMÑÀÈì($ÀÌØí¥¬ôÄì($ÀÌØíYlÀÌØí¥ulÁtôÀÌØí±±YÉ͹±ÉÑ¥½¹ÍlÀÌØí¥

tì($ÀÌØíYlÀÌØí¥ulÅtôÀÌØí±±YÉ͹±ÉÑ¥½¹ÍlÀÌØí¥
¬Åtì)9áÐì)I¥´ÀÌØíYlÀÌØí¥¬ÅulÉt

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

like i told u already, the code which i have posted already gets me the list of variables in an array (which u have done using reg exp). [also, i dont need to know the variable type].

If you see the sample file which needs to be parsed, from line 28 onwards, the variables are used in user-defined methods in that language.

it is in this segment of the file that i need to scan and find out if any of the above variables are present or not.

so, the required output from autoit would be two arrays

1. UnusedVars[]={accountNameValu,AccountNumberTempTable,accountNumberValue,dateCreatedValue,description

Value,detailValue,entriesValue,lastModifiedDateValue}

since these are not used anywhere else, other than in the declaration section of the file.

and

2.UsedVars[][]={{creatorValue,getAsssInfo},{lastModifingUserValue,parseSSSInfo},{nameValue,parseSSSK

ey}}

which is in the format {variablename,Locationname} where location name is the string between two % characters on the line starting with #Location

These two arrays would help me show the user that these un-used variables can be safely removed from his source-code. Thats the basic idea behind doing this stuff.

Edited by dragonlord

Share this post


Link to post
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
Sign in to follow this  
Followers 0