TNO / Rewriters-Ada

Advanced manipulation of Ada code
BSD 3-Clause "New" or "Revised" License
5 stars 1 forks source link

Context too large #5

Open pjljvandelaar opened 2 years ago

pjljvandelaar commented 2 years ago

When a parent AST node has its first child AST node and its last AST node labelled as in rewrite context, currently also the parent might be in incorrectly considered to be in rewrite context.

For example, labelling parenthesis expression for rewriting in

(a+b) + (c+d)

results in (with \B: begin tag \E: end tag)

\B(a+b)\E + \B(c+d)\E

The current logic to check whether a AST node is within a rewrite context, will now also consider the whole expression as a rewrite context.

pjljvandelaar commented 2 years ago

A possible solution is to add an unique identifier to each rewrite context, and check for matching identifiers.

The example would become:

\Bx(a+b)\Ex + \By(c+d)\Ey

And, since \Bx doesn't match \Ey the parent is no longer considered a rewrite context!

pjljvandelaar commented 2 years ago

We might be able to handle sublist in the same way. Making the rewrite context smaller (no longer the parent, but the actual sublist). And making the pretty print context also smaller!

pjljvandelaar commented 4 months ago

Another possible solution is to extract the allowed rewrite contexts first, and then just check whether the AST node is completely within a rewrite contexts.

We need to handled nested contexts. But with a simple counter we can determine that a+b can be rewritten/simplified in this case \B \B a \E + \B b \E \E but not in \B a \E + \B b \E.