Skip to content

Commit 408b52b

Browse files
authored
Merge pull request #1857 from idodeclare/feature/minor_cleanup
Remove a bit of redundancy
2 parents 00442cb + b56b18a commit 408b52b

9 files changed

+64
-88
lines changed

src/org/opensolaris/opengrok/analysis/JFlexXref.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ protected String htmlize(String raw) {
479479
*
480480
* @throws IOException on error when writing the xref
481481
*/
482-
protected void startNewLine() throws IOException {
482+
public void startNewLine() throws IOException {
483483
String iconId = null;
484484
int line = getLineNumber() + 1;
485485
boolean skipNl = false;
@@ -741,6 +741,14 @@ public void yypush(int newState, String popString) {
741741
yybegin(newState);
742742
}
743743

744+
/**
745+
* save current yy state to stack
746+
* @param newState state id
747+
*/
748+
public void yypush(int newState) {
749+
yypush(newState, null);
750+
}
751+
744752
/**
745753
* pop last state from stack
746754
* @throws IOException in case of any I/O problem

src/org/opensolaris/opengrok/analysis/ada/AdaLexHelper.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
* Represents an API for object's using {@link AdaLexHelper}
2929
*/
3030
interface AdaLexListener {
31-
void pushState(int state);
32-
void popState() throws IOException;
33-
void switchState(int state);
3431
void take(String value) throws IOException;
3532
void takeNonword(String value) throws IOException;
3633

@@ -58,13 +55,12 @@ boolean takeSymbol(String value, int captureOffset, boolean ignoreKwd)
5855
*/
5956
void takeKeyword(String value) throws IOException;
6057

61-
void doStartNewLine() throws IOException;
62-
6358
/**
64-
* Pushes back to the scanner a specified number of characters
65-
* @param numChars
59+
* Indicates that the current line is ended.
60+
*
61+
* @throws IOException thrown on error when handling the EOL
6662
*/
67-
void pushback(int numChars);
63+
void startNewLine() throws IOException;
6864
}
6965

7066
/**
@@ -118,7 +114,7 @@ public void takeLiteral(String value, String linePrefix, String lineSuffix)
118114
String sub = value.substring(off, i);
119115
listener.takeNonword(sub);
120116
if (lineSuffix != null) listener.take(lineSuffix);
121-
listener.doStartNewLine();
117+
listener.startNewLine();
122118
if (linePrefix != null) listener.take(linePrefix);
123119
off = i + w;
124120
} while (off < value.length());

src/org/opensolaris/opengrok/analysis/ada/AdaProductions.lexh

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Path = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*[a-zA-Z0-9])+
167167
}
168168

169169
{Comment_token} {
170-
pushState(SCOMMENT);
170+
yypush(SCOMMENT);
171171
take(HtmlConsts.SPAN_C);
172172
takeNonword(yytext());
173173
}
@@ -186,7 +186,7 @@ Path = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*[a-zA-Z0-9])+
186186
<YYINITIAL> {
187187
{WhiteSpace}{EOL} |
188188
{EOL} {
189-
doStartNewLine();
189+
startNewLine();
190190
}
191191
}
192192

src/org/opensolaris/opengrok/analysis/ada/AdaSymbolTokenizer.lex

+7-11
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,12 @@ import org.opensolaris.opengrok.web.Util;
5151

5252
private String lastSymbol;
5353

54-
public void pushState(int state) { yypush(state); }
55-
56-
public void popState() throws IOException { yypop(); }
57-
58-
public void switchState(int state) { yybegin(state); }
59-
54+
@Override
6055
public void take(String value) throws IOException {
6156
// noop
6257
}
6358

59+
@Override
6460
public void takeNonword(String value) throws IOException {
6561
// noop
6662
}
@@ -69,6 +65,7 @@ import org.opensolaris.opengrok.web.Util;
6965
// noop
7066
}
7167

68+
@Override
7269
public boolean takeSymbol(String value, int captureOffset,
7370
boolean ignoreKwd)
7471
throws IOException {
@@ -83,22 +80,21 @@ import org.opensolaris.opengrok.web.Util;
8380
return false;
8481
}
8582

83+
@Override
8684
public void skipSymbol() {
8785
lastSymbol = null;
8886
}
8987

88+
@Override
9089
public void takeKeyword(String value) throws IOException {
9190
lastSymbol = null;
9291
}
9392

94-
public void doStartNewLine() throws IOException {
93+
@Override
94+
public void startNewLine() throws IOException {
9595
// noop
9696
}
9797

98-
public void pushback(int numChars) {
99-
yypushback(numChars);
100-
}
101-
10298
protected boolean takeAllContent() {
10399
return false;
104100
}

src/org/opensolaris/opengrok/analysis/ada/AdaXref.lex

+5-14
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,12 @@ import org.opensolaris.opengrok.web.Util;
5454

5555
private final AdaLexHelper h;
5656

57-
public void pushState(int state) { yypush(state, null); }
58-
59-
public void popState() throws IOException { yypop(); }
60-
61-
public void switchState(int state) { yybegin(state); }
62-
57+
@Override
6358
public void take(String value) throws IOException {
6459
out.write(value);
6560
}
6661

62+
@Override
6763
public void takeNonword(String value) throws IOException {
6864
out.write(htmlize(value));
6965
}
@@ -75,6 +71,7 @@ import org.opensolaris.opengrok.web.Util;
7571
}
7672
}
7773

74+
@Override
7875
public boolean takeSymbol(String value, int captureOffset,
7976
boolean ignoreKwd)
8077
throws IOException {
@@ -90,22 +87,16 @@ import org.opensolaris.opengrok.web.Util;
9087
}
9188
}
9289

90+
@Override
9391
public void skipSymbol() {
9492
// noop
9593
}
9694

95+
@Override
9796
public void takeKeyword(String value) throws IOException {
9897
writeKeyword(value, yyline);
9998
}
10099

101-
public void doStartNewLine() throws IOException {
102-
startNewLine();
103-
}
104-
105-
public void pushback(int numChars) {
106-
yypushback(numChars);
107-
}
108-
109100
protected boolean takeAllContent() {
110101
return true;
111102
}

src/org/opensolaris/opengrok/analysis/perl/PerlLexHelper.java

+15-19
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
* Represents an API for object's using {@link PerlLexHelper}
3232
*/
3333
interface PerlLexListener {
34-
void pushState(int state);
35-
void popState() throws IOException;
36-
void switchState(int state);
34+
void yypush(int state);
35+
void yypop() throws IOException;
36+
void yybegin(int state);
37+
void yypushback(int numChars);
38+
3739
void maybeIntraState();
3840
void take(String value) throws IOException;
3941
void takeNonword(String value) throws IOException;
@@ -62,20 +64,14 @@ boolean takeSymbol(String value, int captureOffset, boolean ignoreKwd)
6264
*/
6365
void takeKeyword(String value) throws IOException;
6466

65-
void doStartNewLine() throws IOException;
67+
void startNewLine() throws IOException;
6668

6769
/**
6870
* Indicates that a premature end of quoting occurred. Everything up to the
6971
* causal character has been written, and anything following will be
70-
* indicated via {@link pushback}.
72+
* indicated via {@link yypushback}.
7173
*/
7274
void abortQuote() throws IOException;
73-
74-
/**
75-
* Pushes back to the scanner a specified number of characters
76-
* @param numChars
77-
*/
78-
void pushback(int numChars);
7975
}
8076

8177
/**
@@ -244,7 +240,7 @@ public void setState(String ltpostop, boolean nointerp) {
244240
state = nolink ? QUOxL : QUO;
245241
}
246242
listener.maybeIntraState();
247-
listener.pushState(state);
243+
listener.yypush(state);
248244
}
249245

250246
/**
@@ -332,7 +328,7 @@ private void takeWhitespace(String whsp) throws IOException {
332328
++numlf;
333329
off = i + 1;
334330
}
335-
while (numlf-- > 0) listener.doStartNewLine();
331+
while (numlf-- > 0) listener.startNewLine();
336332
if (off < whsp.length()) listener.take(whsp.substring(off));
337333
}
338334
}
@@ -416,7 +412,7 @@ public void hop(String capture) throws IOException {
416412
public boolean maybeStartHere() throws IOException {
417413
if (hereSettings != null && hereSettings.size() > 0) {
418414
HereDocSettings settings = hereSettings.peek();
419-
listener.pushState(settings.state);
415+
listener.yypush(settings.state);
420416
listener.take(Consts.SS);
421417
return true;
422418
}
@@ -443,11 +439,11 @@ public boolean maybeEndHere(String capture) throws IOException {
443439

444440
if (hereSettings.size() > 0) {
445441
settings = hereSettings.peek();
446-
listener.switchState(settings.state);
442+
listener.yybegin(settings.state);
447443
if (didZspan) listener.take(Consts.SS);
448444
return false;
449445
} else {
450-
listener.popState();
446+
listener.yypop();
451447
return true;
452448
}
453449
}
@@ -467,7 +463,7 @@ public void sigilID(String capture) throws IOException {
467463
listener.skipSymbol();
468464
listener.takeNonword(sigil);
469465
if (isQuoteEnding(sigil)) listener.abortQuote();
470-
listener.pushback(capture.length() - 1);
466+
listener.yypushback(capture.length() - 1);
471467
return;
472468
}
473469

@@ -504,7 +500,7 @@ public void sigilID(String capture) throws IOException {
504500
}
505501
listener.takeNonword(p0);
506502
if (isQuoteEnding(p0)) listener.abortQuote();
507-
listener.pushback(w1.length());
503+
listener.yypushback(w1.length());
508504
}
509505
}
510506

@@ -564,7 +560,7 @@ public void specialID(String capture) throws IOException {
564560
listener.takeNonword(w);
565561
if (isQuoteEnding(w)) {
566562
listener.abortQuote();
567-
listener.pushback(capture.length() - i - 1);
563+
listener.yypushback(capture.length() - i - 1);
568564
break;
569565
}
570566
}

src/org/opensolaris/opengrok/analysis/perl/PerlProductions.lexh

+7-7
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Mpunc2IN = ([!=]"~" | [\:\?\=\+\-\<\>] | "=="|"!="|"<="|">="|"<=>"|"=>")
215215
[\"\`] { h.qop(yytext(), 0, false); }
216216
\' { h.qop(yytext(), 0, true); }
217217
\# {
218-
pushState(SCOMMENT);
218+
yypush(SCOMMENT);
219219
take(Consts.SC);
220220
take("#");
221221
}
@@ -276,15 +276,15 @@ Mpunc2IN = ([!=]"~" | [\:\?\=\+\-\<\>] | "=="|"!="|"<="|">="|"<=>"|"=>")
276276

277277
// POD start
278278
^ "=" [a-zA-Z_] [a-zA-Z0-9_]* {
279-
pushState(POD);
279+
yypush(POD);
280280
take(Consts.SC);
281281
take(yytext());
282282
}
283283

284284
// FORMAT start
285285
^ {MaybeWhsp} "format" ({WhiteSpace} {Identifier})? {MaybeWhsp} "=" /
286286
{MaybeWhsp}{EOL} {
287-
pushState(FMT);
287+
yypush(FMT);
288288
if (takeAllContent()) {
289289
// split off the " format" as `initial' for keyword processing
290290
String capture = yytext();
@@ -403,7 +403,7 @@ Mpunc2IN = ([!=]"~" | [\:\?\=\+\-\<\>] | "=="|"!="|"<="|">="|"<=>"|"=>")
403403
if (h.isQuoteEnding(capture)) {
404404
yypop();
405405
if (h.areModifiersOK())
406-
pushState(QM);
406+
yypush(QM);
407407
take(Consts.ZS);
408408
}
409409
}
@@ -413,7 +413,7 @@ Mpunc2IN = ([!=]"~" | [\:\?\=\+\-\<\>] | "=="|"!="|"<="|">="|"<=>"|"=>")
413413
{WhiteSpace}{EOL} |
414414
{EOL} {
415415
take(Consts.ZS);
416-
doStartNewLine();
416+
startNewLine();
417417
take(Consts.SS);
418418
}
419419
}
@@ -444,7 +444,7 @@ Mpunc2IN = ([!=]"~" | [\:\?\=\+\-\<\>] | "=="|"!="|"<="|">="|"<=>"|"=>")
444444

445445
{WhiteSpace}{EOL} |
446446
{EOL} {
447-
doStartNewLine();
447+
startNewLine();
448448
}
449449
}
450450

@@ -486,7 +486,7 @@ Mpunc2IN = ([!=]"~" | [\:\?\=\+\-\<\>] | "=="|"!="|"<="|">="|"<=>"|"=>")
486486
if (h.maybeStartHere()) {
487487
yypushback(capture.length());
488488
} else {
489-
doStartNewLine();
489+
startNewLine();
490490
}
491491
}
492492
}

0 commit comments

Comments
 (0)