Skip to content

Commit 1ad339d

Browse files
committed
Close #1885 (grammar)
1 parent 970e72c commit 1ad339d

File tree

9 files changed

+4689
-4255
lines changed

9 files changed

+4689
-4255
lines changed

Rubberduck.Parsing/Grammar/VBALexer.cs

Lines changed: 1161 additions & 1152 deletions
Large diffs are not rendered by default.

Rubberduck.Parsing/Grammar/VBALexer.g4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ lexer grammar VBALexer;
2020
ABS : A B S;
2121
ANY : A N Y;
2222
ARRAY : A R R A Y;
23+
B_CHAR : B; // When trying to define the token `B` for use in the parser, it was being picked up as an IDENTIFIER
24+
BF : B F;
2325
CBOOL : C B O O L;
2426
CBYTE : C B Y T E;
2527
CCUR : C C U R;
@@ -45,6 +47,7 @@ INT : I N T;
4547
LBOUND : L B O U N D;
4648
LEN : L E N;
4749
LENB : L E N B;
50+
LINE : L I N E;
4851
LONGLONG : L O N G L O N G;
4952
LONGPTR : L O N G P T R;
5053
MIDB : M I D B;

Rubberduck.Parsing/Grammar/VBAParser.cs

Lines changed: 3382 additions & 3101 deletions
Large diffs are not rendered by default.

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ blockStmt :
126126
| variableStmt
127127
| whileWendStmt
128128
| withStmt
129+
| lineSpecialForm
129130
| circleSpecialForm
130131
| scaleSpecialForm
131132
| callStmt
132-
| nameStmt
133+
| nameStmt
133134
;
134135

135-
136136
// 5.4.5 File Statements
137137
fileStmt :
138138
openStmt
@@ -511,9 +511,11 @@ withStmt :
511511
;
512512

513513
// Special forms with special syntax, only available in a report.
514+
lineSpecialForm : (expression whiteSpace? DOT whiteSpace?)? LINE whiteSpace (STEP whiteSpace?)? tuple MINUS (STEP whiteSpace?)? tuple whiteSpace? (COMMA whiteSpace? expression)? whiteSpace? (COMMA whiteSpace? lineSpecialFormOption)?;
514515
circleSpecialForm : (expression whiteSpace? DOT whiteSpace?)? CIRCLE whiteSpace (STEP whiteSpace?)? tuple (whiteSpace? COMMA whiteSpace? expression)+;
515516
scaleSpecialForm : (expression whiteSpace? DOT whiteSpace?)? SCALE whiteSpace tuple whiteSpace? MINUS whiteSpace? tuple;
516517
tuple : LPAREN whiteSpace? expression whiteSpace? COMMA whiteSpace? expression whiteSpace? RPAREN;
518+
lineSpecialFormOption: (B_CHAR | BF);
517519

518520
subscripts : subscript (whiteSpace? COMMA whiteSpace? subscript)*;
519521

Rubberduck.Parsing/Grammar/VBAParserBaseListener.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,6 +2958,19 @@ public virtual void EnterTabNumberClause([NotNull] VBAParser.TabNumberClauseCont
29582958
/// <param name="context">The parse tree.</param>
29592959
public virtual void ExitTabNumberClause([NotNull] VBAParser.TabNumberClauseContext context) { }
29602960

2961+
/// <summary>
2962+
/// Enter a parse tree produced by <see cref="VBAParser.lineSpecialForm"/>.
2963+
/// <para>The default implementation does nothing.</para>
2964+
/// </summary>
2965+
/// <param name="context">The parse tree.</param>
2966+
public virtual void EnterLineSpecialForm([NotNull] VBAParser.LineSpecialFormContext context) { }
2967+
/// <summary>
2968+
/// Exit a parse tree produced by <see cref="VBAParser.lineSpecialForm"/>.
2969+
/// <para>The default implementation does nothing.</para>
2970+
/// </summary>
2971+
/// <param name="context">The parse tree.</param>
2972+
public virtual void ExitLineSpecialForm([NotNull] VBAParser.LineSpecialFormContext context) { }
2973+
29612974
/// <summary>
29622975
/// Enter a parse tree produced by <see cref="VBAParser.logicalImpOp"/>.
29632976
/// <para>The default implementation does nothing.</para>
@@ -3218,6 +3231,19 @@ public virtual void EnterLenClause([NotNull] VBAParser.LenClauseContext context)
32183231
/// <param name="context">The parse tree.</param>
32193232
public virtual void ExitLenClause([NotNull] VBAParser.LenClauseContext context) { }
32203233

3234+
/// <summary>
3235+
/// Enter a parse tree produced by <see cref="VBAParser.lineSpecialFormOption"/>.
3236+
/// <para>The default implementation does nothing.</para>
3237+
/// </summary>
3238+
/// <param name="context">The parse tree.</param>
3239+
public virtual void EnterLineSpecialFormOption([NotNull] VBAParser.LineSpecialFormOptionContext context) { }
3240+
/// <summary>
3241+
/// Exit a parse tree produced by <see cref="VBAParser.lineSpecialFormOption"/>.
3242+
/// <para>The default implementation does nothing.</para>
3243+
/// </summary>
3244+
/// <param name="context">The parse tree.</param>
3245+
public virtual void ExitLineSpecialFormOption([NotNull] VBAParser.LineSpecialFormOptionContext context) { }
3246+
32213247
/// <summary>
32223248
/// Enter a parse tree produced by <see cref="VBAParser.moduleDeclarationsElement"/>.
32233249
/// <para>The default implementation does nothing.</para>

Rubberduck.Parsing/Grammar/VBAParserBaseVisitor.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,17 @@ public partial class VBAParserBaseVisitor<Result> : AbstractParseTreeVisitor<Res
25072507
/// <return>The visitor result.</return>
25082508
public virtual Result VisitTabNumberClause([NotNull] VBAParser.TabNumberClauseContext context) { return VisitChildren(context); }
25092509

2510+
/// <summary>
2511+
/// Visit a parse tree produced by <see cref="VBAParser.lineSpecialForm"/>.
2512+
/// <para>
2513+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
2514+
/// on <paramref name="context"/>.
2515+
/// </para>
2516+
/// </summary>
2517+
/// <param name="context">The parse tree.</param>
2518+
/// <return>The visitor result.</return>
2519+
public virtual Result VisitLineSpecialForm([NotNull] VBAParser.LineSpecialFormContext context) { return VisitChildren(context); }
2520+
25102521
/// <summary>
25112522
/// Visit a parse tree produced by <see cref="VBAParser.logicalImpOp"/>.
25122523
/// <para>
@@ -2727,6 +2738,17 @@ public partial class VBAParserBaseVisitor<Result> : AbstractParseTreeVisitor<Res
27272738
/// <return>The visitor result.</return>
27282739
public virtual Result VisitLenClause([NotNull] VBAParser.LenClauseContext context) { return VisitChildren(context); }
27292740

2741+
/// <summary>
2742+
/// Visit a parse tree produced by <see cref="VBAParser.lineSpecialFormOption"/>.
2743+
/// <para>
2744+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
2745+
/// on <paramref name="context"/>.
2746+
/// </para>
2747+
/// </summary>
2748+
/// <param name="context">The parse tree.</param>
2749+
/// <return>The visitor result.</return>
2750+
public virtual Result VisitLineSpecialFormOption([NotNull] VBAParser.LineSpecialFormOptionContext context) { return VisitChildren(context); }
2751+
27302752
/// <summary>
27312753
/// Visit a parse tree produced by <see cref="VBAParser.moduleDeclarationsElement"/>.
27322754
/// <para>

Rubberduck.Parsing/Grammar/VBAParserListener.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,17 @@ public interface IVBAParserListener : IParseTreeListener {
25762576
/// <param name="context">The parse tree.</param>
25772577
void ExitTabNumberClause([NotNull] VBAParser.TabNumberClauseContext context);
25782578

2579+
/// <summary>
2580+
/// Enter a parse tree produced by <see cref="VBAParser.lineSpecialForm"/>.
2581+
/// </summary>
2582+
/// <param name="context">The parse tree.</param>
2583+
void EnterLineSpecialForm([NotNull] VBAParser.LineSpecialFormContext context);
2584+
/// <summary>
2585+
/// Exit a parse tree produced by <see cref="VBAParser.lineSpecialForm"/>.
2586+
/// </summary>
2587+
/// <param name="context">The parse tree.</param>
2588+
void ExitLineSpecialForm([NotNull] VBAParser.LineSpecialFormContext context);
2589+
25792590
/// <summary>
25802591
/// Enter a parse tree produced by the <c>logicalImpOp</c>
25812592
/// labeled alternative in <see cref="VBAParser.expression"/>.
@@ -2804,6 +2815,17 @@ public interface IVBAParserListener : IParseTreeListener {
28042815
/// <param name="context">The parse tree.</param>
28052816
void ExitLenClause([NotNull] VBAParser.LenClauseContext context);
28062817

2818+
/// <summary>
2819+
/// Enter a parse tree produced by <see cref="VBAParser.lineSpecialFormOption"/>.
2820+
/// </summary>
2821+
/// <param name="context">The parse tree.</param>
2822+
void EnterLineSpecialFormOption([NotNull] VBAParser.LineSpecialFormOptionContext context);
2823+
/// <summary>
2824+
/// Exit a parse tree produced by <see cref="VBAParser.lineSpecialFormOption"/>.
2825+
/// </summary>
2826+
/// <param name="context">The parse tree.</param>
2827+
void ExitLineSpecialFormOption([NotNull] VBAParser.LineSpecialFormOptionContext context);
2828+
28072829
/// <summary>
28082830
/// Enter a parse tree produced by <see cref="VBAParser.moduleDeclarationsElement"/>.
28092831
/// </summary>

Rubberduck.Parsing/Grammar/VBAParserVisitor.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,13 @@ public interface IVBAParserVisitor<Result> : IParseTreeVisitor<Result> {
16411641
/// <return>The visitor result.</return>
16421642
Result VisitTabNumberClause([NotNull] VBAParser.TabNumberClauseContext context);
16431643

1644+
/// <summary>
1645+
/// Visit a parse tree produced by <see cref="VBAParser.lineSpecialForm"/>.
1646+
/// </summary>
1647+
/// <param name="context">The parse tree.</param>
1648+
/// <return>The visitor result.</return>
1649+
Result VisitLineSpecialForm([NotNull] VBAParser.LineSpecialFormContext context);
1650+
16441651
/// <summary>
16451652
/// Visit a parse tree produced by the <c>logicalImpOp</c>
16461653
/// labeled alternative in <see cref="VBAParser.expression"/>.
@@ -1785,6 +1792,13 @@ public interface IVBAParserVisitor<Result> : IParseTreeVisitor<Result> {
17851792
/// <return>The visitor result.</return>
17861793
Result VisitLenClause([NotNull] VBAParser.LenClauseContext context);
17871794

1795+
/// <summary>
1796+
/// Visit a parse tree produced by <see cref="VBAParser.lineSpecialFormOption"/>.
1797+
/// </summary>
1798+
/// <param name="context">The parse tree.</param>
1799+
/// <return>The visitor result.</return>
1800+
Result VisitLineSpecialFormOption([NotNull] VBAParser.LineSpecialFormOptionContext context);
1801+
17881802
/// <summary>
17891803
/// Visit a parse tree produced by <see cref="VBAParser.moduleDeclarationsElement"/>.
17901804
/// </summary>

RubberduckTests/Grammar/VBAParserTests.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,61 @@ Me.Circle Step(1, 2), 3, 4, 5, 6, 7
13471347
AssertTree(parseResult.Item1, parseResult.Item2, "//circleSpecialForm");
13481348
}
13491349

1350+
[TestMethod]
1351+
public void TestCircleSpecialForm_WithoutStep()
1352+
{
1353+
string code = @"
1354+
Sub Test()
1355+
Me.Circle (1, 2), 3, 4, 5, 6, 7
1356+
End Sub";
1357+
var parseResult = Parse(code);
1358+
AssertTree(parseResult.Item1, parseResult.Item2, "//circleSpecialForm");
1359+
}
1360+
1361+
[TestMethod]
1362+
public void TestCircleSpecialForm_WithoutOptionalArguments()
1363+
{
1364+
string code = @"
1365+
Sub Test()
1366+
Me.Circle Step(1, 2), 3
1367+
End Sub";
1368+
var parseResult = Parse(code);
1369+
AssertTree(parseResult.Item1, parseResult.Item2, "//circleSpecialForm");
1370+
}
1371+
1372+
[TestMethod]
1373+
public void TestLineAccessReport()
1374+
{
1375+
string code = @"
1376+
Sub Test()
1377+
Me.Line Step(1, 1)-Step(2, 2), vbBlack, B
1378+
End Sub";
1379+
var parseResult = Parse(code);
1380+
AssertTree(parseResult.Item1, parseResult.Item2, "//lineSpecialForm");
1381+
}
1382+
1383+
[TestMethod]
1384+
public void TestLineAccessReport_WithoutOptionalArguments()
1385+
{
1386+
string code = @"
1387+
Sub Test()
1388+
Me.Line (1, 1)-(2, 2)
1389+
End Sub";
1390+
var parseResult = Parse(code);
1391+
AssertTree(parseResult.Item1, parseResult.Item2, "//lineSpecialForm");
1392+
}
1393+
1394+
[TestMethod]
1395+
public void TestLineAccessReport_WithoutStep()
1396+
{
1397+
string code = @"
1398+
Sub Test()
1399+
Me.Line (1, 1)-(2, 2), vbBlack, BF
1400+
End Sub";
1401+
var parseResult = Parse(code);
1402+
AssertTree(parseResult.Item1, parseResult.Item2, "//lineSpecialForm");
1403+
}
1404+
13501405
[TestMethod]
13511406
public void TestScaleSpecialForm()
13521407
{

0 commit comments

Comments
 (0)