Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
Remove . as a operator in Python lexer (rouge-ruby#1375)
Browse files Browse the repository at this point in the history
Rouge, consistent with Pygments, lexes `.` as an operator. Doing so
causes issues with numbers that use `.`. The Python specification does 
not identify `.` as an operator. This commit instead causes `.` to be
lexed as punctuation.
  • Loading branch information
ajnisbet authored and mattt committed May 21, 2020
1 parent 9fcee31 commit 5f0615c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/rouge/lexers/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ def self.exceptions

rule %r/[^\S\n]+/, Text
rule %r(#(.*)?\n?), Comment::Single
rule %r/[\[\]{}:(),;]/, Punctuation
rule %r/[\[\]{}:(),;.]/, Punctuation
rule %r/\\\n/, Text
rule %r/\\/, Text

rule %r/(in|is|and|or|not)\b/, Operator::Word
rule %r/(<<|>>|\/\/|\*\*)=?/, Operator
rule %r/[-~+\/*%=<>&^|@]=?|!=/, Operator
rule %r/\.(?![0-9])/, Operator # so it doesn't match float literals

rule %r/(from)((?:\\\s|\s)+)(#{dotted_identifier})((?:\\\s|\s)+)(import)/ do
groups Keyword::Namespace,
Expand Down
2 changes: 2 additions & 0 deletions spec/visual/samples/python
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,5 @@ float_literals = [
# PEP 465
a = b @ c
x @= y

floats = (19.0, 19.)

0 comments on commit 5f0615c

Please sign in to comment.