mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-17 20:58:08 +02:00
fix: parse all of @foo.bar
as a Python decorator
This commit is contained in:
parent
750df9844d
commit
396f5726a4
@ -379,7 +379,7 @@
|
||||
</rule>
|
||||
</state>
|
||||
<state name="name">
|
||||
<rule pattern="@[_\p{L}][_\p{L}\p{N}]*">
|
||||
<rule pattern="@[_\p{L}][_\p{L}\p{N}]*(\s*\.\s*[_\p{L}][_\p{L}\p{N}]*)*">
|
||||
<token type="NameDecorator"/>
|
||||
</rule>
|
||||
<rule pattern="@">
|
||||
|
@ -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":")"},
|
||||
|
15
lexers/testdata/python/test_decorators.actual
vendored
Normal file
15
lexers/testdata/python/test_decorators.actual
vendored
Normal file
@ -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")
|
61
lexers/testdata/python/test_decorators.expected
vendored
Normal file
61
lexers/testdata/python/test_decorators.expected
vendored
Normal file
@ -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"}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user