1

Codemirror is an excellent JS library for syntax coloring & highlighter etc. I have created a very simple 'macro' language for my project and want to use codemirror for it. However, writing a new mode / lexicon parser for codemirror is not a simple task. Good news though, the excellent codemirror-grammar makes it a relatively simple task to achieve this without being a regexp ninja - it uses a JSON formatted definition file which is very approachable with an easy learning curve. Frustratingly, the docs are not fabulous.

My question is, how can I tell codemirror-grammar that the keywords list should be case-insensitive, for example:

MacroVersion should be matched by 'macroversion'.

Currently 'MacroVersion' is not being highlighted. Image below.

Example of case-sensitivity

What have I tried so far: I looked at the source code for codemirror-grammar and though not fully understanding it I thought there seemed to be a token as in the highlight below for case sensitivity.

Current attempt

I have also looked at other sample codemirror-grammar language examples but have not found a cut-paste solution there.

Research / other SO questions for codemirror:

CodeMirror autocomplete: Case In Sensitive Search : Not a duplicated as is specific to python mode.js and requires source code change in mode file, whereas codemirror-grammar does not have the mode js file.

Vanquished Wombat
  • 9,075
  • 5
  • 28
  • 67

1 Answers1

0

apply caseInsensitive = true for example:

"keyword": {
    "autocomplete": true,
    "caseInsensitive": true,    // <-- make case-insensitive
    "tokens": [
        "if", "then", "else",
        .. 
    ]
}

found here: https://github.com/foo123/codemirror-grammar/issues/12#issuecomment-427387653

Alex
  • 789
  • 8
  • 8