| 2056 | throw new python.Error(`Unexpected token '${c}' ${this.location()}`); |
| 2057 | } |
| 2058 | _number() { |
| 2059 | const octal = (c) => c >= '0' && c <= '7' || c === '_'; |
| 2060 | const binary = (c) => c === '0' || c === '1' || c === '_'; |
| 2061 | const decimal = (c) => c >= '0' && c <= '9' || c === '_'; |
| 2062 | const hex = (c) => decimal(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || c === '_'; |
| 2063 | let c = this._get(this._position); |
| 2064 | let i = this._position; |
| 2065 | c = this._get(i); |
| 2066 | if (c === '0') { |
| 2067 | let radix = 0; |
| 2068 | const n = this._get(i + 1); |
| 2069 | if ((n === 'x' || n === 'X') && hex(this._get(i + 2))) { |
| 2070 | i += 2; |
| 2071 | while (hex(this._get(i))) { |
| 2072 | i += 1; |
| 2073 | } |
| 2074 | if (this._get(i) === 'l' || this._get(i) === 'L') { |
| 2075 | i += 1; |
| 2076 | } |
| 2077 | radix = 16; |
| 2078 | } else if ((n === 'b' || n === 'B') && binary(this._get(i + 2))) { |
| 2079 | i += 2; |
| 2080 | while (binary(this._get(i))) { |
| 2081 | i++; |
| 2082 | } |
| 2083 | radix = 2; |
| 2084 | } else if ((n === 'o' || n === 'O') && octal(this._get(i + 2))) { |
| 2085 | i += 2; |
| 2086 | while (octal(this._get(i))) { |
| 2087 | i++; |
| 2088 | } |
| 2089 | radix = 8; |
| 2090 | } else if (n >= '0' && n <= '7') { |
| 2091 | i++; |
| 2092 | while (octal(this._get(i))) { |
| 2093 | i += 1; |
| 2094 | } |
| 2095 | if (this._get(i) === 'l' || this._get(i) === 'L') { |
| 2096 | i += 1; |
| 2097 | } |
| 2098 | radix = 8; |
| 2099 | } |
| 2100 | if (radix > 0 && this._get(i) !== '.') { |
| 2101 | const radixText = this._text.substring(this._position, i); |
| 2102 | const radixParseText = radixText.indexOf('_') === -1 ? radixText : radixText.split('_').join(''); |
| 2103 | if (!isNaN(parseInt(radixParseText, radix))) { |
| 2104 | return { type: 'int', value: radixText }; |
| 2105 | } |
| 2106 | } |
| 2107 | } |
| 2108 | i = this._position; |
| 2109 | let isDecimal = false; |
| 2110 | if (this._get(i) >= '1' && this._get(i) <= '9') { |
| 2111 | while (decimal(this._get(i))) { |
| 2112 | i++; |
| 2113 | } |
| 2114 | c = this._get(i).toLowerCase(); |
| 2115 | isDecimal = c !== '.' && c !== 'e'; |