diff --git a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/IParser.java b/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/IParser.java index ba7e1bd73d5055549766b479c5f3f579965ee220..30fc88bc9238fbea629848b6333aca20b9ed4d23 100644 --- a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/IParser.java +++ b/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/IParser.java @@ -6,14 +6,4 @@ package de.hhu.stups.sablecc.patch; -import java.util.Map; - - -public interface IParser { - /** - * @deprecated All generated token classes store their own position info. - * Use the {@link PositionedNode} or {@link IToken} APIs to access the positions stored in the tokens. - */ - @Deprecated - public Map<PositionedNode, SourcecodeRange> getMapping(); -} +public interface IParser {} diff --git a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/ITokenListContainer.java b/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/ITokenListContainer.java deleted file mode 100644 index eb07fe5602f8b75df630419a334952d13cc5cf0d..0000000000000000000000000000000000000000 --- a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/ITokenListContainer.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.hhu.stups.sablecc.patch; - -import java.util.List; - -/** - * @deprecated In the future, the generated lexers will not store all tokens anymore, because this leads to significant memory usage for large inputs. - * If you really need this list, please create it yourself, using a custom lexer subclass if necessary. - */ -@Deprecated -public interface ITokenListContainer { - /** - * @deprecated In the future, the generated lexers will not store all tokens anymore, because this leads to significant memory usage for large inputs. - * If you really need this list, please create it yourself, using a custom lexer subclass if necessary. - */ - @Deprecated - public List<IToken> getTokenList(); -} diff --git a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcePositions.java b/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcePositions.java deleted file mode 100644 index 7dc66fd2e9d77ca876b9fc7a2454656f4fecac34..0000000000000000000000000000000000000000 --- a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcePositions.java +++ /dev/null @@ -1,437 +0,0 @@ -/* - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.hhu.stups.sablecc.patch; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * @deprecated All generated token classes store their own position info. - * Use the {@link PositionedNode} or {@link IToken} APIs to access the positions stored in the tokens. - */ -@Deprecated -public class SourcePositions { - private final List<IToken> tokenList; - private final Map<PositionedNode, SourcecodeRange> positions; - - public SourcePositions(final List<IToken> tokenList, - final Map<PositionedNode, SourcecodeRange> positions) { - this.tokenList = tokenList; - this.positions = positions; - } - - /** - * Returns the {@link SourcecodeRange} of this {@link PositionedNode} or - * {@code null} if no {@link SourcecodeRange} is available. - * - * @param node the node with source code information - * @return the source code range of {@code node} - */ - public SourcecodeRange getSourcecodeRange(final PositionedNode node) { - return positions.get(node); - } - - /** - * Returns the line in which this {@link PositionedNode} begins. The value - * {@code 0} is returned if no sourcecode range is available for this - * {@link PositionedNode}. - * - * @param node the node with source code information - * @return the line where the {@code node} starts - */ - public int getBeginLine(final PositionedNode node) { - if (node instanceof IToken) { - return ((IToken) node).getLine(); - } - - return getBeginLine(getSourcecodeRange(node)); - } - - public int getBeginLine(final SourcecodeRange range) { - if (range != null) { - return tokenList.get(range.getBeginIndex()).getLine(); - } else { - return 0; - } - } - - /** - * Returns the column of the first character of this {@link PositionedNode}, - * i.e. the begin column. The value {@code 0} is returned if no - * sourcecode range is available for this {@link PositionedNode}. - * - * @param node the node with source code information - * @return the begin column of {@code node} - */ - public int getBeginColumn(final PositionedNode node) { - if (node instanceof IToken) { - return ((IToken) node).getPos(); - } - - return getBeginColumn(getSourcecodeRange(node)); - } - - public int getBeginColumn(final SourcecodeRange range) { - if (range != null) { - return tokenList.get(range.getBeginIndex()).getPos(); - } else { - return 0; - } - } - - /** - * Returns the line in which the {@link PositionedNode} ends. The value - * {@code 0} is returned if no sourcecode range is available for this - * {@link PositionedNode}. - * - * @param node the node with source code information - * @return the end line of <code>node</code> - */ - public int getEndLine(final PositionedNode node) { - // TODO handle multi line comments - /* - * if (node instanceof TComment) { final TComment comment = (TComment) - * node; return comment.getLine() + countLineBreaks(comment); } - */ - - if (node instanceof IToken) { - return ((IToken) node).getLine(); - } - - return getEndLine(getSourcecodeRange(node)); - } - - private int getEndLine(final SourcecodeRange range) { - if (range != null) { - return tokenList.get(range.getEndIndex()).getLine(); - } else { - return 0; - } - } - - // private int countLineBreaks(final PositionedNode node) { - // final char[] text = getNodeString(node).toCharArray(); - // int count = 0; - // - // for (int i = 0; i < text.length; i++) { - // if (text[i] == '\n' || text[i] == '\r') { - // count++; - // } - // } - // - // return count; - // } - - /** - * Returns the last column of this {@link PositionedNode}, i.e. the column - * of the last character of the {@link PositionedNode}. The value - * {@code 0} is returned if no sourcecode range is available for this - * {@link PositionedNode}. - * - * @param node the node with source code information - * @return the end column of <code>node</code> - */ - public int getEndColumn(final PositionedNode node) { - // TODO handle multi line comments - /* - * if (node instanceof TComment) { return getEndColumn((TComment) node); - * } - */ - - if (node instanceof IToken) { - final IToken token = (IToken) node; - return token.getPos() + token.getText().length() - 1; - } - - return getEndColumn(getSourcecodeRange(node)); - } - - private int getEndColumn(final SourcecodeRange range) { - if (range != null) { - final IToken token = tokenList.get(range.getEndIndex()); - return token.getPos() + token.getText().length() - 1; - } else { - return 0; - } - } - - /* - * private int getEndColumn(final TComment commentToken) { final String - * asString = commentToken.getText(); final StringTokenizer tokenizer = new - * StringTokenizer(asString, "\n\r"); - * - * // multi line comment if (tokenizer.countTokens() > 1) { String line = - * null; while (tokenizer.hasMoreTokens()) { line = tokenizer.nextToken(); } - * - * if (line == null) { return 0; } - * - * return line.length(); } // single line comment else { return - * commentToken.getPos() + asString.length(); } } - */ - - /** - * Returns the array of {@link IToken}s belonging to this - * {@link PositionedNode}. The array may be empty, if no sourcecode range - * can be determined for this {@link PositionedNode}. - * - * @param node the node with source code information - * @return all tokens of {@code node} - */ - public IToken[] getTokens(final PositionedNode node) { - if (node instanceof IToken) { - return new IToken[] { (IToken) node }; - } - - final SourcecodeRange range = getSourcecodeRange(node); - - if (range != null) { - final int beginIndex = range.getBeginIndex(); - final int endIndex = range.getEndIndex(); - final IToken[] result = new IToken[endIndex - beginIndex + 1]; - - for (int i = 0; i + beginIndex <= endIndex; i++) { - result[i] = tokenList.get(i + beginIndex); - } - - return result; - } else { - return new IToken[0]; - } - } - - public String getNodeString(final PositionedNode node) { - // TODO handle comments - /* - * if (node instanceof TComment) { return ((TComment) node).getText(); } - */ - - return getRangeString(getSourcecodeRange(node)); - } - - public String getRangeString(final SourcecodeRange range) { - final StringBuilder buffer = new StringBuilder(); - - if (range != null) { - final int beginIndex = range.getBeginIndex(); - final int endIndex = range.getEndIndex(); - - for (int i = beginIndex; i <= endIndex; i++) { - buffer.append(tokenList.get(i).getText()); - } - } - - return buffer.toString(); - } - - // TODO handle comments - /* - * - * public IToken getCommentBefore(final PositionedNode node) { final - * SourcecodeRange range = getSourcecodeRange(node); final int beginIndex = - * range.getBeginIndex(); if (beginIndex > 0) { final IToken token = - * tokenList.get(beginIndex - 1); if (token instanceof TComment) { return - * token; } else { return null; } } else { return null; } } - * - * public IToken getCommentAfter(final PositionedNode node) { final - * SourcecodeRange range = getSourcecodeRange(node); final int endIndex = - * range.getEndIndex(); if (endIndex < tokenList.size() - 1) { final IToken - * token = tokenList.get(endIndex + 1); if (token instanceof TComment) { - * return token; } else { return null; } } else { return null; } } public - * IToken[] getIncludedComments(final PositionedNode node) { final - * SourcecodeRange range = getSourcecodeRange(node); - * - * if (range != null) { final int beginIndex = range.getBeginIndex(); final - * int endIndex = range.getEndIndex(); final List<IToken> comments = new - * ArrayList<IToken>(); - * - * for (int i = 0; i + beginIndex <= endIndex; i++) { final IToken token = - * tokenList.get(i + beginIndex); if (token instanceof TComment) { - * comments.add(token); } } - * - * return comments.toArray(new IToken[comments.size()]); } else { return new - * IToken[0]; } } - */ - - public List<IToken> getTokenList() { - return tokenList; - } - - public void replaceMapping(final PositionedNode origNode, - final PositionedNode newNode) { - final SourcecodeRange sourcecodeRange = positions.remove(origNode); - - if (sourcecodeRange != null) { - positions.put(newNode, sourcecodeRange); - } - } - - public PositionedNode getSurroundingNode(final int index) { - if (index < 0 || index >= tokenList.size()) { - return null; - } - - PositionedNode bestNode = null; - int bestBeginIndex = 0; - int bestEndIndex = tokenList.size() - 1; - - // TODO find better solution than searching all? - for (final Iterator<PositionedNode> iterator = positions.keySet() - .iterator(); iterator.hasNext();) { - final PositionedNode node = iterator.next(); - final SourcecodeRange range = positions.get(node); - - final int beginIndex = range.getBeginIndex(); - final int endIndex = range.getEndIndex(); - - if (beginIndex <= index && endIndex >= index - && beginIndex >= bestBeginIndex && endIndex <= bestEndIndex) { - bestNode = node; - bestBeginIndex = beginIndex; - bestEndIndex = endIndex; - } - } - - return bestNode; - } - - /** - * <p> - * Finds the index of the token that belongs to the position. - * </p> - * <p> - * If no token list is available {@code -1} is returned. For - * {@code line < 0} the index {@code 0} is returned. If - * {@code line >= 1 && column < 0} the line number is returned. - * </p> - * <p> - * If the line matches but the requested column is beyond the max. length of - * the line, the last token of this line is returned. The last token of all - * tokens (EOF) is chosen if the requested positions is beyond the - * absolutely last token. - * </p> - * <p> - * <b>Attention</b>: Line and column counting starts at 1! - * </p> - * - * @param line - * line of the position - * @param column - * column of the position - * @return Index in {@link #tokenList} - */ - public int getTokenforPosition(final int line, final int column) { - // Sort out nonsense input - if (tokenList.size() == 0) { - return -1; - } - if (line < 1) { - return 0; - } - if (column < 1) { - return line; - } - - /* - * Shortcut for special case: Position beyond last token - */ - final IToken lastToken = tokenList.get(tokenList.size() - 1); - if (line > lastToken.getLine() - || (line == lastToken.getLine() && column > lastToken.getPos() - + lastToken.getText().length())) { - return tokenList.size() - 1; - } - - int result = -1; - int left = 0; - int right = tokenList.size() - 1; - - while (left <= right && result < 0) { - if (left != right) { - final int currentIndex = left + (right - left) / 2; - - final int lineDiff = line - - tokenList.get(currentIndex).getLine(); - - if (lineDiff > 0) { - // continue in right half - left = Math.min(currentIndex + 1, right); - } else if (lineDiff < 0) { - // continue in left half - right = Math.max(currentIndex - 1, left); - } else { - // we are in the correct line now, switch to linear search - IToken token = tokenList.get(currentIndex); - result = currentIndex; - - final int compare = compareTokenColumn(token, column); - - // move left - if (compare < 0) { - while (compareTokenColumn(token, column) < 0) { - result--; - - if (result < 0) { - break; - } - - token = tokenList.get(result); - } - } - // move right - else if (compare > 0) { - while (compareTokenColumn(token, column) > 0) { - result++; - - if (result > tokenList.size() - 1) { - result = tokenList.size() - 1; - break; - } - - token = tokenList.get(result); - - /* - * Only move as long as line end is not reached. - * This happens when queried for column beyond max - * column of this line. Then we return the index of - * the last token in this line. - */ - if (token.getLine() > line) { - result--; - break; - } - } - } - } - } else { - result = left; - } - } - - return result; - } - - /** - * Compares the token position (within line only) with the column. - * - * @return {@code -1} if {@code column < beginColumn}, - * {@code 1} if {@code endColumn < column} or - * {@code 0} if the column is within the range of the token. - */ - private int compareTokenColumn(final IToken token, final int column) { - final int beginColumn = token.getPos(); - final int endColumn = beginColumn + token.getText().length() - 1; - - if (column < beginColumn) { - return -1; - } else if (endColumn < column) { - return 1; - } else { - return 0; - } - } -} diff --git a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcecodeRange.java b/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcecodeRange.java deleted file mode 100644 index f447a79ece3d80c995d1201fb0a12d45c860e87f..0000000000000000000000000000000000000000 --- a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcecodeRange.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.hhu.stups.sablecc.patch; - -@Deprecated -public class SourcecodeRange { - private final int beginIndex; - private final int endIndex; - - public SourcecodeRange(final int beginIndex, final int endIndex) { - this.beginIndex = beginIndex; - this.endIndex = endIndex; - } - - public int getBeginIndex() { - return beginIndex; - } - - public int getEndIndex() { - return endIndex; - } - - @Override - public String toString() { - return "(" + beginIndex + "/" + endIndex + ")"; - } -} diff --git a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java index a582d499010aec9ae53f0529e766388864304d1a..ecabc79fa4e81d054bd38cb22bf5988e5d4b97e6 100644 --- a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java +++ b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java @@ -7,17 +7,15 @@ import java.io.DataInputStream; import java.io.InputStream; import java.io.IOException; import java.io.PushbackReader; -import java.util.ArrayList; import java.util.LinkedList; -import java.util.List; import java.util.Queue; import de.hhu.stups.sablecc.patch.IToken; import org.sablecc.sablecc.node.*; -@SuppressWarnings({"deprecation", "unused"}) // ITokenListContainer is deprecated, but the generated lexer still implements it for compatibility -public class Lexer implements de.hhu.stups.sablecc.patch.ITokenListContainer +@SuppressWarnings("unused") +public class Lexer { protected Token token; protected State state = State.NORMAL; @@ -29,37 +27,16 @@ public class Lexer implements de.hhu.stups.sablecc.patch.ITokenListContainer private boolean eof; private final StringBuilder text = new StringBuilder(); - private List<IToken> tokenList; private final Queue<IToken> nextList = new LinkedList<IToken>(); public Queue<IToken> getNextList() { return nextList; } - /** - * @deprecated In the future, the generated lexers will not store all tokens anymore, because this leads to significant memory usage for large inputs. - * If you really need this list, please create it yourself, using a custom lexer subclass if necessary. - */ - @Deprecated - @Override - public List<IToken> getTokenList() { - return tokenList; - } - private void setToken(Token t) { token = t; } - /** - * @deprecated In the future, the generated lexers will not store all tokens anymore, because this leads to significant memory usage for large inputs. - * If you really need this list, please create it yourself, using a custom lexer subclass if necessary. - */ - @Deprecated - public void setTokenList(final List<IToken> list) { - tokenList = list; - } - - protected void filter() throws LexerException, IOException { // Do nothing @@ -69,7 +46,6 @@ public class Lexer implements de.hhu.stups.sablecc.patch.ITokenListContainer { filter(); if (token != null) { - getTokenList().add(token); nextList.add(token); } } @@ -78,7 +54,6 @@ public class Lexer implements de.hhu.stups.sablecc.patch.ITokenListContainer public Lexer(PushbackReader in) { this.in = in; - setTokenList(new ArrayList<IToken>()); } public Token peek() throws LexerException, IOException diff --git a/src/main/java/org/sablecc/sablecc/parser/Parser.java b/src/main/java/org/sablecc/sablecc/parser/Parser.java index 992afd4ecfdc014ed141f4c19f41e8e0aa3d1f0d..13e8a1da5f1032b52ac87e85c87e9cd33cee19f2 100644 --- a/src/main/java/org/sablecc/sablecc/parser/Parser.java +++ b/src/main/java/org/sablecc/sablecc/parser/Parser.java @@ -7,21 +7,19 @@ import java.io.BufferedInputStream; import java.io.InputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; -import java.util.Map; import de.hhu.stups.sablecc.patch.IParser; -import de.hhu.stups.sablecc.patch.IToken; import de.hhu.stups.sablecc.patch.PositionedNode; +import de.hhu.stups.sablecc.patch.SourcePosition; import org.sablecc.sablecc.lexer.Lexer; import org.sablecc.sablecc.lexer.LexerException; import org.sablecc.sablecc.node.*; -@SuppressWarnings({"deprecation", "rawtypes", "unchecked", "unused"}) // getMapping() is deprecated, but the generated parser still populates it for compatibility +@SuppressWarnings({"rawtypes", "unchecked", "unused"}) public class Parser implements IParser { protected List<Object> nodeList; @@ -44,16 +42,6 @@ public class Parser implements IParser this.lexer = lexer; } - @Deprecated - private Map<PositionedNode, de.hhu.stups.sablecc.patch.SourcecodeRange> mapping = new HashMap<>(); - /** - * @deprecated All generated token classes store their own position info. - * Use the {@link PositionedNode} or {@link IToken} APIs to access the positions stored in the tokens. - */ - @Deprecated - @Override - public Map<PositionedNode, de.hhu.stups.sablecc.patch.SourcecodeRange> getMapping() { return this.mapping; } - private void checkResult(Object elementToCheck, List<Object> beginNodeList, List<Object> endNodeList) { if (elementToCheck instanceof List<?>) { /* @@ -73,31 +61,20 @@ public class Parser implements IParser final PositionedNode node = (PositionedNode) elementToCheck; - if (!this.getMapping().containsKey(node)) { - PositionedNode beginNode = findBeginNode(beginNodeList); - final int begin; - if (beginNode == null) { - /* - * Sometimes (haven't found out why) we get empty list here. In - * the only observed cases we were looking for the source range - * of the whole parse unit. Then the index is 0. - */ - beginNode = (PositionedNode)this.lexer.getTokenList().get(0); - begin = 0; - } else { - begin = findBeginPos(beginNode); - } - - PositionedNode endNode = findEndNode(endNodeList); - int end = findEndPos(endNode); - if (end == -1) end = begin; - final de.hhu.stups.sablecc.patch.SourcecodeRange range = new de.hhu.stups.sablecc.patch.SourcecodeRange(begin, end); - - this.getMapping().put(node, range); - + PositionedNode beginNode = findBeginNode(beginNodeList); + if (beginNode == null) { + /* + * Sometimes (haven't found out why) we get empty list here. In + * the only observed cases we were looking for the source range + * of the whole parse unit. Then the index is 0. + */ + node.setStartPos(new SourcePosition(1, 0)); + } else { node.setStartPos(beginNode.getStartPos()); - node.setEndPos(endNode.getEndPos()); } + + PositionedNode endNode = findEndNode(endNodeList); + node.setEndPos(endNode.getEndPos()); } private PositionedNode findBeginNode(final List<Object> list) { @@ -115,14 +92,6 @@ public class Parser implements IParser return (PositionedNode)first; } - private int findBeginPos(final PositionedNode node) { - if (node instanceof IToken) { - return findIndex((IToken) node); - } - - return this.getMapping().get(node).getBeginIndex(); - } - private PositionedNode findEndNode(final List<Object> list) { Object last = list.get(list.size() - 1); if (last instanceof List<?>) { @@ -133,30 +102,6 @@ public class Parser implements IParser return (PositionedNode)last; } - private int findEndPos(final PositionedNode node) { - if (node instanceof IToken) { - return findIndex((IToken) node); - } - - final de.hhu.stups.sablecc.patch.SourcecodeRange item = this.getMapping().get(node); - if (item == null) { - return -1; - } - return item.getEndIndex(); - } - - private int findIndex(final IToken token) { - final List<IToken> list = this.lexer.getTokenList(); - - for (int i = list.size() - 1; i >= 0; i--) { - if (list.get(i) == token) { - return i; - } - } - - return -1; - } - private void push(int numstate, List<Object> listNode) throws ParserException, LexerException, IOException { this.nodeList = listNode; @@ -223,8 +168,6 @@ public class Parser implements IParser public Start parse() throws ParserException, LexerException, IOException { - this.getMapping().clear(); - push(0, null); while(true) { diff --git a/src/main/resources/org/sablecc/sablecc/lexer.txt b/src/main/resources/org/sablecc/sablecc/lexer.txt index f129be40152c9ae2562978e2e5d07a882943e241..e4bcf54cb701bdd07ac9ec432fe270bd548643c4 100644 --- a/src/main/resources/org/sablecc/sablecc/lexer.txt +++ b/src/main/resources/org/sablecc/sablecc/lexer.txt @@ -31,17 +31,15 @@ import java.io.DataInputStream; import java.io.InputStream; import java.io.IOException; import java.io.PushbackReader; -import java.util.ArrayList; import java.util.LinkedList; -import java.util.List; import java.util.Queue; import de.hhu.stups.sablecc.patch.IToken; import $0$node.*; -@SuppressWarnings({"deprecation", "unused"}) // ITokenListContainer is deprecated, but the generated lexer still implements it for compatibility -public class Lexer implements de.hhu.stups.sablecc.patch.ITokenListContainer +@SuppressWarnings("unused") +public class Lexer { protected Token token; protected State state = State.$1$; @@ -53,37 +51,16 @@ public class Lexer implements de.hhu.stups.sablecc.patch.ITokenListContainer private boolean eof; private final StringBuilder text = new StringBuilder(); - private List<IToken> tokenList; private final Queue<IToken> nextList = new LinkedList<IToken>(); public Queue<IToken> getNextList() { return nextList; } - /** - * @deprecated In the future, the generated lexers will not store all tokens anymore, because this leads to significant memory usage for large inputs. - * If you really need this list, please create it yourself, using a custom lexer subclass if necessary. - */ - @Deprecated - @Override - public List<IToken> getTokenList() { - return tokenList; - } - private void setToken(Token t) { token = t; } - /** - * @deprecated In the future, the generated lexers will not store all tokens anymore, because this leads to significant memory usage for large inputs. - * If you really need this list, please create it yourself, using a custom lexer subclass if necessary. - */ - @Deprecated - public void setTokenList(final List<IToken> list) { - tokenList = list; - } - - protected void filter() throws LexerException, IOException { // Do nothing @@ -93,7 +70,6 @@ public class Lexer implements de.hhu.stups.sablecc.patch.ITokenListContainer { filter(); if (token != null) { - getTokenList().add(token); nextList.add(token); } } @@ -102,7 +78,6 @@ public class Lexer implements de.hhu.stups.sablecc.patch.ITokenListContainer public Lexer(PushbackReader in) { this.in = in; - setTokenList(new ArrayList<IToken>()); } public Token peek() throws LexerException, IOException diff --git a/src/main/resources/org/sablecc/sablecc/parser.txt b/src/main/resources/org/sablecc/sablecc/parser.txt index 302d4d88448d65f0179d1bcf53bac5b21df2674d..36e9c4899604e0be810ed2335359eac06a81d000 100644 --- a/src/main/resources/org/sablecc/sablecc/parser.txt +++ b/src/main/resources/org/sablecc/sablecc/parser.txt @@ -15,21 +15,19 @@ import java.io.BufferedInputStream; import java.io.InputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; -import java.util.Map; import de.hhu.stups.sablecc.patch.IParser; -import de.hhu.stups.sablecc.patch.IToken; import de.hhu.stups.sablecc.patch.PositionedNode; +import de.hhu.stups.sablecc.patch.SourcePosition; import $0$lexer.Lexer; import $0$lexer.LexerException; import $0$node.*; -@SuppressWarnings({"deprecation", "rawtypes", "unchecked", "unused"}) // getMapping() is deprecated, but the generated parser still populates it for compatibility +@SuppressWarnings({"rawtypes", "unchecked", "unused"}) public class Parser implements IParser { protected List<Object> nodeList; @@ -52,16 +50,6 @@ public class Parser implements IParser this.lexer = lexer; } - @Deprecated - private Map<PositionedNode, de.hhu.stups.sablecc.patch.SourcecodeRange> mapping = new HashMap<>(); - /** - * @deprecated All generated token classes store their own position info. - * Use the {@link PositionedNode} or {@link IToken} APIs to access the positions stored in the tokens. - */ - @Deprecated - @Override - public Map<PositionedNode, de.hhu.stups.sablecc.patch.SourcecodeRange> getMapping() { return this.mapping; } - private void checkResult(Object elementToCheck, List<Object> beginNodeList, List<Object> endNodeList) { if (elementToCheck instanceof List<?>) { /* @@ -81,31 +69,20 @@ public class Parser implements IParser final PositionedNode node = (PositionedNode) elementToCheck; - if (!this.getMapping().containsKey(node)) { - PositionedNode beginNode = findBeginNode(beginNodeList); - final int begin; - if (beginNode == null) { - /* - * Sometimes (haven't found out why) we get empty list here. In - * the only observed cases we were looking for the source range - * of the whole parse unit. Then the index is 0. - */ - beginNode = (PositionedNode)this.lexer.getTokenList().get(0); - begin = 0; - } else { - begin = findBeginPos(beginNode); - } - - PositionedNode endNode = findEndNode(endNodeList); - int end = findEndPos(endNode); - if (end == -1) end = begin; - final de.hhu.stups.sablecc.patch.SourcecodeRange range = new de.hhu.stups.sablecc.patch.SourcecodeRange(begin, end); - - this.getMapping().put(node, range); - + PositionedNode beginNode = findBeginNode(beginNodeList); + if (beginNode == null) { + /* + * Sometimes (haven't found out why) we get empty list here. In + * the only observed cases we were looking for the source range + * of the whole parse unit. Then the index is 0. + */ + node.setStartPos(new SourcePosition(1, 0)); + } else { node.setStartPos(beginNode.getStartPos()); - node.setEndPos(endNode.getEndPos()); } + + PositionedNode endNode = findEndNode(endNodeList); + node.setEndPos(endNode.getEndPos()); } private PositionedNode findBeginNode(final List<Object> list) { @@ -123,14 +100,6 @@ public class Parser implements IParser return (PositionedNode)first; } - private int findBeginPos(final PositionedNode node) { - if (node instanceof IToken) { - return findIndex((IToken) node); - } - - return this.getMapping().get(node).getBeginIndex(); - } - private PositionedNode findEndNode(final List<Object> list) { Object last = list.get(list.size() - 1); if (last instanceof List<?>) { @@ -141,30 +110,6 @@ public class Parser implements IParser return (PositionedNode)last; } - private int findEndPos(final PositionedNode node) { - if (node instanceof IToken) { - return findIndex((IToken) node); - } - - final de.hhu.stups.sablecc.patch.SourcecodeRange item = this.getMapping().get(node); - if (item == null) { - return -1; - } - return item.getEndIndex(); - } - - private int findIndex(final IToken token) { - final List<IToken> list = this.lexer.getTokenList(); - - for (int i = list.size() - 1; i >= 0; i--) { - if (list.get(i) == token) { - return i; - } - } - - return -1; - } - $ Macro:ParserInliningPushHeader @@ -257,8 +202,6 @@ Macro:ParserCommon public Start parse() throws ParserException, LexerException, IOException { - this.getMapping().clear(); - push(0, null$0$); while(true) {