예제 #1
0
    def __computeError(self, codeString, codeFile, markupError):
        """Run a regular expression error over a code file to check for syntax errors"""
        error_throw = ' '

        try:
            # search for syntax error
            error_re = re.search(markupError.regularExpression, codeString,
                                 re.DOTALL)

            # if the error is found, throw it
            error_item = error_re.group(0)
            print('herere')
            self.__createThrowErrorReg(markupError, error_item,
                                       codeFile.getLineOfText(error_item))
        except:
            # report debug info
            _Log('failed to throw error in markup reader: GOOD',
                 _LoggerState.DEBUG)
예제 #2
0
    def __removeComments(self, codeString):
        """Remove all comments from a codefile. This should be done before any processing"""
        try:
            # find all <!>...</!> pairings in the codefile
            regComments = re.findall('<!>.+?<!>', codeString, re.DOTALL)

            # itterate through each comment and remove it from the code file
            for i in range(0, len(regComments)):
                # debug statement printing comment
                _Log('COMMENT FOUND: ' + regComments[i], _LoggerState.DEBUG)

                # split the string and re-merge to remove the comment
                codeStringSplit = codeString.split(regComments[i])
                codeStringSum = ''
                for i in range(0, len(codeStringSplit)):
                    codeStringSum += codeStringSplit[i]
                codeString = codeStringSum

        except:
            # if commenting fails, throw error
            self.__createThrowError(ErrorTypes.ERR_BADCOMMENTS, 'unk.', 'unk.')

        return codeString
예제 #3
0
    def run(self, codeFile):
        """Begin reading a markup code file"""

        _Log('...begin reading file...', _LoggerState.WARNING)

        # get the cleaned code from the codefile
        codeString = codeFile.getCleanCodeText()
        # first remove all comments from the code
        codeString_noComments = self.__removeComments(codeString)

        # second check the file for any obvious syntactical errors
        # _Log(codeString_noComments, _LoggerState.DEBUG)
        self.__computeErrors(codeString_noComments, codeFile)

        # if NO errors, continue processing the Markup
        if _Logger_Thread.count_errors == 0:

            # recursively extract markup data into a markup stack
            stackData = []
            self.__regFindNextMarkupObj(codeString_noComments, 0, stackData,
                                        codeFile)

            # check that no errors have been created since extracting data
            if _Logger_Thread.count_errors == 0:

                # re-read the markup stack to create markup objects
                listClassObjs = self.__convertMarkupStackToObjects(stackData)

                # create a log of the output markup objects created for debugging
                totalListLog = ''
                for i in range(0, len(listClassObjs)):
                    totalListLog += listClassObjs[i].toString() + '\n'
                _Log(totalListLog, _LoggerState.DEBUG)

                # if no errors since reading markup data, reading is successful
                if _Logger_Thread.count_errors == 0:
                    _Log('...reading file successful...', _LoggerState.WARNING)
                    return listClassObjs

        # failed to read markup via some error
        _Log('...reading file failed...', _LoggerState.ERROR)
        return None
    def run(self, classObjects):
        """Perform compilation on a list of markup objects"""

        try:
            _Log('...begin compiling...', _LoggerState.WARNING)

            # lists of different compiled carneades classes
            caesProps = []
            caesArgs = []
            caesProofStnd = []
            caesArgWeights = []
            caesCAES = []

            # itterate through each markup object
            for cObj in classObjects:

                # determine if a markup object is able to compile to a Caernades class
                cDefList = cObj.getDefinitionList()
                isCaeObj = CaernadesObjectLayouts.checkObjIsCaernadesObj(
                    cDefList)

                # create unknown-object error if object isn't made with correct constructor
                if isCaeObj == False:
                    self.__createThrowError(ErrorTypes.ERR_HASHCLASSOBJECT,
                                            cObj.name, 'unk.')
                    _Log('...compilation failed...\n', _LoggerState.ERROR)
                    return None, None, None, None, None
                else:
                    # else, create a caernades object instance
                    caesClass = self.__caesClassFactory.createCaesClass(
                        cObj.name, cObj.attributes)

                    # add the caernades object to the corresponding list
                    if caesClass != None:
                        if isinstance(caesClass, CaesProposition):
                            caesProps.append(caesClass)
                        elif isinstance(caesClass, CaesArgument):
                            caesArgs.append(caesClass)
                        elif isinstance(caesClass, CaesCAES):
                            caesCAES.append(caesClass)
                    else:
                        self.__createThrowError(ErrorTypes.ERR_HASHCLASSOBJECT,
                                                cObj.name, 'unk.')
                        _Log('...compilation failed...\n', _LoggerState.ERROR)
                        return None, None, None, None, None

            # process each proposition
            for i in range(0, len(caesProps)):
                self.__propositionCompile(i, caesProps)

            # process each argument to check names
            for i in range(0, len(caesArgs)):
                self.__argumentCompile(i, caesProps, caesArgs)

            # create ProofOfStandard from propositions
            self.__proofOfStandardCompile(caesProps, caesProofStnd)

            # create ArgumentWeights from arguments
            self.__argumentWeightsCompile(caesArgs, caesArgWeights)

            # process and create final CAES
            self.__caesCompile(caesCAES, caesProofStnd, caesArgWeights,
                               caesProps)

            # print objects for debugging
            for prop in caesProps:
                _Log(prop.toString(), _LoggerState.DEBUG)

            for args in caesArgs:
                _Log(args.toString(), _LoggerState.DEBUG)

            for pos in caesProofStnd:
                _Log(pos.toString(), _LoggerState.DEBUG)

            for argWght in caesArgWeights:
                _Log(argWght.toString(), _LoggerState.DEBUG)

            for caes in caesCAES:
                _Log(caes.toString(), _LoggerState.DEBUG)

            _Log('...compilation successful...\n', _LoggerState.WARNING)

            # return the compiled caes classes
            return caesProps, caesArgs, caesProofStnd, caesArgWeights, caesCAES

        except:
            # throw error because markup reader failed to get data from file
            if classObjects == None or len(classObjects) == 0:
                self.__createThrowError(ErrorTypes.ERR_NULLDATA, 'compiler',
                                        'unk.')

        return None, None, None, None, None
 def createThrowError(self, errorType, error_item, line):
     """throw a new error via the _Log and given a predefined error type"""
     markupError = MarkupErrorFactory.createError(errorType)
     errorText = markupError.toString(
     ) + '  ' + '\'' + error_item + '\' at line ' + str(line)
     _Log(errorText, _LoggerState.ERROR)
 def createThrowErrorReg(self, markupErrorReg, error_item, line):
     """throw a pre-built regExp error via the _Log"""
     errorText = markupErrorReg.toString(
     ) + '  ' + '\'' + error_item + '\' at line ' + str(line)
     _Log(errorText, _LoggerState.ERROR)
예제 #7
0
 def addErrorType(self, errorType):
     """Determine which errors to search for during the reading of markup files"""
     mError = MarkupErrorFactory.createError(errorType)
     _Log('ADDING ERROR: ' + str(errorType), _LoggerState.DEBUG)
     self.error_types.append(mError)