diff --git a/org.epic.perleditor/plugin.xml b/org.epic.perleditor/plugin.xml index ba86c6bb..47d0eeb6 100644 --- a/org.epic.perleditor/plugin.xml +++ b/org.epic.perleditor/plugin.xml @@ -1,6 +1,7 @@ + + + + + + + + + Allows observing the Perl parsing process. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/org.epic.perleditor/src/org/epic/core/model/ITokenHandler.java b/org.epic.perleditor/src/org/epic/core/model/ITokenHandler.java new file mode 100644 index 00000000..93519a09 --- /dev/null +++ b/org.epic.perleditor/src/org/epic/core/model/ITokenHandler.java @@ -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 tokens); + void end(); + void handleToken(int currentTokenIdx); + +} diff --git a/org.epic.perleditor/src/org/epic/core/model/SourceFile.java b/org.epic.perleditor/src/org/epic/core/model/SourceFile.java index 10c1ff0e..f0413b57 100644 --- a/org.epic.perleditor/src/org/epic/core/model/SourceFile.java +++ b/org.epic.perleditor/src/org/epic/core/model/SourceFile.java @@ -24,6 +24,7 @@ public class SourceFile private final IDocument doc; private List pods; private List packages; + private List tokenHandlers; /** * Creates a SourceFile which will be reflecting contents of the given @@ -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(); + 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)); + } + } } /** @@ -109,7 +126,12 @@ public synchronized void parse() { try { - ParsingState state = new ParsingState(partitioner.getTokens()); + List tokens = partitioner.getTokens(); + ParsingState state = new ParsingState(tokens, tokenHandlers); + + for (ITokenHandler handler: tokenHandlers) { + handler.start(this, tokens); + } while (state.hasMoreTokens()) state.processToken(); state.finish(); @@ -125,6 +147,12 @@ public synchronized void parse() "in plug-in " + PerlEditorPlugin.getPluginId(), e)); } + finally + { + for (ITokenHandler handler: tokenHandlers) { + handler.end(); + } + } } fireSourceFileChanged(); } @@ -160,6 +188,7 @@ private class ParsingState private int type; private int blockLevel; private boolean afterEnd; + private List tokenHandlers; private Stack pkgStack; private Stack subStack; @@ -171,10 +200,11 @@ private class ParsingState private boolean inSubProto; private PerlToken baseKeyword; - public ParsingState(List tokens) + public ParsingState(List tokens, List tokenHandlers) { this.tIndex = 0; this.tokens = tokens; + this.tokenHandlers = tokenHandlers; this.tokenCount = tokens.size(); this.pkgStack = new Stack(); this.subStack = new Stack(); @@ -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;