Skip to content

Commit 75a2546

Browse files
authored
Merge pull request #4111 from mansellan/3995
VB6 - Add missing VBForm grammar cases
2 parents a7fa2a2 + af46f88 commit 75a2546

File tree

3 files changed

+194
-2
lines changed

3 files changed

+194
-2
lines changed

Rubberduck.Parsing/Grammar/VBALexer.g4

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ POW : '^';
242242
RPAREN : ')';
243243
L_SQUARE_BRACKET : '[';
244244
R_SQUARE_BRACKET : ']';
245+
L_BRACE : '{';
246+
R_BRACE : '}';
245247
STRINGLITERAL : '"' (~["\r\n] | '""')* '"';
246248
OCTLITERAL : '&O' [0-8]+ INTEGERTYPESUFFIX?;
247249
HEXLITERAL : '&H' [0-9A-F]+ INTEGERTYPESUFFIX?;
@@ -298,8 +300,10 @@ SINGLEQUOTE : '\'';
298300
UNDERSCORE : '_';
299301
WS : [ \t];
300302
GUIDLITERAL : '{' [0-9A-F]+ '-' [0-9A-F]+ '-' [0-9A-F]+ '-' [0-9A-F]+ '-' [0-9A-F]+ '}';
301-
IDENTIFIER : ~[[\]()\r\n\t.,'"|!@#$%^&*\-+:=; 0-9-/\\-] ~[[\]()\r\n\t.,'"|!@#$%^&*\-+:=; -]*;
303+
IDENTIFIER : ~[[\](){}\r\n\t.,'"|!@#$%^&*\-+:=; 0-9-/\\-] ~[[\](){}\r\n\t.,'"|!@#$%^&*\-+:=; -]*;
302304
LINE_CONTINUATION : [ \t]* UNDERSCORE [ \t]* '\r'? '\n';
305+
// The following rule is needed in order to capture hex literals without format prefixes which start with a digit. Needed for VBForm resources.
306+
BARE_HEX_LITERAL : [0-9] [0-9a-fA-F]*;
303307
fragment LETTER : [a-zA-Z_äöüÄÖÜ];
304308
fragment DIGIT : [0-9];
305309
fragment LETTERORDIGIT : [a-zA-Z0-9_äöüÄÖÜ];

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ moduleConfigProperty :
6262
;
6363

6464
moduleConfigElement :
65-
unrestrictedIdentifier whiteSpace? EQ whiteSpace? expression (COLON numberLiteral)? endOfStatement
65+
(unrestrictedIdentifier | lExpression) whiteSpace? EQ whiteSpace? (shortcut | resource | expression) endOfStatement
66+
;
67+
68+
shortcut :
69+
(POW singleLetter)
70+
| ((PERCENT | PLUS? POW?) L_BRACE IDENTIFIER R_BRACE)
71+
;
72+
73+
resource :
74+
DOLLAR? expression COLON (numberLiteral | BARE_HEX_LITERAL | unrestrictedIdentifier)
6675
;
6776

6877
moduleAttributes : (attributeStmt endOfStatement)*;

RubberduckTests/Grammar/VBAParserTests.cs

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,185 @@ Begin VB.Form Form1
665665
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
666666
}
667667

668+
[Category("Parser")]
669+
[Test]
670+
public void TestVBFormWithHexLiteralModuleConfig()
671+
{
672+
string code = @"
673+
Begin VB.Form Form1
674+
BackColor = &H00FFFFFF&
675+
Caption = ""Form1""
676+
ClientHeight = 2640
677+
ClientLeft = 45
678+
ClientTop = 375
679+
ClientWidth = 4710
680+
OleObjectBlob = ""Form1.frx"":0000
681+
StartUpPosition = 1 'CenterOwner
682+
End
683+
";
684+
var parseResult = Parse(code);
685+
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
686+
}
687+
688+
[Category("Parser")]
689+
[Test]
690+
public void TestVBFormWithAbsoluteResourcePathConfig()
691+
{
692+
string code = @"
693+
Begin VB.Form Form1
694+
BackColor = &H00FFFFFF&
695+
Caption = ""Form1""
696+
ClientHeight = 2640
697+
ClientLeft = 45
698+
ClientTop = 375
699+
ClientWidth = 4710
700+
OleObjectBlob = ""C:\Test\Form1.frx"":0000
701+
StartUpPosition = 1 'CenterOwner
702+
End
703+
";
704+
var parseResult = Parse(code);
705+
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
706+
}
707+
708+
[Category("Parser")]
709+
[Test]
710+
public void TestVBFormWithDnsUncResourcePathConfig()
711+
{
712+
string code = @"
713+
Begin VB.Form Form1
714+
BackColor = &H00FFFFFF&
715+
Caption = ""Form1""
716+
ClientHeight = 2640
717+
ClientLeft = 45
718+
ClientTop = 375
719+
ClientWidth = 4710
720+
OleObjectBlob = ""\\initech.com\server01\c$\Test\Form1.frx"":0000
721+
StartUpPosition = 1 'CenterOwner
722+
End
723+
";
724+
var parseResult = Parse(code);
725+
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
726+
}
727+
728+
[Category("Parser")]
729+
[Test]
730+
public void TestVBFormWithIPUncResourcePathConfig()
731+
{
732+
string code = @"
733+
Begin VB.Form Form1
734+
BackColor = &H00FFFFFF&
735+
Caption = ""Form1""
736+
ClientHeight = 2640
737+
ClientLeft = 45
738+
ClientTop = 375
739+
ClientWidth = 4710
740+
OleObjectBlob = ""\\127.0.0.1\Test\Form1.frx"":0000
741+
StartUpPosition = 1 'CenterOwner
742+
End
743+
";
744+
var parseResult = Parse(code);
745+
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
746+
}
747+
748+
[Category("Parser")]
749+
[Test]
750+
public void TestVBFormWithDollarPrependedResourceModuleConfig()
751+
{
752+
string code = @"
753+
Begin VB.Form Form1
754+
Caption = ""Form1""
755+
ClientHeight = 2640
756+
ClientLeft = 45
757+
ClientTop = 375
758+
ClientWidth = 4710
759+
OleObjectBlob = $""Form1.frx"":0000
760+
StartUpPosition = 1 'CenterOwner
761+
End
762+
";
763+
var parseResult = Parse(code);
764+
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
765+
}
766+
767+
[Category("Parser")]
768+
[Test]
769+
public void TestVBFormWithAlphaLeadingHexLiteralResourceOffsetModuleConfig()
770+
{
771+
string code = @"
772+
Begin VB.Form Form1
773+
Caption = ""Form1""
774+
ClientHeight = 2640
775+
ClientLeft = 45
776+
ClientTop = 375
777+
ClientWidth = 4710
778+
OleObjectBlob = ""Form1.frx"":ACBD
779+
StartUpPosition = 1 'CenterOwner
780+
End
781+
";
782+
var parseResult = Parse(code);
783+
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
784+
}
785+
786+
[Category("Parser")]
787+
[Test]
788+
public void TestVBFormWithNumericLeadingHexLiteralResourceOffsetModuleConfig()
789+
{
790+
string code = @"
791+
Begin VB.Form Form1
792+
Caption = ""Form1""
793+
ClientHeight = 2640
794+
ClientLeft = 45
795+
ClientTop = 375
796+
ClientWidth = 4710
797+
OleObjectBlob = ""Form1.frx"":9ABC
798+
StartUpPosition = 1 'CenterOwner
799+
End
800+
";
801+
var parseResult = Parse(code);
802+
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 1);
803+
}
804+
805+
[Category("Parser")]
806+
[Test]
807+
[TestCase(@"^A")]
808+
[TestCase(@"^Z")]
809+
[TestCase(@"{F1}")]
810+
[TestCase(@"{F12}")]
811+
[TestCase(@"^{F1}")]
812+
[TestCase(@"^{F12}")]
813+
[TestCase(@"+{F1}")]
814+
[TestCase(@"+{F12}")]
815+
[TestCase(@"+^{F1}")]
816+
[TestCase(@"+^{F12}")]
817+
[TestCase(@"^{INSERT}")]
818+
[TestCase(@"+{INSERT}")]
819+
[TestCase(@"{DEL}")]
820+
[TestCase(@"+{DEL}")]
821+
[TestCase(@"%{BKSP}")]
822+
public void TestVBFormWithMenuShortcutModuleConfig(string shortcut)
823+
{
824+
string code = @"
825+
Begin VB.Form Form1
826+
Caption = ""Form1""
827+
ClientHeight = 2640
828+
ClientLeft = 45
829+
ClientTop = 375
830+
ClientWidth = 4710
831+
OleObjectBlob = ""Form1.frx"":0000
832+
StartUpPosition = 1 'CenterOwner
833+
Begin VB.Menu FileMenu
834+
Caption = ""File""
835+
Begin VB.Menu FileOpenMenu
836+
Caption = ""Open""
837+
Shortcut = " + shortcut + @"
838+
End
839+
End
840+
End
841+
";
842+
var parseResult = Parse(code);
843+
AssertTree(parseResult.Item1, parseResult.Item2, "//moduleConfig", matches => matches.Count == 3);
844+
}
845+
846+
668847
[Category("Parser")]
669848
[Test]
670849
public void TestNestedVbFormModuleConfig()

0 commit comments

Comments
 (0)