view MoinMoin/parser/ @ 3911:348c9b6e0033

ParserBase (and other parsers deriving from it): cleanup / refactorings: source code reformattings / rearrangements, PEP8 fixes using booleans instead of 0/1, use raw strings for regexes reduce code duplication better attr names introduce tabwidth constant as a class member
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 02 Aug 2008 13:48:59 +0200
parents 71d89ce8b878
children 5eb02932f387
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - Pascal Source Parser

    @copyright: 2004-2005 Johannes Berg <>
    @license: GNU GPL, see COPYING for details.

from MoinMoin.parser._ParserBase import ParserBase

Dependencies = ['user'] # the "Toggle line numbers link" depends on user's language

class Parser(ParserBase):

    parsername = 'ColorizedPascal'
    extensions = ['.pas']
    Dependencies = Dependencies

    def __init__(self, raw, request, **kw):
        ParserBase.__init__(self, raw, request, **kw)
        self._ignore_case = True

    def setupRules(self):

        self.addRulePair("Comment", r"\(\*", r"\*\)")
        self.addRulePair("Comment", r"\{", r"\}")
        self.addRule("Comment", r"//.*$")
        self.addRulePair("String", r"'", r"'")
        self.addRule("Char", r"'\\.'|#[a-f0-9][a-f0-9]")
        self.addRule("Number", r"[0-9](\.[0-9]*)?(eE[+-][0-9])?|\$[0-9a-fA-F]+")
        self.addRule("ID", r"[a-zA-Z_][0-9a-zA-Z_]*")
        self.addRule("SPChar", r"[~!%^&*()+=|\[\]:;,.<>/?{}-]")

        reserved_words = ['class', 'interface', 'set', 'uses', 'unit',
                          'byte', 'integer', 'longint', 'float', 'double',
                          'extended', 'char', 'shortint', 'boolean',
                          'var', 'const', 'private', 'public', 'protected',
                          'new', 'this', 'super', 'abstract', 'native',
                          'synchronized', 'transient', 'volatile', 'strictfp',
                          'if', 'else', 'while', 'for', 'do', 'case', 'default',
                          'try', 'except', 'finally', 'raise', 'continue', 'break',
                          'begin', 'end', 'type', 'class', 'implementation',
                          'procedure', 'function', 'constructor', 'destructor', 'program']


        constant_words = ['true', 'false', 'nil']