RETRIEVING LOCATIONS OF HIGHLIGHTED KEYWORDS

I have an open SyntaxEdit window with text that has been 'colorized' and thus categorized with a schema. I would now like to find all the elements of one particular block property. How would I be able to find these programmatically?
Hi Eric,
The easiest way to find all words in the editor's text of particular syntax type (i.e keywords or comments) is to iterate through editor's text lines.
Once parsed, the text lines contain information about color styles, which corresponds to syntax styles in lexer schema, so you can iterate through them to collect all such elements.
Below is a code snippet demonstrating this approach:

IList reswords = new List();
syntaxEdit1.Source.ParseToString(syntaxEdit1.Lines.Count - 1);
FillKeywords();

private struct Keyword
{
public Point Start;
public Point End;
public string Word;
}
private void FillKeywords()
{
reswords.Clear();
for (int i = 0; i < syntaxEdit1.Lines.Count; i++)
{
int startPos = -1;
int endPos = -1;
bool find = false;
IStringItem item = syntaxEdit1.Lines.GetItem(i);
for (int j = 0; j < item.TextData.Length; j++)
{
if (((LexToken)item.TextData[j].Data - 1) == LexToken.Resword)
{
startPos = find ? startPos : j;
endPos = j;
find = true;
}
else
{
if (find)
{
Keyword keyword = new Keyword();
keyword.Start = new Point(startPos, i);
keyword.End = new Point(endPos, i);
keyword.Word = item.String.Substring(startPos, endPos - startPos + 1);
reswords.Add(keyword);
find = false;
}
}
}
}
}
If you need to visually change appearance of any of the syntax elements, you can also use CustomDraw event, here is an example:
syntaxEdit1.CustomDraw += DoCustomDraw;
private void DoCustomDraw(object sender, CustomDrawEventArgs e)
{
if ((e.DrawStage == DrawStage.Before) && (((e.DrawState & DrawState.Text) != 0) && (e.DrawState & DrawState.Selection) == 0))
{
LexToken tok = (LexToken)(e.DrawInfo.Style.Data - 1);
if (tok == LexToken.Resword)
{
e.Painter.TextColor = Color.DeepPink;
e.Painter.FontStyle = FontStyle.Bold;
}
}
}
I'm uploading a sample project demonstrating this approach:
http://www.alternetsoft.com/forum/CustomHighlightKeywords.zip
regards,
Andrew