Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

How do you get LMDSyntaxEdit to fold code with non-keyword tokens?

I have a Syntax Scheme that assigns "if" and "end" to the "statement" token class. I know this is working because colourisation applies the correct colours for "statement" in an EditView. However, I cannot get code folding to work. I have a SyntaxBlock with capture='true', but no matter what I set Start and End to, no code folding takes place. I have tried "[ kw:if ]", "[ id:if ]" and "[ statement:if ]" (and likewise for "end"). The SyntaxBlock is in my root scheme, and I don't inherit any other schemes. Code folding works if I define them as keywords, but not if they are not keywords.


Comments

  • 8 Comments sorted by Votes Date Added
  • As described in our docs:

    https://files.lmd.de/downloads/tutorials/syntaxedit/synax_blocks_and_folding.htm

    keywords, identifiers and symbols have special support, and you can use "kw:if" like syntax to specify exact keyword, identifier or a symbol. Other tokens has no such capabilities, and so, you can only use "statement" to match any statement, which will include "if" and "end".

    As a workaround, you can define two token classes "statement_if" and "statement_end".
  • With apologies Eugene, could you provide more detail, please? All the examples in the doc (which I have read several times before asking the question) use kw: for specific tokens; none of them shows how to use non-keyword tokens. Are you saying I can use something like this:

    <Regex token0-'statement_if' regex='if'/>
    <Regex token0='statemend_end' regex='end' />
    <SyntaxBlock capture='true'>
    <Start> statement_if </Start>
    <End> statement_end </End>
    <SyntaxBlock>
  • <Regex token0-'statement_if' regex='if'/>
    <Regex token0='statemend_end' regex='end' />
    <SyntaxBlock capture='true'>
    <Start> statement_if </Start>
    <End> statement_end </End>
    <SyntaxBlock>

    Yes, like this. Of course in this case "if" and "end" should not be listed in a keywords list.
  • OK, after correcting the XML errors in the example I gave, I put this in my main scheme, and folding "+" signs now appear next to the "if"s. However, folding occurs from any "if" you select up to the very last "end" in the file, not to the matching "end" (or even the first "end").

    In addition, this causes a problem with syntax colouring, because I now would have separate token classes for if, end, else, when, for, foreach, ....

    With apologies, and accepting that LMD syntax was probably never intended to be an all-singing, all-dancing solution to every possible syntax and highlighting requirement, I'm beginning to think that I should just forget about using code folding with it. Even if my requirements were a bit strange (though I don't think they are) checking the MegaDemo shows it has some of the same issues I'm trying to resolve (for example, folding an "if" statement hides the "else" clause").

    Thanks for your help, anyway.
  • You simply has typing errors in your example. Corrected code:

        <Regex token0='statement_if' regex='if'/>
        <Regex token0='statement_end' regex='end' />
        
        <SyntaxBlock capture='true'>
            <Start> statement_if </Start>
            <End> statement_end </End>
        </SyntaxBlock>

    As about several separate tokens - yes, you right. But, here also, if you have something complex, you can develop your own color scheme file format and the corresponding editor/UI. Anyway, I noted this for thinking as a TODO item.

    As about hiding "else" clauses - yes, this is how our engine works. Use what is possible to use.
  • OK, thanks, that fixed the "hides 'til the last end" problem. (I did notice the syntax errors in my post - as I mentioned in my previous post - but I obviously missed one. Sorry about that.)

    "Use what is possible to use". Hard to disagree. For what it's worth, the hiding of the end token is a bit of a showstopper for me, for this current application. It's asking for trouble if folding an if hides an elseif, so I'm going to have to go without syntax folding for the moment. (The application already parses the input, so I have already divided every token into a relevant class, but I was hoping LMDSyntax would give me colouring and code folding, and so save me time. Ah well. C'est la vie.)

    Thanks.
  • Posts: 0 Accepted Answer Vote Up0Vote Down
    Generally our regexp engine supports look ahead. As you can read in docs it can be done via (?= xxx ) syntax. But, folding works using whole lines, this is why the "elseif" still will be folded even if you will use mentioned look ahead feature.

    I cannot predict, whether it will be simple to change, but I will look (not right now)...
  • Thanks Eugene.
Sign In or Register to comment.