Posted 19 years ago
by John Youren

Hi,
I have recently dived into playing with semantics, after getting the rest of the visual features working. What I am having problems with however, is being able to build up a class view (same as VS) of the file.
This is what I have so farThis works great when a person either loads/pastes text or types 'Function blah' and presses return. It however doesn't work when a user goes back and changes the name.
Any ideas?
Thanks,
John
I have recently dived into playing with semantics, after getting the rest of the visual features working. What I am having problems with however, is being able to build up a class view (same as VS) of the file.
This is what I have so far
/// <summary>
/// Allows for performing semantic parsing following a lexical parse.
/// </summary>
/// <param name="document">The <see cref="Document"/> to parse.</param>
/// <param name="modification">The <see cref="DocumentModification"/> that caused the parse.</param>
public override void PostParse(Document document, DocumentModification modification) {
// If programmatically setting the text of a document...
if (modification.HasFlag(DocumentModificationFlags.ProgrammaticTextParse)) {
// Collapse all outlining region nodes
document.Outlining.RootNode.CollapseDescendants("RegionPreProcessorDirective");
}
if (modification.InsertedText.Length > 1)
{
look(modification.InsertedText, true);
}
else if(modification.InsertedText.Length == 1)
{
TokenStream ts = document.GetTokenStream(document.Tokens.GetTokenAtOffset(modification.InsertionEndOffset - 1));
Token t = ts.Read();
Console.WriteLine(t.Key);
if (t.Key == "LineTerminatorToken")
{
look(document.Lines[modification.StartLineIndex].Text, true);
}
}
}
private void look(string text, bool add)
{
int posFunction = 0;
int endFunction;
posFunction = text.ToUpper().IndexOf("FUNCTION", 0);
while(posFunction > -1)
{
posFunction = posFunction + 9;
endFunction = posFunction;
if (posFunction > text.Length)
{
break;
}
for (int i = posFunction; i < text.Length; i++)
{
if (!char.IsLetter(text.Substring(i, 1).ToCharArray()[0]))
{
endFunction = i;
break;
}
}
if (endFunction == posFunction)
{
endFunction = text.Length;
}
MessageBox.Show(text.Substring(posFunction, endFunction - posFunction));
posFunction = text.ToUpper().IndexOf("FUNCTION", endFunction);
}
}
Any ideas?
Thanks,
John