Mode for Bitcoin Script - Issue with Indention


#1

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?


#2

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.