Skip to content

Commit 16ffecb

Browse files
authored
Use String::Affix token for string prefixes in Python lexer (#1635)
String prefixes were given the same token (`Str`) at the string itself. This commit uses the `String::Affix` token for the prefix character. This is consistent with the tokens used by Pygments. New styles for `String::Affix` are also added.
1 parent 7f45c7d commit 16ffecb

12 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/rouge/lexers/python.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def current_string
115115
# TODO: not in python 3
116116
rule %r/`.*?`/, Str::Backtick
117117
rule %r/([rfbu]{0,2})('''|"""|['"])/i do |m|
118-
token Str
118+
groups Str::Affix, Str
119119
current_string.register type: m[1].downcase, delim: m[2]
120120
push :generic_string
121121
end

lib/rouge/themes/base16.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def self.make_light!
6767
style Keyword::Declaration, :fg => :base09
6868

6969
style Literal::String, :fg => :base0B
70+
style Literal::String::Affix, :fg => :base0E
7071
style Literal::String::Regex, :fg => :base0C
7172

7273
style Literal::String::Interpol,

lib/rouge/themes/bw.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class BlackWhiteTheme < CSSTheme
2626
style Name::Tag, :bold => true
2727

2828
style Literal::String, :italic => true
29+
style Literal::String::Affix, :bold => true
2930
style Literal::String::Interpol, :bold => true
3031
style Literal::String::Escape, :bold => true
3132

lib/rouge/themes/colorful.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Colorful < CSSTheme
3737
style Name::Decorator, :fg => "#555", :bold => true
3838

3939
style Literal::String, :bg => "#fff0f0"
40+
style Literal::String::Affix, :fg => "#080", :bold => true
4041
style Literal::String::Char, :fg => "#04D"
4142
style Literal::String::Doc, :fg => "#D42"
4243
style Literal::String::Interpol, :bg => "#eee"

lib/rouge/themes/github.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Github < CSSTheme
3535
style Literal::Number::Integer, :fg => '#009999'
3636
style Literal::Number::Oct, :fg => '#009999'
3737
style Literal::Number, :fg => '#009999'
38+
style Literal::String::Affix, :fg => '#000000', :bold => true
3839
style Literal::String::Backtick, :fg => '#d14'
3940
style Literal::String::Char, :fg => '#d14'
4041
style Literal::String::Doc, :fg => '#d14'

lib/rouge/themes/gruvbox.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def self.make_light!
150150
Literal::String::Interpol,
151151
Literal::String::Regex, :fg => :green, :italic => true
152152

153+
style Literal::String::Affix, :fg => :red
154+
153155
style Literal::String::Escape, :fg => :orange
154156

155157
style Name::Namespace,

lib/rouge/themes/igor_pro.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class IgorPro < CSSTheme
1515
style Keyword::Reserved, :fg => '#007575'
1616
style Keyword, :fg => '#0000FF'
1717
style Literal::String, :fg => '#009C00'
18+
style Literal::String::Affix, :fg => '#0000FF'
1819
style Name::Builtin, :fg => '#C34E00'
1920
end
2021
end

lib/rouge/themes/magritte.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Magritte < CSSTheme
6262
Literal::Date, :fg => :forest, :bold => true
6363
style Literal::String::Symbol, :fg => :forest
6464
style Literal::String, :fg => :wine, :bold => true
65+
style Literal::String::Affix, :fg => :royal, :bold => true
6566
style Literal::String::Escape,
6667
Literal::String::Char,
6768
Literal::String::Interpol, :fg => :purple, :bold => true

lib/rouge/themes/monokai.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Monokai < CSSTheme
5959
Literal::Number::Oct,
6060
Literal::Number,
6161
Literal::String::Escape, :fg => :light_violet
62+
style Literal::String::Affix, :fg => :soft_cyan, :bold => true
6263
style Literal::String::Backtick,
6364
Literal::String::Char,
6465
Literal::String::Doc,

lib/rouge/themes/pastie.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Pastie < CSSTheme
3636
style Num, :fg => '#0000dd', :bold => true
3737

3838
style Str, :fg => '#dd2200', :bg => '#fff0f0'
39+
style Str::Affix, :fg => '#008800', :bold => true
3940
style Str::Escape, :fg => '#0044dd', :bg => '#fff0f0'
4041
style Str::Interpol, :fg => '#3333bb', :bg => '#fff0f0'
4142
style Str::Other, :fg => '#22bb22', :bg => '#f0fff0'

0 commit comments

Comments
 (0)