Skip to content

Commit 5bf8d52

Browse files
committed
Remove some lexer and parser functionality that has been long deprecated.
1 parent 0e4dc82 commit 5bf8d52

14 files changed

+79
-140
lines changed

core/src/main/java/org/jruby/Ruby.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
import org.jruby.internal.runtime.methods.JavaMethod;
8080
import org.jruby.ir.Compiler;
8181
import org.jruby.ir.IRManager;
82-
import org.jruby.ir.IRScriptBody;
8382
import org.jruby.ir.interpreter.Interpreter;
8483
import org.jruby.ir.persistence.IRReader;
8584
import org.jruby.ir.persistence.IRReaderFile;
@@ -158,7 +157,6 @@
158157
import java.security.AccessControlException;
159158
import java.security.SecureRandom;
160159
import java.util.ArrayList;
161-
import java.util.Collections;
162160
import java.util.EnumMap;
163161
import java.util.EnumSet;
164162
import java.util.HashMap;
@@ -172,7 +170,6 @@
172170
import java.util.WeakHashMap;
173171
import java.util.concurrent.Callable;
174172
import java.util.concurrent.ConcurrentHashMap;
175-
import java.util.concurrent.CopyOnWriteArrayList;
176173
import java.util.concurrent.ExecutorService;
177174
import java.util.concurrent.SynchronousQueue;
178175
import java.util.concurrent.ThreadPoolExecutor;
@@ -2673,7 +2670,7 @@ private Node parseFileFromMainAndGetAST(InputStream in, String file, DynamicScop
26732670

26742671
private Node parseFileAndGetAST(InputStream in, String file, DynamicScope scope, int lineNumber, boolean isFromMain) {
26752672
ParserConfiguration parserConfig =
2676-
new ParserConfiguration(this, lineNumber, false, false, true, isFromMain, config);
2673+
new ParserConfiguration(this, lineNumber, false, true, config);
26772674
setupSourceEncoding(parserConfig);
26782675
return parser.parse(file, in, scope, parserConfig);
26792676
}
@@ -2699,8 +2696,7 @@ private void setupSourceEncoding(ParserConfiguration parserConfig) {
26992696

27002697
public Node parseEval(String content, String file, DynamicScope scope, int lineNumber) {
27012698
addEvalParseToStats();
2702-
return parser.parse(file, content.getBytes(), scope, new ParserConfiguration(this,
2703-
lineNumber, false, false, false, false, config));
2699+
return parser.parse(file, content.getBytes(), scope, new ParserConfiguration(this, lineNumber, false, false, config));
27042700
}
27052701

27062702
@Deprecated

core/src/main/java/org/jruby/ast/NilImplicitNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.jruby.ast;
22

3-
import org.jruby.lexer.yacc.ISourcePosition;
3+
import org.jruby.lexer.yacc.InvalidSourcePosition;
44

55
/**
66
* A node which behaves like a nil node, but is not actually present in the AST as a syntactical
@@ -11,7 +11,7 @@ public class NilImplicitNode extends NilNode implements InvisibleNode {
1111
public static final NilImplicitNode NIL = new NilImplicitNode();
1212

1313
public NilImplicitNode() {
14-
super(ISourcePosition.INVALID_POSITION);
14+
super(InvalidSourcePosition.INSTANCE);
1515
}
1616

1717
public boolean isNil() {

core/src/main/java/org/jruby/ast/RequiredKeywordArgumentValueNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.List;
44
import org.jruby.ast.visitor.NodeVisitor;
5-
import org.jruby.lexer.yacc.ISourcePosition;
5+
import org.jruby.lexer.yacc.InvalidSourcePosition;
66

77
/**
88
* Marker to indicate that rather than assigning nil (where in multiple
@@ -14,7 +14,7 @@
1414
*/
1515
public class RequiredKeywordArgumentValueNode extends Node implements InvisibleNode {
1616
public RequiredKeywordArgumentValueNode() {
17-
super(ISourcePosition.INVALID_POSITION);
17+
super(InvalidSourcePosition.INSTANCE);
1818
}
1919

2020
@Override

core/src/main/java/org/jruby/lexer/yacc/ByteArrayLexerSource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ public class ByteArrayLexerSource extends LexerSource {
1616
private Cursor mainCursor, pushbackCursor;
1717
private final boolean captureSource;
1818

19-
public ByteArrayLexerSource(String sourceName, byte[] in, List<String> list, int line,
20-
boolean extraPositionInformation, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
21-
super(sourceName, list, line, extraPositionInformation, sourcePositionFactoryFactory);
19+
public ByteArrayLexerSource(String sourceName, byte[] in, List<String> list, int line, SourcePositionFactory sourcePositionFactory) {
20+
super(sourceName, list, line, sourcePositionFactory);
2221
this.readCursor = new ByteArrayCursor(in);
2322
this.mainCursor = readCursor;
2423
this.pushbackCursor = new PushbackCursor(mainCursor, new ByteList(128));

core/src/main/java/org/jruby/lexer/yacc/ISourcePosition.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,4 @@ public interface ISourcePosition extends PositionAware {
5252
*/
5353
public int getStartLine();
5454

55-
56-
/** For nodes which are added to the AST which are not proper syntactical elements. */
57-
public static final ISourcePosition INVALID_POSITION = new ISourcePosition() {
58-
public String getFile() {
59-
return "dummy";
60-
}
61-
62-
public int getStartLine() {
63-
return -1;
64-
}
65-
66-
public int getLine() {
67-
return -1;
68-
}
69-
};
7055
}

core/src/main/java/org/jruby/lexer/yacc/InputStreamLexerSource.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ public class InputStreamLexerSource extends LexerSource {
3434
* @param sourceName is the file we are reading
3535
* @param in is what represents the contents of file sourceName
3636
* @param line starting line number for source (used by eval)
37-
* @param extraPositionInformation will gives us extra information that an IDE may want
3837
*/
39-
public InputStreamLexerSource(String sourceName, InputStream in, List<String> list, int line,
40-
boolean extraPositionInformation, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
41-
super(sourceName, list, line, extraPositionInformation, sourcePositionFactoryFactory);
38+
public InputStreamLexerSource(String sourceName, InputStream in, List<String> list, int line,
39+
SourcePositionFactory sourcePositionFactory) {
40+
super(sourceName, list, line, sourcePositionFactory);
4241

4342
this.in = in;
4443
this.captureSource = list != null;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/***** BEGIN LICENSE BLOCK *****
2+
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
3+
*
4+
* The contents of this file are subject to the Eclipse Public
5+
* License Version 1.0 (the "License"); you may not use this file
6+
* except in compliance with the License. You may obtain a copy of
7+
* the License at http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Software distributed under the License is distributed on an "AS
10+
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11+
* implied. See the License for the specific language governing
12+
* rights and limitations under the License.
13+
*
14+
* Copyright (C) 2005 Thomas E Enebo <enebo@acm.org>
15+
*
16+
* Alternatively, the contents of this file may be used under the terms of
17+
* either of the GNU General Public License Version 2 or later (the "GPL"),
18+
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19+
* in which case the provisions of the GPL or the LGPL are applicable instead
20+
* of those above. If you wish to allow use of your version of this file only
21+
* under the terms of either the GPL or the LGPL, and not to allow others to
22+
* use your version of this file under the terms of the EPL, indicate your
23+
* decision by deleting the provisions above and replace them with the notice
24+
* and other provisions required by the GPL or the LGPL. If you do not delete
25+
* the provisions above, a recipient may use your version of this file under
26+
* the terms of any one of the EPL, the GPL or the LGPL.
27+
***** END LICENSE BLOCK *****/
28+
package org.jruby.lexer.yacc;
29+
30+
/** For nodes which are added to the AST which are not proper syntactical elements. */
31+
public class InvalidSourcePosition implements ISourcePosition {
32+
33+
public static final ISourcePosition INSTANCE = new InvalidSourcePosition();
34+
35+
public String getFile() {
36+
return "dummy";
37+
}
38+
39+
public int getStartLine() {
40+
return -1;
41+
}
42+
43+
public int getLine() {
44+
return -1;
45+
}
46+
}

core/src/main/java/org/jruby/lexer/yacc/LexerSource.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,11 @@ public abstract class LexerSource {
7878
* Create our food-source for the lexer
7979
*
8080
* @param sourceName is the file we are reading
81-
* @param extraPositionInformation will gives us extra information that an IDE may want (deprecated)
8281
*/
83-
protected LexerSource(String sourceName, List<String> list, int lineOffset,
84-
boolean extraPositionInformation, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
82+
protected LexerSource(String sourceName, List<String> list, int lineOffset, SourcePositionFactory sourcePositionFactory) {
8583
this.sourceName = sourceName;
8684
this.lineOffset = lineOffset;
87-
positionFactory = sourcePositionFactoryFactory.create(this, line);
85+
positionFactory = sourcePositionFactory;
8886
this.list = list;
8987
lineBuffer = new StringBuilder(160);
9088
sourceLine = new StringBuilder(160);
@@ -150,15 +148,13 @@ public ISourcePosition getPosition() {
150148
* @return the new source
151149
*/
152150
public static LexerSource getSource(String name, InputStream content, List<String> list,
153-
ParserConfiguration configuration, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
154-
return new InputStreamLexerSource(name, content, list, configuration.getLineNumber(),
155-
configuration.hasExtraPositionInformation(), sourcePositionFactoryFactory);
151+
ParserConfiguration configuration, SourcePositionFactory sourcePositionFactory) {
152+
return new InputStreamLexerSource(name, content, list, configuration.getLineNumber(), sourcePositionFactory);
156153
}
157154

158155
public static LexerSource getSource(String name, byte[] content, List<String> list,
159-
ParserConfiguration configuration, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
160-
return new ByteArrayLexerSource(name, content, list, configuration.getLineNumber(),
161-
configuration.hasExtraPositionInformation(), sourcePositionFactoryFactory);
156+
ParserConfiguration configuration, SourcePositionFactory sourcePositionFactory) {
157+
return new ByteArrayLexerSource(name, content, list, configuration.getLineNumber(), sourcePositionFactory);
162158
}
163159

164160
private void captureFeatureNewline() {
@@ -261,10 +257,6 @@ public int readCodepoint(int first, Encoding encoding) throws IOException {
261257
*/
262258
public abstract boolean matchMarker(ByteList marker, boolean indent, boolean withNewline) throws IOException;
263259

264-
public SourcePositionFactory getPositionFactory() {
265-
return positionFactory;
266-
}
267-
268260
public abstract int read() throws IOException;
269261
public abstract ByteList readUntil(char c) throws IOException;
270262
public abstract ByteList readLineBytes() throws IOException;

core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,7 @@ public final void reset() {
374374
}
375375

376376
public int nextToken() throws IOException {
377-
src.getPositionFactory().startOfToken();
378-
379377
token = yylex();
380-
381-
if (token != -1) {
382-
src.getPositionFactory().endOfToken();
383-
}
384-
385378
return token == EOF ? 0 : token;
386379
}
387380

core/src/main/java/org/jruby/lexer/yacc/SimpleSourcePositionFactory.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@
3030

3131
public class SimpleSourcePositionFactory implements SourcePositionFactory {
3232

33-
public static class Factory implements SourcePositionFactoryFactory {
34-
35-
@Override
36-
public SourcePositionFactory create(LexerSource source, int line) {
37-
return new SimpleSourcePositionFactory(source, line);
38-
}
39-
40-
}
41-
4233
protected LexerSource source;
4334
protected ISourcePosition lastPosition;
4435

@@ -47,14 +38,6 @@ public SimpleSourcePositionFactory(LexerSource source, int line) {
4738
lastPosition = new SimpleSourcePosition(source.getFilename(), line);
4839
}
4940

50-
@Override
51-
public void startOfToken() {
52-
}
53-
54-
@Override
55-
public void endOfToken() {
56-
}
57-
5841
public ISourcePosition getPosition(ISourcePosition startPosition) {
5942
if (startPosition != null) {
6043
lastPosition = startPosition;

core/src/main/java/org/jruby/lexer/yacc/SourcePositionFactory.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@
1111

1212
public interface SourcePositionFactory {
1313

14-
// Sorry for creating a factory factory (CS)
15-
public interface SourcePositionFactoryFactory {
16-
17-
public SourcePositionFactory create(LexerSource source, int line);
18-
19-
}
20-
21-
void startOfToken();
22-
23-
void endOfToken();
24-
2514
ISourcePosition getPosition(ISourcePosition startPosition);
2615

2716
ISourcePosition getPosition();

core/src/main/java/org/jruby/parser/ParserConfiguration.java

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public class ParserConfiguration {
5252
private boolean inlineSource = false;
5353
// We parse evals more often in source so assume an eval parse.
5454
private boolean isEvalParse = true;
55-
// Should positions added extra IDE-friendly information and leave in all newline nodes
56-
private boolean extraPositionInformation = false;
5755
// Should we display extra debug information while parsing?
5856
private boolean isDebug = false;
5957
// whether we should save the end-of-file data as DATA
@@ -65,35 +63,23 @@ public class ParserConfiguration {
6563
private int[] coverage = EMPTY_COVERAGE;
6664

6765
private static final int[] EMPTY_COVERAGE = new int[0];
68-
69-
public ParserConfiguration(Ruby runtime, int lineNumber, boolean inlineSource,
70-
CompatVersion version) {
71-
this(runtime, lineNumber, false, inlineSource, version);
72-
}
73-
74-
public ParserConfiguration(Ruby runtime, int lineNumber,
75-
boolean extraPositionInformation, boolean inlineSource, CompatVersion version) {
76-
this(runtime, lineNumber, extraPositionInformation, inlineSource, true, version, false);
77-
}
7866

79-
public ParserConfiguration(Ruby runtime, int lineNumber, boolean extraPositionInformation,
80-
boolean inlineSource, boolean isFileParse, boolean saveData) {
67+
public ParserConfiguration(Ruby runtime, int lineNumber, boolean inlineSource, boolean isFileParse, boolean saveData) {
8168
this.runtime = runtime;
8269
this.inlineSource = inlineSource;
8370
this.lineNumber = lineNumber;
84-
this.extraPositionInformation = extraPositionInformation;
8571
this.isEvalParse = !isFileParse;
8672
this.saveData = saveData;
8773
}
8874

89-
public ParserConfiguration(Ruby runtime, int lineNumber, boolean extraPositionInformation,
75+
public ParserConfiguration(Ruby runtime, int lineNumber,
9076
boolean inlineSource, boolean isFileParse, RubyInstanceConfig config) {
91-
this(runtime, lineNumber, extraPositionInformation, inlineSource, isFileParse, false, config);
77+
this(runtime, lineNumber, inlineSource, isFileParse, false, config);
9278
}
9379

94-
public ParserConfiguration(Ruby runtime, int lineNumber, boolean extraPositionInformation,
80+
public ParserConfiguration(Ruby runtime, int lineNumber,
9581
boolean inlineSource, boolean isFileParse, boolean saveData, RubyInstanceConfig config) {
96-
this(runtime, lineNumber, extraPositionInformation, inlineSource, isFileParse, saveData);
82+
this(runtime, lineNumber, inlineSource, isFileParse, saveData);
9783

9884
this.isDebug = config.isParserDebug();
9985
}
@@ -125,22 +111,6 @@ public void setEvalParse(boolean isEvalParse) {
125111
this.isEvalParse = isEvalParse;
126112
}
127113

128-
/**
129-
* Should positions of nodes provide additional information in them (like character offsets).
130-
* @param extraPositionInformation
131-
*/
132-
public void setExtraPositionInformation(boolean extraPositionInformation) {
133-
this.extraPositionInformation = extraPositionInformation;
134-
}
135-
136-
/**
137-
* Should positions of nodes provide addition information?
138-
* @return true if they should
139-
*/
140-
public boolean hasExtraPositionInformation() {
141-
return extraPositionInformation;
142-
}
143-
144114
public boolean isDebug() {
145115
return isDebug;
146116
}
@@ -238,17 +208,4 @@ public int[] getCoverage() {
238208
return coverage;
239209
}
240210

241-
@Deprecated
242-
public ParserConfiguration(Ruby runtime, int lineNumber, boolean extraPositionInformation,
243-
boolean inlineSource, boolean isFileParse, CompatVersion version, boolean saveData) {
244-
this(runtime, lineNumber, extraPositionInformation, inlineSource, isFileParse, saveData);
245-
}
246-
247-
/**
248-
* Get the compatibility version we're targeting with this parse.
249-
*/
250-
@Deprecated
251-
public CompatVersion getVersion() {
252-
return CompatVersion.RUBY2_1;
253-
}
254211
}

0 commit comments

Comments
 (0)