VBScript - improper scope resolution

Started by Arthur, August 10, 2009, 05:47:03 PM

Previous topic - Next topic

Arthur

I can see that HE can be confused by single-line If-Then statements, especially those w/o the corresponding End If. In this case the scope resolution gets incorrectly assigned.
In VBScript it is legit to not have the end if in case the whole statement fits onto one line.
The end if belongs to the upper If statement.

alex

Hi Arthur,

can you please copy here a sample code which is incorrectly parsed, but I think, unfortunately, this could not be solved easy, because to recognize such language construction HE need to have a deep knowledge of VB Script grammar, while I do not see a way how such logic can be described (vb also do not have line end symbols).

Best regards,
Alex.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Arthur

Here is the fragment:

For Each str_Data In str_ADDR_Data

         If i = RanU Then

            If (len(str_Data) > 4) and (Instr(1, str_Data, ",", 0) > 0) then str_U_Item = Split(str_Data, ",")
            If (len(str_G_Data) > 4) and (Instr(1, str_G_Data, "|", 0) > 0) then strG_Item = Split(str_G_Data, "|")

            OutFile.WriteLine(strG_Item(0) & "|" & strG_Item(1) & "|" & strG_Item(2) & "|" & strG_Item(3) & "|" & strG_Item(4) & "|" & strG_Item(5) & "|""" & LeftPad(str_U_Item(0), 30, " " ) & """|""" & str_U_Item(1) & """|""" & str_U_Item(2) & """|" & strG_Item(9) & "|" & strG_Item(10) & "|" & strG_Item(11) & "|" & strG_Item(12) & "|" & strG_Item(13) & "|" & strG_Item(14) & "|" & strG_Item(15) & "|" & strG_Item(16) )
         End If

         i = i + 1
      Next

alex

Thanks for a sample.

This is what I meant... How to recognize here (and instruct HE) that scope:
If (len(str_Data) > 4) and (Instr(1, str_Data, ",", 0) > 0) then str_U_Item = Split(str_Data, ",") is closed?...
and if it would be like this:
If (len(str_Data) > 4) and (Instr(1, str_Data, ",", 0) > 0) then str_U_Item
=
Split(str_Data, ",")


So, ... thanks for a bug report, but when it would be fixed have no idea. I would place this into my todo list and would think about it, maybe some generic solution can be found (I would not build something vb specific)
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Arthur

Yeah, I can see it is not trivial. And not a big deal to me.
I think I can use the full syntax even for consistency and get away from this nag this way :)

Stefan

1.) just an note:
Alex, your second example is not valid for VBS code.
The command has to be at one line OR  if you would use more lines as in your second example they must  have an trailing underscore.

2.) maybe this helps
If we use an one-line If-Then then after the THEN there is some text which is not an comment sign '

Valid one liner:   IF x=y Then someCodehere and then maybe an 'comment
no one-liner:      IF x=y Then 'comment. This is probably the begin of an two or three liner:  IF x=y Then\nElse\nEnd If

Again:
If x=y Then WScript.Quit ' comment this is one line command
If x=y Then 'WScript.Quit  comment this is no one line command
a=b
End IF
Maybe your code can catch this?
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

alex

Thanks Stefan. Now at least case more clear, but problem do not became easier...
In any case I need to formalize it in some way in syntax rules I have (or add new one which can be reused):
      <Scope open="If" middle="Else" close="End If" strict="false">
        <Middle text="Then"/>
        <Middle text="ElseIf"/>
      </Scope>

keeping in mind other syntaxes where it can be used.

Or maybe use regular expression as conditions here, like this done for labels:
      <Label group="Subroutine" match="\&lt;(public|private)?\s*(sub|function)\s+(\w+)\s*(\([^)]*\))" name="\3" descr="\2 \3 \4" image="6" scope="1">
        <Image if="\2" equal="sub" value="9"/>
        <SubImage if="\1" equal="public" value="2"/>
        <SubImage if="\1" equal="private" value="4"/>
      </Label>


So, still not simple :/ And I also do not want to create a special rule for any special case, but would like to have a set of rules I can reuse.
I would think, maybe if I would find more scenarios like this for other syntaxes, system for rule would be more clear.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]