added support for raw/unicode strings in python mode
--HG-- branch : pmacs2
This commit is contained in:
parent
c63e82e9a7
commit
7343156e73
|
@ -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"(?<![\.0-9a-zA-Z_])(?:0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"),
|
||||
PatternRule(r"float", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)(?![\.0-9a-zA-Z_])"),
|
||||
PatternRule(r"imaginary", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+|(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)[jJ])(?![\.0-9a-zA-Z_])"),
|
||||
RegionRule(r'string', r'"""', StringGrammar, r'"""'),
|
||||
RegionRule(r'string', r"'''", StringGrammar, r"'''"),
|
||||
RegionRule(r'string', r'"', StringGrammar, r'"'),
|
||||
RegionRule(r'string', r"'", StringGrammar, r"'"),
|
||||
|
||||
OverridePatternRule(r'comment', r'#@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.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'),
|
||||
|
|
Loading…
Reference in New Issue