Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SableCC STUPS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
SableCC STUPS
Commits
63ebf533
Commit
63ebf533
authored
2 years ago
by
Kristin Rutenkolk
Browse files
Options
Downloads
Patches
Plain Diff
remove node lists from parser
parent
75b747ab
Branches
kristin_optim_test
No related tags found
No related merge requests found
Pipeline
#113032
failed
2 years ago
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/resources/org/sablecc/sablecc/parser.txt
+39
-61
39 additions, 61 deletions
src/main/resources/org/sablecc/sablecc/parser.txt
with
39 additions
and
61 deletions
src/main/resources/org/sablecc/sablecc/parser.txt
+
39
−
61
View file @
63ebf533
...
@@ -28,7 +28,7 @@ import $0$node.*;
...
@@ -28,7 +28,7 @@ import $0$node.*;
@SuppressWarnings({"rawtypes","unchecked","unused"})
@SuppressWarnings({"rawtypes","unchecked","unused"})
public class Parser implements IParser
public class Parser implements IParser
{
{
protected
List<Object> nodeList
;
protected
currentNode
;
private final Lexer lexer;
private final Lexer lexer;
private final Deque<State> stackA = new ArrayDeque<>();
private final Deque<State> stackA = new ArrayDeque<>();
...
@@ -55,7 +55,7 @@ public class Parser implements IParser
...
@@ -55,7 +55,7 @@ public class Parser implements IParser
@Override
@Override
public Map<PositionedNode, SourcecodeRange> getMapping() { return this.mapping; }
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<?>) {
if (elementToCheck instanceof List<?>) {
/*
/*
* special case: this is a list of nodes, for example an identifier
* special case: this is a list of nodes, for example an identifier
...
@@ -75,7 +75,7 @@ public class Parser implements IParser
...
@@ -75,7 +75,7 @@ public class Parser implements IParser
final PositionedNode node = (PositionedNode) elementToCheck;
final PositionedNode node = (PositionedNode) elementToCheck;
if (!this.getMapping().containsKey(node)) {
if (!this.getMapping().containsKey(node)) {
PositionedNode beginNode =
findBegin
Node
(
beginNodeList
)
;
PositionedNode beginNode =
(Positioned
Node
)
beginNodeList;
final int begin;
final int begin;
if (beginNode == null) {
if (beginNode == null) {
/*
/*
...
@@ -89,7 +89,7 @@ public class Parser implements IParser
...
@@ -89,7 +89,7 @@ public class Parser implements IParser
begin = findBeginPos(beginNode);
begin = findBeginPos(beginNode);
}
}
PositionedNode endNode =
findEn
dNode
(
endNodeList
)
;
PositionedNode endNode =
(Positione
dNode
)
endNodeList;
int end = findEndPos(endNode);
int end = findEndPos(endNode);
if (end == -1) end = begin;
if (end == -1) end = begin;
final SourcecodeRange range = new SourcecodeRange(begin, end);
final SourcecodeRange range = new SourcecodeRange(begin, end);
...
@@ -101,20 +101,6 @@ public class Parser implements IParser
...
@@ -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) {
private int findBeginPos(final PositionedNode node) {
if (node instanceof IToken) {
if (node instanceof IToken) {
...
@@ -124,16 +110,6 @@ public class Parser implements IParser
...
@@ -124,16 +110,6 @@ public class Parser implements IParser
return this.getMapping().get(node).getBeginIndex();
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) {
private int findEndPos(final PositionedNode node) {
if (node instanceof IToken) {
if (node instanceof IToken) {
return findIndex((IToken) node);
return findIndex((IToken) node);
...
@@ -160,46 +136,55 @@ public class Parser implements IParser
...
@@ -160,46 +136,55 @@ public class Parser implements IParser
$
$
Macro:ParserInliningPush
Header
Macro:ParserInliningPush
private void push(int numstate,
List<
Object
> listN
ode) throws ParserException, LexerException, IOException
private void push(int numstate, Object
n
ode) throws ParserException, LexerException, IOException
{
{
this.nodeList = listN
ode;
this.currentNode = n
ode;
if(stackB.isEmpty())
{
stackA.push(new State(numstate, node));
return;
}
State s = this.stack.next();
s.state = numstate;
s.node = node;
}
$
$
Macro:ParserNoInliningPush
Header
Macro:ParserNoInliningPush
protected void filter() throws ParserException, LexerException, IOException
protected void filter() throws ParserException, LexerException, IOException
{
{
// Empty body
// Empty body
}
}
private void push(int numstate,
List<
Object
> listN
ode, boolean hidden) throws ParserException, LexerException, IOException
private void push(int numstate, Object
n
ode, boolean hidden) throws ParserException, LexerException, IOException
{
{
this.
nodeList = listN
ode;
this.
currentNode = n
ode;
if(!hidden)
if(!hidden)
{
{
filter();
filter();
}
}
$
Macro:ParserCommon
if(stackB.isEmpty())
if(stackB.isEmpty())
{
{
stackA.push(new State(numstate,
this.nodeList
));
stackA.push(new State(numstate,
node
));
return;
return;
}
}
State s = stackB.pop();
State s = stackB.pop();
stackA.push(s);
stackA.push(s);
s.state = numstate;
s.state = numstate;
s.node
s
=
this.nodeList
;
s.node =
node
;
}
}
$
Macro:ParserCommon
private int goTo(int index)
private int goTo(int index)
{
{
int state = state();
int state = state();
...
@@ -235,11 +220,11 @@ Macro:ParserCommon
...
@@ -235,11 +220,11 @@ Macro:ParserCommon
}
}
private
List<
Object
>
pop()
private Object pop()
{
{
State s = stackA.pop();
State s = stackA.pop();
stackB.push(s);
stackB.push(s);
return s.node
s
;
return s.node;
}
}
private int index(Switchable token)
private int index(Switchable token)
...
@@ -298,9 +283,7 @@ Macro:ParserCommon
...
@@ -298,9 +283,7 @@ Macro:ParserCommon
{
{
case SHIFT:
case SHIFT:
{
{
List<Object> list = new ArrayList<Object>();
push(this.action[1], this.lexer.next());
list.add(this.lexer.next());
push(this.action[1], list$1$);
}
}
break;
break;
case REDUCE:
case REDUCE:
...
@@ -352,20 +335,19 @@ Macro:ParserNewHeader
...
@@ -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
Macro:ParserNewBodyDecl
List<
Object
>
nodeArrayList$0$ = pop();
Object nodeArrayList$0$ = pop();
$
$
Macro:ParserNewBodyDeclNull
Macro:ParserNewBodyDeclNull
List<
Object
>
nodeArrayList$0$ = null;
Object nodeArrayList$0$ = null;
$
$
...
@@ -391,7 +373,7 @@ Macro:ParserListVariableDeclaration
...
@@ -391,7 +373,7 @@ Macro:ParserListVariableDeclaration
$
$
Macro:ParserSimpleTerm
Macro:ParserSimpleTerm
$0$Node$1$ = ($2$)nodeArrayList$3$
.get($4$)
;
$0$Node$1$ = ($2$)nodeArrayList$3$;
$
$
...
@@ -424,22 +406,18 @@ $
...
@@ -424,22 +406,18 @@ $
Macro:ParserTypedLinkedListAddAll
Macro:ParserTypedLinkedListAddAll
if($2$Node$3$ != null)
if($2$Node$3$ != null)
{
{
if(!$0$Node$1$.isEmpty()){
$0$Node$1$.addAll($2$Node$3$);
}else{
$0$Node$1$ = $2$Node$3$;
$0$Node$1$ = $2$Node$3$;
}
}
}
$
$
Macro:ParserNewBodyListAdd
Macro:ParserNewBodyListAdd
nodeList
.add(
$0$Node$1$
)
;
Object
nodeList
==
$0$Node$1$;
$
$
Macro:ParserNewCheck
Macro:ParserNewCheck
checkResult(nodeList
.get(0)
, nodeArrayList1, nodeArrayList$0$);
checkResult(nodeList, nodeArrayList1, nodeArrayList$0$);
$
$
...
@@ -659,12 +637,12 @@ import java.util.List;
...
@@ -659,12 +637,12 @@ import java.util.List;
final class State
final class State
{
{
int state;
int state;
List<
Object
>
node
s; // elements are of type Node or List<Node>
Object node
;
State(int state,
List<
Object
>
node
s
)
State(int state, Object node)
{
{
this.state = state;
this.state = state;
this.node
s
= node
s
;
this.node = node;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment