Using the DynamicLexer as a stand-alone lexer

SyntaxEditor for WPF Forum

Posted 13 years ago by CodyVanZant
Version: 11.1.0544
Avatar
Is this possible? We have multiple projects that require use of the Lexer output but only one that requires the rest (the one contains the syntax editor control). We want to use the Lexer as opposed to re-creating the language in another Lexer/Parser and we want to re-use this Lexer across the various things that need to Tokenize the text.

How would I go about wrapping the Dynamic Lexer to provide a function

public void Parse(string plainText); and pull the results using GetNextToken() or a public property list of all tokens in order?

I have to believe I can use this separately of the Syntax Editor. I know I'll probably need to bring the ClassificationTypeProvider class along... Any help would be appreciated. I need to know if we'll have to roll our own Lexer or not.

Thanks,

Cody

Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Cody,

ILexer has this member defined:
TextRange Parse(TextSnapshotRange snapshotRange, ILexerTarget parseTarget);
So it works off of an ITextSnapshot specified by the snapshotRange. If you have one of those for a string (we don't include one in our framework at this time), and you have a class that implements ILexerTarget, you can get results.

The easier thing to do would be create a new CodeDocument and assign it a new SyntaxLanguage that has your ILexer service on it. You would probably need the token tagger provider service too. Then call document.CurrentSnapshot.GetReader(0) and use that reader to iterate through tokens. It only takes a few lines of code do all that.


Actipro Software Support

Posted 13 years ago by CodyVanZant
Avatar
The ClassificationTypeProvider I'm using has WPF 4.0 Specific stuff in it (SolidColorBrush or any System.Windows.Media thing)

What would you recommend for making this generic WPF 3.5 or 4.0 or even WinForms? The standalone Lexer has no need for colors or brushes.

Thanks,

Cody
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Cody,

Yes but if you are code-generating the lexer from the Language Designer, the requirement for the lexers is an interface version of the ClassificationTypeProvider. You can make a class that implements the interface to just return some static classification types and use that instead.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.