From 813ec8ca3683de09e08a22ec300a71feb735514b Mon Sep 17 00:00:00 2001 From: Victor Petrovykh Date: Thu, 10 Aug 2017 14:28:21 -0400 Subject: [PATCH] Clean-up the grammar so that MagicRegExp does not have missing rules. Thanks to @stoivo for noticing this issue. --- grammars/MagicPython.cson | 46 +++++----- grammars/MagicPython.tmLanguage | 98 +++++++++++----------- grammars/MagicRegExp.cson | 23 +++++ grammars/MagicRegExp.tmLanguage | 49 +++++++++++ grammars/src/MagicPython.syntax.yaml | 16 ---- grammars/src/regexp-common.inc.syntax.yaml | 16 ++++ test/atom-spec/python-re-spec.js | 17 ++++ test/regexp/comments3.re | 10 +++ 8 files changed, 187 insertions(+), 88 deletions(-) create mode 100644 test/regexp/comments3.re diff --git a/grammars/MagicPython.cson b/grammars/MagicPython.cson index efdd9583..568d9944 100644 --- a/grammars/MagicPython.cson +++ b/grammars/MagicPython.cson @@ -252,11 +252,6 @@ repository: captures: "1": name: "keyword.control.flow.python" - codetags: - match: "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)" - captures: - "1": - name: "keyword.codetag.notation.python" "statement-keyword": patterns: [ { @@ -988,24 +983,6 @@ repository: include: "#fstring-formatting-singe-brace" } ] - "fstring-formatting-braces": - patterns: [ - { - comment: "empty braces are illegal" - match: "({)(\\s*?)(})" - captures: - "1": - name: "constant.character.format.placeholder.other.python" - "2": - name: "invalid.illegal.brace.python" - "3": - name: "constant.character.format.placeholder.other.python" - } - { - name: "constant.character.escape.python" - match: "({{|}})" - } - ] "fstring-formatting-singe-brace": name: "invalid.illegal.brace.python" match: "(}(?!}))" @@ -1931,6 +1908,24 @@ repository: include: "#regexp-base-common" } ] + "fstring-formatting-braces": + patterns: [ + { + comment: "empty braces are illegal" + match: "({)(\\s*?)(})" + captures: + "1": + name: "constant.character.format.placeholder.other.python" + "2": + name: "invalid.illegal.brace.python" + "3": + name: "constant.character.format.placeholder.other.python" + } + { + name: "constant.character.escape.python" + match: "({{|}})" + } + ] "regexp-base-common": patterns: [ { @@ -2066,6 +2061,11 @@ repository: include: "#regexp-escape-catchall" } ] + codetags: + match: "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)" + captures: + "1": + name: "keyword.codetag.notation.python" "comments-base": name: "comment.line.number-sign.python" begin: "(\\#)" diff --git a/grammars/MagicPython.tmLanguage b/grammars/MagicPython.tmLanguage index 7291caf0..6545fbab 100644 --- a/grammars/MagicPython.tmLanguage +++ b/grammars/MagicPython.tmLanguage @@ -404,19 +404,6 @@ - codetags - - match - (?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b) - captures - - 1 - - name - keyword.codetag.notation.python - - - statement-keyword patterns @@ -1509,42 +1496,6 @@ - fstring-formatting-braces - - patterns - - - comment - empty braces are illegal - match - ({)(\s*?)(}) - captures - - 1 - - name - constant.character.format.placeholder.other.python - - 2 - - name - invalid.illegal.brace.python - - 3 - - name - constant.character.format.placeholder.other.python - - - - - name - constant.character.escape.python - match - ({{|}}) - - - fstring-formatting-singe-brace name @@ -2978,6 +2929,42 @@ indirectly through syntactic constructs + fstring-formatting-braces + + patterns + + + comment + empty braces are illegal + match + ({)(\s*?)(}) + captures + + 1 + + name + constant.character.format.placeholder.other.python + + 2 + + name + invalid.illegal.brace.python + + 3 + + name + constant.character.format.placeholder.other.python + + + + + name + constant.character.escape.python + match + ({{|}}) + + + regexp-base-common patterns @@ -3188,6 +3175,19 @@ indirectly through syntactic constructs + codetags + + match + (?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b) + captures + + 1 + + name + keyword.codetag.notation.python + + + comments-base name diff --git a/grammars/MagicRegExp.cson b/grammars/MagicRegExp.cson index 69e0c300..175b80f6 100644 --- a/grammars/MagicRegExp.cson +++ b/grammars/MagicRegExp.cson @@ -35,6 +35,24 @@ repository: include: "#regexp-base-common" } ] + "fstring-formatting-braces": + patterns: [ + { + comment: "empty braces are illegal" + match: "({)(\\s*?)(})" + captures: + "1": + name: "constant.character.format.placeholder.other.python" + "2": + name: "invalid.illegal.brace.python" + "3": + name: "constant.character.format.placeholder.other.python" + } + { + name: "constant.character.escape.python" + match: "({{|}})" + } + ] "regexp-base-common": patterns: [ { @@ -170,6 +188,11 @@ repository: include: "#regexp-escape-catchall" } ] + codetags: + match: "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)" + captures: + "1": + name: "keyword.codetag.notation.python" "regexp-expression": patterns: [ { diff --git a/grammars/MagicRegExp.tmLanguage b/grammars/MagicRegExp.tmLanguage index 3bc9d48e..3d19e058 100644 --- a/grammars/MagicRegExp.tmLanguage +++ b/grammars/MagicRegExp.tmLanguage @@ -58,6 +58,42 @@ + fstring-formatting-braces + + patterns + + + comment + empty braces are illegal + match + ({)(\s*?)(}) + captures + + 1 + + name + constant.character.format.placeholder.other.python + + 2 + + name + invalid.illegal.brace.python + + 3 + + name + constant.character.format.placeholder.other.python + + + + + name + constant.character.escape.python + match + ({{|}}) + + + regexp-base-common patterns @@ -268,6 +304,19 @@ + codetags + + match + (?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b) + captures + + 1 + + name + keyword.codetag.notation.python + + + regexp-expression patterns diff --git a/grammars/src/MagicPython.syntax.yaml b/grammars/src/MagicPython.syntax.yaml index f39918b8..2c31e243 100644 --- a/grammars/src/MagicPython.syntax.yaml +++ b/grammars/src/MagicPython.syntax.yaml @@ -351,11 +351,6 @@ repository: captures: '1': {name: keyword.control.flow.python} - codetags: - match: (?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b) - captures: - '1': {name: keyword.codetag.notation.python} - statement-keyword: patterns: - name: storage.type.function.python @@ -824,17 +819,6 @@ repository: - include: '#fstring-formatting-braces' - include: '#fstring-formatting-singe-brace' - fstring-formatting-braces: - patterns: - - comment: empty braces are illegal - match: ({)(\s*?)(}) - captures: - '1': {name: constant.character.format.placeholder.other.python} - '2': {name: invalid.illegal.brace.python} - '3': {name: constant.character.format.placeholder.other.python} - - name: constant.character.escape.python - match: ({{|}}) - fstring-formatting-singe-brace: name: invalid.illegal.brace.python match: (}(?!})) diff --git a/grammars/src/regexp-common.inc.syntax.yaml b/grammars/src/regexp-common.inc.syntax.yaml index d7b02061..e367af87 100644 --- a/grammars/src/regexp-common.inc.syntax.yaml +++ b/grammars/src/regexp-common.inc.syntax.yaml @@ -12,6 +12,17 @@ repository: - match: \{.*?\} - include: '#regexp-base-common' + fstring-formatting-braces: + patterns: + - comment: empty braces are illegal + match: ({)(\s*?)(}) + captures: + '1': {name: constant.character.format.placeholder.other.python} + '2': {name: invalid.illegal.brace.python} + '3': {name: constant.character.format.placeholder.other.python} + - name: constant.character.escape.python + match: ({{|}}) + regexp-base-common: patterns: - name: support.other.match.any.regexp @@ -109,4 +120,9 @@ repository: - include: '#regexp-escape-character' - include: '#regexp-escape-unicode' - include: '#regexp-escape-catchall' + + codetags: + match: (?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b) + captures: + '1': {name: keyword.codetag.notation.python} ... diff --git a/test/atom-spec/python-re-spec.js b/test/atom-spec/python-re-spec.js index 5a5557c5..2874e777 100644 --- a/test/atom-spec/python-re-spec.js +++ b/test/atom-spec/python-re-spec.js @@ -56,6 +56,23 @@ describe("Grammar Tests", function() { expect(tokens[4][3].scopes).toEqual(["source.regexp.python","comment.regexp","punctuation.comment.end.regexp"]); }); + it("test/regexp/comments3.re", + function() { + tokens = grammar.tokenizeLines("foo(?#NOTE:comment)bar") + expect(tokens[0][0].value).toBe("foo"); + expect(tokens[0][0].scopes).toEqual(["source.regexp.python"]); + expect(tokens[0][1].value).toBe("(?#"); + expect(tokens[0][1].scopes).toEqual(["source.regexp.python","comment.regexp","punctuation.comment.begin.regexp"]); + expect(tokens[0][2].value).toBe("NOTE"); + expect(tokens[0][2].scopes).toEqual(["source.regexp.python","comment.regexp","keyword.codetag.notation.python"]); + expect(tokens[0][3].value).toBe(":comment"); + expect(tokens[0][3].scopes).toEqual(["source.regexp.python","comment.regexp"]); + expect(tokens[0][4].value).toBe(")"); + expect(tokens[0][4].scopes).toEqual(["source.regexp.python","comment.regexp","punctuation.comment.end.regexp"]); + expect(tokens[0][5].value).toBe("bar"); + expect(tokens[0][5].scopes).toEqual(["source.regexp.python"]); + }); + it("test/regexp/conditional1.re", function() { tokens = grammar.tokenizeLines("(<)?(\\w+@\\w+(?:\\.\\w+)+)(?(1)>|$)") diff --git a/test/regexp/comments3.re b/test/regexp/comments3.re new file mode 100644 index 00000000..8f1cb962 --- /dev/null +++ b/test/regexp/comments3.re @@ -0,0 +1,10 @@ +foo(?#NOTE:comment)bar + + + +foo : source.regexp.python +(?# : comment.regexp, punctuation.comment.begin.regexp, source.regexp.python +NOTE : comment.regexp, keyword.codetag.notation.python, source.regexp.python +:comment : comment.regexp, source.regexp.python +) : comment.regexp, punctuation.comment.end.regexp, source.regexp.python +bar : source.regexp.python