Changeset 1723
- Timestamp:
- 11/02/08 23:33:20 (2 months ago)
- Location:
- cobra/trunk/Source
- Files:
-
- 4 modified
-
CobraParser.cobra (modified) (4 diffs)
-
CommandLine.cobra (modified) (4 diffs)
-
Compiler.cobra (modified) (5 diffs)
-
TestifyRunner.cobra (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/CobraParser.cobra
r1720 r1723 51 51 52 52 """ 53 54 sig ParseCommandLineArgsSig(args as IList<of String>, isAvailable as out bool) as String? 55 /# 56 CC: 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 #/ 53 64 54 65 test … … 111 122 var _typeProvider as ITypeProvider? 112 123 124 var _parseCommandLineArgs as ParseCommandLineArgsSig? 125 113 126 # TODO: do this with a callback/delegate instead of this bullshit Java-style interface technique 114 127 var _warningRecorder as IWarningRecorder? … … 126 139 127 140 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 """ 128 148 129 149 pro globalNS as NameSpace … … 588 608 if not args.count 589 609 .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.') 596 623 else 597 624 .throwError('Unknown compiler directive.') -
cobra/trunk/Source/CommandLine.cobra
r1722 r1723 435 435 436 436 get options from var 437 438 get argParser from var 437 439 438 440 get verboseLineSeparator as String … … 538 540 .error('No files to process.') 539 541 _compiler = c = Compiler(.verbosity) 542 c.commandLineArgParser = _argParser 540 543 c.options = _options 541 544 c.willPrintSuccessMsg = willPrintSuccessMsg … … 834 837 """ 835 838 836 var _self as ArgParser? is shared837 839 var _versionString as String 838 840 var _verbosity = 0 … … 865 867 _synList = List<of String>() 866 868 _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. 873 873 Return new set of Options from given args list 874 874 """ 875 assert _self , 'ArgParser.init must have been called sometime before using ArgParse.parseToOptions()'876 875 opts = OptionValues() 877 876 paths = List<of String>() 878 877 # TODO: mark which opts as unusable in this context and filter out 879 _ self._optsOnly = true880 _self.parseArgs(args, out opts, out paths)881 if _self.verbosity or opts.getDefault('verbosity', 0) to int878 _optsOnly = true 879 .parseArgs(args, out opts, out paths) 880 if .verbosity or opts.getDefault('verbosity', 0) to int 882 881 print 'parseToOptions Option Dictionary:' 883 882 opts.print -
cobra/trunk/Source/Compiler.cobra
r1721 r1723 52 52 var _verbosity as int 53 53 var _options as OptionValues 54 var _commandLineArgParser as ArgParser? 54 55 var _willPrintSuccessMsg = true 55 56 var _htmlWriter as HtmlWriter? … … 154 155 pro options from var 155 156 157 pro commandLineArgParser from var 158 156 159 pro willPrintSuccessMsg from var 157 160 … … 389 392 extraSource = .options.getDefault('extra-source', '').trim to String 390 393 if extraSource <> '' 394 # CC: parser = Parser(verbosity=_verbosity, typeProvider=this, warningRecorder=this, errorRecorder=this, globalNS=_globalNS, parseCommandLineArgs=ref .parseCommandLineArgsCallBack) 391 395 parser = Parser(verbosity=_verbosity, typeProvider=this, warningRecorder=this, errorRecorder=this, globalNS=_globalNS) 396 parser.parseCommandLineArgs = ref .parseCommandLineArgsCallBack 392 397 module = parser.parseSource('_ch_cobra-extra-source.cobra', extraSource) # ch = compiler helper 393 398 modules.add(module) … … 403 408 parser.warningRecorder = this 404 409 parser.errorRecorder = this 410 parser.parseCommandLineArgs = ref .parseCommandLineArgsCallBack 405 411 parser.globalNS = _globalNS 406 412 # @@ TODO: assert _globalNS is parser.nameSpaceStack[0] … … 422 428 _parsedModules = nil 423 429 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 424 444 425 445 def augmentOptions(opts as OptionValues) -
cobra/trunk/Source/TestifyRunner.cobra
r1721 r1723 357 357 if hasInlineMessages 358 358 try 359 c = Compiler(compilerVerbosity, _cachedTestifyModules )359 c = Compiler(compilerVerbosity, _cachedTestifyModules, commandLineArgParser=_cl.argParser) 360 360 c.testifyFilesNamed([baseName], options, _resultsWriter to !, verbose) 361 361 catch StopCompilation … … 419 419 error = firstLine.substring(index+7).trim.toLower 420 420 try 421 c = Compiler(compilerVerbosity, _cachedTestifyModules )421 c = Compiler(compilerVerbosity, _cachedTestifyModules, commandLineArgParser=_cl.argParser) 422 422 c.testifyFilesNamed(fileNames, options, _resultsWriter to !, verbose) 423 423 catch StopCompilation … … 463 463 # 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. 464 464 try 465 c = Compiler(compilerVerbosity, _cachedTestifyModules )465 c = Compiler(compilerVerbosity, _cachedTestifyModules, commandLineArgParser=_cl.argParser) 466 466 c.testifyFilesNamed(fileNames, options, _resultsWriter to !, verbose) 467 467 catch StopCompilation … … 497 497 return 1 498 498 499 c = Compiler(compilerVerbosity, _cachedTestifyModules )499 c = Compiler(compilerVerbosity, _cachedTestifyModules, commandLineArgParser=_cl.argParser) 500 500 501 501 try
