diff --git a/mode/python.py b/mode/python.py index 7cd270a..7b2eb6b 100644 --- a/mode/python.py +++ b/mode/python.py @@ -8,6 +8,11 @@ class StringGrammar(Grammar): PatternRule(r'octal', r'\\[0-7]{3}'), PatternRule(r'escaped', r'\\.'), ] +class RawStringGrammar(Grammar): + rules = [ + PatternRule(r'escaped', r"\\'"), + PatternRule(r'escaped', r'\\"'), + ] class PythonGrammar(Grammar): rules = [ @@ -21,16 +26,23 @@ class PythonGrammar(Grammar): PatternRule(r'system_identifier', r'__[a-zA-Z0-9_]+__'), PatternRule(r'private_identifier', r'__[a-zA-Z0-9_]*'), PatternRule(r'hidden_identifier', r'_[a-zA-Z0-9_]*'), + + RegionRule(r'rawstring', r'r"""', RawStringGrammar, r'"""'), + RegionRule(r'rawstring', r"r'''", RawStringGrammar, r"'''"), + RegionRule(r'rawstring', r'r"', RawStringGrammar, r'"'), + RegionRule(r'rawstring', r"r'", RawStringGrammar, r"'"), + RegionRule(r'string', r'u?"""', StringGrammar, r'"""'), + RegionRule(r'string', r"u?'''", StringGrammar, r"'''"), + RegionRule(r'string', r'u?"', StringGrammar, r'"'), + RegionRule(r'string', r"u?'", StringGrammar, r"'"), + PatternRule(r'identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule(r'delimiter', r'\(|\)|\[|\]|{|}|@|,|:|\.|`|=|;|\+=|-=|\*=|/=|//=|%=|&=|\|=|\^=|>>=|<<=|\*\*='), PatternRule(r"operator", r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"), PatternRule(r"integer", r"(?[.a-zA-Z0-9_]+):(?P[.a-zA-Z0-9_]+) *$'), PatternRule(r'comment', r'#.*$'), PatternRule(r'continuation', r'\\\n$'), @@ -180,8 +192,11 @@ class Python(mode2.Fundamental): 'string.null': ('green', 'default'), 'string.octal': ('magenta', 'default'), 'string.escaped': ('magenta', 'default'), - 'string.format': ('yellow', 'default'), 'string.end': ('green', 'default'), + 'rawstring.start': ('green', 'default'), + 'rawstring.null': ('green', 'default'), + 'rawstring.escaped': ('green', 'default'), + 'rawstring.end': ('green', 'default'), 'integer': ('default', 'default'), 'float': ('default', 'default'), 'imaginary': ('default', 'default'),