Select matched parens

I am implementing a clojure editor using MPS. To make the parens look like free text, i write a custom cell to draw right parens.

It looks like:

This looking seems good to me. However, when I perform selection, say, i want to select the innermost fn construct:

There should be only right paren be selected, however, in my current implementation, 4 right parens are selected.

 

Any suggestion to fix this? Thanks in advance.

2 comments
Comment actions Permalink

Hi 1424701850,

We had a similar problem when we were developing our calculation language.

The problem was with the operator precedence: having the expression "1 + 2", we could easily change it to "3 * 1 / 4 + 2 * 5 + 6 * 7" BUT the AST would be completely different from the expected result as it would not consider the operators precedence but, instead, the order of change.

I suspect that this is what happened to you in your example.

We resolved our problem creating a side transform action for when we added a new concept of the operator type; in this (these) action handlers, we called a behaviour method that would change the AST so that it would mimic what it was expected from the operators precedence.

So in your case, while looking Ok (I'm considering the colours), your AST must be "wrong". Whenever you insert a parentheses, you should change the AST so that it reflects what it's supposed to!


Regards,

Sérgio Ribeiro

Porto - Portugal

 

1
Comment actions Permalink

Thanks for your detailed explanation, Ribeiro.

I will try to use a side transformation to see if it works.

 

0

Please sign in to leave a comment.