Skip to content

Commit ef3eb61

Browse files
vpetrovykh1st1
authored andcommitted
Update constant highlighting rules.
We consider something to be a "special constant" if it starts with "enough" (2 or more in this case) upper-case letters. Any leading underscores are ignored for the purpose of this definition. Also any number of underscores and digits are allowed in between the first 2 upper-case letters. To fully satisfy the requirement, the "leading" 2 upper-case letters must be followed by only upper-case letters or digits until the first underscore.
1 parent b75b17b commit ef3eb61

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed

Diff for: grammars/MagicPython.cson

+6-1
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,13 @@ repository:
437437
match: '''
438438
(?x)
439439
\\b
440+
# we want to see "enough", meaning 2 or more upper-case
441+
# letters in the beginning of the constant
442+
#
443+
# for more details refer to:
444+
# https://github.com/MagicStack/MagicPython/issues/42
440445
(
441-
_* [[:upper:]]{2}
446+
_* [[:upper:]] [_\\d]* [[:upper:]]
442447
)
443448
[[:upper:]\\d]* (_\\w*)?
444449
\\b

Diff for: grammars/MagicPython.tmLanguage

+6-1
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,13 @@
662662
<key>match</key>
663663
<string>(?x)
664664
\b
665+
# we want to see "enough", meaning 2 or more upper-case
666+
# letters in the beginning of the constant
667+
#
668+
# for more details refer to:
669+
# https://github.com/MagicStack/MagicPython/issues/42
665670
(
666-
_* [[:upper:]]{2}
671+
_* [[:upper:]] [_\d]* [[:upper:]]
667672
)
668673
[[:upper:]\d]* (_\w*)?
669674
\b

Diff for: grammars/src/MagicPython.syntax.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,13 @@ repository:
448448
match: |
449449
(?x)
450450
\b
451+
# we want to see "enough", meaning 2 or more upper-case
452+
# letters in the beginning of the constant
453+
#
454+
# for more details refer to:
455+
# https://github.com/MagicStack/MagicPython/issues/42
451456
(
452-
_* [[:upper:]]{2}
457+
_* [[:upper:]] [_\d]* [[:upper:]]
453458
)
454459
[[:upper:]\d]* (_\w*)?
455460
\b

Diff for: test/atom-spec/python-spec.js

+33
Original file line numberDiff line numberDiff line change
@@ -5025,6 +5025,39 @@ describe("Grammar Tests", function() {
50255025
expect(tokens[1][12].scopes).toEqual(["source.python"]);
50265026
});
50275027

5028+
it("test/expressions/const3.py",
5029+
function() {
5030+
tokens = grammar.tokenizeLines("T61STRING = 20\nT61_STRING\nT_STRING\n_T_S_T_R_I_N_G_\nA_CLASS\n\n# not enough upper-case letters in the beginning\n_T_s_TRING\nA_Class")
5031+
expect(tokens[0][0].value).toBe("T61STRING");
5032+
expect(tokens[0][0].scopes).toEqual(["source.python","constant.other.caps.python"]);
5033+
expect(tokens[0][1].value).toBe(" ");
5034+
expect(tokens[0][1].scopes).toEqual(["source.python"]);
5035+
expect(tokens[0][2].value).toBe("=");
5036+
expect(tokens[0][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]);
5037+
expect(tokens[0][3].value).toBe(" ");
5038+
expect(tokens[0][3].scopes).toEqual(["source.python"]);
5039+
expect(tokens[0][4].value).toBe("20");
5040+
expect(tokens[0][4].scopes).toEqual(["source.python","constant.numeric.dec.python"]);
5041+
expect(tokens[1][0].value).toBe("T61_STRING");
5042+
expect(tokens[1][0].scopes).toEqual(["source.python","constant.other.caps.python"]);
5043+
expect(tokens[2][0].value).toBe("T_STRING");
5044+
expect(tokens[2][0].scopes).toEqual(["source.python","constant.other.caps.python"]);
5045+
expect(tokens[3][0].value).toBe("_T_S_T_R_I_N_G_");
5046+
expect(tokens[3][0].scopes).toEqual(["source.python","constant.other.caps.python"]);
5047+
expect(tokens[4][0].value).toBe("A_CLASS");
5048+
expect(tokens[4][0].scopes).toEqual(["source.python","constant.other.caps.python"]);
5049+
expect(tokens[5][0].value).toBe("");
5050+
expect(tokens[5][0].scopes).toEqual(["source.python"]);
5051+
expect(tokens[6][0].value).toBe("#");
5052+
expect(tokens[6][0].scopes).toEqual(["source.python","comment.line.number-sign.python","punctuation.definition.comment.python"]);
5053+
expect(tokens[6][1].value).toBe(" not enough upper-case letters in the beginning");
5054+
expect(tokens[6][1].scopes).toEqual(["source.python","comment.line.number-sign.python"]);
5055+
expect(tokens[7][0].value).toBe("_T_s_TRING");
5056+
expect(tokens[7][0].scopes).toEqual(["source.python"]);
5057+
expect(tokens[8][0].value).toBe("A_Class");
5058+
expect(tokens[8][0].scopes).toEqual(["source.python"]);
5059+
});
5060+
50285061
it("test/expressions/expr1.py",
50295062
function() {
50305063
tokens = grammar.tokenizeLines("~a + b @ c ^ d // e % f & e and not g or h")

Diff for: test/expressions/const3.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
T61STRING = 20
2+
T61_STRING
3+
T_STRING
4+
_T_S_T_R_I_N_G_
5+
A_CLASS
6+
7+
# not enough upper-case letters in the beginning
8+
_T_s_TRING
9+
A_Class
10+
11+
12+
13+
14+
T61STRING : constant.other.caps.python, source.python
15+
: source.python
16+
= : keyword.operator.assignment.python, source.python
17+
: source.python
18+
20 : constant.numeric.dec.python, source.python
19+
T61_STRING : constant.other.caps.python, source.python
20+
T_STRING : constant.other.caps.python, source.python
21+
_T_S_T_R_I_N_G_ : constant.other.caps.python, source.python
22+
A_CLASS : constant.other.caps.python, source.python
23+
: source.python
24+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
25+
not enough upper-case letters in the beginning : comment.line.number-sign.python, source.python
26+
_T_s_TRING : source.python
27+
A_Class : source.python

0 commit comments

Comments
 (0)