2007-07-23 15:28:27 -04:00
|
|
|
import color, mode2
|
|
|
|
from lex3 import Grammar, PatternRule, RegionRule, PatternGroupRule
|
|
|
|
|
2007-07-23 15:52:53 -04:00
|
|
|
class RSTString(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule('escaped', r'\\.'),
|
|
|
|
]
|
|
|
|
|
2007-07-23 15:28:27 -04:00
|
|
|
class RSTGrammar(Grammar):
|
|
|
|
rules = [
|
2007-07-23 15:52:53 -04:00
|
|
|
PatternGroupRule(r'title', r'title_over', r'^=+\n', r'title', r'^.*?\n',
|
|
|
|
r'title_under', r'^=+\n'),
|
|
|
|
PatternGroupRule(r'title', r'title', r'^.*?\n', r'title_under', r'^=+\n'),
|
|
|
|
PatternGroupRule(r'subtitle', r'subtitle_over', r'^-+\n', r'subtitle',
|
|
|
|
r'^.*?\n', r'subtitle_under', r'^-+\n'),
|
|
|
|
PatternGroupRule(r'subtitle', r'subtitle', r'^.*?\n', r'subtitle_under', r'^-+\n'),
|
|
|
|
|
|
|
|
# this is kind of a hack, ugh
|
|
|
|
PatternGroupRule(r'definition', r'term', r'^[^ ]+\n', r'definition', r'^ +'),
|
|
|
|
PatternRule(r'fieldname', r'^:.+?:'),
|
|
|
|
PatternRule(r'optionname', r'^(?:--|-|/)[a-zA-Z](?: ?[-a-zA-Z_]+)'),
|
|
|
|
|
|
|
|
PatternRule(r'lineblock', r'^\|'),
|
|
|
|
RegionRule(r'blocktest', r'>>>', Grammar, '^\n'),
|
|
|
|
PatternRule(r'transition', r'^[-=.,;]{4,}\n'),
|
|
|
|
|
|
|
|
RegionRule(r'emphasis', r'\*', RSTString, r'\*'),
|
|
|
|
RegionRule(r'strong_emphasis', r'\*\*', RSTString, r'\*\*'),
|
|
|
|
RegionRule(r'interpreted', r'`', RSTString, r'`'),
|
|
|
|
RegionRule(r'inline_literal', r'``', RSTString, r'``'),
|
|
|
|
RegionRule(r'substitution', r'\|', RSTString, r'\|'),
|
|
|
|
|
|
|
|
PatternRule(r'anonymous', r'[a-zA-Z]+__'),
|
|
|
|
PatternRule(r'reference', r'[a-zA-Z]+_'),
|
|
|
|
PatternRule(r'footnote', r'\[[0-9]+\]_'),
|
|
|
|
PatternRule(r'citation', r'\[.+?\]_'),
|
|
|
|
PatternRule(r'url', r'http://[^ ]+'),
|
|
|
|
|
|
|
|
PatternRule(r'bullet', r'^ *[-*+]'),
|
|
|
|
PatternRule(r'enumeration', r'^ *(?:[0-9]+|#)\.'),
|
2007-07-23 15:28:27 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
class RST(mode2.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'RST'
|
|
|
|
extensions = ['.rst']
|
|
|
|
grammar = RSTGrammar
|
|
|
|
colors = {
|
2007-07-23 15:52:53 -04:00
|
|
|
'title': ('blue', 'default'),
|
|
|
|
'title_over': ('blue', 'default'),
|
|
|
|
'title_under': ('blue', 'default'),
|
|
|
|
'subtitle': ('cyan', 'default'),
|
|
|
|
'subtitle_over': ('cyan', 'default'),
|
|
|
|
'subtitle_under': ('cyan', 'default'),
|
|
|
|
|
|
|
|
'definition': ('green', 'default'),
|
|
|
|
'fieldname': ('green', 'default'),
|
|
|
|
'optionname': ('green', 'default'),
|
|
|
|
|
|
|
|
'lineblock': ('cyan', 'default'),
|
|
|
|
'blocktest': ('cyan', 'default'),
|
|
|
|
'transition': ('cyan', 'default'),
|
|
|
|
|
|
|
|
'emphasis': ('red', 'default'),
|
|
|
|
'strong_emphasis': ('red', 'default'),
|
|
|
|
'interpreted': ('magenta', 'default'),
|
|
|
|
'inline_literal': ('magenta', 'default'),
|
|
|
|
'substitution': ('magenta', 'default'),
|
|
|
|
|
|
|
|
'anonymous': ('blue', 'default'),
|
|
|
|
'reference': ('blue', 'default'),
|
|
|
|
'footnote': ('blue', 'default'),
|
|
|
|
'citation': ('blue', 'default'),
|
|
|
|
'url': ('blue', 'default'),
|
|
|
|
|
|
|
|
'bullet': ('magenta', 'default'),
|
|
|
|
'enumeration': ('magenta', 'default'),
|
2007-07-23 15:28:27 -04:00
|
|
|
}
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = RST.install
|