Changeset 1723

Show
Ignore:
Timestamp:
11/02/08 23:33:20 (2 months ago)
Author:
Chuck.Esterbrook
Message:

Code cleanup.
Removed ArgsParser?._self global state.

Location:
cobra/trunk/Source
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/CobraParser.cobra

    r1720 r1723  
    5151 
    5252        """ 
     53 
     54        sig ParseCommandLineArgsSig(args as IList<of String>, isAvailable as out bool) as String? 
     55/# 
     56CC: bug in Cobra parser where putting a doc string after a sig causes problems. 
     57                """ 
     58                The delegate is used to implement the 'args' compiler directive. 
     59                It should set isAvailable. 
     60                If isAvailable, it should return nil on success, or an error message. 
     61                Otherwise, it should return nil. 
     62                """ 
     63#/ 
    5364 
    5465        test 
     
    111122        var _typeProvider as ITypeProvider? 
    112123 
     124        var _parseCommandLineArgs as ParseCommandLineArgsSig? 
     125 
    113126        # TODO: do this with a callback/delegate instead of this bullshit Java-style interface technique 
    114127        var _warningRecorder as IWarningRecorder? 
     
    126139 
    127140        pro typeProvider from var 
     141 
     142        pro parseCommandLineArgs from var 
     143                """ 
     144                The delegate is used to implement the 'args' compiler directive. 
     145                If none is provided and the 'args' directive is encountered, an error is generated. 
     146                See also: ParseCommandLineArgsSig 
     147                """ 
    128148 
    129149        pro globalNS as NameSpace 
     
    588608                                if not args.count  
    589609                                        .throwError('args directive needs at least one arg following.') 
    590                                          
    591                                 comp = .typeProvider to? Compiler 
    592                                 # trace args 
    593                                 if comp 
    594                                         options = ArgParser.parseToOptions(args) 
    595                                         comp.augmentOptions(options) 
     610 
     611                                isAvailable = false 
     612                                if .parseCommandLineArgs 
     613                                        # trace args 
     614                                        parseCommandLineArgs = .parseCommandLineArgs 
     615                                        # errorMsg = parseCommandLineArgs(args, out isAvailable) -- error: COBRA INTERNAL ERROR / NullReferenceException / Object reference not set to an instance of an object. 
     616                                        if true 
     617                                                errorMsg = '' to ? 
     618                                                sharp'errorMsg = parseCommandLineArgs(args, out isAvailable)' 
     619                                                CobraCore.noOp(parseCommandLineArgs) 
     620                                        if isAvailable, if errorMsg, .throwError(errorMsg) 
     621                                if not isAvailable 
     622                                        .throwError('Cannot set command line arguments from directive because no arguments parser is available.') 
    596623                        else 
    597624                                .throwError('Unknown compiler directive.') 
  • cobra/trunk/Source/CommandLine.cobra

    r1722 r1723  
    435435 
    436436        get options from var 
     437 
     438        get argParser from var 
    437439 
    438440        get verboseLineSeparator as String 
     
    538540                        .error('No files to process.') 
    539541                _compiler = c = Compiler(.verbosity) 
     542                c.commandLineArgParser = _argParser 
    540543                c.options = _options 
    541544                c.willPrintSuccessMsg = willPrintSuccessMsg 
     
    834837        """ 
    835838 
    836         var _self as ArgParser? is shared 
    837839        var _versionString as String 
    838840        var _verbosity = 0 
     
    865867                _synList = List<of String>() 
    866868                _initSynonyms 
    867                 _self = this 
    868  
    869         def parseToOptions(args as IList<of String>) as OptionValues is shared 
    870                 """ 
    871                 Reuse ArgParser to parse some additional string option args. Files are not allowed  
    872                 Can be used only after ArgParser has already been constructed providing CommandLineOptionSpecs 
     869 
     870        def parseToOptions(args as IList<of String>) as OptionValues 
     871                """ 
     872                Reuse ArgParser to parse some additional string option args. Files are not allowed. 
    873873                Return new set of Options from given args list 
    874874                """ 
    875                 assert _self , 'ArgParser.init must have been called sometime before using ArgParse.parseToOptions()' 
    876875                opts = OptionValues() 
    877876                paths = List<of String>() 
    878877                # TODO: mark which opts as unusable in this context and filter out 
    879                 _self._optsOnly = true 
    880                 _self.parseArgs(args, out opts, out paths) 
    881                 if _self.verbosity or opts.getDefault('verbosity', 0) to int 
     878                _optsOnly = true 
     879                .parseArgs(args, out opts, out paths) 
     880                if .verbosity or opts.getDefault('verbosity', 0) to int 
    882881                        print 'parseToOptions Option Dictionary:' 
    883882                        opts.print 
  • cobra/trunk/Source/Compiler.cobra

    r1721 r1723  
    5252        var _verbosity as int 
    5353        var _options as OptionValues 
     54        var _commandLineArgParser as ArgParser? 
    5455        var _willPrintSuccessMsg = true 
    5556        var _htmlWriter as HtmlWriter? 
     
    154155        pro options from var 
    155156 
     157        pro commandLineArgParser from var 
     158 
    156159        pro willPrintSuccessMsg from var 
    157160 
     
    389392                                extraSource = .options.getDefault('extra-source', '').trim to String 
    390393                                if extraSource <> '' 
     394                                        # CC: parser = Parser(verbosity=_verbosity, typeProvider=this, warningRecorder=this, errorRecorder=this, globalNS=_globalNS, parseCommandLineArgs=ref .parseCommandLineArgsCallBack) 
    391395                                        parser = Parser(verbosity=_verbosity, typeProvider=this, warningRecorder=this, errorRecorder=this, globalNS=_globalNS) 
     396                                        parser.parseCommandLineArgs = ref .parseCommandLineArgsCallBack 
    392397                                        module = parser.parseSource('_ch_cobra-extra-source.cobra', extraSource)  # ch = compiler helper 
    393398                                        modules.add(module) 
     
    403408                                                parser.warningRecorder = this 
    404409                                                parser.errorRecorder = this 
     410                                                parser.parseCommandLineArgs = ref .parseCommandLineArgsCallBack 
    405411                                                parser.globalNS = _globalNS 
    406412                                                # @@ TODO: assert _globalNS is parser.nameSpaceStack[0] 
     
    422428                                _parsedModules = nil 
    423429                        return modules 
     430 
     431        def parseCommandLineArgsCallBack(args as IList<of String>, isAvailable as out bool) as String? 
     432                """ 
     433                This is the call back for implementing the `args` directive as encountered in the Parser. 
     434                """ 
     435                if .commandLineArgParser 
     436                        isAvailable = true 
     437                        try 
     438                                .augmentOptions(.commandLineArgParser.parseToOptions(args)) 
     439                        catch ape as ArgParseException 
     440                                return ape.message 
     441                else 
     442                        isAvailable = false 
     443                return nil 
    424444 
    425445        def augmentOptions(opts as OptionValues) 
  • cobra/trunk/Source/TestifyRunner.cobra

    r1721 r1723  
    357357                if hasInlineMessages 
    358358                        try 
    359                                 c = Compiler(compilerVerbosity, _cachedTestifyModules) 
     359                                c = Compiler(compilerVerbosity, _cachedTestifyModules, commandLineArgParser=_cl.argParser) 
    360360                                c.testifyFilesNamed([baseName], options, _resultsWriter to !, verbose) 
    361361                        catch StopCompilation 
     
    419419                        error = firstLine.substring(index+7).trim.toLower 
    420420                        try 
    421                                 c = Compiler(compilerVerbosity, _cachedTestifyModules) 
     421                                c = Compiler(compilerVerbosity, _cachedTestifyModules, commandLineArgParser=_cl.argParser) 
    422422                                c.testifyFilesNamed(fileNames, options, _resultsWriter to !, verbose) 
    423423                        catch StopCompilation 
     
    463463                        # TODO: the following code both checks for warnings to be thrown as well as going through a list of warnings. Seems like it should just need to do one or the other. 
    464464                        try 
    465                                 c = Compiler(compilerVerbosity, _cachedTestifyModules) 
     465                                c = Compiler(compilerVerbosity, _cachedTestifyModules, commandLineArgParser=_cl.argParser) 
    466466                                c.testifyFilesNamed(fileNames, options, _resultsWriter to !, verbose) 
    467467                        catch StopCompilation 
     
    497497                        return 1 
    498498 
    499                 c = Compiler(compilerVerbosity, _cachedTestifyModules) 
     499                c = Compiler(compilerVerbosity, _cachedTestifyModules, commandLineArgParser=_cl.argParser) 
    500500 
    501501                try