Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions org.epic.perleditor/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension-point id="tokenHandler" name="Perl Token Handler" schema="schema/tokenHandler.exsd"/>

<extension point="org.eclipse.ui.editors">
<editor
Expand Down
102 changes: 102 additions & 0 deletions org.epic.perleditor/schema/tokenHandler.exsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.epic.perleditor" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.epic.perleditor" id="tokenHandler" name="Perl Token Handler"/>
</appInfo>
<documentation>
Allows observing the Perl parsing process.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="handler"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="handler">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>

</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.epic.core.model.ITokenHandler"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>


</schema>
14 changes: 14 additions & 0 deletions org.epic.perleditor/src/org/epic/core/model/ITokenHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.epic.core.model;

import java.util.List;

import org.epic.core.parser.PerlToken;

public interface ITokenHandler
{

void start(SourceFile sourceFile, List<PerlToken> tokens);
void end();
void handleToken(int currentTokenIdx);

}
38 changes: 36 additions & 2 deletions org.epic.perleditor/src/org/epic/core/model/SourceFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class SourceFile
private final IDocument doc;
private List<PODComment> pods;
private List<Package> packages;
private List<ITokenHandler> tokenHandlers;

/**
* Creates a SourceFile which will be reflecting contents of the given
Expand All @@ -38,6 +39,22 @@ public SourceFile(ILog log, IDocument doc)
this.doc = doc;
this.pods = Collections.emptyList();
this.packages = Collections.emptyList();

this.tokenHandlers = new ArrayList<ITokenHandler>();
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor("org.epic.perleditor.tokenHandler");
for (IConfigurationElement cfg: config) {
Object handler;
try {
handler = cfg.createExecutableExtension("class");
if (handler instanceof ITokenHandler) {
tokenHandlers.add((ITokenHandler)handler);
}
} catch (CoreException e) {
PerlEditorPlugin.getDefault().getLog().log(
new Status(IStatus.WARNING, PerlEditorPlugin.getUniqueIdentifier(),
"failed to load tokenHandler extension", e));
}
}
}

/**
Expand Down Expand Up @@ -109,7 +126,12 @@ public synchronized void parse()
{
try
{
ParsingState state = new ParsingState(partitioner.getTokens());
List<PerlToken> tokens = partitioner.getTokens();
ParsingState state = new ParsingState(tokens, tokenHandlers);

for (ITokenHandler handler: tokenHandlers) {
handler.start(this, tokens);
}

while (state.hasMoreTokens()) state.processToken();
state.finish();
Expand All @@ -125,6 +147,12 @@ public synchronized void parse()
"in plug-in " + PerlEditorPlugin.getPluginId(),
e));
}
finally
{
for (ITokenHandler handler: tokenHandlers) {
handler.end();
}
}
}
fireSourceFileChanged();
}
Expand Down Expand Up @@ -160,6 +188,7 @@ private class ParsingState
private int type;
private int blockLevel;
private boolean afterEnd;
private List<ITokenHandler> tokenHandlers;

private Stack<Package> pkgStack;
private Stack<Subroutine> subStack;
Expand All @@ -171,10 +200,11 @@ private class ParsingState
private boolean inSubProto;
private PerlToken baseKeyword;

public ParsingState(List<PerlToken> tokens)
public ParsingState(List<PerlToken> tokens, List<ITokenHandler> tokenHandlers)
{
this.tIndex = 0;
this.tokens = tokens;
this.tokenHandlers = tokenHandlers;
this.tokenCount = tokens.size();
this.pkgStack = new Stack<Package>();
this.subStack = new Stack<Subroutine>();
Expand All @@ -196,6 +226,10 @@ public void processToken() throws BadLocationException
this.t = tokens.get(tIndex);
this.type = t.getType();

for (ITokenHandler handler: tokenHandlers) {
handler.handleToken(tIndex);
}

if (this.type == PerlTokenTypes.END)
{
afterEnd = true;
Expand Down