Ejemplo n.º 1
0
    def def_fsm_char_pattern(cls, ch, regex, *args):
        """Register new FSM character pattern within tokenizer.
        
        :Parameters:
            ch : str
                the FSM character
            regex 
                regular expression matching all characters from the class,
                it may be either string describing regular expression or
                a regular expression object compiled with ``re.compile()``.
                See documentation of
                `ezmlex.patterns.def_pattern()` for details.
        :Note:
            
            FSM character patterns must not overlap. If one character class
            within tokenizer matches given item, no other pattern in the
            same tokenizer may match this item.

        :Note:

            If it doesn't exist, this method will create the dictionary
            ``_fsm_char_patterns`` within ``cls`` subclass (as a class
            attribute).

        :Note:

            This method may throw exceptions in case the `ch` was already
            registered. For exception specification, see documentation of
            `ezmlex.patterns.def_pattern()`.
        """
        from ezmlex.patterns import def_pattern, ccat
        if ch == '\0':
            raise RuntimeError('FSM char %s is reserved' % ch)
        def_pattern(cls.fsm_char_patterns(), ch, ccat('^', regex, '$'), *args)
Ejemplo n.º 2
0
    def def_pattern(cls, *args):
        """Register new helper pattern within tokenizer.
        
        :Parameters:
            args
                arguments and their meaning are same as for
                `ezmlex.patterns.def_pattern()`,
                except that there must be no ``tab`` argument in 
                ``*args`` list, and the ``*args`` list must start from ``_id``.
        :Note:

            If it doesn't exist, this method will create the dictionary
            ``_patterns`` within ``cls`` subclass (as a class attribute).

        :Note:

            This method may throw exceptions in case the pattern was already
            registered. For exception specification, see documentation of
            `ezmlex.patterns.def_pattern()`.
        """
        from ezmlex.patterns import def_pattern
        def_pattern(cls.patterns(), *args)