Skip to content

Commit 23055ca

Browse files
committed
Subsume delegate AdaLexHelper after 80ef15e
1 parent 36334d3 commit 23055ca

File tree

5 files changed

+53
-77
lines changed

5 files changed

+53
-77
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ada/AdaAnalyzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.ada;
2525

@@ -51,11 +51,11 @@ protected AdaAnalyzer(AnalyzerFactory factory) {
5151
* Gets a version number to be used to tag processed documents so that
5252
* re-analysis can be re-done later if a stored version number is different
5353
* from the current implementation.
54-
* @return 20180208_00
54+
* @return 20190118_00
5555
*/
5656
@Override
5757
protected int getSpecializedVersionNo() {
58-
return 20180208_00; // Edit comment above too!
58+
return 20190118_00; // Edit comment above too!
5959
}
6060

6161
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ada/AdaLexHelper.java renamed to opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ada/AdaLexer.java

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,32 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017, Chris Fraire <[email protected]>.
21+
* Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
2222
*/
2323

2424
package org.opengrok.indexer.analysis.ada;
2525

2626
import java.io.IOException;
27+
2728
import org.opengrok.indexer.analysis.JFlexJointLexer;
29+
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
2830
import org.opengrok.indexer.analysis.Resettable;
2931

3032
/**
31-
* Represents an API for object's using {@link AdaLexHelper}
32-
*/
33-
interface AdaLexer extends JFlexJointLexer {
34-
}
35-
36-
/**
37-
* Represents a helper for Ada lexers
33+
* Represents an abstract base class for Ada lexers.
3834
*/
39-
class AdaLexHelper implements Resettable {
40-
41-
private final AdaLexer lexer;
42-
43-
private final int SCOMMENT;
44-
45-
AdaLexHelper(int sCOMMENT, AdaLexer lexer) {
46-
if (lexer == null) {
47-
throw new IllegalArgumentException("`lexer' is null");
48-
}
49-
this.lexer = lexer;
50-
this.SCOMMENT = sCOMMENT;
51-
}
52-
53-
/**
54-
* Resets the instance to an initial state.
55-
*/
56-
@Override
57-
public void reset() {
58-
// noop
59-
}
35+
abstract class AdaLexer extends JFlexSymbolMatcher
36+
implements JFlexJointLexer, Resettable {
6037

6138
/**
62-
* Write {@code value} to output -- if it contains any EOLs then the
63-
* {@code startNewLine()} is called in lieu of outputting EOL.
39+
* Writes {@code value} to output -- if it contains any EOLs then the
40+
* {@link JFlexJointLexer#startNewLine()} is called in lieu of outputting
41+
* EOL.
6442
*/
6543
public void takeLiteral(String value, String className)
6644
throws IOException {
6745

68-
lexer.disjointSpan(className);
46+
disjointSpan(className);
6947

7048
int off = 0;
7149
do {
@@ -74,7 +52,7 @@ public void takeLiteral(String value, String className)
7452
ni = value.indexOf("\n", off);
7553
if (ri == -1 && ni == -1) {
7654
String sub = value.substring(off);
77-
lexer.offer(sub);
55+
offer(sub);
7856
break;
7957
}
8058
if (ri != -1 && ni != -1) {
@@ -93,22 +71,28 @@ public void takeLiteral(String value, String className)
9371
}
9472

9573
String sub = value.substring(off, i);
96-
lexer.offer(sub);
97-
lexer.disjointSpan(null);
98-
lexer.startNewLine();
99-
lexer.disjointSpan(className);
74+
offer(sub);
75+
disjointSpan(null);
76+
startNewLine();
77+
disjointSpan(className);
10078
off = i + w;
10179
} while (off < value.length());
10280

103-
lexer.disjointSpan(null);
81+
disjointSpan(null);
10482
}
10583

10684
/**
107-
* Calls {@link AdaLexer#phLOC()} if the yystate is not SCOMMENT.
85+
* Calls {@link #phLOC()} if the yystate is not SCOMMENT.
10886
*/
10987
public void chkLOC() {
110-
if (lexer.yystate() != SCOMMENT) {
111-
lexer.phLOC();
88+
if (yystate() != SCOMMENT()) {
89+
phLOC();
11290
}
11391
}
92+
93+
/**
94+
* Subclasses must override to get the constant value created by JFlex to
95+
* represent SCOMMENT.
96+
*/
97+
abstract int SCOMMENT();
11498
}

opengrok-indexer/src/main/resources/analysis/ada/AdaProductions.lexh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
2323
*/
2424

2525
/*
@@ -140,26 +140,26 @@ File = [a-zA-Z]{FNameChar}* "." {FileExt}
140140
%%
141141
<YYINITIAL> {
142142
{Identifier} {
143-
h.chkLOC();
143+
chkLOC();
144144
String id = yytext();
145145
if (offerSymbol(id, 0, false) && returnOnSymbol()) {
146146
return yystate();
147147
}
148148
}
149149

150150
{Character_literal} {
151-
h.chkLOC();
152-
h.takeLiteral(yytext(), HtmlConsts.STRING_CLASS);
151+
chkLOC();
152+
takeLiteral(yytext(), HtmlConsts.STRING_CLASS);
153153
}
154154

155155
{Numeric_literal} {
156-
h.chkLOC();
157-
h.takeLiteral(yytext(), HtmlConsts.NUMBER_CLASS);
156+
chkLOC();
157+
takeLiteral(yytext(), HtmlConsts.NUMBER_CLASS);
158158
}
159159

160160
{String_literal} {
161-
h.chkLOC();
162-
h.takeLiteral(yytext(), HtmlConsts.STRING_CLASS);
161+
chkLOC();
162+
takeLiteral(yytext(), HtmlConsts.STRING_CLASS);
163163
}
164164

165165
{Comment_token} {
@@ -191,7 +191,7 @@ File = [a-zA-Z]{FNameChar}* "." {FileExt}
191191
}
192192
// Only one character at a time because of \s restriction above.
193193
[^\n\r] {
194-
h.chkLOC();
194+
chkLOC();
195195
offer(yytext());
196196
}
197197
}

opengrok-indexer/src/main/resources/analysis/ada/AdaSymbolTokenizer.lex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2323
*/
2424

2525
/*
@@ -30,25 +30,20 @@ package org.opengrok.indexer.analysis.ada;
3030

3131
import java.io.IOException;
3232
import java.util.Locale;
33-
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
3433
import org.opengrok.indexer.web.HtmlConsts;
3534
%%
3635
%public
3736
%class AdaSymbolTokenizer
38-
%extends JFlexSymbolMatcher
39-
%implements AdaLexer
37+
%extends AdaLexer
4038
%unicode
4139
%ignorecase
4240
%int
4341
%char
4442
%init{
45-
h = new AdaLexHelper(SCOMMENT, this);
4643
yyline = 1;
4744
%init}
4845
%include CommonLexer.lexh
4946
%{
50-
private final AdaLexHelper h;
51-
5247
private String lastSymbol;
5348

5449
/**
@@ -57,7 +52,6 @@ import org.opengrok.indexer.web.HtmlConsts;
5752
@Override
5853
public void reset() {
5954
super.reset();
60-
h.reset();
6155
lastSymbol = null;
6256
}
6357

@@ -112,6 +106,12 @@ import org.opengrok.indexer.web.HtmlConsts;
112106
protected boolean returnOnSymbol() {
113107
return lastSymbol != null;
114108
}
109+
110+
/**
111+
* Gets the constant value created by JFlex to represent SCOMMENT.
112+
*/
113+
@Override
114+
int SCOMMENT() { return SCOMMENT; }
115115
%}
116116

117117
%include Common.lexh

opengrok-indexer/src/main/resources/analysis/ada/AdaXref.lex

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
2323
*/
2424

2525
/*
@@ -29,35 +29,21 @@
2929
package org.opengrok.indexer.analysis.ada;
3030

3131
import java.io.IOException;
32-
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
3332
import org.opengrok.indexer.web.HtmlConsts;
3433
%%
3534
%public
3635
%class AdaXref
37-
%extends JFlexSymbolMatcher
38-
%implements AdaLexer
36+
%extends AdaLexer
3937
%unicode
4038
%ignorecase
4139
%int
4240
%char
4341
%init{
44-
h = new AdaLexHelper(SCOMMENT, this);
4542
yyline = 1;
4643
%init}
4744
%include CommonLexer.lexh
4845
%include CommonXref.lexh
4946
%{
50-
private final AdaLexHelper h;
51-
52-
/**
53-
* Resets the Ada tracked state; {@inheritDoc}
54-
*/
55-
@Override
56-
public void reset() {
57-
super.reset();
58-
h.reset();
59-
}
60-
6147
@Override
6248
public void offer(String value) throws IOException {
6349
onNonSymbolMatched(value, yychar);
@@ -106,6 +92,12 @@ import org.opengrok.indexer.web.HtmlConsts;
10692
protected boolean returnOnSymbol() {
10793
return false;
10894
}
95+
96+
/**
97+
* Gets the constant value created by JFlex to represent SCOMMENT.
98+
*/
99+
@Override
100+
int SCOMMENT() { return SCOMMENT; }
109101
%}
110102

111103
%include Common.lexh

0 commit comments

Comments
 (0)