-3

I don't understand how, in this example, the color is match with this regular expression.

name: logfile
scopeName: source.log
fileTypes:
- log
patterns:
- match: \b(ERROR|Error)\b
  name: constant.language.log
uuid: 8728e0fe-14c6-4374-acde-da1857d0a378
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • 1
    Your question is very unclear. Please [edit] it and add additional details. – MattDMo Oct 20 '14 at 15:33
  • In sublime text we can make our own highlight coloration with the package : AAAPackageDev. The coloration is based on regex detection. In this exemple i understand how the regex is built but not how the color is associated. – lachouille Oct 20 '14 at 15:36
  • Yes you can. And... ? – MattDMo Oct 20 '14 at 15:37
  • And i don't see how a color is associated with a regex. – lachouille Oct 20 '14 at 15:43
  • I saw this example in this [link](http://stackoverflow.com/questions/15221150/custom-syntax-highlighting-in-sublime-text-2) if it can be useful. – lachouille Oct 20 '14 at 16:00

1 Answers1

0

The YAML in your question is compiled by PackageDev into a .tmLanguage XML/Plist format. Each regex is associated with one or more scopes. A scope is essentially just a specific region in an editing buffer with a name, in this case constant.language.log. As buffers are modified, Sublime (and TextMate, where the idea originally came from) scans the text for matches to the regexes in the .tmLanguage syntax definition file, and names them appropriately. In this case, anywhere the word ERROR or Error appears on its own, it is assigned the constant.language.log scope.

The coloring comes from your color scheme, the .tmTheme file shown in your User Preferences. Color scheme files are also XML-based, but instead of containing regexes they contain scope selectors, similar to CSS selectors, if you are familiar with them. Each scope selector can be assigned a foreground color, a background color, and/or bold or italic text. So, for example, a color scheme may have the selector constant (which will match constant.language, constant.environment, etc.) and rules to color it purple and make the text bold and italic. Now, every time Sublime assigns the selector constant.* to a region, the color scheme will style that region according to its rules.

MattDMo
  • 100,794
  • 21
  • 241
  • 231