##
## BenchmarkFileParser_KISS2.py
##      - parser class for the KISS2 format
##

# $Id: BenchmarkFileParser_KISS2.py,v 1.11 2007/01/18 22:20:59 jarda Exp $


# import of required modules {{{
from Plex import *

from BenchmarkFileParser import BenchmarkFileParser
from Constants import Constants
from ScannerConstants import ScannerConstants
# }}}


# class BenchmarkFileParser_KISS2() {{{
class BenchmarkFileParser_KISS2(BenchmarkFileParser):
    # DOC {{{
    """Parser class for the KISS2 format.
    """
    # }}}


    # METHODS {{{

    def createLexicon(self):
        # DOC {{{
        """Creates lexicon for the parser.
        """
        # }}}

        # CODE {{{
        self.lexicon = Lexicon([
            (Str('#') + Rep(AnyBut('\n')), ScannerConstants.T_COMMENT,),
            (Str('.i'), ScannerConstants.T_INPUT,),
            (Str('.o'), ScannerConstants.T_OUTPUT,),
            (Str('.p'), ScannerConstants.T_TRANSITIONS_COUNT,),
            (Str('.r'), ScannerConstants.T_RESET_STATE,),
            (Str('.s'), ScannerConstants.T_STATES_COUNT,),
            (Str('.e'), ScannerConstants.T_END,),
            ScannerConstants.R_ASTERISK,
            ScannerConstants.R_NEWLINE,
            ScannerConstants.R_IGNORE_SPACES_AND_TABS,
            ScannerConstants.R_SYMBOL_WITH_T_AND_H,
        ])
        # }}}

    
    def getInitialAttributeValue_DFF_COUNT(self):
        # DOC {{{
        """Returns initial value for DFF COUNT benchmark attribute.
        """
        # }}}

        # CODE {{{
        return Constants.BA_UNSUPPORTED
        # }}}

    
    def getInitialAttributeValue_TRANSITIONS_COUNT(self):
        # DOC {{{
        """Returns initial value for TRANSITIONS COUNT benchmark attribute.
        """
        # }}}

        # CODE {{{
        return 0
        # }}}

    
    def accumulateLine_TRANSITIONS_COUNT(self, lineTokens, getValueMethod, setValueMethod):
        # DOC {{{
        """Accumulator method that updates value of TRANSITIONS COUNT benchmark attribute.

        Parameters

            lineTokens -- tokens from one line of the benchmark file

            getValueMethod -- method that returns the current value of the
                benchmark attribute
                
            setValueMethod -- method that sets value of the benchmark attribute        
        """
        # }}}

        # CODE {{{
        if (lineTokens[0][0] == ScannerConstants.T_TRANSITIONS_COUNT):
            setValueMethod(int(lineTokens[1][1]))
        # }}}

    
    def getInitialAttributeValue_RESET_STATE(self):
        # DOC {{{
        """Returns initial value for RESET STATE benchmark attribute.
        """
        # }}}

        # CODE {{{
        return Constants.BA_NOT_FOUND
        # }}}

    
    def accumulateLine_RESET_STATE(self, lineTokens, getValueMethod, setValueMethod):
        # DOC {{{
        """Accumulator method that updates value of RESET benchmark attribute.

        Parameters

            lineTokens -- tokens from one line of the benchmark file

            getValueMethod -- method that returns the current value of the
                benchmark attribute
                
            setValueMethod -- method that sets value of the benchmark attribute        
        """
        # }}}

        # CODE {{{
        if (lineTokens[0][0] == ScannerConstants.T_RESET_STATE):
            setValueMethod(lineTokens[1][1])
        # }}}

    
    def getInitialAttributeValue_STATES_COUNT(self):
        # DOC {{{
        """Returns initial value for STATES COUNT benchmark attribute.
        """
        # }}}

        # CODE {{{
        return Constants.BA_NOT_FOUND
        # }}}

    
    def accumulateLine_STATES_COUNT(self, lineTokens, getValueMethod, setValueMethod):
        # DOC {{{
        """Accumulator method that updates value of STATES COUNT benchmark attribute.

        Parameters

            lineTokens -- tokens from one line of the benchmark file

            getValueMethod -- method that returns the current value of the
                benchmark attribute
                
            setValueMethod -- method that sets value of the benchmark attribute        
        """
        # }}}

        # CODE {{{
        if (lineTokens[0][0] == ScannerConstants.T_STATES_COUNT):
            setValueMethod(int(lineTokens[1][1]))
        # }}}

    
    def getInitialAttributeValue_INPUTS_COUNT(self):
        # DOC {{{
        """Returns initial value for INPUTS COUNT benchmark attribute.
        """
        # }}}

        # CODE {{{
        return Constants.BA_NOT_FOUND
        # }}}

    
    def accumulateLine_INPUTS_COUNT(self, lineTokens, getValueMethod, setValueMethod):
        # DOC {{{
        """Accumulator method that updates value of INPUTS COUNT benchmark attribute.

        Parameters

            lineTokens -- tokens from one line of the benchmark file

            getValueMethod -- method that returns the current value of the
                benchmark attribute
                
            setValueMethod -- method that sets value of the benchmark attribute        
        """
        # }}}

        # CODE {{{
        if (lineTokens[0][0] == ScannerConstants.T_INPUT):
            setValueMethod(int(lineTokens[1][1]))
        # }}}

    
    def getInitialAttributeValue_OUTPUTS_COUNT(self):
        # DOC {{{
        """Returns initial value for OUTPUTS COUNT benchmark attribute.
        """
        # }}}

        # CODE {{{
        return Constants.BA_NOT_FOUND
        # }}}

    
    def accumulateLine_OUTPUTS_COUNT(self, lineTokens, getValueMethod, setValueMethod):
        # DOC {{{
        """Accumulator method that updates value of OUTPUTS COUNT benchmark attribute.

        Parameters

            lineTokens -- tokens from one line of the benchmark file

            getValueMethod -- method that returns the current value of the
                benchmark attribute
                
            setValueMethod -- method that sets value of the benchmark attribute        
        """
        # }}}

        # CODE {{{
        if (lineTokens[0][0] == ScannerConstants.T_OUTPUT):
            setValueMethod(int(lineTokens[1][1]))
        # }}}


    # }}}
# }}}
