Javascript 如何创建新的代码镜像模式?

Javascript 如何创建新的代码镜像模式?,javascript,tokenize,codemirror,codemirror-modes,Javascript,Tokenize,Codemirror,Codemirror Modes,因此,我最近为一个项目完成了自己的函数式编程语言,我想为该语言创建一个代码镜像模式,因为它可以将组件转换为javascript。我已经为它编写了一个标记器,但我无法理解codemirror构造标记器的方式。这是该语言的基本结构: <FUNCTION>(<ARGUMENT 1>, <ARGUMENT 2>....) nested functions: <FUNCTION 1>(<FUNCTION 2>(<ARGUEMNT 1&g

因此,我最近为一个项目完成了自己的函数式编程语言,我想为该语言创建一个代码镜像模式,因为它可以将组件转换为javascript。我已经为它编写了一个标记器,但我无法理解codemirror构造标记器的方式。这是该语言的基本结构:

<FUNCTION>(<ARGUMENT 1>, <ARGUMENT 2>....)

nested functions:

<FUNCTION 1>(<FUNCTION 2>(<ARGUEMNT 1>), <ARGUMENT 1>....)

series of functions:

<FUNCTION>(<ARGUMENT 1>, <ARGUMENT 2>...), <FUNCTION>()

strings:

`this is a string`

comments:

;this is a comment;
到目前为止还不起作用。如果有人能给我指出正确的方向,或者向我展示这样一种语言的模式是如何工作的,那将是非常有帮助的

(function(mod) {
  if (typeof exports == "object" && typeof module == "object") // CommonJS
    mod(require("../../lib/codemirror"));
  else if (typeof define == "function" && define.amd) // AMD
    define(["../../lib/codemirror"], mod);
  else // Plain browser env
    mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.defineMode("diff", function() {

  var TOKEN_NAMES = {
    '(': 'positive',
    ')': 'negative',
    ',': 'comma',
    ';': 'comment',
    '`': 'strings', 
  };

  return {
    token: function(stream) {
      var tw_pos = stream.string.search(/[\t ]+?$/);

      if (!stream.sol() || tw_pos === 0) {
        stream.skipToEnd();
        return ("error " + (
          TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, '');
      }

      var token_name = TOKEN_NAMES[stream.peek()] || stream.skipToEnd();

      if (tw_pos === -1) {
        stream.skipToEnd();
      } else {
        stream.pos = tw_pos;
      }

      return token_name;
    }
  };
});

CodeMirror.defineMIME("text/x-mylang", "mylang");

});