GithubHelp home page GithubHelp logo

Comments (6)

tommy9 avatar tommy9 commented on June 10, 2024 1

It looks like the VBA language specification does not allow user defined types to include array members without an AS type clause at the end. However, the VBA editor does allow array members but only when declared using both explicit lower and upper bounds e.g. FM(0 to 2). In other words it won't accept FM(2) even though that is identical in meaning.

Private Type X
    A(2) As Variant         'This is fine
    B(0 To 2) As Variant    'This is fine
    C (2)                   'VBA will not compile this (the VBA editor inserts the space between the identifier and array)
    D(0 To 2)               'VBA will compile and work as expected but Rubberduck has a parse error
End Type

In the above example, the 4 members should be identical i.e. arrays of variants with lower bound 0 and upper bound 2. However, VBA will only allow cases A, B and D. Rubberduck only allows A and B.

So to support the reality of what works in VBA, we would need to change the VBAParser.g4 definition to explicitly allow UDT members to have an array with both lower and upper bounds but not a type. An odd special case.

from rubberduck.

tommy9 avatar tommy9 commented on June 10, 2024 1

Submitted a fix which allow Rubberduck to parse cases where there is an array member of the UDT which doesn't have an explicit type declaration. It still requires a type declaration for non-array members as that is consistent with both the language specification and implementation.

from rubberduck.

retailcoder avatar retailcoder commented on June 10, 2024

Looks like an oversight in the parser grammar around UDT member definitions.
Thanks for the report!

from rubberduck.

retailcoder avatar retailcoder commented on June 10, 2024

Seems to be taken into account though:

// 5.2.3.3 User Defined Type Declarations
// member list includes trailing endOfStatement
udtDeclaration : (visibility whiteSpace)? TYPE whiteSpace untypedIdentifier endOfStatement udtMemberList END_TYPE;  
udtMemberList : (udtMember endOfStatement)+; 
udtMember : reservedNameMemberDeclaration | untypedNameMemberDeclaration;
untypedNameMemberDeclaration : untypedIdentifier whiteSpace? optionalArrayClause;
reservedNameMemberDeclaration : unrestrictedIdentifier whiteSpace asTypeClause;
optionalArrayClause : (arrayDim whiteSpace)? asTypeClause;

Specifically:

untypedNameMemberDeclaration : untypedIdentifier whiteSpace? optionalArrayClause;

Just to be sure, the END_TYPE token (i.e. End Type) is indeed present, yeah? The parse error is legit without that token, since the parser rule (which encodes section 5.2.3.3 of the language specifications) understands it's looking at a UDT definition by matching the source code against the grammar tokens:

udtDeclaration : (visibility whiteSpace)? TYPE whiteSpace untypedIdentifier endOfStatement udtMemberList END_TYPE;

In other words, in order to parse a udtDeclaration the source code must look like Type SomeIdentifierName with a mandatory udtMemberList on at least one more line, followed by End Type on another line.

from rubberduck.

huaca2 avatar huaca2 commented on June 10, 2024

Yes, my Type Definition ends correctly with the "End Type" token in the last line.

 Private Type Ficha
       FMT(0 To 2)
       AUT(0 To 2)
       ...
 End Type

from rubberduck.

retailcoder avatar retailcoder commented on June 10, 2024

So this is one of the few areas where the VBE implementation mismatches its own specifications.
In the spirit of RD being able to flag the untyped member declaration as such, indeed it would be necessary to address this, at least in 2.x (and then we carry the grammar into v3).
RD3 would merely be reporting a syntax error there if it's not addressed in the v3 grammar, so no biggie, but confusing enough to warrant aligning with the VBE implementation.

from rubberduck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.