Using an Irony grammar to drive WPF SyntaxEditor

SyntaxEditor for WPF Forum

Posted 11 years ago by Matt Whitfield
Version: 13.1.0581
Avatar

Hello

I was previously a very enthusiatic user of SyntaxEditor for WinForms - and when I needed to implement an editor for our Irony based DSL I was really happy to see that there was Irony support for SyntaxEditor.

Reading the website, it makes it sound like you can point SyntaxEditor to an Irony grammar, and then have syntax highlighting with the added features like AST generation and error handling.

However, downloading the demo it's apparent that's not the case. I found the bit in the documentation where it says why it's not possible (because Irony isn't an incremental lexer) but it's pretty much just 'good luck' from there on in.

Are there any guides or anything that point in the right direction for how to do this? I do remember this about using SyntaxEditor before - that once you have invested the time to learn how the documentation is structured then you can find your way around it - but I'm trying to evaluate the product and I don't have a lot of time - so apologies if this is already answered somewhere - I couldn't find it...

Thanks

M

Comments (9)

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

Hi Matt,

That is correct, we are only able to support Irony's parsing and syntax error reporting capabilities.  However SyntaxEditor is very pluggable and you can use any lexer you want to add syntax highlighting.

I'd recommend you look at the Irony sample project that ships with SyntaxEditor.  It shows how we integrated a language definition's lexer (similar to the WinForms dynamic language lexers) to do syntax highlighting and used Irony as a parser and syntax error reporter.

It also shows how other language services like quick info providers can be added.


Actipro Software Support

Posted 11 years ago by Matt Whitfield
Avatar

I did look at the Irony sample project - and I saw how that was done. However I was hoping that there would be a way of using something to convert the Irony grammar to a langdef (since Irony supports inspection).

It also seems like there would be a relatively easy way to re-code an Irony grammar to use your LL(*) framework - but, again, I couldn't find any guides or examples of how that might be accomplished.

The trouble here is that I don't have a lot of time to invest right now, so I need to find a 'quick and easy' option to get to a proof-of-concept - after which I could then spend more time tweaking / playing.

If there are any guides that I've missed (especially with regard to a general methodology for porting an Irony specified grammar to you LL(*) framework) I'd really appreciate it if you could point me in their direction...

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

Sorry, we don't have anything for building a lexer from Irony.  Our LL(*) Parser Framework does share some concepts with Irony and improves on them.  But we don't have a guide for converting from Irony to ours.  Keep in mind that the LL(*) Parser Framework is still just a parser and requires that a lexer feed it tokens.  Meaning you'd need to make a .langdef lexer or write a programmatic one to use it.


Actipro Software Support

Posted 11 years ago by Matt Whitfield
Avatar

Ok, so I have an odd question.

I've got something that I think might be a reasonable Irony based lexer, and I have this code:

	public partial class MainWindow
	{
		public MainWindow() {
			InitializeComponent();

            AmbientParseRequestDispatcherProvider.Dispatcher = new ThreadedParseRequestDispatcher();
            LayoutGrammar layoutGrammar = new LayoutGrammar();
			syntaxEditor.Document.Language = new IronySyntaxLanguage<LayoutGrammar>(layoutGrammar);
		}
	}

    public class IronySyntaxLanguage<T> : SyntaxLanguage
        where T: Grammar
    {
        public IronySyntaxLanguage(T grammar)
            : base(typeof(T).Name)
        {
            this.RegisterLexer(new IronyLexer(grammar));
        }
    }

 This is on a WPF window with one control only - the syntax editor. The lexer gets constructed just fine - but Parse() is never called. As I start typing into the window, literally nothing happens.

I can't find any examples in the samples folder that implement a non-mergable programmatic lexer, so I've probably missed some basic step - and I can understand that maybe I have a few more steps to undertake before getting it to highlight syntax (such as registering styles in the ambient registry and getting a token tagger to apply classifications to tokens). But I would expect that it would at least call Parse()?

Am I missing something obvious here?

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

Hi Matt,

Please take a look at our Irony integration sample for an example.  You never registered an IronyParser on the language, so there is no parser to execute.

The "Getting Started" topic in the Irony Add-on section of the documentation walks you through everything too.  Be sure to check that out.


Actipro Software Support

Posted 11 years ago by Matt Whitfield
Avatar

Hi

I can't use your IronyParser because it is bound to a version of Irony that is quite out-of-date - so because the newer version of Irony (on which my language is based) has a different interface, it fails at run-time (because they are both v1.0.0.0 assemblies - for reasons unknown).

I registered a dummy IParser with the language and it still doesn't call Parse on my Lexer. It does call Parse() on the IParser, but doesn't call Parse() on the ILexer. I only want a functioning lexer right now, so I can have a syntax-highlighted editor.

Is it possible that reason that the Lexer isn't being called is because I haven't registered a TokenTagger? It's just that the diagram in the Overview topic of the Language Creation guide makes it seem like the lexer is the first port of call.

Thanks

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

Yes to get syntax highlighting you need an ILexer registered as well as a token tagger.  The token tagger ends up calling into the lexer and deciding which classification types to assign to the tokens, which then later resolve to highlighting styles.


Actipro Software Support

Posted 11 years ago by Matt Whitfield
Avatar

I got it working just fine - and got structure matching with validation of tokens against the token ID's I'm parsing out. So all good there.

Will you be updating the IronyParser to the newer version at any point? I'm not sure if the methods I'm using were in the older version - but they support the concept of incremental lexing pretty well out of the box. I'm happy to share my code for the lexer if so.

Thanks for all the help.

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

Hi Matt,

Yes we will be updating the IronyParser for the 2013.2 version to use the latest Irony.dll.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.