Skip to content

Commit 2b59ee2

Browse files
committed
Slightly rewrite Oniguruma indentation rules
1 parent b80b8b5 commit 2b59ee2

File tree

1 file changed

+49
-53
lines changed

1 file changed

+49
-53
lines changed

Package/Sublime Text Syntax Definition/Oniguruma RegExp Indentation Rules.tmPreferences

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,68 +8,64 @@
88
<dict>
99
<key>comment</key>
1010
<string>
11-
Indent any unclosed groups - open parens that don't have a corresponding closing paren on the same line.
12-
Unindent any closed groups - close parens that don't have a corresponding opening paren on the same line.
13-
Also apply to the `expect-regexp` meta scope, because otherwise a line like `- match: (?=\))` in a `.sublime-syntax` file would not have these rules applied to it because the `source.regexp` scope (correctly) doesn't cover the newline.
11+
Indent any unclosed groups
12+
(open paren that doesn't have a corresponding closing paren on the same line).
13+
14+
Unindent when a closing paren is the first non-whitespace character on a line.
15+
16+
Also apply to the `expect-regexp` meta scope,
17+
because otherwise a line like `- match: (?=\))` in a `.sublime-syntax` file
18+
would not have these rules applied to it
19+
because the `source.regexp` scope (correctly) doesn't cover the newline.
20+
1421
Parens inside comments (whether YAML or Regex) are ignored.
1522
</string>
1623
<key>indentParens</key>
1724
<false/>
1825
<key>increaseIndentPattern</key>
19-
<string><![CDATA[(?x)^
26+
<string><![CDATA[(?x)
27+
# define sub-expressions
2028
(?<not_paren>
21-
(?:
22-
[^\\()]++ # anything that isn't a slash or a paren
23-
| \\(?> # this is the "known_char_escape" variable from the syntax definition
24-
[tnrfae]
25-
| [0-7]{3}
26-
| x \h\h
27-
| x \{ \h{1,8} \}
28-
| c \d+
29-
| C- \d+
30-
| M- \d+
31-
| M-\\C- \d+
32-
)
33-
| \\. # a single escape character
29+
[^\\()]++ # anything that isn't a slash or a paren
30+
| \\(?> # this is the "known_char_escape" variable from the syntax definition
31+
[tnrfae]
32+
| [0-7]{3}
33+
| x \h\h
34+
| x \{ \h{1,8} \}
35+
| c \d+
36+
| C- \d+
37+
| M- \d+
38+
| M-\\C- \d+
39+
)
40+
| \\. # a single escape character
41+
){0}
42+
(?<group>
43+
\( # an open paren
44+
( # followed by either
45+
\g<not_paren> # ... anything that's not a group-related paren
46+
| \g<group> # ... or a parens group (recursive)
3447
)*+
35-
)
36-
(?<balanced_paren>(?:
37-
\( # an open paren
38-
\g<not_paren> # followed by anything that's not a group-related paren
39-
\g<balanced_paren> # followed by any number of nested parens
40-
\g<not_paren> # followed by anything that's not a group-related paren
41-
\) # a closing paren
42-
)*+)
43-
\g<not_paren> # followed by anything that's not a group-related paren
44-
\( # followed by an unbalanced open paren
48+
\) # a closing paren
49+
){0}
50+
(?<balanced_pattern>
51+
(
52+
\g<not_paren> # anything that's not a group-related paren
53+
| \g<group> # or a parens group (recursive)
54+
)*+
55+
){0}
56+
57+
# now the actual match
58+
^ # start at the beginning of the line
59+
\g<balanced_pattern> # the longest sequence of groups and non-group characters
60+
\( # followed by an unbalanced open paren
4561
]]></string>
4662
<key>decreaseIndentPattern</key>
47-
<string><![CDATA[(?x)^
48-
(?<not_paren>
49-
(?:
50-
[^\\()]++ # anything that isn't a slash or a paren
51-
| \\(?> # this is the "known_char_escape" variable from the syntax definition
52-
[tnrfae]
53-
| [0-7]{3}
54-
| x \h\h
55-
| x \{ \h{1,8} \}
56-
| c \d+
57-
| C- \d+
58-
| M- \d+
59-
| M-\\C- \d+
60-
)
61-
| \\. # a single escape character
62-
)*+
63-
)
64-
(?<balanced_paren>(?:
65-
\( # an open paren
66-
\g<not_paren> # followed by anything that's not a group-related paren
67-
\g<balanced_paren> # followed by any number of nested parens
68-
\g<not_paren> # followed by anything that's not a group-related paren
69-
\) # a closing paren
70-
)*+)
71-
\g<not_paren> # followed by anything that's not a group-related paren
72-
\) # followed by an unbalanced close paren
63+
<string><![CDATA[(?x)
64+
# decrease indentation (while typing)
65+
# if a closing paren is the first non-whitespace character on a line
66+
^
67+
\s*
68+
\)
7369
]]></string>
7470
</dict>
7571
</dict>

0 commit comments

Comments
 (0)