Random order of the AST nodes

SyntaxEditor for WPF Forum

Posted 9 years ago by Yury Asheshov
Version: 15.1.0622
Avatar

Hi,

I have the following text format (GroupA, GroupB, GroupC are keywords):

GroupA

{

     Properrty1 = 2;

     Properrty2 = 0xFF;

}

GroupB

{

Properrty3 = 3.5;

Properrty4 = "Somthing";

}

GroupC

{

Properrty5 = "One";

Properrty6 = "Two";

}

My problem is that the order of the groups can be random. How I can specify it in grammar? I believe that I need EbnfQuantifier which implements something like "all" from the XSD. It is essential to note that there are about 15 groups in the format which I parse so there is no way to write down all combinations in the grammar...

Comments (5)

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

Hi Yury,

I'm sorry but we'd need more detailed information on what you are trying to do to be able to assist here.  Can you give more detail on what is happening now and what you would like to see happen?  Are you looking to validate AST results or show parse errors for something, etc.?


Actipro Software Support

Posted 9 years ago by Yury Asheshov
Avatar

Hallo Cleveland,

Hope next seaspn LeBron and the team make it better ;)

I mean the following: all groups GroupA, GroupB and GroupC have to be defined in the file, but in any order: A, B, C or C, A, B or A, C, B etc.

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

Hi Yury,

Thanks, we were close this season but the injuries to our star players hurt us badly.

Ok for the parser question, I would have an alternation that allowed any of those groups to be parsed in any order.  Then call the production that contains that alternation with a ZeroOrMore(), which gives it a quantifier.  This would effectively allow zero to many groups to be defined in any order.

Now in a root production that calls into those productions, use an OnSuccess callback on one of the root terms.  That callback will get an IParserState passed to it.  You can look at the state.AstNodeBuilder.Matches to see what AST nodes it constructed.  Build up a dictionary of which groups you require.  Then loop through the AST to see which were defined and flag those as defined in your dictionary (perhaps by removing items as you go from it).  If there are any left, then use the state.ReportError method to report the error in the resulting parse data and make the error range be the end of the document.  If you set up your language to support squiggles for errors, you should see the error show up when appropriate.

I hope that helps!


Actipro Software Support

Posted 9 years ago by Yury Asheshov
Avatar

Thanks, I've assumed that I need something like that. One more question from design point of view: shall I create this dictionary as a CustomData or not?

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

Yes you could put it in CustomData at the start of parsing.  That data stays in the parser state during the entire parsing operation.


Actipro Software Support

The latest build of this product (v24.1.1) 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.