Skip to content

Commit 5cab2bd

Browse files
committed
Subsume delegate EiffelLexHelper after 80ef15e
1 parent 141027e commit 5cab2bd

File tree

5 files changed

+78
-81
lines changed

5 files changed

+78
-81
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/eiffel/EiffelAnalyzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

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

2424
package org.opengrok.indexer.analysis.eiffel;
@@ -48,11 +48,11 @@ protected EiffelAnalyzer(AnalyzerFactory factory) {
4848
* Gets a version number to be used to tag processed documents so that
4949
* re-analysis can be re-done later if a stored version number is different
5050
* from the current implementation.
51-
* @return 20180208_00
51+
* @return 20190118_00
5252
*/
5353
@Override
5454
protected int getSpecializedVersionNo() {
55-
return 20180208_00; // Edit comment above too!
55+
return 20190118_00; // Edit comment above too!
5656
}
5757

5858
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/eiffel/EiffelLexHelper.java renamed to opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/eiffel/EiffelLexer.java

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,35 @@
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.eiffel;
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
import org.opengrok.indexer.web.HtmlConsts;
3032

3133
/**
32-
* Represents an API for object's using {@link EiffelLexHelper}.
33-
*/
34-
interface EiffelLexer extends JFlexJointLexer {
35-
}
36-
37-
/**
38-
* Represents a helper for Eiffel lexers.
34+
* Represents an abstract base class for Eiffel lexers.
3935
*/
40-
class EiffelLexHelper implements Resettable {
41-
42-
private final EiffelLexer lexer;
43-
44-
private final int VSTRING;
45-
private final int SCOMMENT;
36+
abstract class EiffelLexer extends JFlexSymbolMatcher
37+
implements JFlexJointLexer, Resettable {
4638

4739
/**
4840
* When matching a Verbatim_string, the expected closer is stored here.
4941
*/
5042
private String vstring_closer;
5143

52-
EiffelLexHelper(int vSTRING, int sCOMMENT, EiffelLexer lexer) {
53-
if (lexer == null) {
54-
throw new IllegalArgumentException("`lexer' is null");
55-
}
56-
this.lexer = lexer;
57-
this.VSTRING = vSTRING;
58-
this.SCOMMENT = sCOMMENT;
59-
}
60-
6144
/**
6245
* Resets the instance to an initial state.
6346
*/
6447
@Override
6548
public void reset() {
49+
super.reset();
6650
vstring_closer = null;
6751
}
6852

@@ -94,9 +78,9 @@ public void vop(String opener) throws IOException {
9478
}
9579
vstring_closer = close0 + alpha + "\"";
9680

97-
lexer.yypush(VSTRING);
98-
lexer.disjointSpan(HtmlConsts.STRING_CLASS);
99-
lexer.offer(opener);
81+
yypush(VSTRING());
82+
disjointSpan(HtmlConsts.STRING_CLASS);
83+
offer(opener);
10084
}
10185

10286
/**
@@ -112,26 +96,38 @@ public void maybeEndVerbatim(String capture) throws IOException {
11296
int npushback;
11397
if (!capture.startsWith(vstring_closer)) {
11498
// Nope--so just write the double quote, and push back the rest.
115-
lexer.offer(capture.substring(0, 1));
99+
offer(capture.substring(0, 1));
116100
npushback = capture.length() - 1;
117101
} else {
118-
lexer.offer(vstring_closer);
119-
lexer.disjointSpan(null);
120-
lexer.yypop();
102+
offer(vstring_closer);
103+
disjointSpan(null);
104+
yypop();
121105
npushback = capture.length() - vstring_closer.length();
122106
vstring_closer = null;
123107
}
124108
if (npushback > 0) {
125-
lexer.yypushback(npushback);
109+
yypushback(npushback);
126110
}
127111
}
128112

129113
/**
130-
* Calls {@link EiffelLexer#phLOC()} if the yystate is not SCOMMENT.
114+
* Calls {@link #phLOC()} if the yystate is not SCOMMENT.
131115
*/
132116
public void chkLOC() {
133-
if (lexer.yystate() != SCOMMENT) {
134-
lexer.phLOC();
117+
if (yystate() != SCOMMENT()) {
118+
phLOC();
135119
}
136120
}
121+
122+
/**
123+
* Subclasses must override to get the constant value created by JFlex to
124+
* represent SCOMMENT.
125+
*/
126+
abstract int SCOMMENT();
127+
128+
/**
129+
* Subclasses must override to get the constant value created by JFlex to
130+
* represent VSTRING.
131+
*/
132+
abstract int VSTRING();
137133
}

opengrok-indexer/src/main/resources/analysis/eiffel/EiffelProductions.lexh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

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

2424
/*
@@ -110,22 +110,22 @@ Special_character = % ([A-Da-dFfHhLlNnQqRrSsT-Vt-v%\'\"\(\)\<\>] | "/" [0-9]+ "/
110110
%%
111111
<YYINITIAL> {
112112
{Identifier} {
113-
h.chkLOC();
113+
chkLOC();
114114
String id = yytext();
115115
if (offerSymbol(id, 0, false) && returnOnSymbol()) {
116116
return yystate();
117117
}
118118
}
119119

120120
{Number} {
121-
h.chkLOC();
121+
chkLOC();
122122
onDisjointSpanChanged(HtmlConsts.NUMBER_CLASS, yychar);
123123
offer(yytext());
124124
onDisjointSpanChanged(null, yychar);
125125
}
126126

127127
{Character_constant} {
128-
h.chkLOC();
128+
chkLOC();
129129
onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar);
130130
offer(yytext());
131131
onDisjointSpanChanged(null, yychar);
@@ -138,14 +138,14 @@ Special_character = % ([A-Da-dFfHhLlNnQqRrSsT-Vt-v%\'\"\(\)\<\>] | "/" [0-9]+ "/
138138
}
139139

140140
\" {
141-
h.chkLOC();
141+
chkLOC();
142142
yypush(STRING);
143143
onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar);
144144
offer(yytext());
145145
}
146146
\" {Vstring_alpha}* [\[\{] {
147-
h.chkLOC();
148-
h.vop(yytext());
147+
chkLOC();
148+
vop(yytext());
149149
}
150150
}
151151

@@ -159,7 +159,7 @@ Special_character = % ([A-Da-dFfHhLlNnQqRrSsT-Vt-v%\'\"\(\)\<\>] | "/" [0-9]+ "/
159159

160160
<STRING> {
161161
\" {
162-
h.chkLOC();
162+
chkLOC();
163163
offer(yytext());
164164
onDisjointSpanChanged(null, yychar);
165165
yypop();
@@ -175,14 +175,14 @@ Special_character = % ([A-Da-dFfHhLlNnQqRrSsT-Vt-v%\'\"\(\)\<\>] | "/" [0-9]+ "/
175175

176176
<VSTRING> {
177177
[\]\}] {Vstring_alpha}* \" {
178-
h.chkLOC();
179-
h.maybeEndVerbatim(yytext());
178+
chkLOC();
179+
maybeEndVerbatim(yytext());
180180
}
181181
}
182182

183183
<STRING, VSTRING> {
184184
{Special_character} {
185-
h.chkLOC();
185+
chkLOC();
186186
offer(yytext());
187187
}
188188

@@ -197,14 +197,14 @@ Special_character = % ([A-Da-dFfHhLlNnQqRrSsT-Vt-v%\'\"\(\)\<\>] | "/" [0-9]+ "/
197197
{WhspChar}*{EOL} { onEndOfLineMatched(yytext(), yychar); }
198198
\s { offer(yytext()); }
199199
[^] {
200-
h.chkLOC();
200+
chkLOC();
201201
offer(yytext());
202202
}
203203
}
204204

205205
<SCOMMENT, STRING, VSTRING> {
206206
{BrowseableURI} {
207-
h.chkLOC();
207+
chkLOC();
208208
if (takeAllContent()) {
209209
onUriMatched(yytext(), yychar);
210210
}

opengrok-indexer/src/main/resources/analysis/eiffel/EiffelSymbolTokenizer.lex

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,19 @@
1818
*/
1919

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

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

2626
import java.io.IOException;
2727
import java.util.Locale;
28-
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
2928
import org.opengrok.indexer.web.HtmlConsts;
3029
%%
3130
%public
3231
%class EiffelSymbolTokenizer
33-
%extends JFlexSymbolMatcher
34-
%implements EiffelLexer
32+
%extends EiffelLexer
3533
%init{
36-
h = new EiffelLexHelper(VSTRING, SCOMMENT, this);
3734
yyline = 1;
3835
%init}
3936
%unicode
@@ -42,8 +39,6 @@ import org.opengrok.indexer.web.HtmlConsts;
4239
%char
4340
%include CommonLexer.lexh
4441
%{
45-
private final EiffelLexHelper h;
46-
4742
private String lastSymbol;
4843

4944
/**
@@ -52,7 +47,6 @@ import org.opengrok.indexer.web.HtmlConsts;
5247
@Override
5348
public void reset() {
5449
super.reset();
55-
h.reset();
5650
lastSymbol = null;
5751
}
5852

@@ -107,6 +101,18 @@ import org.opengrok.indexer.web.HtmlConsts;
107101
protected boolean returnOnSymbol() {
108102
return lastSymbol != null;
109103
}
104+
105+
/**
106+
* Gets the constant value created by JFlex to represent SCOMMENT.
107+
*/
108+
@Override
109+
int SCOMMENT() { return SCOMMENT; }
110+
111+
/**
112+
* Gets the constant value created by JFlex to represent VSTRING.
113+
*/
114+
@Override
115+
int VSTRING() { return VSTRING; }
110116
%}
111117

112118
/*

opengrok-indexer/src/main/resources/analysis/eiffel/EiffelXref.lex

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,20 @@
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.eiffel;
2525

2626
import java.io.IOException;
27-
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
27+
import java.util.Set;
2828
import org.opengrok.indexer.web.HtmlConsts;
2929
%%
3030
%public
3131
%class EiffelXref
32-
%extends JFlexSymbolMatcher
33-
%implements EiffelLexer
32+
%extends EiffelLexer
3433
%char
3534
%init{
36-
h = new EiffelLexHelper(VSTRING, SCOMMENT, this);
3735
yyline = 1;
3836
%init}
3937
%unicode
@@ -42,31 +40,16 @@ import org.opengrok.indexer.web.HtmlConsts;
4240
%include CommonLexer.lexh
4341
%include CommonXref.lexh
4442
%{
45-
private final EiffelLexHelper h;
46-
47-
/**
48-
* Resets the Eiffel tracked state; {@inheritDoc}
49-
*/
50-
@Override
51-
public void reset() {
52-
super.reset();
53-
h.reset();
54-
}
55-
5643
@Override
5744
public void offer(String value) throws IOException {
5845
onNonSymbolMatched(value, yychar);
5946
}
6047

6148
@Override
6249
public boolean offerSymbol(String value, int captureOffset,
63-
boolean ignoreKwd)
64-
throws IOException {
65-
if (ignoreKwd) {
66-
return onFilteredSymbolMatched(value, yychar, null, false);
67-
} else {
68-
return onFilteredSymbolMatched(value, yychar, Consts.kwd, false);
69-
}
50+
boolean ignoreKwd) throws IOException {
51+
Set<String> keywords = ignoreKwd ? null : Consts.kwd;
52+
return onFilteredSymbolMatched(value, yychar, keywords, false);
7053
}
7154

7255
@Override
@@ -96,6 +79,18 @@ import org.opengrok.indexer.web.HtmlConsts;
9679
protected boolean returnOnSymbol() {
9780
return false;
9881
}
82+
83+
/**
84+
* Gets the constant value created by JFlex to represent SCOMMENT.
85+
*/
86+
@Override
87+
int SCOMMENT() { return SCOMMENT; }
88+
89+
/**
90+
* Gets the constant value created by JFlex to represent VSTRING.
91+
*/
92+
@Override
93+
int VSTRING() { return VSTRING; }
9994
%}
10095

10196
/*

0 commit comments

Comments
 (0)