GiPSy — p2html Class

py2htmlparser.py

"""
Implements a Python-to-HTML scanner based on the GiPSy.

Library Version 1.1

Copyright 2013 Paul Griffiths
Email: mail@paulgriffiths.net

Distributed under the terms of the GNU General Public License.
http://www.gnu.org/licenses/
"""


from gipsy.pyparser import PyParser
from gipsy.code2htmlmixin import Code2HTMLMixin
from gipsy.programtoken import StringToken, CommentToken, KeywordToken
from gipsy.pytoken import DefinitionToken, DecoratorToken, MLStringToken
from gipsy.pytoken import BuiltinToken


class Py2HTMLParser(PyParser, Code2HTMLMixin):

    """
    A Python-to-HTML scanner class.
    """

    def __init__(self):

        """
        Class initializer.
        """

        PyParser.__init__(self)
        Code2HTMLMixin.__init__(self)

    def _set_token_decoration(self):

        # Override the superclass method and
        # set our decorators

        DefinitionToken.dec_open = '<span class="def">'
        DefinitionToken.dec_close = '</span>'
        KeywordToken.dec_open = '<span class="keyword">'
        KeywordToken.dec_close = '</span>'
        MLStringToken.dec_open = '<span class="string">'
        MLStringToken.dec_close = '</span>'
        StringToken.dec_open = '<span class="string">'
        StringToken.dec_close = '</span>'
        CommentToken.dec_open = '<span class="comment">'
        CommentToken.dec_close = '</span>'
        DecoratorToken.dec_open = '<span class="decorator">'
        DecoratorToken.dec_close = '</span>'
        BuiltinToken.dec_open = '<span class="builtin">'
        BuiltinToken.dec_close = '</span>'