private (String Raw, Double Value) ReadLuaHex( ) { var rawNumber = new StringBuilder( ); this.reader.Advance(2); rawNumber.Append("0x"); String integer = this.reader.ReadStringWhile(LJUtils.IsXDigit), fractional = null, shift = null; rawNumber.Append(integer); if (this.reader.IsNext(".")) { this.reader.Advance(1); rawNumber.Append('.'); fractional = this.reader.ReadStringWhile(LJUtils.IsXDigit); rawNumber.Append(fractional); } if (this.reader.IsNext("p") || this.reader.IsNext("P")) { rawNumber.Append(this.reader.ReadString(1)); if (this.reader.IsNext("+") || this.reader.IsNext("-")) { rawNumber.Append(this.reader.ReadString(1)); } shift = this.reader.ReadStringWhile(LJUtils.IsDigit); rawNumber.Append(shift); if (String.IsNullOrEmpty(shift)) { throw new LexException("Malformed number literal (missing exponent).", this.Location); } } if (String.IsNullOrEmpty(integer) && String.IsNullOrEmpty(fractional)) { throw new LexException("Malformed number literal (missing both integral part and fractional part).", this.Location); } return( Raw : rawNumber.ToString( ), Value : CInterop.atof(rawNumber.ToString( )) ); }
private (String Raw, Double Value) ReadLuaDec( ) { var rawNumber = new StringBuilder( ); String integer = this.reader.ReadStringWhile(LJUtils.IsDigit), fractional = null, exp = null; rawNumber.Append(integer); if (this.Consume('.')) { rawNumber.Append('.'); fractional = this.reader.ReadStringWhile(LJUtils.IsDigit); rawNumber.Append(fractional); } if (this.reader.IsNext("e") || this.reader.IsNext("E")) { rawNumber.Append(this.reader.ReadString(1)); if (this.reader.IsNext("+") || this.reader.IsNext("-")) { rawNumber.Append(this.reader.ReadString(1)); } exp = this.reader.ReadStringWhile(LJUtils.IsDigit); rawNumber.Append(exp); if (String.IsNullOrEmpty(exp)) { throw new LexException("Malformed number literal.", this.Location); } } if (String.IsNullOrEmpty(integer) && String.IsNullOrEmpty(fractional)) { throw new LexException("Malformed number literal.", this.Location); } return( Raw : rawNumber.ToString( ), Value : CInterop.atof(rawNumber.ToString( )) ); }