• Products
  • Download
  • Purchase
  • Support
  • Company
Actipro Software company logo
Twitter Follow Actipro RSS Subscribe (RSS Feed)

The Actipro Blog

Tag Cloud

  • blog
  • docking
  • editors
  • intelliprompt
  • micro charts
  • navigation
  • propertygrid
  • ribbon
  • shared library
  • silverlight
  • syntaxeditor
  • themes
  • views
  • web site
  • winforms
  • winrt
  • wpf

Latest Twitter News

May 14, 2012 at 2:50 PM
IntelliPrompt code snippet features have been added to our VS-like code editor control for #WPF and #Silverlight. http://t.co/1IchOJrr

May 10, 2012 at 9:40 PM
Our new Micro Charts control products for #WPF and #Silverlight are out now. Come build some dashboards with them! http://t.co/EEERvff0

May 7, 2012 at 6:47 AM
Today we look at bar charts, for our upcoming #WPF, #Silverlight, and #WinRT Micro Charts product. http://t.co/gxHuPS6B

May 4, 2012 at 6:25 AM
See a gallery of micro area charts in our upcoming release for #WPF, #Silverlight, and #WinRT. http://t.co/qDXGwW8B

May 3, 2012 at 6:32 AM
See a variety of line charts that are easy to make with our upcoming #WPF, #Silverlight, #WinRT Micro Charts product. http://t.co/mbkX6tJd

Twitter Follow us on Twitter

Month List

  • 2012
    • May (9)
    • April (6)
    • March (11)
    • February (11)
    • January (2)
  • 2011
    • December (2)
    • November (7)
    • October (2)
    • September (1)
    • August (5)
    • July (3)
    • June (6)
    • May (5)
    • April (8)
    • March (4)
    • February (5)
    • January (9)
  • 2010
    • December (9)
    • November (10)
    • October (4)
    • September (8)
    • August (12)
    • July (9)
    • June (7)
    • May (6)
    • April (7)
    • March (6)
    • February (6)
    • January (4)
  • 2009
    • December (2)
    • November (2)
    • October (12)
    • September (3)
    • August (11)
    • July (10)
    • June (6)
    • May (3)
    • April (7)
    • March (6)
    • February (8)
    • January (10)
  • 2008
    • December (10)
    • November (2)
    • October (3)
    • September (5)
    • August (5)
    • July (8)
    • June (4)
    • May (4)
    • April (10)
    • March (8)
    • February (1)
    • January (2)

Category List

  • RSS feed for ActiproActipro (321)
  • RSS feed for Blog SummaryBlog Summary (15)
  • RSS feed for GeneralGeneral (43)
  • RSS feed for In developmentIn development (164)
  • RSS feed for New featuresNew features (155)
  • RSS feed for New productNew product (38)
  • RSS feed for PromotionPromotion (2)
  • RSS feed for SilverlightSilverlight (90)
  • RSS feed for Tips and tricksTips and tricks (4)
  • RSS feed for Visual Studio 2008Visual Studio 2008 (2)
  • RSS feed for Windows FormsWindows Forms (22)
  • RSS feed for Windows VistaWindows Vista (10)
  • RSS feed for WinRTWinRT (9)
  • RSS feed for WPFWPF (257)
  • RSS feed for XAMLXAML (23)

About Us

Actipro Software is a leading provider of .NET user interface controls for the WPF, Silverlight, and WinForms frameworks, and is most well-known for their SyntaxEditor syntax-highlighting code editor control.

Please take some time to learn more about us and our product offerings.

SyntaxEditor for WPF to add integration with ANTLR parsers

August 11, 2009 at 10:08 AM
by Bill Henning (Actipro)

We’re very excited to officially announce that the next build of WPF Studio will contain a new assembly that makes it easy to automatically call an ANTLR-generated parser via worker threads whenever SyntaxEditor document text changes.  This new assembly will be included free for use by any of our SyntaxEditor for WPF customers.

What is ANTLR?

ANTLR, ANother Tool for Language Recognition, was created by Terence Parr and is one of the most widely-used parsing frameworks available.  ANTLR is a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages. ANTLR provides excellent support for tree construction, tree walking, translation, error recovery, and error reporting.

New Sample to Demonstrate ANTLR Add-on

We’ve built a new sample project that demos a calculator parser generated by ANTLR.  This new sample project will be in the next WPF Studio build.

AntlrSample

The sample has a SyntaxEditor instance at the lower left.  You can enter a simple integer mathematic equation into the editor.  When text changes occur, SyntaxEditor uses its advanced parsing framework to call an ANTLR parser in a worker thread.  The parser returns its AST result back to the document asynchronously when it completes. 

In the sample, the AST result is loaded into a WPF TreeView.  It even calculates and displays the result!

This is a rather simplistic use of ANTLR but we wanted to show the base concept of how our new add-on works.  It’s just as easy to call any other more complicated ANTLR parser, such as ones for C++, Javascript, etc.

How Does the Add-on Work?

It’s actually very simple.  For the sample above, we made an ANTLR grammar called AntlrCalc.g and used it to generate two classes:  AntlrCalcLexer and AntlrCalcParser.  Next we included those classes in our project.

Now it’s time to use the new add-on to wrap the AntlrCalcParser (via our add-on’s AntlrParser class) and register the AntlrParser as an IParser for the language:

   1: // Construct a SyntaxLanguage based on the ANTLR parser by 
   2: //   using the Actipro ANTLR add-on
   3: SyntaxLanguage language = new SyntaxLanguage("Calc");
   4: language.RegisterService<IParser>(
   5:     new AntlrParser(
   6:         language.Key, 
   7:         typeof(AntlrOutput.AntlrCalcLexer), 
   8:         typeof(AntlrOutput.AntlrCalcParser), 
   9:         "expr"
  10:         ));
  11:  
  12: // Assign the SyntaxLanguage to the SyntaxEditor's document
  13: this.syntaxEditor.Document.Language = language;

The AntlrParser class takes four constructor parameters:  a string key that identifies the parser's language, the Type of core ANTLR lexer and parser, and the root rule name in the core ANTLR parser to execute.  In our ANTLR grammar, the root rule is called expr.

Once our AntlrParser is registered with the language as an IParser and the language is assigned to a document, any changes made to that document (via an attached SyntaxEditor for instance) will cause the ANTLR parser to be run.  Its result is passed back in an IAntlrParseData object to the document’s ParseData property.  This triggers the document’s ParseDataChanged event, so that listeners can know that the parse data was updated.

SyntaxEditor Embraces Third-Party Solutions

With the addition of the ANTLR add-on, we now have two free add-ons that support integration with third-party parsing frameworks.  The first one packaged with SyntaxEditor works with Microsoft’s MGrammar, and now we have dedicated support for Terence Parr’s ANTLR as well.

Just because we don’t have dedicated add-ons for other parsing frameworks doesn’t mean they can’t be used with SyntaxEditor as well.  All these two add-ons do is provide a bridge between the Actipro text/parsing framework and the third-party parser framework.  So if you use another third-party parsing framework, they can be wired up fairly easily with a little bit of coding.

Tags: wpf, syntaxeditor, antlr, mgrammar
Filed under: Actipro, In development, WPF
Submit to DotNetKicks...
Permalink | Comments (4)

Related posts

Actipro SyntaxEditor for WPF and Editors for WPF are released SyntaxEditor for WPF with a custom theme loaded Yesterday evening we published WP...SyntaxEditor for WPF - Adding syntactic/semantic parsing supportAs we move forward on new features for SyntaxEditor for WPF, the next feature area we’ve been ...Integrating MGrammar DSL parsers with SyntaxEditor to implement syntax highlightingNow that the public beta of SyntaxEditor for WPF has been released, I’d like to show off a really ne...

Comments

August 10, 2009 at 04:10  

trackback

SyntaxEditor for WPF to add integration with ANTLR parsers

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com

August 10, 2009 at 06:50  

Scott Currie

I thought I'd call out another scenario, which is similar to this one.  We currently use your XML parser service.  While our language is XML-based, we do a lot of our own custom parsing to map the language onto a custom AST with application specific capabilities.  

When you implement this bridge code for your own XML parsing framework, it would be really great for us if you provided a hook that we could use to call our supplemental parsing code.  Even better would be if you could attach multiple IParsers to do background parses on the same document.  That way, neither our parser or your XML parser would block on each other.  Please email me if you'd like to discuss the scenario in more detail.

Thanks,
-Scott

Scott Currie United States

August 11, 2009 at 03:18  

Bill Henning (Actipro)

Scott,

Actually with the current design it would be very easy to "chain" together multiple IParser instances.  I don't think it would be possible to execute multiple parsers on separate threads at the same time however sequentially chaining them is certainly possible.

Say once we eventually have our advanced XML language done.  You'd create an instance of our add-on's XML language.  Then you'd call language.GetService<IParser>() to get our IParser implementation.  You'd make a custom class that implements IParser.  In the constructor to that class you'd pass in the IParser instance that you got from our language.  Then in your parser's Parse method, first you'd call our existing parser's Parse method directly, followed by executing your logic.  You'd register your custom IParser in place of the one we have in the language by default.  Thus, you have achieved the chaining of two IParsers, where your custom one calls ours first and runs your code second, but still in the worker thread.

Hope that helps!

Bill Henning (Actipro) United States

September 30, 2009 at 21:41  

trackback

Actipro Blog 2009 Q3 posting summary

Actipro Blog 2009 Q3 posting summary

The Actipro Blog - WPF and WinForms Development

Comments are closed
Copyright © 1999-2012 Actipro Software LLC. All rights reserved.
Home Actipro Software | Products | Download | Contact Us