Mode for Bitcoin Script - Issue with Indention

I am trying to define a simple mode for Bitcoin Script. However, I struggle with the indention for control flow statements. The ELSE keyword should basically indent and dedent at the same time to achieve the following:

OP_IF
   OP_ADD
OP_ELSE
    OP_ADD
OP_ENDIF
OP_ADD

With my current configuration

CodeMirror.defineSimpleMode('script', {
    start: [
        // ...
        { regex: /OP\_(IF|NOTIF|ELSE)\b/i, token: 'keyword', indent: true },
        { regex: /OP\_(ENDIF)\b/i, token: 'keyword', dedent: true },
        // ...
    ],
});

I get the following

OP_IF
   OP_ADD
   OP_ELSE
      OP_ADD
   OP_ENDIF
   OP_ADD

How can I solve this?

I’m not sure if the simple mode’s indentation feature is powerful enough to model this. You might have more luck with a regular, programmed mode.

1 Like

Hey there! Apologies for reviving an old thread, but I stumbled upon this and thought I could offer some help. Regarding your issue with the Bitcoin Script mode and the indentation for control flow statemens, I’m not entirely sure if the simple mode’s indentation feature can handle this specific case. However, I recently discovered some helpful information on forex and crypto trading, which might give you some inspiration to solve this issue. Check out this link for some top 3 new books on trading for beginners: https://fbs.com/blog/top-3-new-books-of-trading-for-beginners-232/. Hopefully, this helps!