Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CUP Eclipse Plugin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Schwarz
CUP Eclipse Plugin
Commits
9b418e3c
Commit
9b418e3c
authored
Feb 22, 2016
by
Michael Schwarz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix problems coming from moving first production by inserting explicit
start symbol
parent
cd6346e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
CupPlugin/src/de/tum/in/www2/cupplugin/views/ReduceReduceReorder.java
...c/de/tum/in/www2/cupplugin/views/ReduceReduceReorder.java
+27
-0
No files found.
CupPlugin/src/de/tum/in/www2/cupplugin/views/ReduceReduceReorder.java
View file @
9b418e3c
...
...
@@ -7,6 +7,7 @@ import java.util.List;
import
org.eclipse.jface.text.BadLocationException
;
import
org.eclipse.jface.text.IDocument
;
import
de.in.tum.www2.cup.ast.NonTerminal
;
import
de.in.tum.www2.cup.ast.ParserResult
;
import
de.in.tum.www2.cup.ast.Production
;
import
de.in.tum.www2.cup.ast.ProductionRight
;
...
...
@@ -18,6 +19,8 @@ public class ReduceReduceReorder {
String
textToAppend
;
boolean
flagPresent
;
private
List
<
RangeToRemove
>
rangesToRemove
;
private
boolean
movedFirstProd
=
false
;
private
String
firstNonTermWas
=
""
;
private
class
RangeToRemove
implements
Comparable
<
RangeToRemove
>{
int
start
;
...
...
@@ -52,6 +55,12 @@ public class ReduceReduceReorder {
if
(
p
.
getRightHandSides
().
size
()
==
1
){
try
{
if
(
Model
.
getInstanceForDocument
(
document
).
getAstModel
().
productions
.
indexOf
(
p
)
==
0
){
movedFirstProd
=
true
;
firstNonTermWas
=
p
.
getName
().
name
;
}
String
pString
=
document
.
get
(
p
.
getBegin
().
getOffsetFromStart
(),
p
.
getEnd
().
getOffsetFromStart
()
-
p
.
getBegin
().
getOffsetFromStart
());
...
...
@@ -131,6 +140,7 @@ public class ReduceReduceReorder {
public
void
apply
()
throws
BadLocationException
{
insert
();
removeAllOldItems
();
fixStart
();
}
private
void
insert
()
throws
BadLocationException
{
...
...
@@ -142,6 +152,23 @@ public class ReduceReduceReorder {
document
.
replace
(
positionForProd
,
0
,
textToAppend
);
}
/**
* Add the start with statement if the first production was moved and no start with statement was given
* Otherwise the start symbol defaults to the first production that is usually different
* @throws BadLocationException
*/
private
void
fixStart
()
throws
BadLocationException
{
if
(
movedFirstProd
){
ParserResult
r
=
Model
.
getInstanceForDocument
(
document
).
getAstModel
();
if
(
r
.
startWith
==
null
){
String
toInsert
=
"// Inserted by CUP Eclipse plugin after moving rules\nstart with "
+
firstNonTermWas
+
"; \n\n\n"
;
int
pos
=
r
.
productions
.
get
(
0
).
getRange
().
getBegin
().
getOffsetFromStart
();
document
.
replace
(
pos
,
0
,
toInsert
);
}
}
}
private
void
removeAllOldItems
()
throws
BadLocationException
{
Collections
.
sort
(
rangesToRemove
);
Collections
.
reverse
(
rangesToRemove
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment