Demo entry 6659850



Submitted by anonymous on Nov 13, 2017 at 07:19
Language: Python 3. Code size: 726 Bytes.

from collections import Counter

from pygments.lexers import HtmlLexer, JavascriptLexer
from pygments.token import *

class Lexer:
    def __init__(self, alias, lexer, tier1, tier2, invalids):
        for arg, value in locals().items():
            if arg != 'self':
                setattr(self, arg, value)

    def mimetype(self):
        return self.lexer.mimetypes[0]

    def analyze(self, content):
        lexer = self.lexer()
        return Counter("tier1" if token in self.tier1 else
                       "tier2" if token in self.tier2 else
                       "invalids" if token in self.invalids else
                       None for token, v in lexer.get_tokens(content))

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).