GetParser is returning null on SyntaxEditor Document Language based on a langdef file.

SyntaxEditor for WPF Forum

Posted 6 years ago by Peter MacNeil
Version: 13.2.0590
Avatar

The comments for Getting Started03c state " It doesn't matter whether a dynamic or programmatic lexer is used though. Either will work fine with all of the subsequent steps where we add advanced parsers and functionality."

I'm attempting to reproduce the Getting Started04b exercise based on the langdef Lexer as in Getting Started03a instead of the programmatic Lexer as in Getting Stared03b.

In the Actipro SampleApplication I've modified the Getting Started03a project to add the new code from Getting Started 04a. In particular please see the GetParser line in the code block.

I've updated the 03a MainControl.xaml to include a second SyntaxEditor control, named EbnfEditor, to receive the EBNF text or the text "parser is null".

The call to GetParser is returning null. What am I missing?

I've changed the Getting Started 03a MainControl.xaml.cs to add a GetParser call:

 

namespace ActiproSoftware.ProductSamples.SyntaxEditorSamples.QuickStart.GettingStarted03a {

  /// <summary>
  /// Provides the main user control for this sample.
  /// </summary>
  public partial class MainControl : System.Windows.Controls.UserControl {

    /////////////////////////////////////////////////////////////////////////////////////////////////////
    // OBJECT
    /////////////////////////////////////////////////////////////////////////////////////////////////////
    
    /// <summary>
    /// Initializes an instance of the <c>MainControl</c> class.
    /// </summary>
    public MainControl() {
      InitializeComponent();

      // Load the most basic version of the Simple language
      editor.Document.Language = SyntaxEditorHelper.LoadLanguageDefinitionFromResourceStream("Simple-Advanced.langdef");

      // Load the EBNF language
      EbnfEditor.Document.Language = SyntaxEditorHelper.LoadLanguageDefinitionFromResourceStream("Ebnf.langdef");

      // Show the EBNF
      ILLParser parser = editor.Document.Language.GetParser() as ILLParser; // Returns null.

      if (parser != null)
      {
        EbnfEditor.Document.SetText(parser.Grammar.ToEbnfString());
      }
      else
      {
        EbnfEditor.Document.SetText("parser is null.");
      }
    }
  }
}

  I appreciate what hints you can provide.

 

Thanks,

Pete

[Modified 6 years ago]

Comments (2)

Posted 6 years ago by Peter MacNeil
Avatar

I updated the code section in the original post.

[Modified 6 years ago]

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

Hi Pete,

SyntaxEditorHelper.LoadLanguageDefinitionFromResourceStream will load a completely new language from your .langdef file and will return the result.  This wipes out anything you already may have had in the language.  If you already have a language set up that has a parser in it but you want to add the lexer from the .langdef there are other InitializeXX methods on the helper class that can do so.

But also note that none of the .langdef files will have a parser in them.  You need to programmatically add a parser service, which our samples do.  But we start adding parsers in Getting Started 4a.  Since you didn't do the steps there and are back in the 3's samples, there is no parser yet.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.