Wiki
Version 9 (modified by webnov8, 16 years ago)

Fixes syntaxes that were broken because of docstrings. TODO fix keywords based on context.

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"
            }
         }
      },
      {
         "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" : "support.variable.cobra",
               "match" : "\\bvar|from|as|get\\b"
            },
            {
               "include" : "#type"
            },
            {
                "include" : "#multiline-comments"
            }
         ],
         "name" : "meta.type.method.cobra",
         "end" : "$",
         "beginCaptures" : {
            "1" : {
               "name" : "keyword.operator.method.cobra"
            },
            "2" : {
               "name" : "entity.name.type.cobra"
            }
         }
      },
      {
         "include" : "#multiline-comments"
      }
   ],
   "name" : "Cobra",
   "scopeName" : "source.cobra",
   "fileTypes" : [
      "cobra"
   ],
   "foldingStopMarker" : "^$",
   "foldingStartMarker" : "^\\s*(def|class|cue|get|set)(.*)",
   "repository" : {
      "argument-list" : {
         "begin" : "\\(",
         "patterns" : [
            {
               "include" : "#type"
            },
            {
               "name" : "keyword.operator.cast.cobra",
               "match" : "\\bas\\b"
            }
         ],
         "endCaptures" : {
            "0" : "support"
         },
         "end" : "\\)",
         "beginCaptures" : {
            "0" : "support"
         }
      },
      "multiline-comments" : {
         "begin" : "^\\s*\"\"\"\\s+",
         "name" : "comment.block.cobra",
         "comment" : "comment blocks including docstrings",
         "end" : "(^\\s*|\\s+)\"\"\"$"
      },
      "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"
}