diff options
author | blackbird <devnull@localhost> | 2006-10-28 19:54:04 +0200 |
---|---|---|
committer | blackbird <devnull@localhost> | 2006-10-28 19:54:04 +0200 |
commit | 1612315c4b33db53324d6b1e0176b4a8c3f129ca (patch) | |
tree | 00a89f9ca3c79938aa28e8de5cfe68db7d73b5eb /pygments/lexer.py | |
parent | 186a861c424c8bbbaf2bfa5786a7c2dc9488e0ff (diff) | |
download | pygments-1612315c4b33db53324d6b1e0176b4a8c3f129ca.tar.gz |
[svn] added `guess_lexer_for_filename` method that automatically detects dialects of languages
Diffstat (limited to 'pygments/lexer.py')
-rw-r--r-- | pygments/lexer.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/pygments/lexer.py b/pygments/lexer.py index 049b2868..55a74e19 100644 --- a/pygments/lexer.py +++ b/pygments/lexer.py @@ -1,15 +1,20 @@ # -*- coding: utf-8 -*- """ -pygments.lexer -~~~~~~~~~~~~~~ + pygments.lexer + ~~~~~~~~~~~~~~ -Base lexer classes. + Base lexer classes. -:copyright: 2006 by Georg Brandl. -:license: GNU LGPL, see LICENSE for more details. + :copyright: 2006 by Georg Brandl. + :license: GNU LGPL, see LICENSE for more details. """ import re +try: + set +except NameError: + from sets import Set as set + from types import FunctionType from pygments.token import Error, Text, Other, _TokenType from pygments.util import get_bool_opt, get_int_opt, make_analysator @@ -31,6 +36,9 @@ class LexerMeta(type): def __new__(cls, name, bases, d): if 'analyse_text' in d: d['analyse_text'] = make_analysator(d['analyse_text']) + for key in 'aliases', 'filenames', 'alias_filenames': + if key in d: + d[key] = set(d[key]) return type.__new__(cls, name, bases, d) @@ -57,6 +65,9 @@ class Lexer(object): #: fn match rules filenames = [] + #: fn alias filenames + alias_filenames = [] + __metaclass__ = LexerMeta def __init__(self, **options): @@ -203,7 +214,7 @@ def bygroups(*args): yield match.start(i + 1), action, data else: if ctx: - ctx.pos = match.start(i+1) + ctx.pos = match.start(i + 1) for item in action(lexer, _PseudoMatch(match.start(i + 1), match.group(i + 1)), ctx): if item: |