Building a 'Class View'

SyntaxEditor for Windows Forms Forum

Posted 18 years ago by John Youren
Avatar
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 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);
            }
        }
This 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

Comments (3)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

For the work we're doing on v4.0, we have a live class view working for the C# language
and it looks great. Are you implementing a Visual Basic language here or a different one?

If you'd like to discuss the way that large IDE's accomplish this feature (and how v4.0 will
help you do so) then send over an email. I don't want to post too much about v4.0 here until
it is ready for release.


Actipro Software Support

Posted 18 years ago by NSXDavid
Avatar
... alternatively, you could make it ready for release! (ducks)

Hey, can't blame a guy for trying... we 'weely 'weely want it!

-- David
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Trust me, we 'weely' want to release it too. :) We're working on it non-stop.

We are adding as much functionality as possible to it and trying to make sure the object model to support the major new features is as stable as possible so that it won't have to change much at all in the future to support the new advanced features.


Actipro Software Support

The latest build of this product (v24.1.0) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.