lib/rouge/lexers/python.rb in rouge-4.1.0 vs lib/rouge/lexers/python.rb in rouge-4.1.1
- old
+ new
@@ -78,18 +78,22 @@
rule %r/\n+/m, Text
rule %r/^(:)(\s*)([ru]{,2}""".*?""")/mi do
groups Punctuation, Text, Str::Doc
end
+ rule %r/\.\.\.\B$/, Name::Builtin::Pseudo
+
rule %r/[^\S\n]+/, Text
rule %r(#(.*)?\n?), Comment::Single
rule %r/[\[\]{}:(),;.]/, Punctuation
rule %r/\\\n/, Text
rule %r/\\/, Text
rule %r/@#{dotted_identifier}/i, Name::Decorator
+ rule %r/(>>>|\.\.\.)\B/, Generic::Prompt
+
rule %r/(in|is|and|or|not)\b/, Operator::Word
rule %r/(<<|>>|\/\/|\*\*)=?/, Operator
rule %r/[-~+\/*%=<>&^|@]=?|!=/, Operator
rule %r/(from)((?:\\\s|\s)+)(#{dotted_identifier})((?:\\\s|\s)+)(import)/ do
@@ -118,11 +122,11 @@
rule %r/([A-Z_]\w*)[ \t]*(?=(\(.*\)))/m, Name::Class
# TODO: not in python 3
rule %r/`.*?`/, Str::Backtick
rule %r/([rfbu]{0,2})('''|"""|['"])/i do |m|
- groups Str::Affix, Str
+ groups Str::Affix, Str::Heredoc
current_string.register type: m[1].downcase, delim: m[2]
push :generic_string
end
# using negative lookbehind so we don't match property names
@@ -176,15 +180,16 @@
state :yield do
mixin :raise
end
state :generic_string do
- rule %r/[^'"\\{]+/, Str
+ rule %r/>>>|\.\.\./, Generic::Prompt, :doctest
+ rule %r/[^'"\\{]+?/, Str
rule %r/{{/, Str
rule %r/'''|"""|['"]/ do |m|
- token Str
+ token Str::Heredoc
if current_string.delim? m[0]
current_string.remove
pop!
end
end
@@ -216,9 +221,20 @@
current_string.type?("r") ? token(Str) : token(Str::Escape)
pop!
end
rule %r/\\./, Str, :pop!
+ end
+
+ state :doctest do
+ rule %r/\n\n/, Text, :pop!
+
+ rule %r/'''|"""/ do
+ token Str::Heredoc
+ pop!(2) if in_state?(:generic_string) # pop :doctest and :generic_string
+ end
+
+ mixin :root
end
state :generic_interpol do
rule %r/[^{}!:]+/ do |m|
recurse m[0]