Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dr. Michael Petter
CUP Eclipse Plugin
Commits
a93cb319
Commit
a93cb319
authored
Nov 27, 2014
by
Benedikt Engeser
Browse files
Fehlerhaft
parent
010a7681
Changes
8
Hide whitespace changes
Inline
Side-by-side
CupPlugin/src/de/tum/in/www2/cupplugin/Activator.java
View file @
a93cb319
...
...
@@ -6,23 +6,26 @@ import org.eclipse.core.resources.ResourcesPlugin;
import
org.eclipse.jface.resource.ImageDescriptor
;
import
org.eclipse.ui.plugin.AbstractUIPlugin
;
import
org.osgi.framework.BundleContext
;
import
org.eclipse.core.resources.IWorkspace
;
import
de.tum.in.www2.cupplugin.debug.BreakpointMapper
;
import
de.tum.in.www2.cupplugin.debug.Debugger
;
/**
* The activator class controls the plug-in life cycle
*/
public
class
Activator
extends
AbstractUIPlugin
{
public
class
DebugListener
implements
IResourceChangeListener
{
public
void
resourceChanged
(
IResourceChangeEvent
event
)
{
public
class
DebugListener
implements
IResourceChangeListener
{
public
void
resourceChanged
(
IResourceChangeEvent
event
)
{
System
.
out
.
println
(
"GOT EVENT: "
+
event
.
getType
());
if
(
event
.
getType
()
!=
IResourceChangeEvent
.
POST_BUILD
)
return
;
System
.
out
.
println
(
"GOT POST BUILD EVENT!"
);
}
System
.
out
.
println
(
"GOT EVENT: "
+
event
.
getType
());
Debugger
.
getBreakpointMapper
().
remap
();
if
(
event
.
getType
()
!=
IResourceChangeEvent
.
POST_BUILD
)
return
;
System
.
out
.
println
(
"GOT POST BUILD EVENT!"
);
}
}
// The plug-in ID
...
...
@@ -30,7 +33,7 @@ public class Activator extends AbstractUIPlugin {
// The shared instance
private
static
Activator
plugin
;
/**
* The constructor
*/
...
...
@@ -41,7 +44,10 @@ public class Activator extends AbstractUIPlugin {
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
* )
*/
public
void
start
(
BundleContext
context
)
throws
Exception
{
super
.
start
(
context
);
...
...
@@ -50,7 +56,10 @@ public class Activator extends AbstractUIPlugin {
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
* )
*/
public
void
stop
(
BundleContext
context
)
throws
Exception
{
plugin
=
null
;
...
...
@@ -67,10 +76,11 @@ public class Activator extends AbstractUIPlugin {
}
/**
* Returns an image descriptor for the image file at the given
*
plug-in
relative path
* Returns an image descriptor for the image file at the given
plug-in
* relative path
*
* @param path the path
* @param path
* the path
* @return the image descriptor
*/
public
static
ImageDescriptor
getImageDescriptor
(
String
path
)
{
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/debug/BreakpointMapper.java
View file @
a93cb319
...
...
@@ -20,12 +20,17 @@ import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
import
org.eclipse.jdt.debug.core.JDIDebugModel
;
import
de.in.tum.www2.cup.analysis.GetDebuggerMappingVisitor.Mapping
;
import
de.in.tum.www2.cup.ast.ParserResult
;
import
de.tum.in.www2.cupplugin.GeneratedFileLocator
;
import
de.tum.in.www2.cupplugin.PluginUtility
;
public
class
BreakpointMapper
{
private
Map
<
CupLineBreakpoint
,
IBreakpoint
>
mappings
=
new
HashMap
<
CupLineBreakpoint
,
IBreakpoint
>();
private
Set
<
CupLineBreakpoint
>
breakpoints
=
new
HashSet
<
CupLineBreakpoint
>();
private
GeneratedFileLocator
locator
=
new
GeneratedFileLocator
();
public
IBreakpoint
getRemoteBreakpoint
(
CupLineBreakpoint
breakpoint
)
{
return
mappings
.
get
(
breakpoint
);
}
...
...
@@ -47,8 +52,13 @@ public class BreakpointMapper {
if
(
originResource
==
null
){
return
;
}
IFile
resource
=
PluginUtility
.
findGenerated
(((
IFile
)
origin
.
getResource
()));
ParserResult
astModel
=
Debugger
.
getInstance
(
originResource
).
getParserResult
();
if
(
astModel
==
null
){
return
;
}
IFile
resource
=
locator
.
find
((
IFile
)
originResource
,
astModel
);
if
(
resource
==
null
){
return
;
}
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/debug/Debugger.java
View file @
a93cb319
...
...
@@ -93,7 +93,7 @@ public class Debugger {
}
current
=
null
;
}
Debugger
tmp
=
new
Debugger
(
new
CupTextEditor
());
Debugger
tmp
=
new
Debugger
(
new
CupTextEditor
());
// TODO: lösen
delayedInstances
.
put
(
resource
,
tmp
);
return
tmp
;
...
...
@@ -150,11 +150,9 @@ public class Debugger {
* @return the class name
*/
public
String
getGeneratedTargetClass
(
CupLineBreakpoint
breakpoint
)
{
Model
m
=
Model
.
getInstanceForDocument
(
myEditor
.
getDocumentProvider
()
.
getDocument
(
myEditor
.
getEditorInput
()));
try
{
String
rname
=
m
.
get
AstModel
().
className
.
getName
().
name
;
String
rname
=
get
ParserResult
().
className
.
getName
().
name
;
if
(!
rname
.
trim
().
equals
(
""
))
{
return
rname
;
}
...
...
@@ -166,9 +164,7 @@ public class Debugger {
}
public
Mapping
getDebugId
(
int
lineNumber
)
{
Model
m
=
Model
.
getInstanceForDocument
(
myEditor
.
getDocumentProvider
()
.
getDocument
(
myEditor
.
getEditorInput
()));
ParserResult
astModel
=
m
.
getAstModel
();
ParserResult
astModel
=
getParserResult
();
if
(
astModel
==
null
)
{
return
null
;
...
...
@@ -185,4 +181,13 @@ public class Debugger {
}
public
ParserResult
getParserResult
(){
if
(
myEditor
==
null
){
System
.
out
.
println
(
"myEditor: NULL"
);
}
Model
m
=
Model
.
getInstanceForDocument
(
myEditor
.
getDocument
());
ParserResult
astModel
=
m
.
getAstModel
();
return
astModel
;
}
}
\ No newline at end of file
CupPlugin/src/de/tum/in/www2/cupplugin/wizards/CupJavaProjectWizard.java
View file @
a93cb319
...
...
@@ -238,6 +238,9 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
*/
IContainer
srcDir
=
(
IContainer
)
project
.
findMember
(
new
Path
(
"src"
));
IFolder
cupDir
=
createDirectory
(
srcDir
,
monitor
,
"cup"
);
IFolder
exampleDir
=
createDirectory
(
cupDir
,
monitor
,
"example"
);
IFile
parserFile
=
createFile
(
project
,
monitor
,
"parser.cup"
,
getTemplate
(
"parser.cup"
));
...
...
@@ -245,7 +248,7 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
createFile
(
project
,
monitor
,
"input.txt"
,
getTemplate
(
"input.txt"
));
createFile
(
project
,
monitor
,
"build.xml"
,
getTemplate
(
"build.xml"
));
createFile
(
src
Dir
,
monitor
,
"Driver.java"
,
getTemplate
(
"Driver.java"
));
createFile
(
example
Dir
,
monitor
,
"Driver.java"
,
getTemplate
(
"Driver.java"
));
IFolder
folder
=
createDirectory
(
project
,
monitor
,
"tools"
);
...
...
CupPlugin/templates/Driver.java
View file @
a93cb319
package
cup.example
;
class
Driver
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
CupPlugin/templates/build.xml
View file @
a93cb319
...
...
@@ -11,16 +11,17 @@
<taskdef
name=
"cup"
classname=
"java_cup.anttask.CUPTask"
classpath=
"${tools}/java-cup-11b.jar"
/>
<target
name=
"generate"
>
<jflex
file=
"lexer.jflex"
destdir=
"${java}"
/>
<cup
srcfile=
"${base}/parser.cup"
destdir=
"${java}"
parser=
"Parser"
interface=
"true"
locations=
"true"
debugsymbols=
"true"
/>
<jflex
file=
"lexer.jflex"
destdir=
"${java}"
/>
</target>
<path
id=
"libraries"
>
<files
includes=
"${
lib
}/java-cup-11b-runtime.jar"
/>
<files
includes=
"${
tools
}/java-cup-11b-runtime.jar"
/>
</path>
<target
name=
"compile"
depends=
"generate"
>
...
...
CupPlugin/templates/lexer.jflex
View file @
a93cb319
package
de
.
in
.
tum
.
www2
.
cup
.
internal
;
package
cup
.
example
;
import
java_cup
.
runtime
.
ComplexSymbolFactory
;
import
java_cup
.
runtime
.
ComplexSymbolFactory
.
Location
;
import
java_cup
.
runtime
.
Symbol
;
import
de
.
in
.
tum
.
www2
.
cup
.
Position
;
import
de
.
in
.
tum
.
www2
.
cup
.
ErrorManager
;
import
de
.
in
.
tum
.
www2
.
cup
.
ErrorSource
;
import
java
.
lang
.
Error
;
import
java
.
io
.
InputStreamReader
;
...
...
@@ -19,7 +16,7 @@ import java.io.InputStreamReader;
%
cup
%
char
%{
private
ErrorManager
errMan
;
public
Lexer
(
ComplexSymbolFactory
sf
,
java
.
io
.
InputStream
is
){
this
(
is
);
...
...
@@ -47,12 +44,12 @@ import java.io.InputStreamReader;
}
protected
void
emit_warning
(
String
message
){
System
.
out
.
println
(
"scanner warning: "
+
message
+
" at : 2 +
System
.
out
.
println
(
"scanner warning: "
+
message
+
" at : 2
"
+
(
yyline
+
1
)
+
" "
+
(
yycolumn
+
1
)
+
" "
+
yychar
);
}
protected
void
emit_error
(
String
message
){
System.out.println("
scanner
error
:
" + message + "
at
:
2
+
System
.
out
.
println
(
"scanner error: "
+
message
+
" at : 2
"
+
(
yyline
+
1
)
+
" "
+
(
yycolumn
+
1
)
+
" "
+
yychar
);
}
%}
...
...
@@ -84,10 +81,7 @@ ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
"other"
{
return
symbol
(
"OTHERTERMINAL"
,
OTHERTERMINAL
);
}
}
<
CODESEG
>
{
":}"
{
yybegin
(
YYINITIAL
);
return
symbolFactory
.
newSymbol
(
"CODE_STRING"
,
CODE_STRING
,
new
Location
(
csline
,
cscolumn
),
new
Location
(
yyline
+
1
,
yycolumn
+
1
+
yylength
()),
sb
.
toString
());
}
.|\
n
{
sb
.
append
(
yytext
());
}
}
//
error
fallback
.|\
n
{
emit_warning
(
"Unrecognized character '"
+
yytext
()+
"' -- ignored"
);
}
CupPlugin/templates/parser.cup
View file @
a93cb319
package
cup
.
example
;
import
java_cup
.
runtime
.*;
import
java
.
io
.
File
;
import
java
.
io
.
FileInputStream
;
import
java
.
io
.
IOException
;
parser
code
{:
:}
init with {: :}
scan with {: :}
/*
override
error
routines
*/
protected
Lexer
lexer
;
:};
init
with
{:
ComplexSymbolFactory
f
=
new
ComplexSymbolFactory
();
symbolFactory
=
f
;
File
file
=
new
File
(
"input.txt"
);
FileInputStream
fis
=
null
;
try
{
fis
=
new
FileInputStream
(
file
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
lexer
=
new
Lexer
(
f
,
fis
);
:};
scan
with
{:
return
lexer
.
next_token
();
:};
terminal
MYTERMINAL
,
OTHERTERMINAL
;
non
terminal
Integer
expr
;
...
...
Write
Preview
Supports
Markdown
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