Code folding and UDL
-
Code folding in UDL matches any Open word to any Middle or any Close word. Is it possible to have positional matching? For example if I have Open words Alpha and Bravo, and Close words Charlie and Delta, code folding works from Alpha to Charlie, Alpha to Delta, Bravo to Charlie AND Bravo to Delta. I would prefer if it did not match Alpha to Delta or Bravo to Charlie. Is it possible to do something like that?
Also, if the language has If / (Else / ElseIf) / Endif and While / / EndWhile, it would be nice if folding would work from If to Else, If to ElseIf, If to EndIf, Else to ElseIf, Else to Endif, ElseIf to ElseIf, ElseIf to Endif AND from While to EndWhile ONLY. As things currently stand, folding also works from If to EndWhile and from While to Else or ElseIf, or While to Endif etc.
I have already read whatever there is over at https://ivan-radic.github.io/udl-documentation/ and nothing obvious jumped out at me, and I did some experimenting as well - and that did not yield any useful results either. Obviously the language compiler that I am working with will catch and report errors regarding missing/misplaced middle and end keywords, however it would be nice if NPP would also not fold code at the wrong places.
-
Unfortunately, UDL is not perfect and the end-all solution. It’s great for simple tasks, but it doesn’t support all the nuanced situations that one might run across in a given language.
There is add-on script written for the PythonScript-plugin called
EnhanceAnyLexer.py
that @Ekopalypse shares in his github repo, which can add extra highlighting that cannot be handled by a builtin lexer or the UDL lexer. The concepts there, along with the PythonScript documentation, could likely be used to add new folding rules that cannot be supported by a UDL.But really, a fully-featured purpose-written lexer is the best way to go when you have gone that far beyond the edge of the capabilities of UDL.
-
Did you look into the grouping operator (( ))? There is a UDL example where they “Alpha Bravo” then “((Charlie1 Charlie2)) Delta” for comment syntax middle and it worked as you described for defining what lines are comments and what characters allowed continuation of the comment onto a new line. Perhas simply using the grouping operator on one of the end conditions will limit matching?