Files
i2p.www/i2p2www/lexers.py

48 lines
2.0 KiB
Python
Raw Normal View History

2013-06-12 01:29:36 +00:00
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *
class DataSpecLexer(RegexLexer):
name = 'DataSpec'
aliases = ['dataspec']
filenames = []
tokens = {
'root': [
(r'(\s*)(\+-)', bygroups(Text, Text), 'boundary'),
(r'(\s+)([\+|])', bygroups(Text, Text), 'content'),
(r'~', Generic.Strong, 'content'),
2013-06-12 02:00:14 +00:00
(r'(\s*)([\w=;]+)(\s)(::)(\s)', bygroups(Text, Name.Tag, Text, Operator, Text), 'definition'),
2013-06-12 01:29:36 +00:00
],
'boundary': [
(r'---\+$', Text, '#pop'),
(r'(//)(-\+)?$', bygroups(Generic.Strong, Text), '#pop'),
(r'---\+-', Text),
2013-06-12 02:00:14 +00:00
(r'---\+\s', Text, '#pop', 'content'),
2013-06-12 01:29:36 +00:00
(r'(//)(-\+-)', bygroups(Generic.Strong, Text)),
],
'content': [
(r'(\s*)([\+|])$', bygroups(Text, Text), '#pop'),
2013-06-12 02:00:14 +00:00
(r'(\s*)(\.\.\.)$', bygroups(Text, Generic.Strong), '#pop'),
2013-06-12 01:29:36 +00:00
(r'(\s*)(~)$', bygroups(Text, Generic.Strong), '#pop'),
2013-06-12 02:00:14 +00:00
(r'(\s*)([\w=;]+)$', bygroups(Text, Name.Tag), '#pop'),
(r'(\s*)([\w=;]+)', bygroups(Text, Name.Tag)),
2013-06-12 01:29:36 +00:00
(r'(\s*)(\|)', bygroups(Text, Text)),
2013-06-12 02:00:14 +00:00
(r'(\s*)(\()', bygroups(Text, Punctuation), 'expression'),
],
'expression': [
(r'(\s*)(\))', bygroups(Text, Punctuation), '#pop'),
(r'(\s*)(\+)', bygroups(Text, Punctuation)),
(r'(\s*)(\w+)', bygroups(Text, Name)),
2013-06-12 01:29:36 +00:00
],
'definition': [
2013-06-12 02:00:14 +00:00
(r'(\s*)([\w=;]+)(\s)(::)(\s)', bygroups(Text, Name.Tag, Text, Operator, Text)),
2013-06-12 01:29:36 +00:00
(r'(\s*)((?:[A-Z][a-z]+)+)', bygroups(Text, Name.Class)),
2013-06-12 02:00:14 +00:00
(r'(\s*)([\[\]])', bygroups(Text, Punctuation)),
(r'(\s*)(\$\w+)', bygroups(Text, Name.Tag)),
(r'(\s*)([0-9]+)(\+)?', bygroups(Text, Number, Punctuation)),
(r'(-)([0-9]+)', bygroups(Punctuation, Number)),
(r'(\s*)(->|<=|>=|\*)', bygroups(Text, Operator)),
(r'(\s*)([\w()-=\'<>]+)', bygroups(Text, Comment)),
2013-06-12 01:29:36 +00:00
],
}