python-regex.json 4.3 KB
Newer Older
P
Phodal Huang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
{
	"comment": "Matches Python's regular expression syntax.",
	"fileTypes": [
		"re"
	],
	"foldingStartMarker": "(/\\*|\\{|\\()",
	"foldingStopMarker": "(\\*/|\\}|\\))",
	"name": "Regular Expressions (Python)",
	"patterns": [
		{
			"match": "\\\\[bBAZzG]|\\^|\\$",
			"name": "keyword.control.anchor.regexp"
		},
		{
			"match": "\\\\[1-9][0-9]?",
			"name": "keyword.other.back-reference.regexp"
		},
		{
			"match": "[?+*][?+]?|\\{(\\d+,\\d+|\\d+,|,\\d+|\\d+)\\}\\??",
			"name": "keyword.operator.quantifier.regexp"
		},
		{
			"match": "\\|",
			"name": "keyword.operator.or.regexp"
		},
		{
			"begin": "\\(\\?\\#",
			"end": "\\)",
			"name": "comment.block.regexp"
		},
		{
			"comment": "We are restrictive in what we allow to go after the comment character to avoid false positives, since the availability of comments depend on regexp flags.",
			"match": "(?<=^|\\s)#\\s[[a-zA-Z0-9,. \\t?!-:][^\\x{00}-\\x{7F}]]*$",
			"name": "comment.line.number-sign.regexp"
		},
		{
			"match": "\\(\\?[iLmsux]+\\)",
			"name": "keyword.other.option-toggle.regexp"
		},
		{
			"match": "(\\()(\\?P=([a-zA-Z_][a-zA-Z_0-9]*\\w*))(\\))",
			"name": "keyword.other.back-reference.named.regexp"
		},
		{
			"begin": "(\\()((\\?=)|(\\?!)|(\\?<=)|(\\?<!))",
			"beginCaptures": {
				"1": {
					"name": "punctuation.definition.group.regexp"
				},
				"2": {
					"name": "punctuation.definition.group.assertion.regexp"
				},
				"3": {
					"name": "meta.assertion.look-ahead.regexp"
				},
				"4": {
					"name": "meta.assertion.negative-look-ahead.regexp"
				},
				"5": {
					"name": "meta.assertion.look-behind.regexp"
				},
				"6": {
					"name": "meta.assertion.negative-look-behind.regexp"
				}
			},
			"end": "(\\))",
			"endCaptures": {
				"1": {
					"name": "punctuation.definition.group.regexp"
				}
			},
			"name": "meta.group.assertion.regexp",
			"patterns": [
				{
					"include": "$self"
				}
			]
		},
		{
			"begin": "(\\()(\\?\\(([1-9][0-9]?|[a-zA-Z_][a-zA-Z_0-9]*)\\))",
			"beginCaptures": {
				"1": {
					"name": "punctuation.definition.group.regexp"
				},
				"2": {
					"name": "punctuation.definition.group.assertion.conditional.regexp"
				},
				"3": {
					"name": "entity.name.section.back-reference.regexp"
				}
			},
			"comment": "we can make this more sophisticated to match the | character that separates yes-pattern from no-pattern, but it's not really necessary.",
			"end": "(\\))",
			"name": "meta.group.assertion.conditional.regexp",
			"patterns": [
				{
					"include": "$self"
				}
			]
		},
		{
			"begin": "(\\()((\\?P<)([a-z]\\w*)(>)|(\\?:))?",
			"beginCaptures": {
				"1": {
					"name": "punctuation.definition.group.regexp"
				},
				"3": {
					"name": "punctuation.definition.group.capture.regexp"
				},
				"4": {
					"name": "entity.name.section.group.regexp"
				},
				"5": {
					"name": "punctuation.definition.group.capture.regexp"
				},
				"6": {
					"name": "punctuation.definition.group.no-capture.regexp"
				}
			},
			"end": "(\\))",
			"endCaptures": {
				"1": {
					"name": "punctuation.definition.group.regexp"
				}
			},
			"name": "meta.group.regexp",
			"patterns": [
				{
					"include": "$self"
				}
			]
		},
		{
			"include": "#character-class"
		}
	],
	"repository": {
		"character-class": {
			"patterns": [
				{
					"match": "\\\\[wWsSdDhH]|\\.",
					"name": "constant.character.character-class.regexp"
				},
				{
					"match": "\\\\.",
					"name": "constant.character.escape.backslash.regexp"
				},
				{
					"begin": "(\\[)(\\^)?",
					"beginCaptures": {
						"1": {
							"name": "punctuation.definition.character-class.regexp"
						},
						"2": {
							"name": "keyword.operator.negation.regexp"
						}
					},
					"end": "(\\])",
					"endCaptures": {
						"1": {
							"name": "punctuation.definition.character-class.regexp"
						}
					},
					"name": "constant.other.character-class.set.regexp",
					"patterns": [
						{
							"include": "#character-class"
						},
						{
							"captures": {
								"2": {
									"name": "constant.character.escape.backslash.regexp"
								},
								"4": {
									"name": "constant.character.escape.backslash.regexp"
								}
							},
							"match": "((\\\\.)|.)\\-((\\\\.)|[^\\]])",
							"name": "constant.other.character-class.range.regexp"
						}
					]
				}
			]
		}
	},
	"scopeName": "source.regexp.python"
}