Wiki
Version 8 (modified by webnov8, 15 years ago)

--

E-TextEditor, InType, etc. TextMate-based language syntax

  1. Open the bundle editor: "Bundles" -> "Edit Bundles" -> "Show Bundle Editor"
  2. Add a bundle named "Cobra" (if you do not already have one)
  3. Add a language file name "Cobra"
  4. Paste the code below
  5. Save the language file

All files with the Cobra extension will now be highlighted per the grammars found in the file. At the moment enough grammars to get by is presented. Please discuss improvements or make them yourself using the guidelines at  TextMate Manual Language Grammars.

{
   "patterns" : [
      {
         "name" : "comment.line.cobra",
         "match" : "(#).*$"
      },
      {
         "name" : "constant.numeric.hexadecimal.cobra",
         "match" : "\\b(?i:(0x\\h*)L?)"
      },
      {
         "name" : "constant.numeric.octal.cobra",
         "match" : "\\b(?i:(0[0-7]+)L?)"
      },
      {
         "name" : "constant.numeric.float.cobra",
         "match" : "\\b(?i:(\\d+\\.\\d*(e[\\-\\+]?\\d+)?))(?=[^a-zA-Z_])"
      },
      {
         "name" : "constant.numeric.float.cobra",
         "match" : "(?<=[^0-9a-zA-Z_])(?i:(\\.\\d+(e[\\-\\+]?\\d+)?))"
      },
      {
         "name" : "constant.numeric.float.cobra",
         "match" : "\\b(?i:(\\d+e[\\-\\+]?\\d+))"
      },
      {
         "name" : "constant.numeric.integer.long.decimal.cobra",
         "match" : "\\b(?i:([1-9]+[0-9]*|0)L)"
      },
      {
         "name" : "constant.numeric.integer.decimal.cobra",
         "match" : "\\b([1-9]+[0-9]*|0)"
      },
      {
         "name" : "keyword.control.cobra",
         "match" : "\\b(inherits|branch|on|else|catch|finally|for|if|try|while|break|continue|pass|raise|return|using|yield)\\b"
      },
      {
         "name" : "keyword.operator.logical.cobra",
         "match" : "\\b(and|in|not|or)\\b"
      },
      {
         "name" : "keyword.other.cobra",
         "match" : "\\b(as|assert|print|var|invariant|is|is\\s*shared)\\b"
      },
      {
         "name" : "keyword.operator.comparison.cobra",
         "match" : "<\\=|>\\=|\\=\\=|<|>|<>"
      },
      {
         "name" : "keyword.operator.assignment.cobra",
         "match" : "\\=|\\+\\=|-\\=|\\*\\=|/\\=|//\\=|%\\=|&\\=|\\|\\=|\\^\\=|>>\\=|<<\\=|\\*\\*\\="
      },
      {
         "name" : "keyword.operator.arithmetic.cobra",
         "match" : "\\+|\\-|\\*|\\*\\*|/|//|%|<<|>>|&|\\||\\^|~"
      },
      {
         "match" : "\\s*(use|namespace)\\s+([a-zA-Z0-9_.]+)$",
         "captures" : {
            "1" : {
               "name" : "keyword.other.namespacing.cobra"
            },
            "2" : {
               "name" : "constant.class.cobra"
            }
         }
      },
      {
         "begin" : "^\\s*\"\"\"\\s+",
         "name" : "comment.block.cobra",
         "comment" : "comment blocks including docstrings",
         "end" : "^\\s*\"\"\"$"
      },
      {
         "name" : "storage.type.function.cobra",
         "match" : "\\b(def|cue|get|set|test|ensure|body|require)\\b"
      },
      {
         "name" : "support.function.cobra",
         "match" : "\\b(base|(?<!is\\s)shared)\\b",
         "comment" : "language variables that are builtin"
      },
      {
         "begin" : "r?'",
         "patterns" : [
            {
               "include" : "#escaped-characters"
            }
         ],
         "name" : "string.quoted.single.cobra",
         "end" : "'"
      },
      {
         "begin" : "r?\"",
         "patterns" : [
            {
               "include" : "#escaped-characters"
            }
         ],
         "name" : "string.quoted.double.cobra",
         "end" : "\""
      },
      {
         "name" : "support.type.cobra",
         "match" : "\\b(bool|char|int|uint|float|decimal|number|dynamic|int8|int16|int32|int64|uint8|uint16|uint32|uint64)\\b",
         "comment" : "list of native primitive types"
      },
      {
         "name" : "support.class.cobra",
         "match" : "\\b(String|List|Dictionary|Set|Stack|Queue|TextWriter|TextReader|StringBuilder)(?:\\?)?\\s*(<of\\s*[a-zA-Z0-9_]+>)\\b"
      },
      {
         "include" : "#type"
      },
      {
         "begin" : "\\b(?:class)\\s*([a-zA-Z0-9_]+)",
         "patterns" : [
            {
               "name" : "keyword.operator.cobra",
               "match" : "(inherits|implements|is|partial)"
            },
            {
               "name" : "entity.name.type.cobra",
               "match" : "[a-zA-Z0-9_]+"
            },
            {
               "include" : "#type"
            }
         ],
         "name" : "storage.type.class.cobra",
         "end" : "$",
         "beginCaptures" : {
            "1" : {
               "name" : "entity.name.type.cobra"
            }
         }
      },
      {
         "begin" : "^\\s*(def|cue|get|pro)\\s+([a-zA-Z0-9_]+)",
         "patterns" : [
            {
               "include" : "#argument-list"
            },
            {
               "name" : "keyword.operator.from.cobra",
               "match" : "\\bfrom|as\\b"
            },
            {
               "name" : "support.variable.cobra",
               "match" : "\\bvar\\b"
            }
         ],
         "name" : "meta.type.method.cobra",
         "end" : "$",
         "beginCaptures" : {
            "1" : {
               "name" : "keyword.operator.method.cobra"
            },
            "2" : {
               "name" : "entity.name.type.cobra"
            }
         }
      }
   ],
   "name" : "Cobra",
   "scopeName" : "source.cobra",
   "fileTypes" : [
      "cobra"
   ],
   "foldingStopMarker" : "^\\s*$",
   "foldingStartMarker" : "^\\s*(def|class|cue)(.*)",
   "repository" : {
      "argument-list" : {
         "begin" : "\\(",
         "patterns" : [
            {
               "include" : "#type"
            },
            {
               "name" : "keyword.operator.cast.cobra",
               "match" : "\\bas\\b"
            }
         ],
         "endCaptures" : {
            "0" : "support"
         },
         "end" : "\\)",
         "beginCaptures" : {
            "0" : "support"
         }
      },
      "escaped-characters" : {
         "name" : "constant.character.escape.cobra",
         "match" : "(\\\\x[0-9A-F]{2})|(\\\\[0-7]{3})|(\\\\\\n)|(\\\\\\\\)|(\\\\\\\")|(\\\\')|(\\\\a)|(\\\\b)|(\\\\f)|(\\\\n)|(\\\\r)|(\\\\t)|(\\\\v)"
      },
      "type" : {
         "match" : "(?<=as|\\=)\\s+([A-Z][a-zA-Z0-9_]+)\\s*(\\??|<\\s*of\\s+[a-zA-Z0-9]+>)?",
         "captures" : {
            "1" : {
               "name" : "entity.name.class.cobra"
            },
            "2" : {
               "name" : "entity.name.generic.cobra"
            }
         }
      }
   },
   "firstLineMatch" : "^#!/.*\\bcobra\\b"
}