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

Removed some grammars in an attempt to keep the syntax file as short as possible. TODO: Folding end marker

Draft for TextMate-like editor syntax file

Initial attempt at creating a syntax for use in editors such as E-TextEditor, and InType. These are windows editors that mimic TextMate hence it should be similar for TextMate.

{
   "patterns" : [
      {
         "name" : "comment.line.cobra",
         "match" : "(#).*$"
      },
      {
         "name" : "constant.numeric.integer.long.hexadecimal.cobra",
         "match" : "\\b(?i:(0x\\h*)L)"
      },
      {
         "name" : "constant.numeric.integer.hexadecimal.cobra",
         "match" : "\\b(?i:(0x\\h*))"
      },
      {
         "name" : "constant.numeric.integer.long.octal.cobra",
         "match" : "\\b(?i:(0[0-7]+)L)"
      },
      {
         "name" : "constant.numeric.integer.octal.cobra",
         "match" : "\\b(0[0-7]+)"
      },
      {
         "name" : "constant.numeric.complex.cobra",
         "match" : "\\b(?i:(((\\d+(\\.(?=[^a-zA-Z_])\\d*)?|(?<=[^0-9a-zA-Z_])\\.\\d+)(e[\\-\\+]?\\d+)?))J)"
      },
      {
         "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" : "constant.keyword.control.cobra",
         "match" : "\\b(branch|on|else|except|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)\\s+([a-zA-Z0-9_.]+)$",
         "captures" : {
            "1" : {
               "name" : "keyword.other.use.cobra"
            },
            "2" : {
               "name" : "support.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)\\b"
      },
      {
         "name" : "support.function.cobra",
         "match" : "\\b(base|test|require|ensure|var|get|(?<!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"
      },
      {
         "begin" : "\\b(?:class)\\s*([a-zA-Z0-9_]+)",
         "patterns" : [
            {
               "name" : "keyword.operator.cobra",
               "match" : "(inherits|implements)"
            },
            {
               "name" : "entity.name.type.cobra",
               "match" : "[a-zA-Z0-9_]+"
            },
            {
               "name" : "support.name.generic.cobra",
               "match" : "<\\s*of\\s+[a-zA-Z0-9]+>"
            }
         ],
         "name" : "storage.type.class.cobra",
         "end" : "$",
         "beginCaptures" : {
            "1" : {
               "name" : "entity.name.type.cobra"
            }
         }
      },
      {
         "begin" : "^\\s*(?:def)\\s*([a-zA-Z0-9_]+)",
         "patterns" : [
            {
               "include" : "#argument-list"
            }
         ],
         "name" : "meta.type.method.cobra",
         "end" : "$",
         "beginCaptures" : {
            "1" : {
               "name" : "entity.name.type.cobra"
            }
         }
      }
   ],
   "name" : "Cobra",
   "scopeName" : "source.cobra",
   "fileTypes" : [
      "cobra"
   ],
   "foldingStopMarker" : "^\\s*$",
   "foldingStartMarker" : "^\\s*(def|class|cue)(.*)",
   "repository" : {
      "argument-list" : {
         "begin" : "\\(",
         "endCaptures" : {
            "0" : "support"
         },
         "end" : "\\)",
         "beginCaptures" : {
            "0" : "support"
         }
      },
      "constant_placeholder" : {
         "name" : "constant.other.placeholder.cobra",
         "match" : "(?i:%(\\([a-z_]+\\))?#?0?\\-?[ ]?\\+?([0-9]*|\\*)(\\.([0-9]*|\\*))?[hL]?[a-z%])"
      },
      "generic_names" : {
         "match" : "[A-Za-z_][A-Za-z0-9_]*"
      },
      "escaped_characters" : {
         "name" : "constant.character.escape.cobra",
         "match" : "(\\\\x[0-9A-F]{2})|(\\\\[0-7]{3})|(\\\\\\n)|(\\\\\\\\)|(\\\\\\\")|(\\\\')|(\\\\a)|(\\\\b)|(\\\\f)|(\\\\n)|(\\\\r)|(\\\\t)|(\\\\v)"
      }
   },
   "firstLineMatch" : "^#!/.*\\bcobra\\b"
}