From 396f5726a4a21b433bbe6153fad8630c4d8f107c Mon Sep 17 00:00:00 2001 From: mhmdanas Date: Tue, 3 May 2022 03:06:17 +0300 Subject: [PATCH] fix: parse all of `@foo.bar` as a Python decorator --- lexers/embedded/python.xml | 2 +- .../python/test_complex_file1.expected | 8 +-- lexers/testdata/python/test_decorators.actual | 15 +++++ .../testdata/python/test_decorators.expected | 61 +++++++++++++++++++ 4 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 lexers/testdata/python/test_decorators.actual create mode 100644 lexers/testdata/python/test_decorators.expected diff --git a/lexers/embedded/python.xml b/lexers/embedded/python.xml index e92867222..a6e889c64 100644 --- a/lexers/embedded/python.xml +++ b/lexers/embedded/python.xml @@ -379,7 +379,7 @@ - + diff --git a/lexers/testdata/python/test_complex_file1.expected b/lexers/testdata/python/test_complex_file1.expected index ff3592d5d..64c9f5b00 100644 --- a/lexers/testdata/python/test_complex_file1.expected +++ b/lexers/testdata/python/test_complex_file1.expected @@ -713,9 +713,7 @@ {"type":"Keyword","value":"else"}, {"type":"Punctuation","value":":"}, {"type":"Text","value":"\n "}, - {"type":"NameDecorator","value":"@functools"}, - {"type":"Operator","value":"."}, - {"type":"Name","value":"wraps"}, + {"type":"NameDecorator","value":"@functools.wraps"}, {"type":"Punctuation","value":"("}, {"type":"Name","value":"func"}, {"type":"Punctuation","value":")"}, @@ -863,9 +861,7 @@ {"type":"Keyword","value":"else"}, {"type":"Punctuation","value":":"}, {"type":"Text","value":"\n "}, - {"type":"NameDecorator","value":"@functools"}, - {"type":"Operator","value":"."}, - {"type":"Name","value":"wraps"}, + {"type":"NameDecorator","value":"@functools.wraps"}, {"type":"Punctuation","value":"("}, {"type":"Name","value":"func"}, {"type":"Punctuation","value":")"}, diff --git a/lexers/testdata/python/test_decorators.actual b/lexers/testdata/python/test_decorators.actual new file mode 100644 index 000000000..4b9cddc4f --- /dev/null +++ b/lexers/testdata/python/test_decorators.actual @@ -0,0 +1,15 @@ +@decorator1 +def foo(): + print("foo") + +@decorator2.member +def bar(): + print("bar") + +@decorator3 . member(param=1) +def baz(): + print("baz") + +@decorator4 . member1 .member2 (param=1) +def bat(): + print("bat") diff --git a/lexers/testdata/python/test_decorators.expected b/lexers/testdata/python/test_decorators.expected new file mode 100644 index 000000000..d03dcc361 --- /dev/null +++ b/lexers/testdata/python/test_decorators.expected @@ -0,0 +1,61 @@ +[ + {"type":"NameDecorator","value":"@decorator1"}, + {"type":"Text","value":"\n"}, + {"type":"Keyword","value":"def"}, + {"type":"Text","value":" "}, + {"type":"NameFunction","value":"foo"}, + {"type":"Punctuation","value":"():"}, + {"type":"Text","value":"\n "}, + {"type":"NameBuiltin","value":"print"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralStringDouble","value":"\"foo\""}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":"\n\n"}, + {"type":"NameDecorator","value":"@decorator2.member"}, + {"type":"Text","value":"\n"}, + {"type":"Keyword","value":"def"}, + {"type":"Text","value":" "}, + {"type":"NameFunction","value":"bar"}, + {"type":"Punctuation","value":"():"}, + {"type":"Text","value":"\n "}, + {"type":"NameBuiltin","value":"print"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralStringDouble","value":"\"bar\""}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":"\n\n"}, + {"type":"NameDecorator","value":"@decorator3 . member"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"param"}, + {"type":"Operator","value":"="}, + {"type":"LiteralNumberInteger","value":"1"}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":"\n"}, + {"type":"Keyword","value":"def"}, + {"type":"Text","value":" "}, + {"type":"NameFunction","value":"baz"}, + {"type":"Punctuation","value":"():"}, + {"type":"Text","value":"\n "}, + {"type":"NameBuiltin","value":"print"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralStringDouble","value":"\"baz\""}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":"\n\n"}, + {"type":"NameDecorator","value":"@decorator4 . member1 .member2"}, + {"type":"Text","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"param"}, + {"type":"Operator","value":"="}, + {"type":"LiteralNumberInteger","value":"1"}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":"\n"}, + {"type":"Keyword","value":"def"}, + {"type":"Text","value":" "}, + {"type":"NameFunction","value":"bat"}, + {"type":"Punctuation","value":"():"}, + {"type":"Text","value":"\n "}, + {"type":"NameBuiltin","value":"print"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralStringDouble","value":"\"bat\""}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":"\n"} +]