implements nicer floating point literals
This commit is contained in:
parent
86d64b2f5e
commit
df8e151408
2 changed files with 14 additions and 13 deletions
|
|
@ -236,7 +236,7 @@ proc matchTwoChars(L: TLexer, first: Char, second: TCharSet): bool =
|
||||||
result = (L.buf[L.bufpos] == first) and (L.buf[L.bufpos + 1] in Second)
|
result = (L.buf[L.bufpos] == first) and (L.buf[L.bufpos + 1] in Second)
|
||||||
|
|
||||||
proc isFloatLiteral(s: string): bool =
|
proc isFloatLiteral(s: string): bool =
|
||||||
for i in countup(0, len(s) + 0 - 1):
|
for i in countup(0, len(s) - 1):
|
||||||
if s[i] in {'.', 'e', 'E'}:
|
if s[i] in {'.', 'e', 'E'}:
|
||||||
return true
|
return true
|
||||||
result = false
|
result = false
|
||||||
|
|
@ -250,16 +250,18 @@ proc GetNumber(L: var TLexer): TToken =
|
||||||
result.literal = ""
|
result.literal = ""
|
||||||
result.base = base10 # BUGFIX
|
result.base = base10 # BUGFIX
|
||||||
pos = L.bufpos # make sure the literal is correct for error messages:
|
pos = L.bufpos # make sure the literal is correct for error messages:
|
||||||
|
var eallowed = false
|
||||||
if L.buf[pos] == '0' and L.buf[pos+1] in {'X', 'x'}:
|
if L.buf[pos] == '0' and L.buf[pos+1] in {'X', 'x'}:
|
||||||
matchUnderscoreChars(L, result, {'A'..'F', 'a'..'f', '0'..'9', 'X', 'x'})
|
matchUnderscoreChars(L, result, {'A'..'F', 'a'..'f', '0'..'9', 'X', 'x'})
|
||||||
else:
|
else:
|
||||||
matchUnderscoreChars(L, result, {'0'..'9', 'b', 'B', 'o', 'c', 'C'})
|
matchUnderscoreChars(L, result, {'0'..'9', 'b', 'B', 'o', 'c', 'C'})
|
||||||
|
eallowed = true
|
||||||
if (L.buf[L.bufpos] == '.') and (L.buf[L.bufpos + 1] in {'0'..'9'}):
|
if (L.buf[L.bufpos] == '.') and (L.buf[L.bufpos + 1] in {'0'..'9'}):
|
||||||
add(result.literal, '.')
|
add(result.literal, '.')
|
||||||
inc(L.bufpos)
|
inc(L.bufpos)
|
||||||
#matchUnderscoreChars(L, result, ['A'..'Z', 'a'..'z', '0'..'9'])
|
|
||||||
matchUnderscoreChars(L, result, {'0'..'9'})
|
matchUnderscoreChars(L, result, {'0'..'9'})
|
||||||
if L.buf[L.bufpos] in {'e', 'E'}:
|
eallowed = true
|
||||||
|
if eallowed and L.buf[L.bufpos] in {'e', 'E'}:
|
||||||
add(result.literal, 'e')
|
add(result.literal, 'e')
|
||||||
inc(L.bufpos)
|
inc(L.bufpos)
|
||||||
if L.buf[L.bufpos] in {'+', '-'}:
|
if L.buf[L.bufpos] in {'+', '-'}:
|
||||||
|
|
@ -268,7 +270,6 @@ proc GetNumber(L: var TLexer): TToken =
|
||||||
matchUnderscoreChars(L, result, {'0'..'9'})
|
matchUnderscoreChars(L, result, {'0'..'9'})
|
||||||
endpos = L.bufpos
|
endpos = L.bufpos
|
||||||
if L.buf[endpos] in {'\'', 'f', 'F', 'i', 'I', 'u', 'U'}:
|
if L.buf[endpos] in {'\'', 'f', 'F', 'i', 'I', 'u', 'U'}:
|
||||||
#matchUnderscoreChars(L, result, ['''', 'f', 'F', 'i', 'I', '0'..'9']);
|
|
||||||
if L.buf[endpos] == '\'': inc(endpos)
|
if L.buf[endpos] == '\'': inc(endpos)
|
||||||
L.bufpos = pos # restore position
|
L.bufpos = pos # restore position
|
||||||
case L.buf[endpos]
|
case L.buf[endpos]
|
||||||
|
|
|
||||||
|
|
@ -352,7 +352,7 @@ Numerical constants
|
||||||
UINT64_LIT = INT_LIT ['\''] ('u' | 'U') '64'
|
UINT64_LIT = INT_LIT ['\''] ('u' | 'U') '64'
|
||||||
|
|
||||||
exponent = ('e' | 'E' ) ['+' | '-'] digit ( ['_'] digit )*
|
exponent = ('e' | 'E' ) ['+' | '-'] digit ( ['_'] digit )*
|
||||||
FLOAT_LIT = digit (['_'] digit)* ('.' (['_'] digit)* [exponent] |exponent)
|
FLOAT_LIT = digit (['_'] digit)* (('.' (['_'] digit)* [exponent]) |exponent)
|
||||||
FLOAT32_LIT = HEX_LIT '\'' ('f'|'F') '32'
|
FLOAT32_LIT = HEX_LIT '\'' ('f'|'F') '32'
|
||||||
| (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] ('f'|'F') '32'
|
| (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] ('f'|'F') '32'
|
||||||
FLOAT64_LIT = HEX_LIT '\'' ('f'|'F') '64'
|
FLOAT64_LIT = HEX_LIT '\'' ('f'|'F') '64'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue