textmate
April 6, 2018 · View on GitHub
TextMate Language Grammars
name- This should be a unique name for the grammar, following the convention of being a dot-separated name where each new (left-most) part specializes the name.
- Normally it would be a two-part name where the first is either
textorsourceand the second is the name of the language or document type. - But if you are specializing an existing type, you probably want to derive the name from the type you are specializing.
scopeName- This should be a unique name for the grammar.
fileTypes- This is an array of file type extensions that the grammar should (by default) be used with.
firstLineMatch- A regular expression which is matched against the first line of the document (when it is first loaded).
patterns- An array with the actual rules used to parse the document.
repository- A dictionary (i.e. key/value pairs) of rules which can be included from other places in the grammar.
- The key is the name of the rule and the value is the actual rule.
name- The name which gets assigned to the portion matched.
- This is used for styling and scope-specific settings and actions, which means it should generally be derived from one of the standard names.
match- A regular expression which is used to identify the portion of text to which the
nameshould be assigned. - Example: '\b(true|false)\b'.
- A regular expression which is used to identify the portion of text to which the
begin,end- These keys allow matches which span several lines and must both be mutually exclusive with the
matchkey. - Each is a regular expression pattern.
beginis the pattern that starts the block andendis the pattern which ends the block. - Captures from the
beginpattern can be referenced in theendpattern by using normal regular expression back-references.
- These keys allow matches which span several lines and must both be mutually exclusive with the
contentName- This key is similar to the
namekey but only assigns thenameto the text between what is matched by thebegin/endpatterns.
- This key is similar to the
captures,beginCaptures,endCaptures- These keys allow you to assign attributes to the captures of the
match,begin, orendpatterns. - Using the captures key for a
begin/endrule is short-hand for giving bothbeginCapturesandendCaptureswith same values. - The value of these keys is a dictionary with the key being the capture number and the value being a dictionary of attributes to assign to the captured text.
- Currently
nameis the only attribute supported.
- These keys allow you to assign attributes to the captures of the
include- This allows you to reference a different language, recursively reference the grammar itself or a rule declared in this file’s
repository.
- This allows you to reference a different language, recursively reference the grammar itself or a rule declared in this file’s