summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitsuhiko <devnull@localhost>2007-09-09 18:16:20 +0200
committermitsuhiko <devnull@localhost>2007-09-09 18:16:20 +0200
commitd2bdf8b4bc030f1cee5e95f6aa397a83f99ef9d6 (patch)
treefa3ba69d8734400032a5d4849fd39cca64e9f379
parentd3861fc4a66f4c3c9c63c581f1cecaed593d2b51 (diff)
downloadpygments-d2bdf8b4bc030f1cee5e95f6aa397a83f99ef9d6.tar.gz
integrated weechatlog lexer directly into the existing irc lexer
-rw-r--r--pygments/lexers/_mapping.py3
-rw-r--r--pygments/lexers/text.py47
2 files changed, 15 insertions, 35 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 862c84da..e71c9035 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -48,7 +48,7 @@ LEXERS = {
'HtmlPhpLexer': ('pygments.lexers.templates', 'HTML+PHP', ('html+php',), ('*.phtml',), ('application/x-php', 'application/x-httpd-php', 'application/x-httpd-php3', 'application/x-httpd-php4', 'application/x-httpd-php5')),
'HtmlSmartyLexer': ('pygments.lexers.templates', 'HTML+Smarty', ('html+smarty',), (), ('text/html+smarty',)),
'IniLexer': ('pygments.lexers.text', 'INI', ('ini', 'cfg'), ('*.ini', '*.cfg'), ('text/x-ini',)),
- 'IrcLogsLexer': ('pygments.lexers.text', 'IRC logs', ('irc',), (), ('text/x-irclog',)),
+ 'IrcLogsLexer': ('pygments.lexers.text', 'IRC logs', ('irc',), ('*.weechatlog',), ('text/x-irclog',)),
'JavaLexer': ('pygments.lexers.compiled', 'Java', ('java',), ('*.java',), ('text/x-java',)),
'JavascriptDjangoLexer': ('pygments.lexers.templates', 'JavaScript+Django/Jinja', ('js+django', 'javascript+django', 'js+jinja', 'javascript+jinja'), (), ('application/x-javascript+django', 'application/x-javascript+jinja', 'text/x-javascript+django', 'text/x-javascript+jinja', 'text/javascript+django', 'text/javascript+jinja')),
'JavascriptErbLexer': ('pygments.lexers.templates', 'JavaScript+Ruby', ('js+erb', 'javascript+erb', 'js+ruby', 'javascript+ruby'), (), ('application/x-javascript+ruby', 'text/x-javascript+ruby', 'text/javascript+ruby')),
@@ -95,7 +95,6 @@ LEXERS = {
'TextLexer': ('pygments.lexers.special', 'Text only', ('text',), ('*.txt',), ('text/plain',)),
'VbNetLexer': ('pygments.lexers.dotnet', 'VB.net', ('vb.net', 'vbnet'), ('*.vb', '*.bas'), ('text/x-vbnet', 'text/x-vba')),
'VimLexer': ('pygments.lexers.text', 'VimL', ('vim',), ('*.vim', '.vimrc'), ('text/x-vim',)),
- 'WeechatLogLexer': ('pygments.lexers.text', 'Weechat Log', ('weechatlog',), ('*.weechatlog',), ('text/x-weechatlog',)),
'XmlDjangoLexer': ('pygments.lexers.templates', 'XML+Django/Jinja', ('xml+django', 'xml+jinja'), (), ('application/xml+django', 'application/xml+jinja')),
'XmlErbLexer': ('pygments.lexers.templates', 'XML+Ruby', ('xml+erb', 'xml+ruby'), (), ('application/xml+ruby',)),
'XmlLexer': ('pygments.lexers.web', 'XML', ('xml',), ('*.xml', '*.xsl', '*.rss', '*.xslt'), ('text/xml', 'application/xml', 'image/svg+xml', 'application/rss+xml', 'application/atom+xml', 'application/xsl+xml', 'application/xslt+xml')),
diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py
index 12abd35d..4ed18d17 100644
--- a/pygments/lexers/text.py
+++ b/pygments/lexers/text.py
@@ -30,7 +30,7 @@ from pygments.util import get_bool_opt
__all__ = ['IniLexer', 'SourcesListLexer', 'MakefileLexer', 'DiffLexer',
'IrcLogsLexer', 'TexLexer', 'GroffLexer', 'ApacheConfLexer',
'BBCodeLexer', 'MoinWikiLexer', 'RstLexer', 'VimLexer',
- 'GettextLexer', 'WeechatLogLexer']
+ 'GettextLexer']
class IniLexer(RegexLexer):
@@ -202,17 +202,25 @@ class IrcLogsLexer(RegexLexer):
name = 'IRC logs'
aliases = ['irc']
+ filenames = ['*.weechatlog']
mimetypes = ['text/x-irclog']
flags = re.VERBOSE | re.MULTILINE
timestamp = r"""
- ( (?: \[|\()? # Opening bracket or paren for the timestamp
+ (
+ # irssi / xchat and others
+ (?: \[|\()? # Opening bracket or paren for the timestamp
(?: # Timestamp
(?: (?:\d{1,4} [-/]?)+ # Date as - or /-separated groups of digits
[T ])? # Date/time separator: T or space
(?: \d?\d [:.]?)+ # Time as :/.-separated groups of 1 or 2 digits
)
- (?: \]|\))?\s+ )? # Closing bracket or paren for the timestamp
+ (?: \]|\))?\s+ # Closing bracket or paren for the timestamp
+ |
+ # weechat
+ \d{4}\s\w{3}\s\d{2}\s # Date
+ \d{2}:\d{2}:\d{2}\s+ # Time + Whitespace
+ )?
"""
tokens = {
'root': [
@@ -227,9 +235,9 @@ class IrcLogsLexer(RegexLexer):
bygroups(Comment.Preproc, Keyword, Generic.Inserted)),
# join/part msgs
("^" + timestamp + r"""
- (\s*(?:[*]{3}|-!-)\s*) # Star(s)
- ([^\s]+\s+) # Nick + Space
- (.*?\n) # Rest of message """,
+ (\s*(?:\*{3}|<?-[!@=P]?->?)\s*) # Star(s) or symbols
+ ([^\s]+\s+) # Nick + Space
+ (.*?\n) # Rest of message """,
bygroups(Comment.Preproc, Keyword, String, Comment)),
(r"^.*?\n", Text),
],
@@ -702,30 +710,3 @@ class GettextLexer(RegexLexer):
bygroups(Name.Variable, Number.Integer, Name.Variable, Text, String)),
]
}
-
-
-class WeechatLogLexer(RegexLexer):
- """
- Lexer for weechat log files.
-
- *New in Pygments 0.9.*
- """
- name = 'Weechat Log'
- aliases = ['weechatlog']
- filenames = ['*.weechatlog']
- mimetypes = ['text/x-weechatlog']
-
- tokens = {
- 'root' : [
- # date
- (r'(\d{4} \w{3} \d{2} \d{2}:\d{2}:\d{2})(\s+)',
- bygroups(Comment.Preproc, Whitespace)),
- # operators
- (r'(-=-|<--|-->|-@-|-P-)(.*)', bygroups(Operator, Text)),
- # messages
- (r'(<)(\w+)(>)(.*)', bygroups(Operator, Name, Operator, Text)),
- # log start/end
- (r'(\*\*\*\*[\w\s]+)(\d{4} \w{3} \d{2} \d{2}:\d{2}:\d{2}\s+)(\*\*\*\*)',
- Comment)
- ]
- }