manual parse request not getting ITextSnapShotReader

SyntaxEditor for WPF Forum

Posted 12 years ago by Matt Yaeger
Version: 11.1.0545
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
Avatar

I am attempting to create manual parse requests according to your documentation.  Code from your documentation is below.  Instead of creating a ParseRequest object with a reader I provided an ISyntaxLanguage (as recomended in your doc).  Inside my parser the Parse method gets called just like I expect.  The problem is my parser uses an ITextSnapshotReader to do its parsing (this makes sense right?  A parser should/can use the output of a lexer) and it is null.  Specifically, the call IParseRequest.Snapshot.GetReader(0) returns null.  How do I manually parse when the parser needs a reference to a ITextSnapshotReader?

 

Thanks

 

// Create the request
string sourceKey = @"c:\myfilename.txt";
ITextBufferReader reader = new StringTextBufferReader("Text to parse");
IParser parser = new MyTextParser(); // Some class implementing IParser
IParseTarget parseTarget = this; // Assuming class that executes this code implements IParseTarget
IParseRequest request = new ParseRequest(sourceKey, reader, parser, parseTarget);
request.Priority = ParseRequest.LowPriority;

// Queue the request
if (AmbientParseRequestDispatcherProvider.Dispatcher != null)
AmbientParseRequestDispatcherProvider.Dispatcher.QueueRequest(request);

Comments (1)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Matt,

The IParseRequest's Snapshot property is not filled in unless you manually assign it.  So you could assign the snapshot right after creating the request.

Or you could just new up a CodeDocument, set its language (with your custom parser), and call its QueueParseRequest method, described in the section before the section you are looking at in the documentation topic.

Also if you have the ActiproSoftware.Text.Parsing namespace imported, a third option is there is an extension method available for ISyntaxLanguage called Parse where you just pass it a text string.  And it will create a CodeDocument, set the snapshot, etc. and call the parser and return the result all in the same thread.  The other previous two options will go to a worker thread.


Actipro Software Support

The latest build of this product (v24.1.2) was released 0 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.