Storing and retrieving SemanticParseData from Tokens

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Marianne
Avatar
In general, I have always found the SemanticParseData property unwieldy to work with. In another thread you indicate that it can be used like a Tag property. I have not found this to be the case. In a very simple example if I try to do this in a SemanticParser:
            if (modification.HasFlag(DocumentModificationFlags.ProgrammaticTextParse))
            {
                // Collapse all outlining region nodes
                document.Outlining.RootNode.CollapseDescendants("Region");
                foreach (Token t in document.Tokens)
                {
                    if (t.Key == "MyToken")
                        t.SemanticParseData = document.GetTokenText(t);
                }
            }
I get a illegal implicit cast error... so I try an explicit cast:

t.SemanticParseData = (ISemanticParseData)document.GetTokenText(t);
But as you might guess I get a 'Cannot convert from type 'String' to type 'ISemanticParseData'. So, I figure I'll try to cast the string to a generic object and then recast that to ISemanticParseData as such:

t.SemanticParseData = (ISemanticParseData)(object)document.GetTokenText(t);
This example will compile but instead of a design-time error it waits until runtime to generate an exception.

In short, this is nothing like a Tag object because there seems to be no way to generate an appropriate object type in which to stuff into this ISemanticParseData interface. I know that a long time ago I had succeeded to make it work but ever since I haven't been able to recreate that magic. After searching the forums and the help, I don't see one example of how to actually populate the SemanticParseData of a Token with some data. Can you please explain it to those of us that aren't quite following at all what is happening here. Thank you.

[Modified at 03/05/2006 10:31 AM]

------------------------------- Marianne

Comments (3)

Posted 14 years ago by Boyd - Automated Software Testing Consultant / Developer, Patterson Consulting, LLC
Avatar
I haven't personally used this, but I'm guessing you can create your own class that implements the ISemanticParseData interface. You can then create instances of this class that define the data important to you and place it on the SemanticParseData property. Unlike the Tag property that takes any Object, this property has to take a class that implements the ISemanticParseData interface.
Posted 14 years ago by Marianne
Avatar
That's what I would assume as well. So you'd have to do something like:
public class MySemanticClass : ISemanticParseData
For simple changes, though, it seems like a lot of work if you just wanted a string or number.

------------------------------- Marianne

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
That's a very good point. Maybe we'll turn it simply into an Object instead of ISemanticParseData for an upcoming release to make this easier.


Actipro Software Support

The latest build of this product (v2018.1 build 0342) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.