Skip to content

Commit

Permalink
Remove some lexer and parser functionality that has been long depreca…
Browse files Browse the repository at this point in the history
…ted.
  • Loading branch information
chrisseaton committed Oct 26, 2014
1 parent 0e4dc82 commit 5bf8d52
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 140 deletions.
8 changes: 2 additions & 6 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -79,7 +79,6 @@
import org.jruby.internal.runtime.methods.JavaMethod;
import org.jruby.ir.Compiler;
import org.jruby.ir.IRManager;
import org.jruby.ir.IRScriptBody;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.persistence.IRReader;
import org.jruby.ir.persistence.IRReaderFile;
Expand Down Expand Up @@ -158,7 +157,6 @@
import java.security.AccessControlException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
Expand All @@ -172,7 +170,6 @@
import java.util.WeakHashMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
Expand Down Expand Up @@ -2673,7 +2670,7 @@ private Node parseFileFromMainAndGetAST(InputStream in, String file, DynamicScop

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

public Node parseEval(String content, String file, DynamicScope scope, int lineNumber) {
addEvalParseToStats();
return parser.parse(file, content.getBytes(), scope, new ParserConfiguration(this,
lineNumber, false, false, false, false, config));
return parser.parse(file, content.getBytes(), scope, new ParserConfiguration(this, lineNumber, false, false, config));
}

@Deprecated
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ast/NilImplicitNode.java
@@ -1,6 +1,6 @@
package org.jruby.ast;

import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.lexer.yacc.InvalidSourcePosition;

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

public NilImplicitNode() {
super(ISourcePosition.INVALID_POSITION);
super(InvalidSourcePosition.INSTANCE);
}

public boolean isNil() {
Expand Down
Expand Up @@ -2,7 +2,7 @@

import java.util.List;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.lexer.yacc.InvalidSourcePosition;

/**
* Marker to indicate that rather than assigning nil (where in multiple
Expand All @@ -14,7 +14,7 @@
*/
public class RequiredKeywordArgumentValueNode extends Node implements InvisibleNode {
public RequiredKeywordArgumentValueNode() {
super(ISourcePosition.INVALID_POSITION);
super(InvalidSourcePosition.INSTANCE);
}

@Override
Expand Down
Expand Up @@ -16,9 +16,8 @@ public class ByteArrayLexerSource extends LexerSource {
private Cursor mainCursor, pushbackCursor;
private final boolean captureSource;

public ByteArrayLexerSource(String sourceName, byte[] in, List<String> list, int line,
boolean extraPositionInformation, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
super(sourceName, list, line, extraPositionInformation, sourcePositionFactoryFactory);
public ByteArrayLexerSource(String sourceName, byte[] in, List<String> list, int line, SourcePositionFactory sourcePositionFactory) {
super(sourceName, list, line, sourcePositionFactory);
this.readCursor = new ByteArrayCursor(in);
this.mainCursor = readCursor;
this.pushbackCursor = new PushbackCursor(mainCursor, new ByteList(128));
Expand Down
15 changes: 0 additions & 15 deletions core/src/main/java/org/jruby/lexer/yacc/ISourcePosition.java
Expand Up @@ -52,19 +52,4 @@ public interface ISourcePosition extends PositionAware {
*/
public int getStartLine();


/** For nodes which are added to the AST which are not proper syntactical elements. */
public static final ISourcePosition INVALID_POSITION = new ISourcePosition() {
public String getFile() {
return "dummy";
}

public int getStartLine() {
return -1;
}

public int getLine() {
return -1;
}
};
}
Expand Up @@ -34,11 +34,10 @@ public class InputStreamLexerSource extends LexerSource {
* @param sourceName is the file we are reading
* @param in is what represents the contents of file sourceName
* @param line starting line number for source (used by eval)
* @param extraPositionInformation will gives us extra information that an IDE may want
*/
public InputStreamLexerSource(String sourceName, InputStream in, List<String> list, int line,
boolean extraPositionInformation, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
super(sourceName, list, line, extraPositionInformation, sourcePositionFactoryFactory);
public InputStreamLexerSource(String sourceName, InputStream in, List<String> list, int line,
SourcePositionFactory sourcePositionFactory) {
super(sourceName, list, line, sourcePositionFactory);

this.in = in;
this.captureSource = list != null;
Expand Down
46 changes: 46 additions & 0 deletions core/src/main/java/org/jruby/lexer/yacc/InvalidSourcePosition.java
@@ -0,0 +1,46 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2005 Thomas E Enebo <enebo@acm.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby.lexer.yacc;

/** For nodes which are added to the AST which are not proper syntactical elements. */
public class InvalidSourcePosition implements ISourcePosition {

public static final ISourcePosition INSTANCE = new InvalidSourcePosition();

public String getFile() {
return "dummy";
}

public int getStartLine() {
return -1;
}

public int getLine() {
return -1;
}
}
20 changes: 6 additions & 14 deletions core/src/main/java/org/jruby/lexer/yacc/LexerSource.java
Expand Up @@ -78,13 +78,11 @@ public abstract class LexerSource {
* Create our food-source for the lexer
*
* @param sourceName is the file we are reading
* @param extraPositionInformation will gives us extra information that an IDE may want (deprecated)
*/
protected LexerSource(String sourceName, List<String> list, int lineOffset,
boolean extraPositionInformation, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
protected LexerSource(String sourceName, List<String> list, int lineOffset, SourcePositionFactory sourcePositionFactory) {
this.sourceName = sourceName;
this.lineOffset = lineOffset;
positionFactory = sourcePositionFactoryFactory.create(this, line);
positionFactory = sourcePositionFactory;
this.list = list;
lineBuffer = new StringBuilder(160);
sourceLine = new StringBuilder(160);
Expand Down Expand Up @@ -150,15 +148,13 @@ public ISourcePosition getPosition() {
* @return the new source
*/
public static LexerSource getSource(String name, InputStream content, List<String> list,
ParserConfiguration configuration, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
return new InputStreamLexerSource(name, content, list, configuration.getLineNumber(),
configuration.hasExtraPositionInformation(), sourcePositionFactoryFactory);
ParserConfiguration configuration, SourcePositionFactory sourcePositionFactory) {
return new InputStreamLexerSource(name, content, list, configuration.getLineNumber(), sourcePositionFactory);
}

public static LexerSource getSource(String name, byte[] content, List<String> list,
ParserConfiguration configuration, SourcePositionFactory.SourcePositionFactoryFactory sourcePositionFactoryFactory) {
return new ByteArrayLexerSource(name, content, list, configuration.getLineNumber(),
configuration.hasExtraPositionInformation(), sourcePositionFactoryFactory);
ParserConfiguration configuration, SourcePositionFactory sourcePositionFactory) {
return new ByteArrayLexerSource(name, content, list, configuration.getLineNumber(), sourcePositionFactory);
}

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

public SourcePositionFactory getPositionFactory() {
return positionFactory;
}

public abstract int read() throws IOException;
public abstract ByteList readUntil(char c) throws IOException;
public abstract ByteList readLineBytes() throws IOException;
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Expand Up @@ -374,14 +374,7 @@ public final void reset() {
}

public int nextToken() throws IOException {
src.getPositionFactory().startOfToken();

token = yylex();

if (token != -1) {
src.getPositionFactory().endOfToken();
}

return token == EOF ? 0 : token;
}

Expand Down
Expand Up @@ -30,15 +30,6 @@

public class SimpleSourcePositionFactory implements SourcePositionFactory {

public static class Factory implements SourcePositionFactoryFactory {

@Override
public SourcePositionFactory create(LexerSource source, int line) {
return new SimpleSourcePositionFactory(source, line);
}

}

protected LexerSource source;
protected ISourcePosition lastPosition;

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

@Override
public void startOfToken() {
}

@Override
public void endOfToken() {
}

public ISourcePosition getPosition(ISourcePosition startPosition) {
if (startPosition != null) {
lastPosition = startPosition;
Expand Down
11 changes: 0 additions & 11 deletions core/src/main/java/org/jruby/lexer/yacc/SourcePositionFactory.java
Expand Up @@ -11,17 +11,6 @@

public interface SourcePositionFactory {

// Sorry for creating a factory factory (CS)
public interface SourcePositionFactoryFactory {

public SourcePositionFactory create(LexerSource source, int line);

}

void startOfToken();

void endOfToken();

ISourcePosition getPosition(ISourcePosition startPosition);

ISourcePosition getPosition();
Expand Down
53 changes: 5 additions & 48 deletions core/src/main/java/org/jruby/parser/ParserConfiguration.java
Expand Up @@ -52,8 +52,6 @@ public class ParserConfiguration {
private boolean inlineSource = false;
// We parse evals more often in source so assume an eval parse.
private boolean isEvalParse = true;
// Should positions added extra IDE-friendly information and leave in all newline nodes
private boolean extraPositionInformation = false;
// Should we display extra debug information while parsing?
private boolean isDebug = false;
// whether we should save the end-of-file data as DATA
Expand All @@ -65,35 +63,23 @@ public class ParserConfiguration {
private int[] coverage = EMPTY_COVERAGE;

private static final int[] EMPTY_COVERAGE = new int[0];

public ParserConfiguration(Ruby runtime, int lineNumber, boolean inlineSource,
CompatVersion version) {
this(runtime, lineNumber, false, inlineSource, version);
}

public ParserConfiguration(Ruby runtime, int lineNumber,
boolean extraPositionInformation, boolean inlineSource, CompatVersion version) {
this(runtime, lineNumber, extraPositionInformation, inlineSource, true, version, false);
}

public ParserConfiguration(Ruby runtime, int lineNumber, boolean extraPositionInformation,
boolean inlineSource, boolean isFileParse, boolean saveData) {
public ParserConfiguration(Ruby runtime, int lineNumber, boolean inlineSource, boolean isFileParse, boolean saveData) {
this.runtime = runtime;
this.inlineSource = inlineSource;
this.lineNumber = lineNumber;
this.extraPositionInformation = extraPositionInformation;
this.isEvalParse = !isFileParse;
this.saveData = saveData;
}

public ParserConfiguration(Ruby runtime, int lineNumber, boolean extraPositionInformation,
public ParserConfiguration(Ruby runtime, int lineNumber,
boolean inlineSource, boolean isFileParse, RubyInstanceConfig config) {
this(runtime, lineNumber, extraPositionInformation, inlineSource, isFileParse, false, config);
this(runtime, lineNumber, inlineSource, isFileParse, false, config);
}

public ParserConfiguration(Ruby runtime, int lineNumber, boolean extraPositionInformation,
public ParserConfiguration(Ruby runtime, int lineNumber,
boolean inlineSource, boolean isFileParse, boolean saveData, RubyInstanceConfig config) {
this(runtime, lineNumber, extraPositionInformation, inlineSource, isFileParse, saveData);
this(runtime, lineNumber, inlineSource, isFileParse, saveData);

this.isDebug = config.isParserDebug();
}
Expand Down Expand Up @@ -125,22 +111,6 @@ public void setEvalParse(boolean isEvalParse) {
this.isEvalParse = isEvalParse;
}

/**
* Should positions of nodes provide additional information in them (like character offsets).
* @param extraPositionInformation
*/
public void setExtraPositionInformation(boolean extraPositionInformation) {
this.extraPositionInformation = extraPositionInformation;
}

/**
* Should positions of nodes provide addition information?
* @return true if they should
*/
public boolean hasExtraPositionInformation() {
return extraPositionInformation;
}

public boolean isDebug() {
return isDebug;
}
Expand Down Expand Up @@ -238,17 +208,4 @@ public int[] getCoverage() {
return coverage;
}

@Deprecated
public ParserConfiguration(Ruby runtime, int lineNumber, boolean extraPositionInformation,
boolean inlineSource, boolean isFileParse, CompatVersion version, boolean saveData) {
this(runtime, lineNumber, extraPositionInformation, inlineSource, isFileParse, saveData);
}

/**
* Get the compatibility version we're targeting with this parse.
*/
@Deprecated
public CompatVersion getVersion() {
return CompatVersion.RUBY2_1;
}
}

0 comments on commit 5bf8d52

Please sign in to comment.