Skip to content
Snippets Groups Projects
Commit 63ebf533 authored by Kristin Rutenkolk's avatar Kristin Rutenkolk
Browse files

remove node lists from parser

parent 75b747ab
Branches
No related tags found
No related merge requests found
Pipeline #113032 failed
......@@ -28,7 +28,7 @@ import $0$node.*;
@SuppressWarnings({"rawtypes","unchecked","unused"})
public class Parser implements IParser
{
protected List<Object> nodeList;
protected currentNode;
private final Lexer lexer;
private final Deque<State> stackA = new ArrayDeque<>();
......@@ -55,7 +55,7 @@ public class Parser implements IParser
@Override
public Map<PositionedNode, SourcecodeRange> getMapping() { return this.mapping; }
private void checkResult(Object elementToCheck, List<Object> beginNodeList, List<Object> endNodeList) {
private void checkResult(Object elementToCheck, Object beginNodeList, Object endNodeList) {
if (elementToCheck instanceof List<?>) {
/*
* special case: this is a list of nodes, for example an identifier
......@@ -75,7 +75,7 @@ public class Parser implements IParser
final PositionedNode node = (PositionedNode) elementToCheck;
if (!this.getMapping().containsKey(node)) {
PositionedNode beginNode = findBeginNode(beginNodeList);
PositionedNode beginNode = (PositionedNode) beginNodeList;
final int begin;
if (beginNode == null) {
/*
......@@ -89,7 +89,7 @@ public class Parser implements IParser
begin = findBeginPos(beginNode);
}
PositionedNode endNode = findEndNode(endNodeList);
PositionedNode endNode = (PositionedNode)endNodeList;
int end = findEndPos(endNode);
if (end == -1) end = begin;
final SourcecodeRange range = new SourcecodeRange(begin, end);
......@@ -101,20 +101,6 @@ public class Parser implements IParser
}
}
private PositionedNode findBeginNode(final List<Object> list) {
Object first = list.get(0);
if (first instanceof List<?>) {
List<?> list2 = (List<?>) first;
if (list2.size() > 0) {
return (PositionedNode)list2.get(0);
} else {
return null;
}
}
return (PositionedNode)first;
}
private int findBeginPos(final PositionedNode node) {
if (node instanceof IToken) {
......@@ -124,16 +110,6 @@ public class Parser implements IParser
return this.getMapping().get(node).getBeginIndex();
}
private PositionedNode findEndNode(final List<Object> list) {
Object last = list.get(list.size() - 1);
if (last instanceof List<?>) {
final List<?> list2 = (List<?>) last;
return (PositionedNode)list2.get(list2.size() - 1);
}
return (PositionedNode)last;
}
private int findEndPos(final PositionedNode node) {
if (node instanceof IToken) {
return findIndex((IToken) node);
......@@ -160,46 +136,55 @@ public class Parser implements IParser
$
Macro:ParserInliningPushHeader
Macro:ParserInliningPush
private void push(int numstate, List<Object> listNode) throws ParserException, LexerException, IOException
private void push(int numstate, Object node) throws ParserException, LexerException, IOException
{
this.nodeList = listNode;
this.currentNode = node;
if(stackB.isEmpty())
{
stackA.push(new State(numstate, node));
return;
}
State s = this.stack.next();
s.state = numstate;
s.node = node;
}
$
Macro:ParserNoInliningPushHeader
Macro:ParserNoInliningPush
protected void filter() throws ParserException, LexerException, IOException
{
// Empty body
}
private void push(int numstate, List<Object> listNode, boolean hidden) throws ParserException, LexerException, IOException
private void push(int numstate, Object node, boolean hidden) throws ParserException, LexerException, IOException
{
this.nodeList = listNode;
this.currentNode = node;
if(!hidden)
{
filter();
}
$
Macro:ParserCommon
if(stackB.isEmpty())
{
stackA.push(new State(numstate, this.nodeList));
stackA.push(new State(numstate, node));
return;
}
State s = stackB.pop();
stackA.push(s);
s.state = numstate;
s.nodes = this.nodeList;
s.node = node;
}
$
Macro:ParserCommon
private int goTo(int index)
{
int state = state();
......@@ -235,11 +220,11 @@ Macro:ParserCommon
}
private List<Object> pop()
private Object pop()
{
State s = stackA.pop();
stackB.push(s);
return s.nodes;
return s.node;
}
private int index(Switchable token)
......@@ -298,9 +283,7 @@ Macro:ParserCommon
{
case SHIFT:
{
List<Object> list = new ArrayList<Object>();
list.add(this.lexer.next());
push(this.action[1], list$1$);
push(this.action[1], this.lexer.next());
}
break;
case REDUCE:
......@@ -352,20 +335,19 @@ Macro:ParserNewHeader
private List<Object> new$0$() /* reduce $1$ */
private Object new$0$() /* reduce $1$ */
{
List<Object> nodeList = new ArrayList<>();
$
Macro:ParserNewBodyDecl
List<Object> nodeArrayList$0$ = pop();
Object nodeArrayList$0$ = pop();
$
Macro:ParserNewBodyDeclNull
List<Object> nodeArrayList$0$ = null;
Object nodeArrayList$0$ = null;
$
......@@ -391,7 +373,7 @@ Macro:ParserListVariableDeclaration
$
Macro:ParserSimpleTerm
$0$Node$1$ = ($2$)nodeArrayList$3$.get($4$);
$0$Node$1$ = ($2$)nodeArrayList$3$;
$
......@@ -424,22 +406,18 @@ $
Macro:ParserTypedLinkedListAddAll
if($2$Node$3$ != null)
{
if(!$0$Node$1$.isEmpty()){
$0$Node$1$.addAll($2$Node$3$);
}else{
$0$Node$1$ = $2$Node$3$;
}
}
$
Macro:ParserNewBodyListAdd
nodeList.add($0$Node$1$);
Object nodeList == $0$Node$1$;
$
Macro:ParserNewCheck
checkResult(nodeList.get(0), nodeArrayList1, nodeArrayList$0$);
checkResult(nodeList, nodeArrayList1, nodeArrayList$0$);
$
......@@ -659,12 +637,12 @@ import java.util.List;
final class State
{
int state;
List<Object> nodes; // elements are of type Node or List<Node>
Object node;
State(int state, List<Object> nodes)
State(int state, Object node)
{
this.state = state;
this.nodes = nodes;
this.node = node;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment