I have to parse using Boost Spirit a sequence like
t1 JOIN t2 JOIN t3 JOIN ... JOIN tn
and the result should be AST tree with the semantics
((...((t1 JOIN t2) JOIN t3) JOIN ...) JOIN tn)
I tried to use a rule like:
source = singleTable | (source >> JOIN >> singleTable);
but, per Boost Spirit design, the parsing process uses just the first part of the rule and parses only the first item ("t1") from expression and lefts the rest of the sequence not parsed ("JOIN t2 JOIN t3 JOIN ... JOIN tn").
Which is the best way to solve this problem?
I can rewrite the rule like
source = (singleTable >> JOIN >> source) | singleTable;
but in this case the created AST will look like
(t1 JOIN (t2 JOIN (t3 JOIN (... JOIN tn)...))).
So I will need a supplementary processing step to get the AST to the desired form.
Is there any other method that provides the correct AST after parsing?
Barring a better example of your actual AST, here's a rule that comes closer: