##
## BenchmarkFileParser_PLA.py
##      - parser class for the PLA format
##

# $Id: BenchmarkFileParser_PLA.py,v 1.8 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_PLA() {{{
class BenchmarkFileParser_PLA(BenchmarkFileParser):
    # DOC {{{
    """Parser class for the PLA format.
    """
    # }}}


    # METHODS {{{

    def createLexicon(self):
        # DOC {{{
        """Creates and returns a lexicon for the scanner.
        """
        # }}}

        # CODE {{{
        self.lexicon = Lexicon([
            (Str('#') + Rep(AnyBut('\n')), ScannerConstants.T_COMMENT,),
            (Str('.i'), ScannerConstants.T_INPUTS,),
            (Str('.o'), ScannerConstants.T_OUTPUTS,),
            (Str('.p'), ScannerConstants.T_TERMS_COUNT,),
            (Str('.e'), ScannerConstants.T_END,),
            (Str('.type'), ScannerConstants.T_MATRIX_TYPE,),
            (Str('.ob'), ScannerConstants.T_OUTPUT_FUNCTION_NAMES,),
            (Str('.ilb'), ScannerConstants.T_BINARY_VARIABLE_NAMES,),
            (Str('.I'), ScannerConstants.T_INPUT,),
            (Str('.O'), ScannerConstants.T_OUTPUT,),
            (Str('.N'), ScannerConstants.T_NAME,),
            ScannerConstants.R_BAR,
            ScannerConstants.R_EQ_EQUAL_SIGN,
            ScannerConstants.R_DOUBLE_QUOTE,
            ScannerConstants.R_NEWLINE,
            ScannerConstants.R_PLA_SYMBOL,
            ScannerConstants.R_IGNORE_SPACES_AND_TABS,
        ])
        # }}}


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

        # CODE {{{
        return 0
        # }}}


    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_INPUTS):
            setValueMethod(int(lineTokens[1][1]))
        # }}}


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

        # CODE {{{
        return 0
        # }}}


    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_OUTPUTS):
            setValueMethod(int(lineTokens[1][1]))
        # }}}


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

        # CODE {{{
        return 0
        # }}}


    def accumulateLine_TERMS_COUNT(self, lineTokens, getValueMethod, setValueMethod):
        # DOC {{{
        """Accumulator method that updates value of TERMS 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_TERMS_COUNT):
            setValueMethod(int(lineTokens[1][1]))
        # }}}


    # }}}
# }}}
