From db32a0d840b3a44d03596e31a4d5a936d99a8d8a Mon Sep 17 00:00:00 2001 From: Victor Petrovykh Date: Fri, 31 Jul 2020 05:08:47 -0400 Subject: [PATCH 1/3] Add Python 3.8 features. Add walrus operator `:=`. Add positional only args separator `/`. Add `=` to f-string formatting. Fixes #189 --- grammars/MagicPython.cson | 32 +++- grammars/MagicPython.tmLanguage | 43 ++++- grammars/src/MagicPython.syntax.yaml | 7 + grammars/src/pyfstring.inc.syntax.yaml | 8 +- misc/example.py | 12 +- misc/scopes | 1 + test/atom-spec/python-spec.js | 228 +++++++++++++++++++++++++ test/expressions/expr21.py | 39 +++++ test/fstrings/simple10.py | 18 ++ test/functions/decl15.py | 34 ++++ test/functions/lambda10.py | 35 ++++ 11 files changed, 439 insertions(+), 18 deletions(-) create mode 100644 test/expressions/expr21.py create mode 100644 test/fstrings/simple10.py create mode 100644 test/functions/decl15.py create mode 100644 test/functions/lambda10.py diff --git a/grammars/MagicPython.cson b/grammars/MagicPython.cson index 6486dba4..b137f776 100644 --- a/grammars/MagicPython.cson +++ b/grammars/MagicPython.cson @@ -619,6 +619,8 @@ repository: | (!= | == | >= | <= | < | >) (?# 5) + | (:=) (?# 6) + ''' captures: "1": @@ -631,6 +633,8 @@ repository: name: "keyword.operator.arithmetic.python" "5": name: "keyword.operator.comparison.python" + "6": + name: "keyword.operator.assignment.python" punctuation: patterns: [ { @@ -1255,6 +1259,10 @@ repository: name: "punctuation.section.function.lambda.begin.python" contentName: "meta.function.lambda.parameters.python" patterns: [ + { + name: "keyword.operator.positional.parameter.python" + match: "/" + } { name: "keyword.operator.unpacking.parameter.python" match: "(\\*\\*|\\*)" @@ -1402,6 +1410,10 @@ repository: "1": name: "punctuation.definition.parameters.end.python" patterns: [ + { + name: "keyword.operator.positional.parameter.python" + match: "/" + } { name: "keyword.operator.unpacking.parameter.python" match: "(\\*\\*|\\*)" @@ -4720,12 +4732,16 @@ repository: patterns: [ { name: "storage.type.format.python" - match: "(![rsa])(?=})" + match: "(=(![rsa])?)(?=})" + } + { + name: "storage.type.format.python" + match: "(=?![rsa])(?=})" } { match: ''' (?x) - (![rsa])? + ( (?: =?) (?: ![rsa])? ) ( : \\w? [<>=^]? [-+ ]? \\#? \\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )(?=}) @@ -4741,7 +4757,7 @@ repository: } ] "fstring-terminator-single-tail": - begin: "(![rsa])?(:)(?=.*?{)" + begin: "((?:=?)(?:![rsa])?)(:)(?=.*?{)" end: "(?=})|(?=\\n)" beginCaptures: "1": @@ -4944,12 +4960,16 @@ repository: patterns: [ { name: "storage.type.format.python" - match: "(![rsa])(?=})" + match: "(=(![rsa])?)(?=})" + } + { + name: "storage.type.format.python" + match: "(=?![rsa])(?=})" } { match: ''' (?x) - (![rsa])? + ( (?: =?) (?: ![rsa])? ) ( : \\w? [<>=^]? [-+ ]? \\#? \\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )(?=}) @@ -4965,7 +4985,7 @@ repository: } ] "fstring-terminator-multi-tail": - begin: "(![rsa])?(:)(?=.*?{)" + begin: "((?:=?)(?:![rsa])?)(:)(?=.*?{)" end: "(?=})" beginCaptures: "1": diff --git a/grammars/MagicPython.tmLanguage b/grammars/MagicPython.tmLanguage index 5a07f545..a4f973df 100644 --- a/grammars/MagicPython.tmLanguage +++ b/grammars/MagicPython.tmLanguage @@ -933,6 +933,8 @@ E.g. "arr[idx](args)" | (\*\* | \* | \+ | - | % | // | / | @) (?# 4) | (!= | == | >= | <= | < | >) (?# 5) + + | (:=) (?# 6) captures @@ -961,6 +963,11 @@ E.g. "arr[idx](args)" name keyword.operator.comparison.python + 6 + + name + keyword.operator.assignment.python + punctuation @@ -1936,6 +1943,12 @@ E.g. "arr[idx](args)" meta.function.lambda.parameters.python patterns + + name + keyword.operator.positional.parameter.python + match + / + name keyword.operator.unpacking.parameter.python @@ -2184,6 +2197,12 @@ correctly identify the "in" as a control flow keyword. patterns + + name + keyword.operator.positional.parameter.python + match + / + name keyword.operator.unpacking.parameter.python @@ -8259,12 +8278,18 @@ indirectly through syntactic constructs name storage.type.format.python match - (![rsa])(?=}) + (=(![rsa])?)(?=}) + + + name + storage.type.format.python + match + (=?![rsa])(?=}) match (?x) - (![rsa])? + ( (?: =?) (?: ![rsa])? ) ( : \w? [<>=^]? [-+ ]? \#? \d* ,? (\.\d+)? [bcdeEfFgGnosxX%]? )(?=}) @@ -8291,7 +8316,7 @@ indirectly through syntactic constructs fstring-terminator-single-tail begin - (![rsa])?(:)(?=.*?{) + ((?:=?)(?:![rsa])?)(:)(?=.*?{) end (?=})|(?=\n) beginCaptures @@ -8631,12 +8656,18 @@ indirectly through syntactic constructs name storage.type.format.python match - (![rsa])(?=}) + (=(![rsa])?)(?=}) + + + name + storage.type.format.python + match + (=?![rsa])(?=}) match (?x) - (![rsa])? + ( (?: =?) (?: ![rsa])? ) ( : \w? [<>=^]? [-+ ]? \#? \d* ,? (\.\d+)? [bcdeEfFgGnosxX%]? )(?=}) @@ -8663,7 +8694,7 @@ indirectly through syntactic constructs fstring-terminator-multi-tail begin - (![rsa])?(:)(?=.*?{) + ((?:=?)(?:![rsa])?)(:)(?=.*?{) end (?=}) beginCaptures diff --git a/grammars/src/MagicPython.syntax.yaml b/grammars/src/MagicPython.syntax.yaml index 9c80c8b3..83948dc1 100644 --- a/grammars/src/MagicPython.syntax.yaml +++ b/grammars/src/MagicPython.syntax.yaml @@ -582,12 +582,15 @@ repository: | (!= | == | >= | <= | < | >) (?# 5) + | (:=) (?# 6) + captures: '1': {name: keyword.operator.logical.python} '2': {name: keyword.control.flow.python} '3': {name: keyword.operator.bitwise.python} '4': {name: keyword.operator.arithmetic.python} '5': {name: keyword.operator.comparison.python} + '6': {name: keyword.operator.assignment.python} punctuation: patterns: @@ -1002,6 +1005,8 @@ repository: contentName: meta.function.lambda.parameters.python patterns: + - name: keyword.operator.positional.parameter.python + match: / - name: keyword.operator.unpacking.parameter.python match: (\*\*|\*) - include: '#lambda-nested-incomplete' @@ -1096,6 +1101,8 @@ repository: '1': {name: punctuation.definition.parameters.end.python} patterns: + - name: keyword.operator.positional.parameter.python + match: / - name: keyword.operator.unpacking.parameter.python match: (\*\*|\*) - include: '#lambda-incomplete' diff --git a/grammars/src/pyfstring.inc.syntax.yaml b/grammars/src/pyfstring.inc.syntax.yaml index 993707cf..e605f17c 100644 --- a/grammars/src/pyfstring.inc.syntax.yaml +++ b/grammars/src/pyfstring.inc.syntax.yaml @@ -127,10 +127,12 @@ fstring-${line}-brace: fstring-terminator-${line}: patterns: - name: storage.type.format.python - match: (![rsa])(?=}) + match: (=(![rsa])?)(?=}) + - name: storage.type.format.python + match: (=?![rsa])(?=}) - match: | (?x) - (![rsa])? + ( (?: =?) (?: ![rsa])? ) ( : \w? [<>=^]? [-+ ]? \#? \d* ,? (\.\d+)? [bcdeEfFgGnosxX%]? )(?=}) captures: @@ -148,7 +150,7 @@ fstring-terminator-${line}: - include: '#fstring-terminator-${line}-tail' fstring-terminator-${line}-tail: - begin: (![rsa])?(:)(?=.*?{) + begin: ((?:=?)(?:![rsa])?)(:)(?=.*?{) end: (?=})${fguard} beginCaptures: '1': {name: storage.type.format.python} diff --git a/misc/example.py b/misc/example.py index 6b820e63..e6ea7ad0 100644 --- a/misc/example.py +++ b/misc/example.py @@ -1,7 +1,7 @@ import asyncio -def showcase(): +def showcase(a, b, /, c, d, *, e, f): """Some code to showcase the syntax. Docstrings are recognized and have an additional scope. @@ -21,7 +21,7 @@ async def coroutine(db:aio_db.DatabaseConnection) -> List[str]: async with db.transaction(): result = await db.query(...) - print(f'Result: {result!r}') + print(f'Result: {result!r} {a=} {b=!r}') mapping = None # type: Dict[int, Any] # PEP 484 @@ -41,8 +41,14 @@ async def coroutine(db:aio_db.DatabaseConnection) -> List[str]: # NOTE Numbers with leading zeros are invalid in Python 3, # use 0o... answer = func(0xdeadbeef + 0b00100001 + 0123 + 0o123 + - 1_005_123 + # PEP 515 + 1_005_123 + # PEP 515 # complex numbers .10e12 + 2j) @ mat + # walrus operator + filtered_data = [y for x in data if (y := f(x)) is not None] + + # position-only params + bar = lambda q, w, /, e, r: (q + w + e + r) + return R'''No escapes '\' in this \one''' diff --git a/misc/scopes b/misc/scopes index 12785af1..8eec651e 100644 --- a/misc/scopes +++ b/misc/scopes @@ -56,6 +56,7 @@ keyword.operator.lookahead.regexp keyword.operator.lookbehind.negative.regexp keyword.operator.lookbehind.regexp keyword.operator.negation.regexp +keyword.operator.positional.parameter.python keyword.operator.python keyword.operator.quantifier.regexp keyword.operator.unpacking.arguments.python diff --git a/test/atom-spec/python-spec.js b/test/atom-spec/python-spec.js index 032c3682..da7d08c1 100644 --- a/test/atom-spec/python-spec.js +++ b/test/atom-spec/python-spec.js @@ -5800,6 +5800,77 @@ describe("Grammar Tests", function() { expect(tokens[5][4].scopes).toEqual(["source.python"]); }); + it("test/expressions/expr21.py", + function() { + tokens = grammar.tokenizeLines("while chunk := file.read(8192):\n process(chunk)\n y0 = (y1 := f(x))") + expect(tokens[0][0].value).toBe("while"); + expect(tokens[0][0].scopes).toEqual(["source.python","keyword.control.flow.python"]); + expect(tokens[0][1].value).toBe(" "); + expect(tokens[0][1].scopes).toEqual(["source.python"]); + expect(tokens[0][2].value).toBe("chunk"); + expect(tokens[0][2].scopes).toEqual(["source.python"]); + expect(tokens[0][3].value).toBe(" "); + expect(tokens[0][3].scopes).toEqual(["source.python"]); + expect(tokens[0][4].value).toBe(":="); + expect(tokens[0][4].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[0][5].value).toBe(" "); + expect(tokens[0][5].scopes).toEqual(["source.python"]); + expect(tokens[0][6].value).toBe("file"); + expect(tokens[0][6].scopes).toEqual(["source.python","variable.legacy.builtin.python"]); + expect(tokens[0][7].value).toBe("."); + expect(tokens[0][7].scopes).toEqual(["source.python","meta.member.access.python","punctuation.separator.period.python"]); + expect(tokens[0][8].value).toBe("read"); + expect(tokens[0][8].scopes).toEqual(["source.python","meta.member.access.python","meta.function-call.python","meta.function-call.generic.python"]); + expect(tokens[0][9].value).toBe("("); + expect(tokens[0][9].scopes).toEqual(["source.python","meta.member.access.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]); + expect(tokens[0][10].value).toBe("8192"); + expect(tokens[0][10].scopes).toEqual(["source.python","meta.member.access.python","meta.function-call.python","meta.function-call.arguments.python","constant.numeric.dec.python"]); + expect(tokens[0][11].value).toBe(")"); + expect(tokens[0][11].scopes).toEqual(["source.python","meta.member.access.python","meta.function-call.python","punctuation.definition.arguments.end.python"]); + expect(tokens[0][12].value).toBe(":"); + expect(tokens[0][12].scopes).toEqual(["source.python","punctuation.separator.colon.python"]); + expect(tokens[1][0].value).toBe(" "); + expect(tokens[1][0].scopes).toEqual(["source.python"]); + expect(tokens[1][1].value).toBe("process"); + expect(tokens[1][1].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.generic.python"]); + expect(tokens[1][2].value).toBe("("); + expect(tokens[1][2].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]); + expect(tokens[1][3].value).toBe("chunk"); + expect(tokens[1][3].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]); + expect(tokens[1][4].value).toBe(")"); + expect(tokens[1][4].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.end.python"]); + expect(tokens[2][0].value).toBe(" "); + expect(tokens[2][0].scopes).toEqual(["source.python"]); + expect(tokens[2][1].value).toBe("y0"); + expect(tokens[2][1].scopes).toEqual(["source.python"]); + expect(tokens[2][2].value).toBe(" "); + expect(tokens[2][2].scopes).toEqual(["source.python"]); + expect(tokens[2][3].value).toBe("="); + expect(tokens[2][3].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[2][4].value).toBe(" "); + expect(tokens[2][4].scopes).toEqual(["source.python"]); + expect(tokens[2][5].value).toBe("("); + expect(tokens[2][5].scopes).toEqual(["source.python","punctuation.parenthesis.begin.python"]); + expect(tokens[2][6].value).toBe("y1"); + expect(tokens[2][6].scopes).toEqual(["source.python"]); + expect(tokens[2][7].value).toBe(" "); + expect(tokens[2][7].scopes).toEqual(["source.python"]); + expect(tokens[2][8].value).toBe(":="); + expect(tokens[2][8].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[2][9].value).toBe(" "); + expect(tokens[2][9].scopes).toEqual(["source.python"]); + expect(tokens[2][10].value).toBe("f"); + expect(tokens[2][10].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.generic.python"]); + expect(tokens[2][11].value).toBe("("); + expect(tokens[2][11].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]); + expect(tokens[2][12].value).toBe("x"); + expect(tokens[2][12].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]); + expect(tokens[2][13].value).toBe(")"); + expect(tokens[2][13].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.end.python"]); + expect(tokens[2][14].value).toBe(")"); + expect(tokens[2][14].scopes).toEqual(["source.python","punctuation.parenthesis.end.python"]); + }); + it("test/expressions/expr3.py", function() { tokens = grammar.tokenizeLines("(a, *rest, b) = range(5)") @@ -7490,6 +7561,37 @@ describe("Grammar Tests", function() { expect(tokens[2][20].scopes).toEqual(["source.python","comment.line.number-sign.python"]); }); + it("test/fstrings/simple10.py", + function() { + tokens = grammar.tokenizeLines("f'values: {a=} {b=!r}'") + expect(tokens[0][0].value).toBe("f"); + expect(tokens[0][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.single.python string.interpolated.python"]); + expect(tokens[0][1].value).toBe("'"); + expect(tokens[0][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.single.python string.interpolated.python punctuation.definition.string.begin.python"]); + expect(tokens[0][2].value).toBe("values: "); + expect(tokens[0][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.single.python string.interpolated.python"]); + expect(tokens[0][3].value).toBe("{"); + expect(tokens[0][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][4].value).toBe("a"); + expect(tokens[0][4].scopes).toEqual(["source.python","meta.fstring.python"]); + expect(tokens[0][5].value).toBe("="); + expect(tokens[0][5].scopes).toEqual(["source.python","meta.fstring.python","storage.type.format.python"]); + expect(tokens[0][6].value).toBe("}"); + expect(tokens[0][6].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][7].value).toBe(" "); + expect(tokens[0][7].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.single.python string.interpolated.python"]); + expect(tokens[0][8].value).toBe("{"); + expect(tokens[0][8].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][9].value).toBe("b"); + expect(tokens[0][9].scopes).toEqual(["source.python","meta.fstring.python"]); + expect(tokens[0][10].value).toBe("=!r"); + expect(tokens[0][10].scopes).toEqual(["source.python","meta.fstring.python","storage.type.format.python"]); + expect(tokens[0][11].value).toBe("}"); + expect(tokens[0][11].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][12].value).toBe("'"); + expect(tokens[0][12].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.single.python string.interpolated.python punctuation.definition.string.end.python"]); + }); + it("test/fstrings/simple2.py", function() { tokens = grammar.tokenizeLines("a = f\"normal {{ normal }} normal } {10!r} normal {fo.__add__!s}\"") @@ -8501,6 +8603,67 @@ describe("Grammar Tests", function() { expect(tokens[14][9].scopes).toEqual(["source.python","constant.numeric.dec.python"]); }); + it("test/functions/decl15.py", + function() { + tokens = grammar.tokenizeLines("def showcase(a, b, /, c, d, *, e, f):\n return") + expect(tokens[0][0].value).toBe("def"); + expect(tokens[0][0].scopes).toEqual(["source.python","meta.function.python","storage.type.function.python"]); + expect(tokens[0][1].value).toBe(" "); + expect(tokens[0][1].scopes).toEqual(["source.python","meta.function.python"]); + expect(tokens[0][2].value).toBe("showcase"); + expect(tokens[0][2].scopes).toEqual(["source.python","meta.function.python","entity.name.function.python"]); + expect(tokens[0][3].value).toBe("("); + expect(tokens[0][3].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.definition.parameters.begin.python"]); + expect(tokens[0][4].value).toBe("a"); + expect(tokens[0][4].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","variable.parameter.function.language.python"]); + expect(tokens[0][5].value).toBe(","); + expect(tokens[0][5].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.separator.parameters.python"]); + expect(tokens[0][6].value).toBe(" "); + expect(tokens[0][6].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python"]); + expect(tokens[0][7].value).toBe("b"); + expect(tokens[0][7].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","variable.parameter.function.language.python"]); + expect(tokens[0][8].value).toBe(","); + expect(tokens[0][8].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.separator.parameters.python"]); + expect(tokens[0][9].value).toBe(" "); + expect(tokens[0][9].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python"]); + expect(tokens[0][10].value).toBe("/"); + expect(tokens[0][10].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","keyword.operator.positional.parameter.python"]); + expect(tokens[0][11].value).toBe(", "); + expect(tokens[0][11].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python"]); + expect(tokens[0][12].value).toBe("c"); + expect(tokens[0][12].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","variable.parameter.function.language.python"]); + expect(tokens[0][13].value).toBe(","); + expect(tokens[0][13].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.separator.parameters.python"]); + expect(tokens[0][14].value).toBe(" "); + expect(tokens[0][14].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python"]); + expect(tokens[0][15].value).toBe("d"); + expect(tokens[0][15].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","variable.parameter.function.language.python"]); + expect(tokens[0][16].value).toBe(","); + expect(tokens[0][16].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.separator.parameters.python"]); + expect(tokens[0][17].value).toBe(" "); + expect(tokens[0][17].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python"]); + expect(tokens[0][18].value).toBe("*"); + expect(tokens[0][18].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","keyword.operator.unpacking.parameter.python"]); + expect(tokens[0][19].value).toBe(", "); + expect(tokens[0][19].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python"]); + expect(tokens[0][20].value).toBe("e"); + expect(tokens[0][20].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","variable.parameter.function.language.python"]); + expect(tokens[0][21].value).toBe(","); + expect(tokens[0][21].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.separator.parameters.python"]); + expect(tokens[0][22].value).toBe(" "); + expect(tokens[0][22].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python"]); + expect(tokens[0][23].value).toBe("f"); + expect(tokens[0][23].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","variable.parameter.function.language.python"]); + expect(tokens[0][24].value).toBe(")"); + expect(tokens[0][24].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.definition.parameters.end.python"]); + expect(tokens[0][25].value).toBe(":"); + expect(tokens[0][25].scopes).toEqual(["source.python","meta.function.python","punctuation.section.function.begin.python"]); + expect(tokens[1][0].value).toBe(" "); + expect(tokens[1][0].scopes).toEqual(["source.python"]); + expect(tokens[1][1].value).toBe("return"); + expect(tokens[1][1].scopes).toEqual(["source.python","keyword.control.flow.python"]); + }); + it("test/functions/decl2.py", function() { tokens = grammar.tokenizeLines("def result_annot(lambda, lambda=) -> qqq[None]:\n pass") @@ -9632,6 +9795,71 @@ describe("Grammar Tests", function() { expect(tokens[1][3].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.end.python"]); }); + it("test/functions/lambda10.py", + function() { + tokens = grammar.tokenizeLines("showcase = lambda a, /, b, *, c: (a + b + c)") + expect(tokens[0][0].value).toBe("showcase"); + expect(tokens[0][0].scopes).toEqual(["source.python"]); + expect(tokens[0][1].value).toBe(" "); + expect(tokens[0][1].scopes).toEqual(["source.python"]); + expect(tokens[0][2].value).toBe("="); + expect(tokens[0][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[0][3].value).toBe(" "); + expect(tokens[0][3].scopes).toEqual(["source.python"]); + expect(tokens[0][4].value).toBe("lambda"); + expect(tokens[0][4].scopes).toEqual(["source.python","meta.lambda-function.python","storage.type.function.lambda.python"]); + expect(tokens[0][5].value).toBe(" "); + expect(tokens[0][5].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python"]); + expect(tokens[0][6].value).toBe("a"); + expect(tokens[0][6].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python","variable.parameter.function.language.python"]); + expect(tokens[0][7].value).toBe(","); + expect(tokens[0][7].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python","punctuation.separator.parameters.python"]); + expect(tokens[0][8].value).toBe(" "); + expect(tokens[0][8].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python"]); + expect(tokens[0][9].value).toBe("/"); + expect(tokens[0][9].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python","keyword.operator.positional.parameter.python"]); + expect(tokens[0][10].value).toBe(", "); + expect(tokens[0][10].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python"]); + expect(tokens[0][11].value).toBe("b"); + expect(tokens[0][11].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python","variable.parameter.function.language.python"]); + expect(tokens[0][12].value).toBe(","); + expect(tokens[0][12].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python","punctuation.separator.parameters.python"]); + expect(tokens[0][13].value).toBe(" "); + expect(tokens[0][13].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python"]); + expect(tokens[0][14].value).toBe("*"); + expect(tokens[0][14].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python","keyword.operator.unpacking.parameter.python"]); + expect(tokens[0][15].value).toBe(", "); + expect(tokens[0][15].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python"]); + expect(tokens[0][16].value).toBe("c"); + expect(tokens[0][16].scopes).toEqual(["source.python","meta.lambda-function.python","meta.function.lambda.parameters.python","variable.parameter.function.language.python"]); + expect(tokens[0][17].value).toBe(":"); + expect(tokens[0][17].scopes).toEqual(["source.python","meta.lambda-function.python","punctuation.section.function.lambda.begin.python"]); + expect(tokens[0][18].value).toBe(" "); + expect(tokens[0][18].scopes).toEqual(["source.python"]); + expect(tokens[0][19].value).toBe("("); + expect(tokens[0][19].scopes).toEqual(["source.python","punctuation.parenthesis.begin.python"]); + expect(tokens[0][20].value).toBe("a"); + expect(tokens[0][20].scopes).toEqual(["source.python"]); + expect(tokens[0][21].value).toBe(" "); + expect(tokens[0][21].scopes).toEqual(["source.python"]); + expect(tokens[0][22].value).toBe("+"); + expect(tokens[0][22].scopes).toEqual(["source.python","keyword.operator.arithmetic.python"]); + expect(tokens[0][23].value).toBe(" "); + expect(tokens[0][23].scopes).toEqual(["source.python"]); + expect(tokens[0][24].value).toBe("b"); + expect(tokens[0][24].scopes).toEqual(["source.python"]); + expect(tokens[0][25].value).toBe(" "); + expect(tokens[0][25].scopes).toEqual(["source.python"]); + expect(tokens[0][26].value).toBe("+"); + expect(tokens[0][26].scopes).toEqual(["source.python","keyword.operator.arithmetic.python"]); + expect(tokens[0][27].value).toBe(" "); + expect(tokens[0][27].scopes).toEqual(["source.python"]); + expect(tokens[0][28].value).toBe("c"); + expect(tokens[0][28].scopes).toEqual(["source.python"]); + expect(tokens[0][29].value).toBe(")"); + expect(tokens[0][29].scopes).toEqual(["source.python","punctuation.parenthesis.end.python"]); + }); + it("test/functions/lambda2.py", function() { tokens = grammar.tokenizeLines("lll(lambda=1)") diff --git a/test/expressions/expr21.py b/test/expressions/expr21.py new file mode 100644 index 00000000..59556710 --- /dev/null +++ b/test/expressions/expr21.py @@ -0,0 +1,39 @@ +while chunk := file.read(8192): + process(chunk) + y0 = (y1 := f(x)) + + + +while : keyword.control.flow.python, source.python + : source.python +chunk : source.python + : source.python +:= : keyword.operator.assignment.python, source.python + : source.python +file : source.python, variable.legacy.builtin.python +. : meta.member.access.python, punctuation.separator.period.python, source.python +read : meta.function-call.generic.python, meta.function-call.python, meta.member.access.python, source.python +( : meta.function-call.python, meta.member.access.python, punctuation.definition.arguments.begin.python, source.python +8192 : constant.numeric.dec.python, meta.function-call.arguments.python, meta.function-call.python, meta.member.access.python, source.python +) : meta.function-call.python, meta.member.access.python, punctuation.definition.arguments.end.python, source.python +: : punctuation.separator.colon.python, source.python + : source.python +process : meta.function-call.generic.python, meta.function-call.python, source.python +( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python +chunk : meta.function-call.arguments.python, meta.function-call.python, source.python +) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python + : source.python +y0 : source.python + : source.python += : keyword.operator.assignment.python, source.python + : source.python +( : punctuation.parenthesis.begin.python, source.python +y1 : source.python + : source.python +:= : keyword.operator.assignment.python, source.python + : source.python +f : meta.function-call.generic.python, meta.function-call.python, source.python +( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python +x : meta.function-call.arguments.python, meta.function-call.python, source.python +) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python +) : punctuation.parenthesis.end.python, source.python diff --git a/test/fstrings/simple10.py b/test/fstrings/simple10.py new file mode 100644 index 00000000..ae793021 --- /dev/null +++ b/test/fstrings/simple10.py @@ -0,0 +1,18 @@ +f'values: {a=} {b=!r}' + + + + +f : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.quoted.single.python +values: : meta.fstring.python, source.python, string.interpolated.python, string.quoted.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +a : meta.fstring.python, source.python += : meta.fstring.python, source.python, storage.type.format.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python + : meta.fstring.python, source.python, string.interpolated.python, string.quoted.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +b : meta.fstring.python, source.python +=!r : meta.fstring.python, source.python, storage.type.format.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.single.python diff --git a/test/functions/decl15.py b/test/functions/decl15.py new file mode 100644 index 00000000..7f5c4ecc --- /dev/null +++ b/test/functions/decl15.py @@ -0,0 +1,34 @@ +def showcase(a, b, /, c, d, *, e, f): + return + + + + +def : meta.function.python, source.python, storage.type.function.python + : meta.function.python, source.python +showcase : entity.name.function.python, meta.function.python, source.python +( : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.begin.python, source.python +a : meta.function.parameters.python, meta.function.python, source.python, variable.parameter.function.language.python +, : meta.function.parameters.python, meta.function.python, punctuation.separator.parameters.python, source.python + : meta.function.parameters.python, meta.function.python, source.python +b : meta.function.parameters.python, meta.function.python, source.python, variable.parameter.function.language.python +, : meta.function.parameters.python, meta.function.python, punctuation.separator.parameters.python, source.python + : meta.function.parameters.python, meta.function.python, source.python +/ : keyword.operator.positional.parameter.python, meta.function.parameters.python, meta.function.python, source.python +, : meta.function.parameters.python, meta.function.python, source.python +c : meta.function.parameters.python, meta.function.python, source.python, variable.parameter.function.language.python +, : meta.function.parameters.python, meta.function.python, punctuation.separator.parameters.python, source.python + : meta.function.parameters.python, meta.function.python, source.python +d : meta.function.parameters.python, meta.function.python, source.python, variable.parameter.function.language.python +, : meta.function.parameters.python, meta.function.python, punctuation.separator.parameters.python, source.python + : meta.function.parameters.python, meta.function.python, source.python +* : keyword.operator.unpacking.parameter.python, meta.function.parameters.python, meta.function.python, source.python +, : meta.function.parameters.python, meta.function.python, source.python +e : meta.function.parameters.python, meta.function.python, source.python, variable.parameter.function.language.python +, : meta.function.parameters.python, meta.function.python, punctuation.separator.parameters.python, source.python + : meta.function.parameters.python, meta.function.python, source.python +f : meta.function.parameters.python, meta.function.python, source.python, variable.parameter.function.language.python +) : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.end.python, source.python +: : meta.function.python, punctuation.section.function.begin.python, source.python + : source.python +return : keyword.control.flow.python, source.python diff --git a/test/functions/lambda10.py b/test/functions/lambda10.py new file mode 100644 index 00000000..c033ac71 --- /dev/null +++ b/test/functions/lambda10.py @@ -0,0 +1,35 @@ +showcase = lambda a, /, b, *, c: (a + b + c) + + + + +showcase : source.python + : source.python += : keyword.operator.assignment.python, source.python + : source.python +lambda : meta.lambda-function.python, source.python, storage.type.function.lambda.python + : meta.function.lambda.parameters.python, meta.lambda-function.python, source.python +a : meta.function.lambda.parameters.python, meta.lambda-function.python, source.python, variable.parameter.function.language.python +, : meta.function.lambda.parameters.python, meta.lambda-function.python, punctuation.separator.parameters.python, source.python + : meta.function.lambda.parameters.python, meta.lambda-function.python, source.python +/ : keyword.operator.positional.parameter.python, meta.function.lambda.parameters.python, meta.lambda-function.python, source.python +, : meta.function.lambda.parameters.python, meta.lambda-function.python, source.python +b : meta.function.lambda.parameters.python, meta.lambda-function.python, source.python, variable.parameter.function.language.python +, : meta.function.lambda.parameters.python, meta.lambda-function.python, punctuation.separator.parameters.python, source.python + : meta.function.lambda.parameters.python, meta.lambda-function.python, source.python +* : keyword.operator.unpacking.parameter.python, meta.function.lambda.parameters.python, meta.lambda-function.python, source.python +, : meta.function.lambda.parameters.python, meta.lambda-function.python, source.python +c : meta.function.lambda.parameters.python, meta.lambda-function.python, source.python, variable.parameter.function.language.python +: : meta.lambda-function.python, punctuation.section.function.lambda.begin.python, source.python + : source.python +( : punctuation.parenthesis.begin.python, source.python +a : source.python + : source.python ++ : keyword.operator.arithmetic.python, source.python + : source.python +b : source.python + : source.python ++ : keyword.operator.arithmetic.python, source.python + : source.python +c : source.python +) : punctuation.parenthesis.end.python, source.python From 5b5f388fc46e45dff7e48edc90242c7f578d8705 Mon Sep 17 00:00:00 2001 From: Victor Petrovykh Date: Fri, 31 Jul 2020 06:22:53 -0400 Subject: [PATCH 2/3] Make raw f-strings consistent. Any f-string allows variable interpolation, that includes a raw f-string. Make all raw prefixes (`r` or `R`) behave the same way in combination with `f` prefix. Fixes #186 --- grammars/MagicPython.cson | 910 +----------- grammars/MagicPython.tmLanguage | 1788 +----------------------- grammars/src/MagicPython.syntax.yaml | 80 -- grammars/src/pyfstring.inc.syntax.yaml | 2 +- misc/example.py | 2 + test/atom-spec/python-spec.js | 744 +++++----- test/fstrings/empty2.py | 36 +- test/fstrings/fraw1.py | 40 + test/fstrings/fraw2.py | 36 + test/fstrings/fraw3.py | 36 + test/fstrings/fraw4.py | 45 + test/fstrings/prefixes2.py | 24 +- test/fstrings/prefixes3.py | 24 +- test/regexp/fregexp1.py | 56 - test/regexp/fregexp2.py | 28 - test/regexp/fregexp3.py | 28 - test/regexp/fregexp4.py | 36 - test/regexp/fregexp5.py | 26 - test/regexp/fregexp6.py | 39 - 19 files changed, 546 insertions(+), 3434 deletions(-) create mode 100644 test/fstrings/fraw1.py create mode 100644 test/fstrings/fraw2.py create mode 100644 test/fstrings/fraw3.py create mode 100644 test/fstrings/fraw4.py delete mode 100644 test/regexp/fregexp1.py delete mode 100644 test/regexp/fregexp2.py delete mode 100644 test/regexp/fregexp3.py delete mode 100644 test/regexp/fregexp4.py delete mode 100644 test/regexp/fregexp5.py delete mode 100644 test/regexp/fregexp6.py diff --git a/grammars/MagicPython.cson b/grammars/MagicPython.cson index b137f776..afb32a6d 100644 --- a/grammars/MagicPython.cson +++ b/grammars/MagicPython.cson @@ -785,18 +785,6 @@ repository: { include: "#regexp-double-one-line" } - { - include: "#fregexp-single-three-line" - } - { - include: "#fregexp-double-three-line" - } - { - include: "#fregexp-single-one-line" - } - { - include: "#fregexp-double-one-line" - } ] string: patterns: [ @@ -3334,900 +3322,6 @@ repository: include: "#double-three-regexp-expression" } ] - "single-one-fregexp-expression": - patterns: [ - { - include: "#fregexp-base-expression" - } - { - include: "#single-one-regexp-character-set" - } - { - include: "#single-one-regexp-comments" - } - { - include: "#regexp-flags" - } - { - include: "#single-one-regexp-named-group" - } - { - include: "#regexp-backreference" - } - { - include: "#single-one-fregexp-lookahead" - } - { - include: "#single-one-fregexp-lookahead-negative" - } - { - include: "#single-one-fregexp-lookbehind" - } - { - include: "#single-one-fregexp-lookbehind-negative" - } - { - include: "#single-one-fregexp-conditional" - } - { - include: "#single-one-fregexp-parentheses-non-capturing" - } - { - include: "#single-one-fregexp-parentheses" - } - ] - "single-one-fregexp-named-group": - name: "meta.named.regexp" - begin: ''' - (?x) - (\\() (\\?P <\\w+(?:\\s+[[:alnum:]]+)?>) - - ''' - end: "(\\)|(?=\\'))|((?=(?) - - ''' - end: "(\\)|(?=\\'\\'\\'))" - beginCaptures: - "1": - name: "punctuation.parenthesis.named.begin.regexp support.other.parenthesis.regexp" - "2": - name: "entity.name.tag.named.group.regexp" - endCaptures: - "1": - name: "punctuation.parenthesis.named.end.regexp support.other.parenthesis.regexp" - "2": - name: "invalid.illegal.newline.python" - patterns: [ - { - include: "#single-three-fregexp-expression" - } - { - include: "#comments-string-single-three" - } - ] - "single-three-fregexp-lookahead": - begin: "(\\()\\?=" - end: "(\\)|(?=\\'\\'\\'))" - beginCaptures: - "0": - name: "keyword.operator.lookahead.regexp" - "1": - name: "punctuation.parenthesis.lookahead.begin.regexp" - endCaptures: - "1": - name: "punctuation.parenthesis.lookahead.end.regexp keyword.operator.lookahead.regexp" - "2": - name: "invalid.illegal.newline.python" - patterns: [ - { - include: "#single-three-fregexp-expression" - } - { - include: "#comments-string-single-three" - } - ] - "single-three-fregexp-lookahead-negative": - begin: "(\\()\\?!" - end: "(\\)|(?=\\'\\'\\'))" - beginCaptures: - "0": - name: "keyword.operator.lookahead.negative.regexp" - "1": - name: "punctuation.parenthesis.lookahead.begin.regexp" - endCaptures: - "1": - name: "punctuation.parenthesis.lookahead.end.regexp keyword.operator.lookahead.negative.regexp" - "2": - name: "invalid.illegal.newline.python" - patterns: [ - { - include: "#single-three-fregexp-expression" - } - { - include: "#comments-string-single-three" - } - ] - "single-three-fregexp-lookbehind": - begin: "(\\()\\?<=" - end: "(\\)|(?=\\'\\'\\'))" - beginCaptures: - "0": - name: "keyword.operator.lookbehind.regexp" - "1": - name: "punctuation.parenthesis.lookbehind.begin.regexp" - endCaptures: - "1": - name: "punctuation.parenthesis.lookbehind.end.regexp keyword.operator.lookbehind.regexp" - "2": - name: "invalid.illegal.newline.python" - patterns: [ - { - include: "#single-three-fregexp-expression" - } - { - include: "#comments-string-single-three" - } - ] - "single-three-fregexp-lookbehind-negative": - begin: "(\\()\\?) - - ''' - end: "(\\)|(?=\"))|((?=(?) - - ''' - end: "(\\)|(?=\"\"\"))" - beginCaptures: - "1": - name: "punctuation.parenthesis.named.begin.regexp support.other.parenthesis.regexp" - "2": - name: "entity.name.tag.named.group.regexp" - endCaptures: - "1": - name: "punctuation.parenthesis.named.end.regexp support.other.parenthesis.regexp" - "2": - name: "invalid.illegal.newline.python" - patterns: [ - { - include: "#double-three-fregexp-expression" - } - { - include: "#comments-string-double-three" - } - ] - "double-three-fregexp-lookahead": - begin: "(\\()\\?=" - end: "(\\)|(?=\"\"\"))" - beginCaptures: - "0": - name: "keyword.operator.lookahead.regexp" - "1": - name: "punctuation.parenthesis.lookahead.begin.regexp" - endCaptures: - "1": - name: "punctuation.parenthesis.lookahead.end.regexp keyword.operator.lookahead.regexp" - "2": - name: "invalid.illegal.newline.python" - patterns: [ - { - include: "#double-three-fregexp-expression" - } - { - include: "#comments-string-double-three" - } - ] - "double-three-fregexp-lookahead-negative": - begin: "(\\()\\?!" - end: "(\\)|(?=\"\"\"))" - beginCaptures: - "0": - name: "keyword.operator.lookahead.negative.regexp" - "1": - name: "punctuation.parenthesis.lookahead.begin.regexp" - endCaptures: - "1": - name: "punctuation.parenthesis.lookahead.end.regexp keyword.operator.lookahead.negative.regexp" - "2": - name: "invalid.illegal.newline.python" - patterns: [ - { - include: "#double-three-fregexp-expression" - } - { - include: "#comments-string-double-three" - } - ] - "double-three-fregexp-lookbehind": - begin: "(\\()\\?<=" - end: "(\\)|(?=\"\"\"))" - beginCaptures: - "0": - name: "keyword.operator.lookbehind.regexp" - "1": - name: "punctuation.parenthesis.lookbehind.begin.regexp" - endCaptures: - "1": - name: "punctuation.parenthesis.lookbehind.end.regexp keyword.operator.lookbehind.regexp" - "2": - name: "invalid.illegal.newline.python" - patterns: [ - { - include: "#double-three-fregexp-expression" - } - { - include: "#comments-string-double-three" - } - ] - "double-three-fregexp-lookbehind-negative": - begin: "(\\()\\?include #regexp-double-one-line - - include - #fregexp-single-three-line - - - include - #fregexp-double-three-line - - - include - #fregexp-single-one-line - - - include - #fregexp-double-one-line - string @@ -5646,1774 +5630,6 @@ indirectly through syntactic constructs - single-one-fregexp-expression - - patterns - - - include - #fregexp-base-expression - - - include - #single-one-regexp-character-set - - - include - #single-one-regexp-comments - - - include - #regexp-flags - - - include - #single-one-regexp-named-group - - - include - #regexp-backreference - - - include - #single-one-fregexp-lookahead - - - include - #single-one-fregexp-lookahead-negative - - - include - #single-one-fregexp-lookbehind - - - include - #single-one-fregexp-lookbehind-negative - - - include - #single-one-fregexp-conditional - - - include - #single-one-fregexp-parentheses-non-capturing - - - include - #single-one-fregexp-parentheses - - - - single-one-fregexp-named-group - - name - meta.named.regexp - begin - (?x) - (\() (\?P <\w+(?:\s+[[:alnum:]]+)?>) - - end - (\)|(?=\'))|((?=(?<!\\)\n)) - beginCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.named.begin.regexp - - 2 - - name - entity.name.tag.named.group.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.named.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-one-fregexp-expression - - - - single-one-fregexp-lookahead - - begin - (\()\?= - end - (\)|(?=\'))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.lookahead.regexp - - 1 - - name - punctuation.parenthesis.lookahead.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookahead.regexp punctuation.parenthesis.lookahead.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-one-fregexp-expression - - - - single-one-fregexp-lookahead-negative - - begin - (\()\?! - end - (\)|(?=\'))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.lookahead.negative.regexp - - 1 - - name - punctuation.parenthesis.lookahead.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookahead.negative.regexp punctuation.parenthesis.lookahead.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-one-fregexp-expression - - - - single-one-fregexp-lookbehind - - begin - (\()\?<= - end - (\)|(?=\'))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.lookbehind.regexp - - 1 - - name - punctuation.parenthesis.lookbehind.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookbehind.regexp punctuation.parenthesis.lookbehind.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-one-fregexp-expression - - - - single-one-fregexp-lookbehind-negative - - begin - (\()\?<! - end - (\)|(?=\'))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.lookbehind.negative.regexp - - 1 - - name - punctuation.parenthesis.lookbehind.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookbehind.negative.regexp punctuation.parenthesis.lookbehind.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-one-fregexp-expression - - - - single-one-fregexp-conditional - - begin - (\()\?\((\w+(?:\s+[[:alnum:]]+)?|\d+)\) - end - (\)|(?=\'))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.conditional.regexp - - 1 - - name - punctuation.parenthesis.conditional.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.conditional.negative.regexp punctuation.parenthesis.conditional.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-one-fregexp-expression - - - - single-one-fregexp-parentheses-non-capturing - - begin - \(\?: - end - (\)|(?=\'))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - support.other.parenthesis.regexp punctuation.parenthesis.non-capturing.begin.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.non-capturing.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-one-fregexp-expression - - - - single-one-fregexp-parentheses - - begin - \( - end - (\)|(?=\'))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - support.other.parenthesis.regexp punctuation.parenthesis.begin.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-one-fregexp-expression - - - - single-three-fregexp-expression - - patterns - - - include - #fregexp-base-expression - - - include - #single-three-regexp-character-set - - - include - #single-three-regexp-comments - - - include - #regexp-flags - - - include - #single-three-regexp-named-group - - - include - #regexp-backreference - - - include - #single-three-fregexp-lookahead - - - include - #single-three-fregexp-lookahead-negative - - - include - #single-three-fregexp-lookbehind - - - include - #single-three-fregexp-lookbehind-negative - - - include - #single-three-fregexp-conditional - - - include - #single-three-fregexp-parentheses-non-capturing - - - include - #single-three-fregexp-parentheses - - - include - #comments-string-single-three - - - - single-three-fregexp-named-group - - name - meta.named.regexp - begin - (?x) - (\() (\?P <\w+(?:\s+[[:alnum:]]+)?>) - - end - (\)|(?=\'\'\')) - beginCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.named.begin.regexp - - 2 - - name - entity.name.tag.named.group.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.named.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-three-fregexp-expression - - - include - #comments-string-single-three - - - - single-three-fregexp-lookahead - - begin - (\()\?= - end - (\)|(?=\'\'\')) - beginCaptures - - 0 - - name - keyword.operator.lookahead.regexp - - 1 - - name - punctuation.parenthesis.lookahead.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookahead.regexp punctuation.parenthesis.lookahead.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-three-fregexp-expression - - - include - #comments-string-single-three - - - - single-three-fregexp-lookahead-negative - - begin - (\()\?! - end - (\)|(?=\'\'\')) - beginCaptures - - 0 - - name - keyword.operator.lookahead.negative.regexp - - 1 - - name - punctuation.parenthesis.lookahead.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookahead.negative.regexp punctuation.parenthesis.lookahead.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-three-fregexp-expression - - - include - #comments-string-single-three - - - - single-three-fregexp-lookbehind - - begin - (\()\?<= - end - (\)|(?=\'\'\')) - beginCaptures - - 0 - - name - keyword.operator.lookbehind.regexp - - 1 - - name - punctuation.parenthesis.lookbehind.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookbehind.regexp punctuation.parenthesis.lookbehind.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-three-fregexp-expression - - - include - #comments-string-single-three - - - - single-three-fregexp-lookbehind-negative - - begin - (\()\?<! - end - (\)|(?=\'\'\')) - beginCaptures - - 0 - - name - keyword.operator.lookbehind.negative.regexp - - 1 - - name - punctuation.parenthesis.lookbehind.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookbehind.negative.regexp punctuation.parenthesis.lookbehind.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-three-fregexp-expression - - - include - #comments-string-single-three - - - - single-three-fregexp-conditional - - begin - (\()\?\((\w+(?:\s+[[:alnum:]]+)?|\d+)\) - end - (\)|(?=\'\'\')) - beginCaptures - - 0 - - name - keyword.operator.conditional.regexp - - 1 - - name - punctuation.parenthesis.conditional.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.conditional.negative.regexp punctuation.parenthesis.conditional.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-three-fregexp-expression - - - include - #comments-string-single-three - - - - single-three-fregexp-parentheses-non-capturing - - begin - \(\?: - end - (\)|(?=\'\'\')) - beginCaptures - - 0 - - name - support.other.parenthesis.regexp punctuation.parenthesis.non-capturing.begin.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.non-capturing.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-three-fregexp-expression - - - include - #comments-string-single-three - - - - single-three-fregexp-parentheses - - begin - \( - end - (\)|(?=\'\'\')) - beginCaptures - - 0 - - name - support.other.parenthesis.regexp punctuation.parenthesis.begin.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-three-fregexp-expression - - - include - #comments-string-single-three - - - - double-one-fregexp-expression - - patterns - - - include - #fregexp-base-expression - - - include - #double-one-regexp-character-set - - - include - #double-one-regexp-comments - - - include - #regexp-flags - - - include - #double-one-regexp-named-group - - - include - #regexp-backreference - - - include - #double-one-fregexp-lookahead - - - include - #double-one-fregexp-lookahead-negative - - - include - #double-one-fregexp-lookbehind - - - include - #double-one-fregexp-lookbehind-negative - - - include - #double-one-fregexp-conditional - - - include - #double-one-fregexp-parentheses-non-capturing - - - include - #double-one-fregexp-parentheses - - - - double-one-fregexp-named-group - - name - meta.named.regexp - begin - (?x) - (\() (\?P <\w+(?:\s+[[:alnum:]]+)?>) - - end - (\)|(?="))|((?=(?<!\\)\n)) - beginCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.named.begin.regexp - - 2 - - name - entity.name.tag.named.group.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.named.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-one-fregexp-expression - - - - double-one-fregexp-lookahead - - begin - (\()\?= - end - (\)|(?="))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.lookahead.regexp - - 1 - - name - punctuation.parenthesis.lookahead.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookahead.regexp punctuation.parenthesis.lookahead.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-one-fregexp-expression - - - - double-one-fregexp-lookahead-negative - - begin - (\()\?! - end - (\)|(?="))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.lookahead.negative.regexp - - 1 - - name - punctuation.parenthesis.lookahead.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookahead.negative.regexp punctuation.parenthesis.lookahead.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-one-fregexp-expression - - - - double-one-fregexp-lookbehind - - begin - (\()\?<= - end - (\)|(?="))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.lookbehind.regexp - - 1 - - name - punctuation.parenthesis.lookbehind.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookbehind.regexp punctuation.parenthesis.lookbehind.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-one-fregexp-expression - - - - double-one-fregexp-lookbehind-negative - - begin - (\()\?<! - end - (\)|(?="))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.lookbehind.negative.regexp - - 1 - - name - punctuation.parenthesis.lookbehind.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookbehind.negative.regexp punctuation.parenthesis.lookbehind.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-one-fregexp-expression - - - - double-one-fregexp-conditional - - begin - (\()\?\((\w+(?:\s+[[:alnum:]]+)?|\d+)\) - end - (\)|(?="))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - keyword.operator.conditional.regexp - - 1 - - name - punctuation.parenthesis.conditional.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.conditional.negative.regexp punctuation.parenthesis.conditional.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-one-fregexp-expression - - - - double-one-fregexp-parentheses-non-capturing - - begin - \(\?: - end - (\)|(?="))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - support.other.parenthesis.regexp punctuation.parenthesis.non-capturing.begin.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.non-capturing.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-one-fregexp-expression - - - - double-one-fregexp-parentheses - - begin - \( - end - (\)|(?="))|((?=(?<!\\)\n)) - beginCaptures - - 0 - - name - support.other.parenthesis.regexp punctuation.parenthesis.begin.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-one-fregexp-expression - - - - double-three-fregexp-expression - - patterns - - - include - #fregexp-base-expression - - - include - #double-three-regexp-character-set - - - include - #double-three-regexp-comments - - - include - #regexp-flags - - - include - #double-three-regexp-named-group - - - include - #regexp-backreference - - - include - #double-three-fregexp-lookahead - - - include - #double-three-fregexp-lookahead-negative - - - include - #double-three-fregexp-lookbehind - - - include - #double-three-fregexp-lookbehind-negative - - - include - #double-three-fregexp-conditional - - - include - #double-three-fregexp-parentheses-non-capturing - - - include - #double-three-fregexp-parentheses - - - include - #comments-string-double-three - - - - double-three-fregexp-named-group - - name - meta.named.regexp - begin - (?x) - (\() (\?P <\w+(?:\s+[[:alnum:]]+)?>) - - end - (\)|(?=""")) - beginCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.named.begin.regexp - - 2 - - name - entity.name.tag.named.group.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.named.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-three-fregexp-expression - - - include - #comments-string-double-three - - - - double-three-fregexp-lookahead - - begin - (\()\?= - end - (\)|(?=""")) - beginCaptures - - 0 - - name - keyword.operator.lookahead.regexp - - 1 - - name - punctuation.parenthesis.lookahead.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookahead.regexp punctuation.parenthesis.lookahead.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-three-fregexp-expression - - - include - #comments-string-double-three - - - - double-three-fregexp-lookahead-negative - - begin - (\()\?! - end - (\)|(?=""")) - beginCaptures - - 0 - - name - keyword.operator.lookahead.negative.regexp - - 1 - - name - punctuation.parenthesis.lookahead.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookahead.negative.regexp punctuation.parenthesis.lookahead.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-three-fregexp-expression - - - include - #comments-string-double-three - - - - double-three-fregexp-lookbehind - - begin - (\()\?<= - end - (\)|(?=""")) - beginCaptures - - 0 - - name - keyword.operator.lookbehind.regexp - - 1 - - name - punctuation.parenthesis.lookbehind.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookbehind.regexp punctuation.parenthesis.lookbehind.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-three-fregexp-expression - - - include - #comments-string-double-three - - - - double-three-fregexp-lookbehind-negative - - begin - (\()\?<! - end - (\)|(?=""")) - beginCaptures - - 0 - - name - keyword.operator.lookbehind.negative.regexp - - 1 - - name - punctuation.parenthesis.lookbehind.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.lookbehind.negative.regexp punctuation.parenthesis.lookbehind.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-three-fregexp-expression - - - include - #comments-string-double-three - - - - double-three-fregexp-conditional - - begin - (\()\?\((\w+(?:\s+[[:alnum:]]+)?|\d+)\) - end - (\)|(?=""")) - beginCaptures - - 0 - - name - keyword.operator.conditional.regexp - - 1 - - name - punctuation.parenthesis.conditional.begin.regexp - - - endCaptures - - 1 - - name - keyword.operator.conditional.negative.regexp punctuation.parenthesis.conditional.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-three-fregexp-expression - - - include - #comments-string-double-three - - - - double-three-fregexp-parentheses-non-capturing - - begin - \(\?: - end - (\)|(?=""")) - beginCaptures - - 0 - - name - support.other.parenthesis.regexp punctuation.parenthesis.non-capturing.begin.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.non-capturing.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-three-fregexp-expression - - - include - #comments-string-double-three - - - - double-three-fregexp-parentheses - - begin - \( - end - (\)|(?=""")) - beginCaptures - - 0 - - name - support.other.parenthesis.regexp punctuation.parenthesis.begin.regexp - - - endCaptures - - 1 - - name - support.other.parenthesis.regexp punctuation.parenthesis.end.regexp - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-three-fregexp-expression - - - include - #comments-string-double-three - - - - fregexp-single-one-line - - name - string.interpolated.python string.regexp.quoted.single.python - begin - \b(([uU]r)|([fF]r)|(r[fF]?))(\') - end - (\')|(?<!\\)(\n) - beginCaptures - - 2 - - name - invalid.deprecated.prefix.python - - 3 - - name - storage.type.string.python - - 4 - - name - storage.type.string.python - - 5 - - name - punctuation.definition.string.begin.python - - - endCaptures - - 1 - - name - punctuation.definition.string.end.python - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-one-fregexp-expression - - - - fregexp-single-three-line - - name - string.interpolated.python string.regexp.quoted.multi.python - begin - \b(([uU]r)|([fF]r)|(r[fF]?))(\'\'\') - end - (\'\'\') - beginCaptures - - 2 - - name - invalid.deprecated.prefix.python - - 3 - - name - storage.type.string.python - - 4 - - name - storage.type.string.python - - 5 - - name - punctuation.definition.string.begin.python - - - endCaptures - - 1 - - name - punctuation.definition.string.end.python - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #single-three-fregexp-expression - - - - fregexp-double-one-line - - name - string.interpolated.python string.regexp.quoted.single.python - begin - \b(([uU]r)|([fF]r)|(r[fF]?))(") - end - (")|(?<!\\)(\n) - beginCaptures - - 2 - - name - invalid.deprecated.prefix.python - - 3 - - name - storage.type.string.python - - 4 - - name - storage.type.string.python - - 5 - - name - punctuation.definition.string.begin.python - - - endCaptures - - 1 - - name - punctuation.definition.string.end.python - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-one-fregexp-expression - - - - fregexp-double-three-line - - name - string.interpolated.python string.regexp.quoted.multi.python - begin - \b(([uU]r)|([fF]r)|(r[fF]?))(""") - end - (""") - beginCaptures - - 2 - - name - invalid.deprecated.prefix.python - - 3 - - name - storage.type.string.python - - 4 - - name - storage.type.string.python - - 5 - - name - punctuation.definition.string.begin.python - - - endCaptures - - 1 - - name - punctuation.definition.string.end.python - - 2 - - name - invalid.illegal.newline.python - - - patterns - - - include - #double-three-fregexp-expression - - - string-raw-quoted-single-line name @@ -8137,7 +6353,7 @@ indirectly through syntactic constructs name meta.fstring.python begin - (\b(?:[R][fF]|[fF][R]))((['"])) + (\b(?:[rR][fF]|[fF][rR]))((['"])) end (\2)|((?<!\\)\n) beginCaptures @@ -8515,7 +6731,7 @@ indirectly through syntactic constructs name meta.fstring.python begin - (\b(?:[R][fF]|[fF][R]))('''|""") + (\b(?:[rR][fF]|[fF][rR]))('''|""") end (\2) beginCaptures diff --git a/grammars/src/MagicPython.syntax.yaml b/grammars/src/MagicPython.syntax.yaml index 83948dc1..bd740829 100644 --- a/grammars/src/MagicPython.syntax.yaml +++ b/grammars/src/MagicPython.syntax.yaml @@ -103,82 +103,6 @@ repository: bquote: '(""")' equote: '(""")' - - file: 'regexp.inc.syntax.yaml' - vars: - prefix: 'single-one-' - basename: 'fregexp' - marker: "|(?=\\')" - nested: '' - guard: "|((?=(? List[str]: async with db.transaction(): result = await db.query(...) print(f'Result: {result!r} {a=} {b=!r}') + print(Rf'data: {c=}') + print(rf'data: {c=}') mapping = None # type: Dict[int, Any] # PEP 484 diff --git a/test/atom-spec/python-spec.js b/test/atom-spec/python-spec.js index da7d08c1..cf00b257 100644 --- a/test/atom-spec/python-spec.js +++ b/test/atom-spec/python-spec.js @@ -6610,39 +6610,313 @@ describe("Grammar Tests", function() { function() { tokens = grammar.tokenizeLines("rf\"{} { }\"\nrf\"\"\"{}\n{ }\n\"\"\"") expect(tokens[0][0].value).toBe("rf"); - expect(tokens[0][0].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); + expect(tokens[0][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); expect(tokens[0][1].value).toBe("\""); - expect(tokens[0][1].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); + expect(tokens[0][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); expect(tokens[0][2].value).toBe("{"); - expect(tokens[0][2].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][2].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); expect(tokens[0][3].value).toBe("}"); - expect(tokens[0][3].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); expect(tokens[0][4].value).toBe(" "); - expect(tokens[0][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); + expect(tokens[0][4].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); expect(tokens[0][5].value).toBe("{"); - expect(tokens[0][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); expect(tokens[0][6].value).toBe(" "); - expect(tokens[0][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","invalid.illegal.brace.python"]); + expect(tokens[0][6].scopes).toEqual(["source.python","meta.fstring.python","invalid.illegal.brace.python"]); expect(tokens[0][7].value).toBe("}"); - expect(tokens[0][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][7].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); expect(tokens[0][8].value).toBe("\""); - expect(tokens[0][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); + expect(tokens[0][8].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); expect(tokens[1][0].value).toBe("rf"); - expect(tokens[1][0].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","storage.type.string.python"]); + expect(tokens[1][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.multi.python string.interpolated.python"]); expect(tokens[1][1].value).toBe("\"\"\""); - expect(tokens[1][1].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.begin.python"]); + expect(tokens[1][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python punctuation.definition.string.begin.python"]); expect(tokens[1][2].value).toBe("{"); - expect(tokens[1][2].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","constant.character.format.placeholder.other.python"]); + expect(tokens[1][2].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); expect(tokens[1][3].value).toBe("}"); - expect(tokens[1][3].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","constant.character.format.placeholder.other.python"]); + expect(tokens[1][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[1][4].value).toBe(""); + expect(tokens[1][4].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python"]); expect(tokens[2][0].value).toBe("{"); - expect(tokens[2][0].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","constant.character.format.placeholder.other.python"]); + expect(tokens[2][0].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); expect(tokens[2][1].value).toBe(" "); - expect(tokens[2][1].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","invalid.illegal.brace.python"]); + expect(tokens[2][1].scopes).toEqual(["source.python","meta.fstring.python","invalid.illegal.brace.python"]); expect(tokens[2][2].value).toBe("}"); - expect(tokens[2][2].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","constant.character.format.placeholder.other.python"]); + expect(tokens[2][2].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[2][3].value).toBe(""); + expect(tokens[2][3].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python"]); expect(tokens[3][0].value).toBe("\"\"\""); - expect(tokens[3][0].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.end.python"]); + expect(tokens[3][0].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python punctuation.definition.string.end.python"]); + }); + + it("test/fstrings/fraw1.py", + function() { + tokens = grammar.tokenizeLines("a = fr'[a-z]'\na = Fr'[a-z]'\na = rf'[a-z]'\na = rF'[a-z]'") + expect(tokens[0][0].value).toBe("a"); + expect(tokens[0][0].scopes).toEqual(["source.python"]); + expect(tokens[0][1].value).toBe(" "); + expect(tokens[0][1].scopes).toEqual(["source.python"]); + expect(tokens[0][2].value).toBe("="); + expect(tokens[0][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[0][3].value).toBe(" "); + expect(tokens[0][3].scopes).toEqual(["source.python"]); + expect(tokens[0][4].value).toBe("fr"); + expect(tokens[0][4].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][5].value).toBe("'"); + expect(tokens[0][5].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[0][6].value).toBe("[a-z]"); + expect(tokens[0][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][7].value).toBe("'"); + expect(tokens[0][7].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[1][0].value).toBe("a"); + expect(tokens[1][0].scopes).toEqual(["source.python"]); + expect(tokens[1][1].value).toBe(" "); + expect(tokens[1][1].scopes).toEqual(["source.python"]); + expect(tokens[1][2].value).toBe("="); + expect(tokens[1][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[1][3].value).toBe(" "); + expect(tokens[1][3].scopes).toEqual(["source.python"]); + expect(tokens[1][4].value).toBe("Fr"); + expect(tokens[1][4].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][5].value).toBe("'"); + expect(tokens[1][5].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[1][6].value).toBe("[a-z]"); + expect(tokens[1][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][7].value).toBe("'"); + expect(tokens[1][7].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[2][0].value).toBe("a"); + expect(tokens[2][0].scopes).toEqual(["source.python"]); + expect(tokens[2][1].value).toBe(" "); + expect(tokens[2][1].scopes).toEqual(["source.python"]); + expect(tokens[2][2].value).toBe("="); + expect(tokens[2][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[2][3].value).toBe(" "); + expect(tokens[2][3].scopes).toEqual(["source.python"]); + expect(tokens[2][4].value).toBe("rf"); + expect(tokens[2][4].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[2][5].value).toBe("'"); + expect(tokens[2][5].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[2][6].value).toBe("[a-z]"); + expect(tokens[2][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[2][7].value).toBe("'"); + expect(tokens[2][7].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[3][0].value).toBe("a"); + expect(tokens[3][0].scopes).toEqual(["source.python"]); + expect(tokens[3][1].value).toBe(" "); + expect(tokens[3][1].scopes).toEqual(["source.python"]); + expect(tokens[3][2].value).toBe("="); + expect(tokens[3][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[3][3].value).toBe(" "); + expect(tokens[3][3].scopes).toEqual(["source.python"]); + expect(tokens[3][4].value).toBe("rF"); + expect(tokens[3][4].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[3][5].value).toBe("'"); + expect(tokens[3][5].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[3][6].value).toBe("[a-z]"); + expect(tokens[3][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[3][7].value).toBe("'"); + expect(tokens[3][7].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + }); + + it("test/fstrings/fraw2.py", + function() { + tokens = grammar.tokenizeLines("rf'fo{{2}}'\nrf\"fo{{2}}\"\nrf'''fo{{2}}'''\nrf\"\"\"fo{{2}}\"\"\"") + expect(tokens[0][0].value).toBe("rf"); + expect(tokens[0][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][1].value).toBe("'"); + expect(tokens[0][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[0][2].value).toBe("fo"); + expect(tokens[0][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][3].value).toBe("{{"); + expect(tokens[0][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[0][4].value).toBe("2"); + expect(tokens[0][4].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][5].value).toBe("}}"); + expect(tokens[0][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[0][6].value).toBe("'"); + expect(tokens[0][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[1][0].value).toBe("rf"); + expect(tokens[1][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][1].value).toBe("\""); + expect(tokens[1][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[1][2].value).toBe("fo"); + expect(tokens[1][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][3].value).toBe("{{"); + expect(tokens[1][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[1][4].value).toBe("2"); + expect(tokens[1][4].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][5].value).toBe("}}"); + expect(tokens[1][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[1][6].value).toBe("\""); + expect(tokens[1][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[2][0].value).toBe("rf"); + expect(tokens[2][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[2][1].value).toBe("'''"); + expect(tokens[2][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python punctuation.definition.string.begin.python"]); + expect(tokens[2][2].value).toBe("fo"); + expect(tokens[2][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[2][3].value).toBe("{{"); + expect(tokens[2][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[2][4].value).toBe("2"); + expect(tokens[2][4].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[2][5].value).toBe("}}"); + expect(tokens[2][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[2][6].value).toBe("'''"); + expect(tokens[2][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[3][0].value).toBe("rf"); + expect(tokens[3][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[3][1].value).toBe("\"\"\""); + expect(tokens[3][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python punctuation.definition.string.begin.python"]); + expect(tokens[3][2].value).toBe("fo"); + expect(tokens[3][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[3][3].value).toBe("{{"); + expect(tokens[3][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[3][4].value).toBe("2"); + expect(tokens[3][4].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[3][5].value).toBe("}}"); + expect(tokens[3][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[3][6].value).toBe("\"\"\""); + expect(tokens[3][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python punctuation.definition.string.end.python"]); + }); + + it("test/fstrings/fraw3.py", + function() { + tokens = grammar.tokenizeLines("rf'fo{2}'\nrf\"fo{2}\"\nrf'''fo{2}'''\nrf\"\"\"fo{2}\"\"\"") + expect(tokens[0][0].value).toBe("rf"); + expect(tokens[0][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][1].value).toBe("'"); + expect(tokens[0][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[0][2].value).toBe("fo"); + expect(tokens[0][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][3].value).toBe("{"); + expect(tokens[0][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][4].value).toBe("2"); + expect(tokens[0][4].scopes).toEqual(["source.python","meta.fstring.python","constant.numeric.dec.python"]); + expect(tokens[0][5].value).toBe("}"); + expect(tokens[0][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][6].value).toBe("'"); + expect(tokens[0][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[1][0].value).toBe("rf"); + expect(tokens[1][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][1].value).toBe("\""); + expect(tokens[1][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[1][2].value).toBe("fo"); + expect(tokens[1][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][3].value).toBe("{"); + expect(tokens[1][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[1][4].value).toBe("2"); + expect(tokens[1][4].scopes).toEqual(["source.python","meta.fstring.python","constant.numeric.dec.python"]); + expect(tokens[1][5].value).toBe("}"); + expect(tokens[1][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[1][6].value).toBe("\""); + expect(tokens[1][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[2][0].value).toBe("rf"); + expect(tokens[2][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[2][1].value).toBe("'''"); + expect(tokens[2][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python punctuation.definition.string.begin.python"]); + expect(tokens[2][2].value).toBe("fo"); + expect(tokens[2][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[2][3].value).toBe("{"); + expect(tokens[2][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[2][4].value).toBe("2"); + expect(tokens[2][4].scopes).toEqual(["source.python","meta.fstring.python","constant.numeric.dec.python"]); + expect(tokens[2][5].value).toBe("}"); + expect(tokens[2][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[2][6].value).toBe("'''"); + expect(tokens[2][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[3][0].value).toBe("rf"); + expect(tokens[3][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[3][1].value).toBe("\"\"\""); + expect(tokens[3][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python punctuation.definition.string.begin.python"]); + expect(tokens[3][2].value).toBe("fo"); + expect(tokens[3][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python"]); + expect(tokens[3][3].value).toBe("{"); + expect(tokens[3][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[3][4].value).toBe("2"); + expect(tokens[3][4].scopes).toEqual(["source.python","meta.fstring.python","constant.numeric.dec.python"]); + expect(tokens[3][5].value).toBe("}"); + expect(tokens[3][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[3][6].value).toBe("\"\"\""); + expect(tokens[3][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.multi.python string.interpolated.python punctuation.definition.string.end.python"]); + }); + + it("test/fstrings/fraw4.py", + function() { + tokens = grammar.tokenizeLines("a = rf'fo{{{2}}}'\na = rf'fo{{{bar}}}'\na = rf'fo{{2}}'") + expect(tokens[0][0].value).toBe("a"); + expect(tokens[0][0].scopes).toEqual(["source.python"]); + expect(tokens[0][1].value).toBe(" "); + expect(tokens[0][1].scopes).toEqual(["source.python"]); + expect(tokens[0][2].value).toBe("="); + expect(tokens[0][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[0][3].value).toBe(" "); + expect(tokens[0][3].scopes).toEqual(["source.python"]); + expect(tokens[0][4].value).toBe("rf"); + expect(tokens[0][4].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][5].value).toBe("'"); + expect(tokens[0][5].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[0][6].value).toBe("fo"); + expect(tokens[0][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][7].value).toBe("{{"); + expect(tokens[0][7].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[0][8].value).toBe("{"); + expect(tokens[0][8].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][9].value).toBe("2"); + expect(tokens[0][9].scopes).toEqual(["source.python","meta.fstring.python","constant.numeric.dec.python"]); + expect(tokens[0][10].value).toBe("}"); + expect(tokens[0][10].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][11].value).toBe("}}"); + expect(tokens[0][11].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[0][12].value).toBe("'"); + expect(tokens[0][12].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[1][0].value).toBe("a"); + expect(tokens[1][0].scopes).toEqual(["source.python"]); + expect(tokens[1][1].value).toBe(" "); + expect(tokens[1][1].scopes).toEqual(["source.python"]); + expect(tokens[1][2].value).toBe("="); + expect(tokens[1][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[1][3].value).toBe(" "); + expect(tokens[1][3].scopes).toEqual(["source.python"]); + expect(tokens[1][4].value).toBe("rf"); + expect(tokens[1][4].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][5].value).toBe("'"); + expect(tokens[1][5].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[1][6].value).toBe("fo"); + expect(tokens[1][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][7].value).toBe("{{"); + expect(tokens[1][7].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[1][8].value).toBe("{"); + expect(tokens[1][8].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[1][9].value).toBe("bar"); + expect(tokens[1][9].scopes).toEqual(["source.python","meta.fstring.python"]); + expect(tokens[1][10].value).toBe("}"); + expect(tokens[1][10].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[1][11].value).toBe("}}"); + expect(tokens[1][11].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[1][12].value).toBe("'"); + expect(tokens[1][12].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); + expect(tokens[2][0].value).toBe("a"); + expect(tokens[2][0].scopes).toEqual(["source.python"]); + expect(tokens[2][1].value).toBe(" "); + expect(tokens[2][1].scopes).toEqual(["source.python"]); + expect(tokens[2][2].value).toBe("="); + expect(tokens[2][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); + expect(tokens[2][3].value).toBe(" "); + expect(tokens[2][3].scopes).toEqual(["source.python"]); + expect(tokens[2][4].value).toBe("rf"); + expect(tokens[2][4].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[2][5].value).toBe("'"); + expect(tokens[2][5].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); + expect(tokens[2][6].value).toBe("fo"); + expect(tokens[2][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[2][7].value).toBe("{{"); + expect(tokens[2][7].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[2][8].value).toBe("2"); + expect(tokens[2][8].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[2][9].value).toBe("}}"); + expect(tokens[2][9].scopes).toEqual(["source.python","meta.fstring.python","constant.character.escape.python"]); + expect(tokens[2][10].value).toBe("'"); + expect(tokens[2][10].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); }); it("test/fstrings/nested1.py", @@ -7084,25 +7358,33 @@ describe("Grammar Tests", function() { expect(tokens[1][6].value).toBe("'"); expect(tokens[1][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.single.python string.interpolated.python punctuation.definition.string.end.python"]); expect(tokens[2][0].value).toBe("rf"); - expect(tokens[2][0].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); + expect(tokens[2][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); expect(tokens[2][1].value).toBe("'"); - expect(tokens[2][1].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); + expect(tokens[2][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); expect(tokens[2][2].value).toBe("some "); - expect(tokens[2][2].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[2][3].value).toBe("{obj}"); - expect(tokens[2][3].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[2][4].value).toBe("'"); - expect(tokens[2][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); + expect(tokens[2][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[2][3].value).toBe("{"); + expect(tokens[2][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[2][4].value).toBe("obj"); + expect(tokens[2][4].scopes).toEqual(["source.python","meta.fstring.python"]); + expect(tokens[2][5].value).toBe("}"); + expect(tokens[2][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[2][6].value).toBe("'"); + expect(tokens[2][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); expect(tokens[3][0].value).toBe("rF"); - expect(tokens[3][0].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); + expect(tokens[3][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); expect(tokens[3][1].value).toBe("'"); - expect(tokens[3][1].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); + expect(tokens[3][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); expect(tokens[3][2].value).toBe("some "); - expect(tokens[3][2].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[3][3].value).toBe("{obj}"); - expect(tokens[3][3].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[3][4].value).toBe("'"); - expect(tokens[3][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); + expect(tokens[3][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[3][3].value).toBe("{"); + expect(tokens[3][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[3][4].value).toBe("obj"); + expect(tokens[3][4].scopes).toEqual(["source.python","meta.fstring.python"]); + expect(tokens[3][5].value).toBe("}"); + expect(tokens[3][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[3][6].value).toBe("'"); + expect(tokens[3][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); expect(tokens[4][0].value).toBe("Rf"); expect(tokens[4][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); expect(tokens[4][1].value).toBe("'"); @@ -7137,25 +7419,33 @@ describe("Grammar Tests", function() { function() { tokens = grammar.tokenizeLines("fr'some {obj}'\nFr'some {obj}'\nfR'some {obj}'\nFR'some {obj}'") expect(tokens[0][0].value).toBe("fr"); - expect(tokens[0][0].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); + expect(tokens[0][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); expect(tokens[0][1].value).toBe("'"); - expect(tokens[0][1].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); + expect(tokens[0][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); expect(tokens[0][2].value).toBe("some "); - expect(tokens[0][2].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[0][3].value).toBe("{obj}"); - expect(tokens[0][3].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[0][4].value).toBe("'"); - expect(tokens[0][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); + expect(tokens[0][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[0][3].value).toBe("{"); + expect(tokens[0][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][4].value).toBe("obj"); + expect(tokens[0][4].scopes).toEqual(["source.python","meta.fstring.python"]); + expect(tokens[0][5].value).toBe("}"); + expect(tokens[0][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[0][6].value).toBe("'"); + expect(tokens[0][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); expect(tokens[1][0].value).toBe("Fr"); - expect(tokens[1][0].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); + expect(tokens[1][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); expect(tokens[1][1].value).toBe("'"); - expect(tokens[1][1].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); + expect(tokens[1][1].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python punctuation.definition.string.begin.python"]); expect(tokens[1][2].value).toBe("some "); - expect(tokens[1][2].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[1][3].value).toBe("{obj}"); - expect(tokens[1][3].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[1][4].value).toBe("'"); - expect(tokens[1][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); + expect(tokens[1][2].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python"]); + expect(tokens[1][3].value).toBe("{"); + expect(tokens[1][3].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[1][4].value).toBe("obj"); + expect(tokens[1][4].scopes).toEqual(["source.python","meta.fstring.python"]); + expect(tokens[1][5].value).toBe("}"); + expect(tokens[1][5].scopes).toEqual(["source.python","meta.fstring.python","constant.character.format.placeholder.other.python"]); + expect(tokens[1][6].value).toBe("'"); + expect(tokens[1][6].scopes).toEqual(["source.python","meta.fstring.python","string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"]); expect(tokens[2][0].value).toBe("fR"); expect(tokens[2][0].scopes).toEqual(["source.python","meta.fstring.python","storage.type.string.python string.quoted.raw.single.python string.interpolated.python"]); expect(tokens[2][1].value).toBe("'"); @@ -10724,370 +11014,6 @@ describe("Grammar Tests", function() { expect(tokens[0][15].scopes).toEqual(["source.python","string.regexp.quoted.multi.python","punctuation.definition.string.end.python"]); }); - it("test/regexp/fregexp1.py", - function() { - tokens = grammar.tokenizeLines("a = fr'[a-z]'\na = Fr'[a-z]'\na = rf'[a-z]'\na = rF'[a-z]'") - expect(tokens[0][0].value).toBe("a"); - expect(tokens[0][0].scopes).toEqual(["source.python"]); - expect(tokens[0][1].value).toBe(" "); - expect(tokens[0][1].scopes).toEqual(["source.python"]); - expect(tokens[0][2].value).toBe("="); - expect(tokens[0][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[0][3].value).toBe(" "); - expect(tokens[0][3].scopes).toEqual(["source.python"]); - expect(tokens[0][4].value).toBe("fr"); - expect(tokens[0][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[0][5].value).toBe("'"); - expect(tokens[0][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[0][6].value).toBe("["); - expect(tokens[0][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.other.set.regexp punctuation.character.set.begin.regexp"]); - expect(tokens[0][7].value).toBe("a"); - expect(tokens[0][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[0][8].value).toBe("-"); - expect(tokens[0][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[0][9].value).toBe("z"); - expect(tokens[0][9].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[0][10].value).toBe("]"); - expect(tokens[0][10].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.other.set.regexp punctuation.character.set.end.regexp"]); - expect(tokens[0][11].value).toBe("'"); - expect(tokens[0][11].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[1][0].value).toBe("a"); - expect(tokens[1][0].scopes).toEqual(["source.python"]); - expect(tokens[1][1].value).toBe(" "); - expect(tokens[1][1].scopes).toEqual(["source.python"]); - expect(tokens[1][2].value).toBe("="); - expect(tokens[1][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[1][3].value).toBe(" "); - expect(tokens[1][3].scopes).toEqual(["source.python"]); - expect(tokens[1][4].value).toBe("Fr"); - expect(tokens[1][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[1][5].value).toBe("'"); - expect(tokens[1][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[1][6].value).toBe("["); - expect(tokens[1][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.other.set.regexp punctuation.character.set.begin.regexp"]); - expect(tokens[1][7].value).toBe("a"); - expect(tokens[1][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[1][8].value).toBe("-"); - expect(tokens[1][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[1][9].value).toBe("z"); - expect(tokens[1][9].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[1][10].value).toBe("]"); - expect(tokens[1][10].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.other.set.regexp punctuation.character.set.end.regexp"]); - expect(tokens[1][11].value).toBe("'"); - expect(tokens[1][11].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[2][0].value).toBe("a"); - expect(tokens[2][0].scopes).toEqual(["source.python"]); - expect(tokens[2][1].value).toBe(" "); - expect(tokens[2][1].scopes).toEqual(["source.python"]); - expect(tokens[2][2].value).toBe("="); - expect(tokens[2][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[2][3].value).toBe(" "); - expect(tokens[2][3].scopes).toEqual(["source.python"]); - expect(tokens[2][4].value).toBe("rf"); - expect(tokens[2][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[2][5].value).toBe("'"); - expect(tokens[2][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[2][6].value).toBe("["); - expect(tokens[2][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.other.set.regexp punctuation.character.set.begin.regexp"]); - expect(tokens[2][7].value).toBe("a"); - expect(tokens[2][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[2][8].value).toBe("-"); - expect(tokens[2][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[2][9].value).toBe("z"); - expect(tokens[2][9].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[2][10].value).toBe("]"); - expect(tokens[2][10].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.other.set.regexp punctuation.character.set.end.regexp"]); - expect(tokens[2][11].value).toBe("'"); - expect(tokens[2][11].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[3][0].value).toBe("a"); - expect(tokens[3][0].scopes).toEqual(["source.python"]); - expect(tokens[3][1].value).toBe(" "); - expect(tokens[3][1].scopes).toEqual(["source.python"]); - expect(tokens[3][2].value).toBe("="); - expect(tokens[3][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[3][3].value).toBe(" "); - expect(tokens[3][3].scopes).toEqual(["source.python"]); - expect(tokens[3][4].value).toBe("rF"); - expect(tokens[3][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[3][5].value).toBe("'"); - expect(tokens[3][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[3][6].value).toBe("["); - expect(tokens[3][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.other.set.regexp punctuation.character.set.begin.regexp"]); - expect(tokens[3][7].value).toBe("a"); - expect(tokens[3][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[3][8].value).toBe("-"); - expect(tokens[3][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[3][9].value).toBe("z"); - expect(tokens[3][9].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.character.set.regexp"]); - expect(tokens[3][10].value).toBe("]"); - expect(tokens[3][10].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","meta.character.set.regexp","constant.other.set.regexp punctuation.character.set.end.regexp"]); - expect(tokens[3][11].value).toBe("'"); - expect(tokens[3][11].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - }); - - it("test/regexp/fregexp2.py", - function() { - tokens = grammar.tokenizeLines("rf'fo{{2}}'\nrf\"fo{{2}}\"\nrf'''fo{{2}}'''\nrf\"\"\"fo{{2}}\"\"\"") - expect(tokens[0][0].value).toBe("rf"); - expect(tokens[0][0].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[0][1].value).toBe("'"); - expect(tokens[0][1].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[0][2].value).toBe("fo"); - expect(tokens[0][2].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[0][3].value).toBe("{{2}}"); - expect(tokens[0][3].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","keyword.operator.quantifier.regexp"]); - expect(tokens[0][4].value).toBe("'"); - expect(tokens[0][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[1][0].value).toBe("rf"); - expect(tokens[1][0].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[1][1].value).toBe("\""); - expect(tokens[1][1].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[1][2].value).toBe("fo"); - expect(tokens[1][2].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[1][3].value).toBe("{{2}}"); - expect(tokens[1][3].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","keyword.operator.quantifier.regexp"]); - expect(tokens[1][4].value).toBe("\""); - expect(tokens[1][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[2][0].value).toBe("rf"); - expect(tokens[2][0].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[2][1].value).toBe("'''"); - expect(tokens[2][1].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[2][2].value).toBe("fo"); - expect(tokens[2][2].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python"]); - expect(tokens[2][3].value).toBe("{{2}}"); - expect(tokens[2][3].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","keyword.operator.quantifier.regexp"]); - expect(tokens[2][4].value).toBe("'''"); - expect(tokens[2][4].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[3][0].value).toBe("rf"); - expect(tokens[3][0].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[3][1].value).toBe("\"\"\""); - expect(tokens[3][1].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[3][2].value).toBe("fo"); - expect(tokens[3][2].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python"]); - expect(tokens[3][3].value).toBe("{{2}}"); - expect(tokens[3][3].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","keyword.operator.quantifier.regexp"]); - expect(tokens[3][4].value).toBe("\"\"\""); - expect(tokens[3][4].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.end.python"]); - }); - - it("test/regexp/fregexp3.py", - function() { - tokens = grammar.tokenizeLines("rf'fo{2}'\nrf\"fo{2}\"\nrf'''fo{2}'''\nrf\"\"\"fo{2}\"\"\"") - expect(tokens[0][0].value).toBe("rf"); - expect(tokens[0][0].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[0][1].value).toBe("'"); - expect(tokens[0][1].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[0][2].value).toBe("fo"); - expect(tokens[0][2].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[0][3].value).toBe("{2}"); - expect(tokens[0][3].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[0][4].value).toBe("'"); - expect(tokens[0][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[1][0].value).toBe("rf"); - expect(tokens[1][0].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[1][1].value).toBe("\""); - expect(tokens[1][1].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[1][2].value).toBe("fo"); - expect(tokens[1][2].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[1][3].value).toBe("{2}"); - expect(tokens[1][3].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[1][4].value).toBe("\""); - expect(tokens[1][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[2][0].value).toBe("rf"); - expect(tokens[2][0].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[2][1].value).toBe("'''"); - expect(tokens[2][1].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[2][2].value).toBe("fo"); - expect(tokens[2][2].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python"]); - expect(tokens[2][3].value).toBe("{2}"); - expect(tokens[2][3].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python"]); - expect(tokens[2][4].value).toBe("'''"); - expect(tokens[2][4].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[3][0].value).toBe("rf"); - expect(tokens[3][0].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[3][1].value).toBe("\"\"\""); - expect(tokens[3][1].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[3][2].value).toBe("fo"); - expect(tokens[3][2].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python"]); - expect(tokens[3][3].value).toBe("{2}"); - expect(tokens[3][3].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python"]); - expect(tokens[3][4].value).toBe("\"\"\""); - expect(tokens[3][4].scopes).toEqual(["source.python","string.regexp.quoted.multi.python string.interpolated.python","punctuation.definition.string.end.python"]); - }); - - it("test/regexp/fregexp4.py", - function() { - tokens = grammar.tokenizeLines("a = rf'fo{{2}}'\na = r'fo{{2}}'\na = r'fo{2}'") - expect(tokens[0][0].value).toBe("a"); - expect(tokens[0][0].scopes).toEqual(["source.python"]); - expect(tokens[0][1].value).toBe(" "); - expect(tokens[0][1].scopes).toEqual(["source.python"]); - expect(tokens[0][2].value).toBe("="); - expect(tokens[0][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[0][3].value).toBe(" "); - expect(tokens[0][3].scopes).toEqual(["source.python"]); - expect(tokens[0][4].value).toBe("rf"); - expect(tokens[0][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[0][5].value).toBe("'"); - expect(tokens[0][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[0][6].value).toBe("fo"); - expect(tokens[0][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[0][7].value).toBe("{{2}}"); - expect(tokens[0][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","keyword.operator.quantifier.regexp"]); - expect(tokens[0][8].value).toBe("'"); - expect(tokens[0][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[1][0].value).toBe("a"); - expect(tokens[1][0].scopes).toEqual(["source.python"]); - expect(tokens[1][1].value).toBe(" "); - expect(tokens[1][1].scopes).toEqual(["source.python"]); - expect(tokens[1][2].value).toBe("="); - expect(tokens[1][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[1][3].value).toBe(" "); - expect(tokens[1][3].scopes).toEqual(["source.python"]); - expect(tokens[1][4].value).toBe("r"); - expect(tokens[1][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python","storage.type.string.python"]); - expect(tokens[1][5].value).toBe("'"); - expect(tokens[1][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python","punctuation.definition.string.begin.python"]); - expect(tokens[1][6].value).toBe("fo{"); - expect(tokens[1][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python"]); - expect(tokens[1][7].value).toBe("{2}"); - expect(tokens[1][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python","keyword.operator.quantifier.regexp"]); - expect(tokens[1][8].value).toBe("}"); - expect(tokens[1][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python"]); - expect(tokens[1][9].value).toBe("'"); - expect(tokens[1][9].scopes).toEqual(["source.python","string.regexp.quoted.single.python","punctuation.definition.string.end.python"]); - expect(tokens[2][0].value).toBe("a"); - expect(tokens[2][0].scopes).toEqual(["source.python"]); - expect(tokens[2][1].value).toBe(" "); - expect(tokens[2][1].scopes).toEqual(["source.python"]); - expect(tokens[2][2].value).toBe("="); - expect(tokens[2][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[2][3].value).toBe(" "); - expect(tokens[2][3].scopes).toEqual(["source.python"]); - expect(tokens[2][4].value).toBe("r"); - expect(tokens[2][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python","storage.type.string.python"]); - expect(tokens[2][5].value).toBe("'"); - expect(tokens[2][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python","punctuation.definition.string.begin.python"]); - expect(tokens[2][6].value).toBe("fo"); - expect(tokens[2][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python"]); - expect(tokens[2][7].value).toBe("{2}"); - expect(tokens[2][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python","keyword.operator.quantifier.regexp"]); - expect(tokens[2][8].value).toBe("'"); - expect(tokens[2][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python","punctuation.definition.string.end.python"]); - }); - - it("test/regexp/fregexp5.py", - function() { - tokens = grammar.tokenizeLines("a = rf'{{foo}}'\na = r'\\{foo\\}'") - expect(tokens[0][0].value).toBe("a"); - expect(tokens[0][0].scopes).toEqual(["source.python"]); - expect(tokens[0][1].value).toBe(" "); - expect(tokens[0][1].scopes).toEqual(["source.python"]); - expect(tokens[0][2].value).toBe("="); - expect(tokens[0][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[0][3].value).toBe(" "); - expect(tokens[0][3].scopes).toEqual(["source.python"]); - expect(tokens[0][4].value).toBe("rf"); - expect(tokens[0][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[0][5].value).toBe("'"); - expect(tokens[0][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[0][6].value).toBe("{{"); - expect(tokens[0][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.escape.python"]); - expect(tokens[0][7].value).toBe("foo"); - expect(tokens[0][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[0][8].value).toBe("}}"); - expect(tokens[0][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.escape.python"]); - expect(tokens[0][9].value).toBe("'"); - expect(tokens[0][9].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[1][0].value).toBe("a"); - expect(tokens[1][0].scopes).toEqual(["source.python"]); - expect(tokens[1][1].value).toBe(" "); - expect(tokens[1][1].scopes).toEqual(["source.python"]); - expect(tokens[1][2].value).toBe("="); - expect(tokens[1][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[1][3].value).toBe(" "); - expect(tokens[1][3].scopes).toEqual(["source.python"]); - expect(tokens[1][4].value).toBe("r"); - expect(tokens[1][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python","storage.type.string.python"]); - expect(tokens[1][5].value).toBe("'"); - expect(tokens[1][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python","punctuation.definition.string.begin.python"]); - expect(tokens[1][6].value).toBe("\\{"); - expect(tokens[1][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python","constant.character.escape.regexp"]); - expect(tokens[1][7].value).toBe("foo"); - expect(tokens[1][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python"]); - expect(tokens[1][8].value).toBe("\\}"); - expect(tokens[1][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python","constant.character.escape.regexp"]); - expect(tokens[1][9].value).toBe("'"); - expect(tokens[1][9].scopes).toEqual(["source.python","string.regexp.quoted.single.python","punctuation.definition.string.end.python"]); - }); - - it("test/regexp/fregexp6.py", - function() { - tokens = grammar.tokenizeLines("a = rf'fo{{{2}}}'\na = rf'fo{{{bar}}}'\na = rf'fo{{2}}'") - expect(tokens[0][0].value).toBe("a"); - expect(tokens[0][0].scopes).toEqual(["source.python"]); - expect(tokens[0][1].value).toBe(" "); - expect(tokens[0][1].scopes).toEqual(["source.python"]); - expect(tokens[0][2].value).toBe("="); - expect(tokens[0][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[0][3].value).toBe(" "); - expect(tokens[0][3].scopes).toEqual(["source.python"]); - expect(tokens[0][4].value).toBe("rf"); - expect(tokens[0][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[0][5].value).toBe("'"); - expect(tokens[0][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[0][6].value).toBe("fo"); - expect(tokens[0][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[0][7].value).toBe("{{"); - expect(tokens[0][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.escape.python"]); - expect(tokens[0][8].value).toBe("{2}"); - expect(tokens[0][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[0][9].value).toBe("}}"); - expect(tokens[0][9].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.escape.python"]); - expect(tokens[0][10].value).toBe("'"); - expect(tokens[0][10].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[1][0].value).toBe("a"); - expect(tokens[1][0].scopes).toEqual(["source.python"]); - expect(tokens[1][1].value).toBe(" "); - expect(tokens[1][1].scopes).toEqual(["source.python"]); - expect(tokens[1][2].value).toBe("="); - expect(tokens[1][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[1][3].value).toBe(" "); - expect(tokens[1][3].scopes).toEqual(["source.python"]); - expect(tokens[1][4].value).toBe("rf"); - expect(tokens[1][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[1][5].value).toBe("'"); - expect(tokens[1][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[1][6].value).toBe("fo"); - expect(tokens[1][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[1][7].value).toBe("{{"); - expect(tokens[1][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.escape.python"]); - expect(tokens[1][8].value).toBe("{bar}"); - expect(tokens[1][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[1][9].value).toBe("}}"); - expect(tokens[1][9].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","constant.character.escape.python"]); - expect(tokens[1][10].value).toBe("'"); - expect(tokens[1][10].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - expect(tokens[2][0].value).toBe("a"); - expect(tokens[2][0].scopes).toEqual(["source.python"]); - expect(tokens[2][1].value).toBe(" "); - expect(tokens[2][1].scopes).toEqual(["source.python"]); - expect(tokens[2][2].value).toBe("="); - expect(tokens[2][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]); - expect(tokens[2][3].value).toBe(" "); - expect(tokens[2][3].scopes).toEqual(["source.python"]); - expect(tokens[2][4].value).toBe("rf"); - expect(tokens[2][4].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","storage.type.string.python"]); - expect(tokens[2][5].value).toBe("'"); - expect(tokens[2][5].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.begin.python"]); - expect(tokens[2][6].value).toBe("fo"); - expect(tokens[2][6].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python"]); - expect(tokens[2][7].value).toBe("{{2}}"); - expect(tokens[2][7].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","keyword.operator.quantifier.regexp"]); - expect(tokens[2][8].value).toBe("'"); - expect(tokens[2][8].scopes).toEqual(["source.python","string.regexp.quoted.single.python string.interpolated.python","punctuation.definition.string.end.python"]); - }); - it("test/regexp/python1.py", function() { tokens = grammar.tokenizeLines("a = r'[a-z]'\na = R'[a-z]'") diff --git a/test/fstrings/empty2.py b/test/fstrings/empty2.py index 77dc9087..9a007e14 100644 --- a/test/fstrings/empty2.py +++ b/test/fstrings/empty2.py @@ -7,20 +7,22 @@ -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -" : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -{ : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -} : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.single.python - : source.python, string.interpolated.python, string.regexp.quoted.single.python -{ : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.single.python - : invalid.illegal.brace.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -} : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -" : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.multi.python -""" : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -{ : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -} : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -{ : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python - : invalid.illegal.brace.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -} : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -""" : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python + : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python + : invalid.illegal.brace.python, meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python +""" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python + : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python + : invalid.illegal.brace.python, meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python + : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +""" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python diff --git a/test/fstrings/fraw1.py b/test/fstrings/fraw1.py new file mode 100644 index 00000000..31e2196e --- /dev/null +++ b/test/fstrings/fraw1.py @@ -0,0 +1,40 @@ +a = fr'[a-z]' +a = Fr'[a-z]' +a = rf'[a-z]' +a = rF'[a-z]' + + + + +a : source.python + : source.python += : keyword.operator.assignment.python, source.python + : source.python +fr : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +[a-z] : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +a : source.python + : source.python += : keyword.operator.assignment.python, source.python + : source.python +Fr : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +[a-z] : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +a : source.python + : source.python += : keyword.operator.assignment.python, source.python + : source.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +[a-z] : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +a : source.python + : source.python += : keyword.operator.assignment.python, source.python + : source.python +rF : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +[a-z] : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python diff --git a/test/fstrings/fraw2.py b/test/fstrings/fraw2.py new file mode 100644 index 00000000..df0a2fed --- /dev/null +++ b/test/fstrings/fraw2.py @@ -0,0 +1,36 @@ +rf'fo{{2}}' +rf"fo{{2}}" +rf'''fo{{2}}''' +rf"""fo{{2}}""" + + + + +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{{ : constant.character.escape.python, meta.fstring.python, source.python +2 : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +}} : constant.character.escape.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{{ : constant.character.escape.python, meta.fstring.python, source.python +2 : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +}} : constant.character.escape.python, meta.fstring.python, source.python +" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python +''' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +{{ : constant.character.escape.python, meta.fstring.python, source.python +2 : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +}} : constant.character.escape.python, meta.fstring.python, source.python +''' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python +""" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +{{ : constant.character.escape.python, meta.fstring.python, source.python +2 : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +}} : constant.character.escape.python, meta.fstring.python, source.python +""" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python diff --git a/test/fstrings/fraw3.py b/test/fstrings/fraw3.py new file mode 100644 index 00000000..da1a6aff --- /dev/null +++ b/test/fstrings/fraw3.py @@ -0,0 +1,36 @@ +rf'fo{2}' +rf"fo{2}" +rf'''fo{2}''' +rf"""fo{2}""" + + + + +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +2 : constant.numeric.dec.python, meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +2 : constant.numeric.dec.python, meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python +''' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +2 : constant.numeric.dec.python, meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +''' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python +""" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +2 : constant.numeric.dec.python, meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +""" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python diff --git a/test/fstrings/fraw4.py b/test/fstrings/fraw4.py new file mode 100644 index 00000000..2bf2d465 --- /dev/null +++ b/test/fstrings/fraw4.py @@ -0,0 +1,45 @@ +a = rf'fo{{{2}}}' +a = rf'fo{{{bar}}}' +a = rf'fo{{2}}' + + + + + +a : source.python + : source.python += : keyword.operator.assignment.python, source.python + : source.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{{ : constant.character.escape.python, meta.fstring.python, source.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +2 : constant.numeric.dec.python, meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +}} : constant.character.escape.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +a : source.python + : source.python += : keyword.operator.assignment.python, source.python + : source.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{{ : constant.character.escape.python, meta.fstring.python, source.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +bar : meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +}} : constant.character.escape.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +a : source.python + : source.python += : keyword.operator.assignment.python, source.python + : source.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{{ : constant.character.escape.python, meta.fstring.python, source.python +2 : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +}} : constant.character.escape.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python diff --git a/test/fstrings/prefixes2.py b/test/fstrings/prefixes2.py index 861d2b66..78ee4246 100644 --- a/test/fstrings/prefixes2.py +++ b/test/fstrings/prefixes2.py @@ -22,16 +22,20 @@ obj : meta.fstring.python, source.python } : constant.character.format.placeholder.other.python, meta.fstring.python, source.python ' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.single.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -some : source.python, string.interpolated.python, string.regexp.quoted.single.python -{obj} : source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -rF : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -some : source.python, string.interpolated.python, string.regexp.quoted.single.python -{obj} : source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python +rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +some : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +obj : meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +rF : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +some : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +obj : meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python Rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python ' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python some : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python diff --git a/test/fstrings/prefixes3.py b/test/fstrings/prefixes3.py index 200fa896..46d12ffb 100644 --- a/test/fstrings/prefixes3.py +++ b/test/fstrings/prefixes3.py @@ -6,16 +6,20 @@ -fr : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -some : source.python, string.interpolated.python, string.regexp.quoted.single.python -{obj} : source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -Fr : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -some : source.python, string.interpolated.python, string.regexp.quoted.single.python -{obj} : source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python +fr : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +some : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +obj : meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python +Fr : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python +' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python +some : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python +{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +obj : meta.fstring.python, source.python +} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python +' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python fR : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python ' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python some : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python diff --git a/test/regexp/fregexp1.py b/test/regexp/fregexp1.py deleted file mode 100644 index 9e77d66b..00000000 --- a/test/regexp/fregexp1.py +++ /dev/null @@ -1,56 +0,0 @@ -a = fr'[a-z]' -a = Fr'[a-z]' -a = rf'[a-z]' -a = rF'[a-z]' - - - - -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -fr : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -[ : constant.other.set.regexp, meta.character.set.regexp, punctuation.character.set.begin.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -- : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -z : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -] : constant.other.set.regexp, meta.character.set.regexp, punctuation.character.set.end.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -Fr : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -[ : constant.other.set.regexp, meta.character.set.regexp, punctuation.character.set.begin.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -- : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -z : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -] : constant.other.set.regexp, meta.character.set.regexp, punctuation.character.set.end.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -[ : constant.other.set.regexp, meta.character.set.regexp, punctuation.character.set.begin.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -- : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -z : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -] : constant.other.set.regexp, meta.character.set.regexp, punctuation.character.set.end.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -rF : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -[ : constant.other.set.regexp, meta.character.set.regexp, punctuation.character.set.begin.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -- : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -z : constant.character.set.regexp, meta.character.set.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -] : constant.other.set.regexp, meta.character.set.regexp, punctuation.character.set.end.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python diff --git a/test/regexp/fregexp2.py b/test/regexp/fregexp2.py deleted file mode 100644 index 72eccc28..00000000 --- a/test/regexp/fregexp2.py +++ /dev/null @@ -1,28 +0,0 @@ -rf'fo{{2}}' -rf"fo{{2}}" -rf'''fo{{2}}''' -rf"""fo{{2}}""" - - - - -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -fo : source.python, string.interpolated.python, string.regexp.quoted.single.python -{{2}} : keyword.operator.quantifier.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -" : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -fo : source.python, string.interpolated.python, string.regexp.quoted.single.python -{{2}} : keyword.operator.quantifier.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -" : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.multi.python -''' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -fo : source.python, string.interpolated.python, string.regexp.quoted.multi.python -{{2}} : keyword.operator.quantifier.regexp, source.python, string.interpolated.python, string.regexp.quoted.multi.python -''' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.multi.python -""" : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -fo : source.python, string.interpolated.python, string.regexp.quoted.multi.python -{{2}} : keyword.operator.quantifier.regexp, source.python, string.interpolated.python, string.regexp.quoted.multi.python -""" : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python diff --git a/test/regexp/fregexp3.py b/test/regexp/fregexp3.py deleted file mode 100644 index ede8a6c3..00000000 --- a/test/regexp/fregexp3.py +++ /dev/null @@ -1,28 +0,0 @@ -rf'fo{2}' -rf"fo{2}" -rf'''fo{2}''' -rf"""fo{2}""" - - - - -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -fo : source.python, string.interpolated.python, string.regexp.quoted.single.python -{2} : source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -" : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -fo : source.python, string.interpolated.python, string.regexp.quoted.single.python -{2} : source.python, string.interpolated.python, string.regexp.quoted.single.python -" : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.multi.python -''' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -fo : source.python, string.interpolated.python, string.regexp.quoted.multi.python -{2} : source.python, string.interpolated.python, string.regexp.quoted.multi.python -''' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.multi.python -""" : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python -fo : source.python, string.interpolated.python, string.regexp.quoted.multi.python -{2} : source.python, string.interpolated.python, string.regexp.quoted.multi.python -""" : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python diff --git a/test/regexp/fregexp4.py b/test/regexp/fregexp4.py deleted file mode 100644 index 5b707ad3..00000000 --- a/test/regexp/fregexp4.py +++ /dev/null @@ -1,36 +0,0 @@ -a = rf'fo{{2}}' -a = r'fo{{2}}' -a = r'fo{2}' - - - - - -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -fo : source.python, string.interpolated.python, string.regexp.quoted.single.python -{{2}} : keyword.operator.quantifier.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -r : source.python, storage.type.string.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.regexp.quoted.single.python -fo{ : source.python, string.regexp.quoted.single.python -{2} : keyword.operator.quantifier.regexp, source.python, string.regexp.quoted.single.python -} : source.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.regexp.quoted.single.python -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -r : source.python, storage.type.string.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.regexp.quoted.single.python -fo : source.python, string.regexp.quoted.single.python -{2} : keyword.operator.quantifier.regexp, source.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.regexp.quoted.single.python diff --git a/test/regexp/fregexp5.py b/test/regexp/fregexp5.py deleted file mode 100644 index 0d339e27..00000000 --- a/test/regexp/fregexp5.py +++ /dev/null @@ -1,26 +0,0 @@ -a = rf'{{foo}}' -a = r'\{foo\}' - - - - -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -{{ : constant.character.escape.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -foo : source.python, string.interpolated.python, string.regexp.quoted.single.python -}} : constant.character.escape.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -r : source.python, storage.type.string.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.regexp.quoted.single.python -\{ : constant.character.escape.regexp, source.python, string.regexp.quoted.single.python -foo : source.python, string.regexp.quoted.single.python -\} : constant.character.escape.regexp, source.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.regexp.quoted.single.python diff --git a/test/regexp/fregexp6.py b/test/regexp/fregexp6.py deleted file mode 100644 index a51311d0..00000000 --- a/test/regexp/fregexp6.py +++ /dev/null @@ -1,39 +0,0 @@ -a = rf'fo{{{2}}}' -a = rf'fo{{{bar}}}' -a = rf'fo{{2}}' - - - - - -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -fo : source.python, string.interpolated.python, string.regexp.quoted.single.python -{{ : constant.character.escape.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -{2} : source.python, string.interpolated.python, string.regexp.quoted.single.python -}} : constant.character.escape.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -fo : source.python, string.interpolated.python, string.regexp.quoted.single.python -{{ : constant.character.escape.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -{bar} : source.python, string.interpolated.python, string.regexp.quoted.single.python -}} : constant.character.escape.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -a : source.python - : source.python -= : keyword.operator.assignment.python, source.python - : source.python -rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python -fo : source.python, string.interpolated.python, string.regexp.quoted.single.python -{{2}} : keyword.operator.quantifier.regexp, source.python, string.interpolated.python, string.regexp.quoted.single.python -' : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python From 7d0f2b22a5ad8fccbd7341bc7b7a715169283044 Mon Sep 17 00:00:00 2001 From: Victor Petrovykh Date: Tue, 18 Oct 2022 03:43:20 -0400 Subject: [PATCH 3/3] Update the syntax to Python 3.10 Update the built-ins, dunders and add `match` and `case` keywords. --- grammars/MagicPython.cson | 81 +- grammars/MagicPython.tmLanguage | 85 +- grammars/src/MagicPython.syntax.yaml | 76 +- test/atom-spec/python-spec.js | 1210 +++++++++++++++++++++++++- test/builtins/builtins3.py | 12 + test/builtins/builtins7.py | 8 + test/classes/class9.py | 16 + test/expressions/expr22.py | 33 + test/expressions/special2.py | 2 +- test/statements/match1.py | 61 ++ test/statements/match2.py | 112 +++ test/statements/match3.py | 114 +++ test/statements/match4.py | 59 ++ test/statements/match5.py | 112 +++ test/statements/match6.py | 53 ++ test/statements/match7.py | 97 +++ 16 files changed, 2028 insertions(+), 103 deletions(-) create mode 100644 test/expressions/expr22.py create mode 100644 test/statements/match1.py create mode 100644 test/statements/match2.py create mode 100644 test/statements/match3.py create mode 100644 test/statements/match4.py create mode 100644 test/statements/match5.py create mode 100644 test/statements/match6.py create mode 100644 test/statements/match7.py diff --git a/grammars/MagicPython.cson b/grammars/MagicPython.cson index afb32a6d..d837d6a3 100644 --- a/grammars/MagicPython.cson +++ b/grammars/MagicPython.cson @@ -308,6 +308,18 @@ repository: name: "storage.type.class.python" match: "\\b(?match \b(?<!\.)(class)\b + + match + (?x) + ^\s*( + case | match + )(?=\s*([-+\w\d(\[{'":#]|$))\b + + captures + + 1 + + name + keyword.control.flow.python + + + expression-bare @@ -2852,14 +2868,14 @@ correctly identify the "in" as a control flow keyword. match (?x) (?<!\.) \b( - __import__ | abs | all | any | ascii | bin | breakpoint | callable - | chr | compile | copyright | credits | delattr | dir | divmod - | enumerate | eval | exec | exit | filter | format | getattr - | globals | hasattr | hash | help | hex | id | input - | isinstance | issubclass | iter | len | license | locals | map - | max | memoryview | min | next | oct | open | ord | pow | print - | quit | range | reload | repr | reversed | round - | setattr | sorted | sum | vars | zip + __import__ | abs | aiter | all | any | anext | ascii | bin + | breakpoint | callable | chr | compile | copyright | credits + | delattr | dir | divmod | enumerate | eval | exec | exit + | filter | format | getattr | globals | hasattr | hash | help + | hex | id | input | isinstance | issubclass | iter | len + | license | locals | map | max | memoryview | min | next + | oct | open | ord | pow | print | quit | range | reload | repr + | reversed | round | setattr | sorted | sum | vars | zip )\b @@ -2904,24 +2920,29 @@ indirectly through syntactic constructs (?x) \b( __(?: - abs | add | aenter | aexit | aiter | and | anext | await - | bool | call | ceil | cmp | coerce | complex | contains - | copy | deepcopy | del | delattr | delete | delitem - | delslice | dir | div | divmod | enter | eq | exit | float - | floor | floordiv | format | ge | get | getattr - | getattribute | getinitargs | getitem | getnewargs - | getslice | getstate | gt | hash | hex | iadd | iand | idiv - | ifloordiv | ilshift | imod | imul | index | init - | instancecheck | int | invert | ior | ipow | irshift | isub - | iter | itruediv | ixor | le | len | long | lshift | lt - | missing | mod | mul | ne | neg | new | next | nonzero | oct | or - | pos | pow | radd | rand | rdiv | rdivmod | reduce - | reduce_ex | repr | reversed | rfloordiv | rlshift | rmod - | rmul | ror | round | rpow | rrshift | rshift | rsub - | rtruediv | rxor | set | setattr | setitem | setslice - | setstate | sizeof | str | sub | subclasscheck | truediv - | trunc | unicode | xor | matmul | rmatmul | imatmul - | init_subclass | set_name | fspath | bytes | prepare + abs | add | aenter | aexit | aiter | and | anext + | await | bool | call | ceil | class_getitem + | cmp | coerce | complex | contains | copy + | deepcopy | del | delattr | delete | delitem + | delslice | dir | div | divmod | enter | eq + | exit | float | floor | floordiv | format | ge + | get | getattr | getattribute | getinitargs + | getitem | getnewargs | getslice | getstate | gt + | hash | hex | iadd | iand | idiv | ifloordiv | + | ilshift | imod | imul | index | init + | instancecheck | int | invert | ior | ipow + | irshift | isub | iter | itruediv | ixor | le + | len | long | lshift | lt | missing | mod | mul + | ne | neg | new | next | nonzero | oct | or | pos + | pow | radd | rand | rdiv | rdivmod | reduce + | reduce_ex | repr | reversed | rfloordiv | + | rlshift | rmod | rmul | ror | round | rpow + | rrshift | rshift | rsub | rtruediv | rxor | set + | setattr | setitem | set_name | setslice + | setstate | sizeof | str | sub | subclasscheck + | truediv | trunc | unicode | xor | matmul + | rmatmul | imatmul | init_subclass | set_name + | fspath | bytes | prepare | length_hint )__ )\b @@ -2942,12 +2963,12 @@ indirectly through syntactic constructs (?x) \b( __(?: - all | bases | builtins | class | class_getitem | code | debug - | defaults | dict | doc | file | func | kwdefaults | members - | metaclass | methods | module | mro | mro_entries | name - | qualname | post_init | self | signature | slots | subclasses - | version | weakref | wrapped | annotations | classcell - | spec | path | package | future | traceback + all | annotations | bases | builtins | class + | closure | code | debug | defaults | dict | doc | file | func + | globals | kwdefaults | match_args | members | metaclass | methods + | module | mro | mro_entries | name | qualname | post_init | self + | signature | slots | subclasses | version | weakref | wrapped + | classcell | spec | path | package | future | traceback )__ )\b diff --git a/grammars/src/MagicPython.syntax.yaml b/grammars/src/MagicPython.syntax.yaml index bd740829..ebfccdaf 100644 --- a/grammars/src/MagicPython.syntax.yaml +++ b/grammars/src/MagicPython.syntax.yaml @@ -313,6 +313,13 @@ repository: )\b - name: storage.type.class.python match: \b(?