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
Dr. Michael Petter
CUP Eclipse Plugin
Commits
4f414a07
Commit
4f414a07
authored
Nov 28, 2014
by
Johannes Roith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganize.
parent
15038b8b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
265 deletions
+50
-265
CupParser/src/de/in/tum/www2/cup/analysis/LocationPatchVisitor.java
...src/de/in/tum/www2/cup/analysis/LocationPatchVisitor.java
+4
-4
CupPlugin/src/de/tum/in/www2/cupplugin/editors/CupDocumentListener.java
...de/tum/in/www2/cupplugin/editors/CupDocumentListener.java
+2
-2
CupPlugin/src/de/tum/in/www2/cupplugin/editors/CupSourceViewerConfiguration.java
.../www2/cupplugin/editors/CupSourceViewerConfiguration.java
+3
-247
CupPlugin/src/de/tum/in/www2/cupplugin/editors/CupTextEditor.java
...n/src/de/tum/in/www2/cupplugin/editors/CupTextEditor.java
+33
-6
CupPlugin/src/de/tum/in/www2/cupplugin/editors/CupTextHover.java
...in/src/de/tum/in/www2/cupplugin/editors/CupTextHover.java
+0
-2
CupPlugin/src/de/tum/in/www2/cupplugin/editors/MultiPageEditor.java
...src/de/tum/in/www2/cupplugin/editors/MultiPageEditor.java
+7
-3
CupPlugin/src/de/tum/in/www2/cupplugin/views/CupOverviewView.java
...n/src/de/tum/in/www2/cupplugin/views/CupOverviewView.java
+1
-1
No files found.
CupParser/src/de/in/tum/www2/cup/analysis/LocationPatchVisitor.java
View file @
4f414a07
...
...
@@ -20,12 +20,12 @@ public class LocationPatchVisitor extends WildcardVisitor<Object>
this
.
diffOffset
=
diffOffset
;
}
private
void
fixPosition
(
String
comment
,
AbstractNode
node
,
Position
pos
)
{
private
void
fixPosition
(
AbstractNode
node
,
Position
pos
)
{
if
(
pos
!=
null
&&
pos
.
getOffsetFromStart
()
>=
fixAfterOffset
)
{
int
cols
=
diffColumns
;
if
(
fixColumnUntilOffset
!=
-
1
&&
pos
.
getOffsetFromStart
()
>=
fixColumnUntilOffset
)
cols
=
0
;
// System.out.print("fixing (diffColumns: " + diffColumns + ", cols: " + cols + ") " +
comment +
"..." + node.getClass().getName() + " from " + pos);
// System.out.print("fixing (diffColumns: " + diffColumns + ", cols: " + cols + ") " + "..." + node.getClass().getName() + " from " + pos);
pos
.
move
(
diffLines
,
cols
,
diffOffset
);
// System.out.println(" to " + pos);
}
...
...
@@ -39,8 +39,8 @@ public class LocationPatchVisitor extends WildcardVisitor<Object>
@Override
public
void
postVisitWildcard
(
AbstractNode
node
,
Object
data
)
{
if
(
node
!=
null
)
{
fixPosition
(
"begin"
,
node
,
node
.
getBegin
());
fixPosition
(
"end"
,
node
,
node
.
getEnd
());
fixPosition
(
node
,
node
.
getBegin
());
fixPosition
(
node
,
node
.
getEnd
());
}
}
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/editors/C
TE
DocumentListener.java
→
CupPlugin/src/de/tum/in/www2/cupplugin/editors/C
up
DocumentListener.java
View file @
4f414a07
...
...
@@ -11,9 +11,9 @@ import de.in.tum.www2.cup.ast.ParserResult;
import
de.tum.in.www2.cupplugin.controller.Controller
;
import
de.tum.in.www2.cupplugin.model.Model
;
class
C
TE
DocumentListener
implements
IDocumentListener
{
class
C
up
DocumentListener
implements
IDocumentListener
{
public
C
TE
DocumentListener
()
{
public
C
up
DocumentListener
()
{
}
private
int
linesRemoved
=
0
;
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/editors/CupSourceViewerConfiguration.java
View file @
4f414a07
...
...
@@ -47,6 +47,9 @@ import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import
de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges
;
import
de.tum.in.www2.cupplugin.model.ICupParserASTChangeObserver
;
import
de.tum.in.www2.cupplugin.model.Model
;
import
de.tum.in.www2.cupplugin.syntax.CupTokenScanner
;
import
de.tum.in.www2.cupplugin.syntax.JavaTokenScanner
;
import
de.tum.in.www2.cupplugin.syntax.SingleTokenScanner
;
public
class
CupSourceViewerConfiguration
extends
SourceViewerConfiguration
{
CupTextEditor
editor
;
...
...
@@ -189,251 +192,4 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
return
pr
;
}
static
class
JavaTokenScanner
implements
ITokenScanner
{
private
ParserResult
ast
;
private
JavaScanner
scanner
;
private
JavaSymbol
last
;
private
int
offset
;
private
Range
previousCodeBlockRange
;
private
HashSet
<
String
>
currentLabels
=
null
;
public
JavaTokenScanner
()
{
this
.
currentLabels
=
new
HashSet
<
String
>();
}
public
void
updateParserResult
(
ParserResult
result
)
{
System
.
out
.
println
(
"UPDATING PARSER RESULT"
);
this
.
ast
=
result
;
this
.
previousCodeBlockRange
=
null
;
}
private
void
refreshSpecialSymbols
(
Position
pos
)
{
// System.out.println("TRYING TO FIND POSITION: " + pos);
this
.
currentLabels
.
clear
();
AbstractNode
node
=
ast
.
findAtPosition
(
pos
);
if
(
node
==
null
)
return
;
previousCodeBlockRange
=
node
.
getRange
();
if
(
node
instanceof
ActionCodeBlock
)
{
ActionCodeBlock
codeBlock
=
(
ActionCodeBlock
)
node
;
AbstractNode
parent
=
codeBlock
.
getParent
();
if
(
parent
instanceof
ProductionRight
)
{
ProductionRight
pr
=
(
ProductionRight
)
parent
;
for
(
IProductionRightPart
part
:
pr
.
getList
())
{
if
(
part
instanceof
LabeledProductionSymbolRef
)
{
LabeledProductionSymbolRef
lpsr
=
(
LabeledProductionSymbolRef
)
part
;
String
label
=
lpsr
.
label
;
currentLabels
.
add
(
label
);
currentLabels
.
add
(
label
+
"xleft"
);
currentLabels
.
add
(
label
+
"xright"
);
currentLabels
.
add
(
label
+
"left"
);
currentLabels
.
add
(
label
+
"right"
);
}
}
}
}
}
public
void
setRange
(
IDocument
document
,
int
offset
,
int
length
)
{
StringReader
reader
=
new
StringReader
(
document
.
get
().
substring
(
offset
,
offset
+
length
));
this
.
scanner
=
new
JavaScanner
(
reader
);
this
.
last
=
null
;
this
.
offset
=
offset
;
if
(
ast
==
null
)
{
this
.
currentLabels
.
clear
();
}
else
{
// TODO: we convert offset to line number / position.
// TODO: centralize this type of code, so we have our bugs in
// one place :-)
int
line
;
int
column
;
try
{
line
=
document
.
getLineOfOffset
(
offset
);
column
=
offset
-
document
.
getLineOffset
(
line
);
}
catch
(
BadLocationException
e
)
{
e
.
printStackTrace
();
return
;
}
line
+=
1
;
column
+=
2
;
// TODO: adding two here is a hack!
Position
pos
=
new
Position
(
line
,
column
,
-
1
);
if
(
previousCodeBlockRange
!=
null
&&
previousCodeBlockRange
.
contains
(
pos
))
{
// the old AST is till valid and we are within the same code
// block.
// -> just keep the existing labels.
return
;
}
else
{
refreshSpecialSymbols
(
pos
);
}
}
}
static
final
Token
javaComment
=
new
Token
(
new
TextAttribute
(
CupTextEditor
.
COMMENT
));
static
final
Token
javaKeyword
=
new
Token
(
new
TextAttribute
(
CupTextEditor
.
JAVA_KEYWORD
));
static
final
Token
javaTextualLiteral
=
new
Token
(
new
TextAttribute
(
CupTextEditor
.
JAVA_TEXTUAL
));
static
final
Token
cupDefinedVariable
=
new
Token
(
new
TextAttribute
(
CupTextEditor
.
JAVA_CUP_DEFINED
,
null
,
SWT
.
ITALIC
));
public
IToken
nextToken
()
{
try
{
last
=
scanner
.
next_token
();
}
catch
(
Exception
e
)
{
last
=
null
;
return
Token
.
EOF
;
}
catch
(
Error
err
)
{
last
=
null
;
return
Token
.
EOF
;
}
if
(
last
.
isEOF
())
return
Token
.
EOF
;
if
(
last
.
isComment
())
return
javaComment
;
if
(
last
.
isKeyword
()
||
last
.
isBooleanLiteral
()
||
last
.
isNullLiteral
())
return
javaKeyword
;
if
(
last
.
isTextualLiteral
())
return
javaTextualLiteral
;
if
(
last
.
getValue
()
instanceof
String
)
{
String
lastValueStr
=
(
String
)
last
.
getValue
();
if
(
lastValueStr
.
equals
(
"RESULT"
)
||
currentLabels
.
contains
(
lastValueStr
))
return
cupDefinedVariable
;
}
return
Token
.
UNDEFINED
;
}
public
int
getTokenOffset
()
{
return
this
.
offset
+
(
last
.
getLeft
());
}
public
int
getTokenLength
()
{
return
last
.
getRight
()
-
last
.
getLeft
()
+
1
;
}
}
// TODO: move the TokenScanner into a separate file, along with a custom
// presentation reconciler.
static
class
CupTokenScanner
implements
ITokenScanner
{
private
CupScanner
scanner
;
private
CupSymbol
last
;
private
int
offset
;
private
Declarations
decls
;
private
HashSet
<
Integer
>
constants
;
public
Declarations
getDeclarations
()
{
return
decls
;
}
public
void
updateDeclarations
(
Declarations
decls
)
{
this
.
decls
=
decls
;
}
public
CupTokenScanner
()
{
constants
=
new
HashSet
<
Integer
>();
}
static
final
Token
keyword
=
new
Token
(
new
TextAttribute
(
CupTextEditor
.
KEYWORD
,
null
,
SWT
.
BOLD
));
static
final
Token
literal
=
new
Token
(
new
TextAttribute
(
CupTextEditor
.
STRING
));
static
final
Token
terminal
=
new
Token
(
new
TextAttribute
(
CupTextEditor
.
TERMINAL
));
static
final
Token
nonterminal
=
new
Token
(
new
TextAttribute
(
CupTextEditor
.
NONTERMINAL
));
static
final
Token
specialErrorTerminal
=
new
Token
(
new
TextAttribute
(
CupTextEditor
.
SPECIAL_ERROR_TERMINAL
));
public
void
setRange
(
IDocument
document
,
int
offset
,
int
length
)
{
StringReader
reader
=
new
StringReader
(
document
.
get
().
substring
(
offset
,
offset
+
length
));
scanner
=
new
CupScanner
(
new
NoopErrorReporter
(),
reader
);
this
.
last
=
null
;
this
.
offset
=
offset
;
}
public
IToken
nextToken
()
{
try
{
last
=
scanner
.
next_token
();
}
catch
(
IOException
e
)
{
last
=
null
;
return
Token
.
EOF
;
}
if
(
last
.
isEOF
())
return
Token
.
EOF
;
if
(
last
.
isKeyword
())
return
keyword
;
if
(
constants
.
contains
(
last
.
getSymbolId
()))
return
literal
;
if
(
last
.
isTerminal
(
decls
))
return
terminal
;
if
(
last
.
isNonTerminal
(
decls
))
return
nonterminal
;
if
(
last
.
isSpecialErrorTerminal
())
return
specialErrorTerminal
;
return
Token
.
UNDEFINED
;
}
public
int
getTokenOffset
()
{
int
mOffset
=
this
.
offset
+
last
.
getLeft
();
return
mOffset
;
}
public
int
getTokenLength
()
{
int
length
=
last
.
getRight
()
-
last
.
getLeft
();
return
length
;
}
}
public
class
SingleTokenScanner
extends
RuleBasedScanner
{
/**
* Creates a single token scanner.
*/
public
SingleTokenScanner
(
TextAttribute
attribute
)
{
setDefaultReturnToken
(
new
Token
(
attribute
));
}
}
}
CupPlugin/src/de/tum/in/www2/cupplugin/editors/CupTextEditor.java
View file @
4f414a07
package
de.tum.in.www2.cupplugin.editors
;
import
java.util.EnumSet
;
import
org.eclipse.core.runtime.IProgressMonitor
;
import
org.eclipse.debug.ui.actions.ToggleBreakpointAction
;
import
org.eclipse.jface.action.IAction
;
...
...
@@ -23,12 +25,18 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import
de.in.tum.www2.cup.Position
;
import
de.tum.in.www2.cupplugin.PluginUtility
;
import
de.tum.in.www2.cupplugin.controller.Controller
;
import
de.tum.in.www2.cupplugin.controller.Controller.JobsToDo
;
import
de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges
;
import
de.tum.in.www2.cupplugin.model.ICupParserASTChangeObserver
;
import
de.tum.in.www2.cupplugin.model.Model
;
public
class
CupTextEditor
extends
TextEditor
{
public
class
CupTextEditor
extends
TextEditor
implements
ICupParserASTChangeObserver
,
IRegisterForControllerChanges
{
IVerticalRulerInfo
ruler
=
null
;
private
CupContentOutlinePage
outlinePage
;
private
Position
lastPosition
;
private
boolean
hasRequestedPostSaveSyntaxRefresh
;
static
Color
gray
;
static
Color
blue
;
...
...
@@ -54,7 +62,6 @@ public class CupTextEditor extends TextEditor {
red
=
new
Color
(
display
,
255
,
0
,
0
);
pink
=
new
Color
(
display
,
255
,
0
,
255
);
brown
=
new
Color
(
display
,
132
,
90
,
49
);
}
public
static
final
Color
HYPERLINK
=
blue
;
...
...
@@ -74,13 +81,30 @@ public class CupTextEditor extends TextEditor {
public
CupTextEditor
()
{
super
();
setSourceViewerConfiguration
(
new
CupSourceViewerConfiguration
(
this
));
Controller
.
getInstance
(
this
);
}
public
void
init
()
{
getModel
().
registerModelObserver
(
this
);
Controller
.
getInstance
(
this
).
registerObserver
(
this
);
}
@Override
public
EnumSet
<
JobsToDo
>
getRequiredJobs
()
{
return
EnumSet
.
of
(
JobsToDo
.
parseCode
);
}
public
Model
getModel
()
{
return
Model
.
getInstanceForDocument
(
getDocument
());
}
@Override
public
void
modelChanged
(
Model
model
)
{
if
(
hasRequestedPostSaveSyntaxRefresh
)
{
PluginUtility
.
fullSyntaxRefresh
(
getSourceViewer
());
hasRequestedPostSaveSyntaxRefresh
=
false
;
}
}
public
IDocument
getDocument
()
{
IDocumentProvider
provider
=
getDocumentProvider
();
if
(
provider
!=
null
)
...
...
@@ -118,9 +142,12 @@ public class CupTextEditor extends TextEditor {
Controller
controller
=
Controller
.
getInstance
(
this
);
controller
.
requestJobRun
();
}
// TODO: maybe synchronize the debug breakpoints here.
PluginUtility
.
fullSyntaxRefresh
(
getSourceViewer
());
// we fresh the syntax now and try to refresh a second time after saving.
PluginUtility
.
fullSyntaxRefresh
(
getSourceViewer
());
hasRequestedPostSaveSyntaxRefresh
=
true
;
}
@Override
...
...
@@ -193,5 +220,5 @@ public class CupTextEditor extends TextEditor {
}
}
}
CupPlugin/src/de/tum/in/www2/cupplugin/editors/CupTextHover.java
View file @
4f414a07
...
...
@@ -47,7 +47,6 @@ public class CupTextHover implements ITextHover,
@Override
public
IRegion
getHoverRegion
(
ITextViewer
textViewer
,
int
offset
)
{
if
(
this
.
ast
==
null
)
return
null
;
System
.
out
.
println
(
"offset: "
+
offset
);
...
...
@@ -75,7 +74,6 @@ public class CupTextHover implements ITextHover,
@Override
public
void
modelChanged
(
Model
model
)
{
System
.
out
.
println
(
"MODEL CHANGED!"
);
this
.
ast
=
model
.
getAstModel
();
}
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/editors/MultiPageEditor.java
View file @
4f414a07
...
...
@@ -28,6 +28,7 @@ import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
import
de.tum.in.www2.cupplugin.controller.Controller
;
import
de.tum.in.www2.cupplugin.debug.Debugger
;
import
de.tum.in.www2.cupplugin.views.CupOverviewView
;
public
class
MultiPageEditor
extends
MultiPageEditorPart
implements
IResourceChangeListener
{
...
...
@@ -70,8 +71,11 @@ public class MultiPageEditor extends MultiPageEditorPart implements
addHooksToMainTextEditor
(
editor
);
editor
.
addActions
();
IDocument
doc
=
editor
.
getDocumentProvider
().
getDocument
(
editor
.
getEditorInput
());
IDocument
doc
=
editor
.
getDocument
();
// we need to call init _after_ the editor has a document.
editor
.
init
();
Controller
controller
=
Controller
.
getInstance
(
doc
);
controller
.
initialRun
();
...
...
@@ -248,7 +252,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements
IDocument
doc
=
dp
.
getDocument
(
getEditorInput
());
if
(
doc
==
null
)
return
false
;
doc
.
addDocumentListener
(
new
C
TE
DocumentListener
());
doc
.
addDocumentListener
(
new
C
up
DocumentListener
());
if
(
editor
instanceof
CupTextEditor
)
{
if
(!
Debugger
.
addDebugHooksToTextEditor
((
CupTextEditor
)
editor
))
{
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/
editor
s/CupOverviewView.java
→
CupPlugin/src/de/tum/in/www2/cupplugin/
view
s/CupOverviewView.java
View file @
4f414a07
package
de.tum.in.www2.cupplugin.
editor
s
;
package
de.tum.in.www2.cupplugin.
view
s
;
import
org.eclipse.jface.text.IDocument
;
import
org.eclipse.swt.SWT
;
...
...
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