Wiki

Ticket #132: ticket132-number-fractional-lit.patch

File ticket132-number-fractional-lit.patch, 4.3 KB (added by hopscc, 16 years ago)
  • Source/CobraParser.cobra

     
    220220        _tokens = nil 
    221221        if _tokenizer is nil 
    222222            _tokenizer = CobraTokenizer(tokVerbosity) 
     223        _tokenizer.typeProvider = .typeProvider  
     224             
    223225        tokenizer = _tokenizer 
    224226        try 
    225227            tokens = tokenizer.startSource(_fileName, source).allTokens 
  • Source/CobraTokenizer.cobra

     
    5454    var _inSubstStringDouble = false 
    5555    var _inDocString = false 
    5656    var _inCommentBlock = 0 
    57  
     57    set typeProvider from var as ITypeProvider? 
     58     
    5859    def init 
    5960        base.init 
    6061 
     
    498499    def onFRACTIONAL_LIT(tok as IToken) as IToken? 
    499500        s = tok.text.replace('_', '') 
    500501        try 
    501             tok.value = decimal.parse(s, Utils.cultureInfoForNumbers) 
     502            numTypeStr = 'decimal' 
     503            assert _typeProvider 
     504            numberType = _typeProvider.numberType 
     505            # parse literal to same type as numberType 
     506            if numberType inherits DecimalType 
     507                tok.value = decimal.parse(s, Utils.cultureInfoForNumbers) 
     508            else 
     509                numTypeStr = 'float' 
     510                tok.value = float.parse(s, Utils.cultureInfoForNumbers) 
     511                tok.which = 'FLOAT_LIT' 
     512                tok.info = if(numberType == _typeProvider.floatType(32), 32, 64) 
    502513        catch FormatException 
    503514            assert false, 'not expecting to get here given regex' 
    504515        catch OverflowException 
    505             assert false, 'TODO: FRACTIONAL_LIT Overflow' 
     516            .throwError('[numTypeStr] Overflow in parse of Fractional Literal [tok.text]') 
    506517        return tok 
    507518 
    508519    def onINTEGER_LIT(tok as IToken) as IToken? 
  • Tests/820-errors/600-other/130-number-lit-decimal.cobra

     
     1class NumbFloat 
     2    def main is shared 
     3        a as number = 79_228_162_514_264_337_593_543_950_33.4 
     4        assert a.getType is Single 
     5        # literal > max decimal 
     6        b as number = 80_228_162_514_264_337_593_543_950_335.1 #.error. decimal overflow in parse 
     7        assert b.getType is Single 
     8 
     9        c = 85_228_162_514_264_337_593_543_950_335.1  # .error. decimal overflow in parse 
     10        assert c.getType is Single 
  • Tests/200-misc/300-number-type/110-number-lit-float.cobra

     
     1# .args. -number:float 
     2class NumbFloat 
     3    def main is shared 
     4        # < max Decimal 
     5        a as number = 79_228_162_514_264_337_593_543_950_33.4 
     6        # literal > max decimal 
     7        b as number =  80_228_162_514_264_337_593_543_950_335.1 
     8        assert a.getType is Double 
     9        assert b.getType is Double 
     10 
     11        c = 85_228_162_514_264_337_593_543_950_335.1 
     12        assert c.getType is Double 
  • Tests/200-misc/300-number-type/112-number-lit-float32.cobra

     
     1# .args. -number:float32 
     2class NumbFloat 
     3    def main is shared 
     4        # < max Decimal 
     5        a as number = 79_228_162_514_264_337_593_543_950_33.4 
     6        assert a.getType is Single 
     7        # literal > max decimal 
     8        b as number =  80_228_162_514_264_337_593_543_950_335.1 
     9        assert b.getType is Single 
     10 
     11        c = 85_228_162_514_264_337_593_543_950_335.1 
     12        assert c.getType is Single 
  • Developer/IntermediateReleaseNotes.text

     
    295295* Fixed: Cannot qualify an attribute. ticket:121 
    296296 
    297297* Fixed: Cannot read nested classes in binary libraries in some circumstances. ticket:127 
     298 
     299* Fixed: Fractional Literals dont parse to non Decimal -number setting. ticket:132