forked from rhizomedotorg/classic.rhizome.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmypygments.py
40 lines (37 loc) · 1.08 KB
/
mypygments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *
from pygments.lexers._mapping import LEXERS
import re
__all__ = ['MyBBCodeLexer']
class MyBBCodeLexer(RegexLexer):
"""
Lexer for my extended bbcode.
"""
name = "MyBBCode"
aliases = ['mybbcode', 'bbdocs']
flags = re.DOTALL
tokens = {
'root' : [
(r'[^[\]]+', Text),
(r'(\[)(/?[^\]\n\r=]+)(\])',
bygroups(Keyword, Keyword.Pseudo, Keyword)),
(r'(\[)([^\]\n\r=]+)(=)("[^\]\n\r="]+"|[^\]\n\r= ]+)(\])',
bygroups(Keyword, Keyword.Pseudo, Operator, String, Keyword)),
(r'(\[)([^\]\n\r= ]+)( )',
bygroups(Keyword, Keyword.Pseudo, Text),
'multiarg'),
],
'multiarg' : [
(r'([^\]\n\r= ]+)(=)("[^\]\n\r="]+"|[^\]\n\r= ]+)',
bygroups(Name.Attribute, Operator, String)),
(' ', Text),
(r'\]', Keyword, '#pop'),
],
}
LEXERS['MyBBCodeLexer'] = (
'bbcode.mypygments.',
'MyBBCode',
('mybbcode', 'bbdocs'),
(),
(),
)