Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/rouge/demos/python
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
lazy import re


def fib(n): # write Fibonacci series up to n
"""Print a Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print a,
a, b = b, a+b


_ANSI_RE = None

def strip_ansi(s: str) -> str:
"""Remove ANSI escapes from a string."""
if _ANSI_RE is None:
global _ANSI_RE
_ANSI_RE = re.compile(r"\033\[[;?0-9]*[a-zA-Z]")
return _ANSI_RE.sub("", s)
6 changes: 6 additions & 0 deletions lib/rouge/lexers/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def current_string

rule %r/class\b/, Keyword, :classname

# handle `lazy import` soft keyword usage
# since `import` is a hard keyword, we know that this usage has to be
# the soft-keyword case
rule %r/lazy\b(?=#{inline_ws}import\b)/, Keyword

rule %r/`.*?`/, Str::Backtick
rule %r/([rtfbu]{0,2})('''|"""|['"])/i do |m|
groups Str::Affix, Str::Heredoc
Expand Down Expand Up @@ -173,6 +178,7 @@ def current_string
# import after from, meaning we don't push the :import state
state :from_import do
mixin :inline_whitespace
rule %r/lazy\b/, Keyword::Namespace
rule %r/import\b/, Keyword::Namespace, :pop!
rule(//) { pop! }
end
Expand Down
10 changes: 10 additions & 0 deletions spec/visual/samples/python
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,13 @@ match (100, 200):
thing \
:
other


lazy = "deferred"
lazy import requests
lazy \
import \
re
from typing lazy import Iterator
from typing lazy \
import Generator