Passing an instance to the grammar class

SyntaxEditor for WPF Forum

Posted 2 years ago by Daisuke Nakada
Version: 17.2.0662
Avatar

Hi,

I want to pass 2 instances to grammar class.

One is a literal-validation instance, which checks if a literal expression is correct.

The other is a database, which is used to see a variable name is really defined and available.

(all of the defined names of variables and functions are registered on the database)

 

If any of the above checks fail, I want to show a quick info when mouse hover, and a squiggle line.

This is the same specification as the built-in syntax check, so I think I should write those code in the grammar class,

like in "variableName.Production.SuccessCallback" or ""variableName.Production.CompleteCallback".

 

Please tell me how to pass an instance to the grammar class.

Also, please give some advice if there is a better way to achieve what I want to do.

 

Thank you.

Comments (2)

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

Hello,

Yes you could pass the two instances into the grammar class constructor and update your parser constructor to also allow passing in the grammar, using your the grammar constructor with the two instance parameters.  Then in the grammar constructor, store those instances as fields on the grammar class.

Once you have those fields, you can add the success callbacks (see documentation and samples on how to do that) and just reference your instance field values as appropriate to do validation.

In your success callback, if you detect an error, then call the "state.ReportError()" method to report it.  The IParserState object is passed into the callbacks.

As long as you have the lines in your language setup that are shown in our GettingStarted05 QuickStart's SimpleSyntaxLanguage file, you'll get squiggle lines for parse errors and quick info tips when hovering over them.


Actipro Software Support

Posted 2 years ago by Daisuke Nakada
Avatar

Thank you very much.

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.