<commit_before>#
#                              ITF1788
#
#   Interval Test Framework for IEEE 1788 Standard for Interval Arithmetic
#
#
#   Copyright 2014
#
#   <NAME> (<EMAIL>)
#   <NAME> (<EMAIL>)
#
#   Department of Computer Science
#   University of Wuerzburg, Germany
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

import dslparser
import testAST
import discovery
import lang
import os
import optparse
import re
from ast import literal_eval as makeTuple
import time
import ntpath
import textwrap


# inherit from OptionParser to overwrite format_epilog method
# this allows properly formatted multiline strings in help messages
class ConsoleParser(optparse.OptionParser):

        '''Handles the arguments passed to the program.'''
                
        def __init__(self):
            '''
            Define the valid options.
            '''
            super(ConsoleParser, self).__init__()
            self.add_option("-s", "--sourceDirectory", dest="sourceDir",
                     # TODO: check for operating systems other than linux
                     default='../ITL files',
                     help="Directory with DSL tests")

            self.add_option("-f", "--fileRegex", dest="fileRegex",
                            default='.*',
                            help="Regex for names of the desired DSL tests")

            self.add_option("-c", "--configurations", dest="configurations",
                            help="""Specify the plugin configurations.""")

            self.add_option("-o", "--outputDirectory", dest="outDir",
                            default="../output",
                            help="Output directory for generated files")
                            
            self.add_option("-v", "--verbose", action="store_true",
                            dest="verbose")
        
                     
        def processConsoleParameters(self):
            '''
            Read the passed arguments and process them.
            '''       
            (options, args) = self.parse_args()
            self._checkSrcDir(options)
            self._checkFileRegex(options)
            self.specList = self._buildSpecList(options)
            self.testFiles = self._buildTestFileList(options)
            self.outDir = options.outDir
            self.verbose = options.verbose
        
        def _buildSpecList(self, options):
            '''
            Use the passed arguments and build a list of he configurations that
            shall be generated.
            '''
            # if no specific configurations are given, generate tests for all
            # configurations
            if options.configurations is None or options.configurations == '*':
                return discovery.getSpecList()
            
            
            # regexes that are used to interpret the 'configurations'
            # console parameter
            identRegex = r"'[a-zA-Z][a-zA-Z0-9_]*'"
            wildcardRegex = r"'\*'"
            specListRegex = r"\s*\(\s*'.+'\s*,\s*'.+'\s*,\s*'.+'\s*\)\s*" + \
                            r"(\s*;\s*\(\s*'.+'\s*,\s*'.+'\s*,\s*'.+'\s*\)\s*)*"
            LTARegex = r"\s*\(\s*" + identRegex + r"\s*,\s*" + identRegex + \
                       r"\s*,\s*" + identRegex + r"\s*\)\s*"
            LTWRegex = r"\s*\(\s*" + identRegex + r"\s*,\s*" + identRegex + \
                       r"\s*,\s*" + wildcardRegex + r"\s*\)\s*"
            LWARegex = r"\s*\(\s*" + identRegex + r"\s*,\s*" + wildcardRegex + \
                       r"\s*,\s*" + identRegex + r"\s*\)\s*"
            LWWRegex = r"\s*\(\s*" + identRegex + r"\s*,\s*" + wildcardRegex + \
                       r"\s*,\s*" + wildcardRegex + r"\s*\)\s*"

            if re.match(specListRegex, options.configurations):
                # use configurations list parameter
                tmp = options.configurations.split(';')
                
                try:
                    tmp = [makeTuple(el.strip()) for el in tmp]
                    valid = True
                except:
                    valid = False
                if not valid:
                    raise IOError('Invalid specification list:' +\
                                    options.configurations +\
                                    '\nRun "python3 main.py --help" to see the\
                                    correct syntax.')

                specList = []

                for spec in tmp:
                    if re.match(LTARegex, str(spec)):
                        specList += [spec]
                    elif re.match(LTWRegex, str(spec)):
                        specList += \
                         discovery.getSpecListByLanguageAndTestLibrary(spec[0],
                                                                       spec[1])
                    elif re.match(LWARegex, str(spec)):
                        specList += \
                         discovery.getSpecListByLanguageAndArithmeticLibrary(spec[0],
                                                                             spec[2])
                    elif re.match(LWWRegex, str(spec)):
                        specList += discovery.getSpecListByLanguage(spec[0])

            else:<commit_msg>Changed configurations option<commit_after>#
#                              ITF1788
#
#   Interval Test Framework for IEEE 1788 Standard for Interval Arithmetic
#
#
#   Copyright 2014
#
#   <NAME> (<EMAIL>)
#   <NAME> (<EMAIL>)
#
#   Department of Computer Science
#   University of Wuerzburg, Germany
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

import dslparser
import testAST
import discovery
import lang
import os
import optparse
import re
from ast import literal_eval as makeTuple
import time
import ntpath
import textwrap


# inherit from OptionParser to overwrite format_epilog method
# this allows properly formatted multiline strings in help messages
class ConsoleParser(optparse.OptionParser):

        '''Handles the arguments passed to the program.'''
                
        def __init__(self):
            '''
            Define the valid options.
            '''
            super(ConsoleParser, self).__init__()
            self.add_option("-s", "--sourceDirectory", dest="sourceDir",
                     # TODO: check for operating systems other than linux
                     default='../ITL files',
                     help="Directory with DSL tests")

            self.add_option("-f", "--fileRegex", dest="fileRegex",
                            default='.*',
                            help="Regex for names of the desired DSL tests")

            self.add_option("-c", "--configurations", dest="configurations",
                            help="""Specify the plugin configurations.""")

            self.add_option("-o", "--outputDirectory", dest="outDir",
                            default="../output",
                            help="Output directory for generated files")
                            
            self.add_option("-v", "--verbose", action="store_true",
                            dest="verbose")
        
                     
        def processConsoleParameters(self):
            '''
            Read the passed arguments and process them.
            '''       
            (options, args) = self.parse_args()
            self._checkSrcDir(options)
            self._checkFileRegex(options)
            self.specList = self._buildSpecList(options)
            self.testFiles = self._buildTestFileList(options)
            self.outDir = options.outDir
            self.verbose = options.verbose
        
        def _buildSpecList(self, options):
            '''
            Use the passed arguments and build a list of he configurations that
            shall be generated.
            '''
            # if no specific configurations are given, generate tests for all
            # configurations
            if options.configurations is None or options.configurations == '*':
                return discovery.getSpecList()
            
            
            # regexes that are used to interpret the 'configurations'
            # console parameter
            identRegex = r"'[a-zA-Z](\s?[a-zA-Z0-9_])*'"
            wildcardRegex = r"'\*'"
            specListRegex = r"\s*\(\s*.+\s*,\s*.+\s*,\s*.+\s*\)\s*" + \
                            r"(\s*;\s*\(\s*.+\s*,\s*.+\s*,\s*.+\s*\)\s*)*"
            LTARegex = r"\s*\(\s*" + identRegex + r"\s*,\s*" + identRegex + \
                       r"\s*,\s*" + identRegex + r"\s*\)\s*"
            LTWRegex = r"\s*\(\s*" + identRegex + r"\s*,\s*" + identRegex + \
                       r"\s*,\s*" + wildcardRegex + r"\s*\)\s*"
            LWARegex = r"\s*\(\s*" + identRegex + r"\s*,\s*" + wildcardRegex + \
                       r"\s*,\s*" + identRegex + r"\s*\)\s*"
            LWWRegex = r"\s*\(\s*" + identRegex + r"\s*,\s*" + wildcardRegex + \
                       r"\s*,\s*" + wildcardRegex + r"\s*\)\s*"

            if re.match(specListRegex, options.configurations):
                # use configurations list parameter
                tmp = options.configurations.split(';')

                # enclose tuple values in quotation marks, required for
                # the makeTuple method
                for i in range(0, len(tmp)):
                    conf = tmp[i].strip()
                    # remove parentheses and leading/trailing whitespace
                    conf = conf[1:][:-1].strip()
                    # get tuple values and remove leading/trailing whitespace
                    vals = [v.strip() for v in conf.split(',')]
                    # add quotation marks and concat again
                    conf = '(' + ','.join(["'" + v + "'" for v in vals]) + ')'
                    # replace original config
                    tmp[i] = conf

                try:
                    tmp = [makeTuple(el.strip()) for el in tmp]
                    valid = True
                except:
                    valid = False
                if not valid:
                    raise IOError('Invalid specification list:' +\
                                    options.configurations +\
                                    '\nRun "python3 main.py --help" to see the\
                                    correct syntax.')

                specList = []

                for spec in tmp:
                    if re.match(LTARegex, str(spec)):
                        specList += [spec]
                    elif re.match(LTWRegex, str(spec)):
                        specList += \
                         discovery.getSpecListByLanguageAndTestLibrary(spec[0],
                                                                       spec[1])
                    elif re.match(LWARegex, str(spec)):
                        specList += \
                         discovery.getSpecListByLanguageAndArithmeticLibrary(spec[0],
                                                                             spec[2])
                    elif re.match(LWWRegex, str(spec)):
                        specList += discovery.getSpecListByLanguage(spec[0])

            else:
{'fraction_non_alphanumeric': 0.11309228991249794, 'fraction_numerical': 0.004210004952947003, 'mean_word_length': 1.4052015088346237, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '45884', 'n_tokens_mistral': 3055, 'n_tokens_neox': 2902, 'n_words': 829}