
Hello all,
I have a SyntaxEditor working very nicely in my application, but I'd like to be able to interrogate it for all function/method definitions. However, I think I'm going about it in the wrong way. Here is basically what I'm doing:
internal List<String> functionList()
{
ITextSnapshotReader reader = _codeEditor.Document.CurrentSnapshot.GetReader(0);
List<String> items = new List<String>();
while (reader.GoToNextToken()) {
IToken tok = reader.ReadToken();
if (tok != null) {
if (tok.Key != null) {
if (tok.Key.Equals("Identifier"))
{
ActiproSoftware.Text.TextRange range = tok.TextRange;
String alltext = _codeEditor.Document.CurrentSnapshot.GetText(LineTerminator.Newline);
String funcitem = alltext.Substring(range.StartOffset, range.AbsoluteLength);
items.Add(funcitem);
}
}
}
}
return items;
}
And what I end up with for this simple bit of C:
#include <stdio.h>
int func1(void)
{
return 0;
}
int func2(void)
{
return 0;
}
int func3(void)
{
return 0;
}
int func4(void)
{
return 0;
}
Is:
func1
func2
func4
So, it's missing func3, and I don't know why. The same thing happens for PHP or Python code, I just seem to be missing one or two function definitions. Using the key 'Identifier' will also give me function calls and variable names, but I can probably work around that. My real problem is that some function definitions are missing.
Am I going about this in really the wrong way? Must I use Antlr instead? I don't need a full-blown lexing of the source code, just function/method definitions, which my above code gets me 95% of the way there, I'm just mysteriously missing definitions for some reason.
Thanks
Garry