Skip to content

Commit 67125e9

Browse files
author
Scott Dennison
committed
[PR-4815] Review feedback. Also commited java files, making it so that checking the java builds OK is part of the build.
1 parent 13087a4 commit 67125e9

File tree

20 files changed

+495
-12
lines changed

20 files changed

+495
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,6 @@ CodeGraphData/
183183
/Rubberduck.Deployment/Properties/launchSettings.json
184184
/Rubberduck.Deployment/Rubberduck.API.idl
185185
/Rubberduck.Deployment/Rubberduck.idl
186+
187+
#Gradle
188+
/.gradle/

Rubberduck.Parsing/Grammar/VBABaseLexer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public abstract class VBABaseLexer : Lexer
77
public VBABaseLexer(ICharStream input) : base(input) { }
88

99
#region Semantic predicate helper methods
10-
protected int LA(int i)
10+
protected int CharAtRelativePosition(int i)
1111
{
1212
return _input.La(i);
1313
}

Rubberduck.Parsing/Grammar/VBABaseParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ public abstract class VBABaseParser : Parser
99
public VBABaseParser(ITokenStream input) : base(input) { }
1010

1111
#region Semantic predicate helper methods
12-
protected int LA(int i)
12+
protected int TokenTypeAtRelativePosition(int i)
1313
{
1414
return _input.La(i);
1515
}
1616

17-
protected IToken LT(int i)
17+
protected IToken TokenAtRelativePosition(int i)
1818
{
1919
return _input.Lt(i);
2020
}
2121

22-
protected string Text(IToken token)
22+
protected string TextOf(IToken token)
2323
{
2424
return token.Text;
2525
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Antlr4.Runtime;
2+
using System;
3+
using System.Text.RegularExpressions;
4+
5+
namespace Rubberduck.Parsing.Grammar
6+
{
7+
// Currently this class does nothing, except allow other languages/implementations to define a custom contextSuperclass without having to change the grammar.
8+
public abstract class VBABaseParserRuleContext : ParserRuleContext
9+
{
10+
public VBABaseParserRuleContext() : base() { }
11+
12+
public VBABaseParserRuleContext(Antlr4.Runtime.ParserRuleContext parent, int invokingStateNumber) : base(parent, invokingStateNumber) { }
13+
}
14+
}

Rubberduck.Parsing/Grammar/VBALexer.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ lexer grammar VBALexer;
1919

2020
options {
2121
superClass = VBABaseLexer;
22+
contextSuperClass = VBABaseParser;
2223
}
2324

2425
ABS : A B S;
@@ -308,7 +309,7 @@ IDENTIFIER : ~[[\](){}\r\n\t.,'"|!@#$%^&*\-+:=; 0-9-/\\-] ~[[\](){}\r\n\t.,'"|!
308309
LINE_CONTINUATION : [ \t]+ UNDERSCORE [ \t]* '\r'? '\n' WS_NOT_FOLLOWED_BY_LINE_CONTINUATION*;
309310
// The following rule is needed in order to capture hex literals without format prefixes which start with a digit. Needed for VBForm resources.
310311
BARE_HEX_LITERAL : [0-9] [0-9a-fA-F]*;
311-
fragment WS_NOT_FOLLOWED_BY_LINE_CONTINUATION : [ \t] {!IsChar(LA(1),'_') || !IsChar(LA(2),'\r','\n','\t',' ')}?;
312+
fragment WS_NOT_FOLLOWED_BY_LINE_CONTINUATION : [ \t] {!IsChar(CharAtRelativePosition(1),'_') || !IsChar(CharAtRelativePosition(2),'\r','\n','\t',' ')}?;
312313
fragment LETTER : [a-zA-Z_äöüÄÖÜ];
313314
fragment DIGIT : [0-9];
314315
fragment LETTERORDIGIT : [a-zA-Z0-9_äöüÄÖÜ];

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ parser grammar VBAParser;
2222
options {
2323
tokenVocab = VBALexer;
2424
superClass = VBABaseParser;
25+
contextSuperClass = VBABaseParserRuleContext;
2526
}
2627

2728
startRule : module EOF;
@@ -322,14 +323,14 @@ defType :
322323
// singleLetter must appear at the end to prevent premature bailout
323324
letterSpec : universalLetterRange | letterRange | singleLetter;
324325

325-
singleLetter : {MatchesRegex(Text(LT(1)),"^[a-zA-Z]$")}? IDENTIFIER;
326+
singleLetter : {MatchesRegex(TextOf(TokenAtRelativePosition(1)),"^[a-zA-Z]$")}? IDENTIFIER;
326327

327328
// We make a separate universalLetterRange rule because it is treated specially in VBA. This makes it easy for users of the parser
328329
// to identify this case. Quoting MS VBAL:
329330
// "A <universal-letter-range> defines a single implicit declared type for every <IDENTIFIER> within
330331
// a module, even those with a first character that would otherwise fall outside this range if it was
331332
// interpreted as a <letter-range> from A-Z.""
332-
universalLetterRange : {EqualsString(Text(LT(1)),"A") && EqualsString(Text(LT(3)),"Z")}? IDENTIFIER MINUS IDENTIFIER;
333+
universalLetterRange : {EqualsString(TextOf(TokenAtRelativePosition(1)),"A") && EqualsString(TextOf(TokenAtRelativePosition(3)),"Z")}? IDENTIFIER MINUS IDENTIFIER;
333334

334335
letterRange : singleLetter MINUS singleLetter;
335336

@@ -572,22 +573,22 @@ circleSpecialForm : (expression whiteSpace? DOT whiteSpace?)? CIRCLE whiteSpace
572573
scaleSpecialForm : (expression whiteSpace? DOT whiteSpace?)? SCALE whiteSpace tuple whiteSpace? MINUS whiteSpace? tuple;
573574
pSetSpecialForm : (expression whiteSpace? DOT whiteSpace?)? PSET (whiteSpace STEP)? whiteSpace? tuple whiteSpace? (COMMA whiteSpace? expression)?;
574575
tuple : LPAREN whiteSpace? expression whiteSpace? COMMA whiteSpace? expression whiteSpace? RPAREN;
575-
lineSpecialFormOption : {EqualsStringIgnoringCase(Text(LT(1)),"b","bf")}? unrestrictedIdentifier;
576+
lineSpecialFormOption : {EqualsStringIgnoringCase(TextOf(TokenAtRelativePosition(1)),"b","bf")}? unrestrictedIdentifier;
576577

577578
subscripts : subscript (whiteSpace? COMMA whiteSpace? subscript)*;
578579

579580
subscript : (expression whiteSpace TO whiteSpace)? expression;
580581

581582
unrestrictedIdentifier : identifier | statementKeyword | markerKeyword;
582-
legalLabelIdentifier : { !IsTokenType(LA(1),DOEVENTS,END,CLOSE,ELSE,LOOP,NEXT,RANDOMIZE,REM,RESUME,RETURN,STOP,WEND)}? identifier | markerKeyword;
583+
legalLabelIdentifier : { !IsTokenType(TokenTypeAtRelativePosition(1),DOEVENTS,END,CLOSE,ELSE,LOOP,NEXT,RANDOMIZE,REM,RESUME,RETURN,STOP,WEND)}? identifier | markerKeyword;
583584
//The predicate in the following rule has been introduced to lessen the problem that VBA uses the same characters used as type hints in other syntactical constructs,
584585
//e.g. in the bang notation (see withDictionaryAccessExpr). Generally, it is not legal to have an identifier or opening bracket follow immediately after a type hint.
585586
//The first part of the predicate tries to exclude these two situations. Unfortunately, predicates have to be at the start of a rule. So, an assumption about the number
586587
//of tokens in the identifier is made. All untypedIdentifers not a foreignNames consist of exactly one token and a typedIdentifier is an untyped one followed by a typeHint,
587588
//again a single token. So, in the majority of situations, the third token is the token following the potential type hint.
588589
//For foreignNames, no assumption can be made because they consist of a pair of brackets containing arbitrarily many tokens.
589590
//That is why the second part of the predicate looks at the first character in order to determine whether the identifier is a foreignName.
590-
identifier : {!IsTokenType(LA(3),IDENTIFIER,L_SQUARE_BRACKET) || IsTokenType(LA(1),L_SQUARE_BRACKET)}? typedIdentifier
591+
identifier : {!IsTokenType(TokenTypeAtRelativePosition(3),IDENTIFIER,L_SQUARE_BRACKET) || IsTokenType(TokenTypeAtRelativePosition(1),L_SQUARE_BRACKET)}? typedIdentifier
591592
| untypedIdentifier;
592593
untypedIdentifier : identifierValue;
593594
typedIdentifier : untypedIdentifier typeHint;
@@ -615,7 +616,7 @@ complexType :
615616
fieldLength : MULT whiteSpace? (numberLiteral | identifierValue);
616617

617618
//Statement labels can only appear at the start of a line.
618-
statementLabelDefinition : {IsTokenType(LA(-1),NEWLINE,LINE_CONTINUATION)}? (combinedLabels | identifierStatementLabel | standaloneLineNumberLabel);
619+
statementLabelDefinition : {IsTokenType(TokenTypeAtRelativePosition(-1),NEWLINE,LINE_CONTINUATION)}? (combinedLabels | identifierStatementLabel | standaloneLineNumberLabel);
619620
identifierStatementLabel : legalLabelIdentifier whiteSpace? COLON;
620621
standaloneLineNumberLabel :
621622
lineNumberLabel whiteSpace? COLON

appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ cache:
3939
- packages/ -> **/packages.config
4040

4141
install:
42-
set PATH=C:\Program Files (x86)\MSBuild\15.0\Bin;%PATH%
42+
set PATH=C:\Program Files (x86)\MSBuild\15.0\Bin;C:\Program Files (x86)\Java\jdk1.8.0;%PATH%
4343

4444
# patch version specifiers in the base project
4545
dotnet_csproj:
@@ -51,6 +51,7 @@ dotnet_csproj:
5151

5252

5353
before_build:
54+
- development/java/Rubberduck.Parsing/Grammar/gradlew.bat -p development/java/Rubberduck.Parsing/Grammar clean build
5455
- cinst innosetup
5556
- cinst codecov
5657
- cinst opencover.portable
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# Created by https://www.gitignore.io/api/git,gradle
3+
# Edit at https://www.gitignore.io/?templates=git,gradle
4+
5+
### Git ###
6+
# Created by git for backups. To disable backups in Git:
7+
# $ git config --global mergetool.keepBackup false
8+
*.orig
9+
10+
# Created by git when using merge tools for conflicts
11+
*.BACKUP.*
12+
*.BASE.*
13+
*.LOCAL.*
14+
*.REMOTE.*
15+
*_BACKUP_*.txt
16+
*_BASE_*.txt
17+
*_LOCAL_*.txt
18+
*_REMOTE_*.txt
19+
20+
### Gradle ###
21+
.gradle
22+
build/
23+
24+
# Ignore Gradle GUI config
25+
gradle-app.setting
26+
27+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
28+
!gradle-wrapper.jar
29+
30+
# Cache of project
31+
.gradletasknamecache
32+
33+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
34+
# gradle/wrapper/gradle-wrapper.properties
35+
36+
### Gradle Patch ###
37+
**/build/
38+
39+
# End of https://www.gitignore.io/api/git,gradle
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral();
4+
}
5+
6+
dependencies {
7+
classpath group: 'org.antlr', name: 'antlr4', version: '4.7.2'
8+
}
9+
}
10+
11+
plugins {
12+
id 'java'
13+
}
14+
15+
group 'com.rubberduckvba.rubberduck.parsing'
16+
version '1'
17+
18+
repositories {
19+
mavenCentral()
20+
}
21+
22+
dependencies {
23+
compile group: 'org.antlr', name: 'antlr4-runtime', version: '4.7.2'
24+
}
25+
26+
def grammerCodeGenDest = "${projectDir}/src/main/gen"
27+
def grammarSource = "${projectDir}/../../../../Rubberduck.Parsing/Grammar/"
28+
def grammarDest = "${projectDir}/src/main/antlr/com/rubberduckvba/rubberduck/parsing/grammar"
29+
30+
sourceSets {
31+
main {
32+
java {
33+
srcDir "${grammerCodeGenDest}"
34+
}
35+
}
36+
}
37+
38+
task copyGrammarFiles(type: Copy) {
39+
from grammarSource
40+
into grammarDest
41+
include "VBALexer.g4"
42+
include "VBAParser.g4"
43+
}
44+
45+
task generateGrammarSources(type: JavaExec) {
46+
main 'org.antlr.v4.Tool'
47+
classpath = buildscript.configurations.classpath
48+
args "-o", "${grammerCodeGenDest}", "-visitor", "-package", "com.rubberduckvba.rubberduck.parsing.grammar", "${grammarDest}/VBALexer.g4", "${grammarDest}/VBAParser.g4"
49+
}
50+
51+
generateGrammarSources.dependsOn copyGrammarFiles
52+
build.dependsOn generateGrammarSources
Binary file not shown.

0 commit comments

Comments
 (0)