Simple Ast Node property question

SyntaxEditor for WPF Forum

Posted 6 years ago by zach heylmun
Version: 13.1.0583
Avatar

Hi, I am currently building a grammar for a scripting language and I am very happy with the tools.  I do have one quick question about setting simple properties on Ast nodes generated using the language tool though.  I had no problem setting a simple text property ( or even complex nested nodes for that matter), but I can't for the life of me figure out how to set a boolean property based on the inclusion of an optional terminal.

For a simple example, a variable declaration node might have a const bool, a type and a name.  I want to set the value of the const property based on whether the optional const token precedes the variable declaration.  Thanks for your time, Zach Heylmun

Comments (3)

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

Hi Zach,

You can do this sort of thing in a tree construction portion of a production (when using our LL(*) Parser Framework):

Ast<QualifiedName>().SetProperty(qn => qn.IsGlobal, true);

The above is what we do in our VB grammar for the .NET Languages Add-on in one spot.


Actipro Software Support

Posted 6 years ago by zach heylmun
Avatar

I may have misunderstood something, but setting the property to true results in the variable always being true.  I understand how to set the property, the issue is doing so conditionally based on whether or not an optional terminal is present.

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

Hi Zach,

Ok in that case, you can do the same thing but instead of passing true explicitly, you can have it look at a matched result like AstFrom("myterminal").  If that value is "true" then it will set the property as true.  Likewise, "false" will set the property as false.  Any other value won't touch the property.

So the related production could be like:

aNonTerminal.Production = ... + @myterminal["myterminal"].Optional() + ...

And then you'd have your tree construction per above for this production.  I hope that clarifies it better. 


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.