textmate-grammar

Use when creating or editing TextMate grammar files for VS Code syntax highlighting - patterns, scopes, and language tokenization

$ 安裝

git clone https://github.com/mcclowes/omg /tmp/omg && cp -r /tmp/omg/.claude/skills/textmate-grammar ~/.claude/skills/omg

// tip: Run this command in your terminal to install the skill


name: textmate-grammar

prettier-ignore

description: Use when creating or editing TextMate grammar files for VS Code syntax highlighting - patterns, scopes, and language tokenization

TextMate Grammar

Quick Start

{
  "scopeName": "source.omg",
  "patterns": [{ "include": "#main" }],
  "repository": {
    "main": {
      "patterns": [
        { "include": "#comments" },
        { "include": "#strings" },
        { "include": "#keywords" }
      ]
    },
    "keywords": {
      "match": "\\b(if|else|while|return)\\b",
      "name": "keyword.control.omg"
    },
    "strings": {
      "begin": "\"",
      "end": "\"",
      "name": "string.quoted.double.omg",
      "patterns": [{ "include": "#escapes" }]
    }
  }
}

Core Concepts

  • scopeName: Unique identifier like source.js, text.html
  • patterns: Array of rules applied in order
  • repository: Named rule groups for reuse via #name
  • match: Single-line regex pattern
  • begin/end: Multi-line patterns with nested content

Scope Naming Conventions

PrefixUsage
keyword.controlif, else, for, return
keyword.operator+, -, =, &&
storage.typeclass, function, var
entity.name.functionfunction names
entity.name.typetype/class names
variable.parameterfunction parameters
string.quotedquoted strings
comment.linesingle-line comments
constant.numericnumbers
punctuation.definitionbrackets, braces

Key Patterns

  • Use captures to assign scopes to regex groups: "captures": { "1": { "name": "..." } }
  • Use contentName for scope of content between begin/end
  • Escape backslashes in JSON: \\b for word boundary
  • Order matters: first matching pattern wins