mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
' is optional in type suffixes for numerical literals
This commit is contained in:
@@ -266,7 +266,10 @@ proc GetNumber(L: var TLexer): TToken =
|
||||
result.literal = ""
|
||||
result.base = base10 # BUGFIX
|
||||
pos = L.bufpos # make sure the literal is correct for error messages:
|
||||
matchUnderscoreChars(L, result, {'A'..'Z', 'a'..'z', '0'..'9'})
|
||||
if L.buf[pos] == '0' and L.buf[pos+1] in {'X', 'x'}:
|
||||
matchUnderscoreChars(L, result, {'A'..'F', 'a'..'f', '0'..'9', 'X', 'x'})
|
||||
else:
|
||||
matchUnderscoreChars(L, result, {'0'..'9', 'b', 'B', 'o', 'c', 'C'})
|
||||
if (L.buf[L.bufpos] == '.') and (L.buf[L.bufpos + 1] in {'0'..'9'}):
|
||||
add(result.literal, '.')
|
||||
inc(L.bufpos)
|
||||
@@ -280,9 +283,9 @@ proc GetNumber(L: var TLexer): TToken =
|
||||
inc(L.bufpos)
|
||||
matchUnderscoreChars(L, result, {'0'..'9'})
|
||||
endpos = L.bufpos
|
||||
if L.buf[endpos] == '\'':
|
||||
if L.buf[endpos] in {'\'', 'f', 'F', 'i', 'I', 'u', 'U'}:
|
||||
#matchUnderscoreChars(L, result, ['''', 'f', 'F', 'i', 'I', '0'..'9']);
|
||||
inc(endpos)
|
||||
if L.buf[endpos] == '\'': inc(endpos)
|
||||
L.bufpos = pos # restore position
|
||||
case L.buf[endpos]
|
||||
of 'f', 'F':
|
||||
|
||||
@@ -42,6 +42,7 @@ primary ::= primaryPrefix* (symbol [generalizedLit] |
|
||||
generalizedLit ::= GENERALIZED_STR_LIT | GENERALIZED_TRIPLESTR_LIT
|
||||
|
||||
literal ::= INT_LIT | INT8_LIT | INT16_LIT | INT32_LIT | INT64_LIT
|
||||
| UINT_LIT | UINT8_LIT | UINT16_LIT | UINT32_LIT | UINT64_LIT
|
||||
| FLOAT_LIT | FLOAT32_LIT | FLOAT64_LIT
|
||||
| STR_LIT | RSTR_LIT | TRIPLESTR_LIT
|
||||
| CHAR_LIT
|
||||
|
||||
@@ -303,20 +303,33 @@ Numerical constants
|
||||
hexdigit ::= digit | 'A'..'F' | 'a'..'f'
|
||||
octdigit ::= '0'..'7'
|
||||
bindigit ::= '0'..'1'
|
||||
INT_LIT ::= digit ( ['_'] digit )*
|
||||
| '0' ('x' | 'X' ) hexdigit ( ['_'] hexdigit )*
|
||||
| '0o' octdigit ( ['_'] octdigit )*
|
||||
| '0' ('b' | 'B' ) bindigit ( ['_'] bindigit )*
|
||||
HEX_LIT ::= '0' ('x' | 'X' ) hexdigit ( ['_'] hexdigit )*
|
||||
DEC_LIT ::= digit ( ['_'] digit )*
|
||||
OCT_LIT ::= '0o' octdigit ( ['_'] octdigit )*
|
||||
BIN_LIT ::= '0' ('b' | 'B' ) bindigit ( ['_'] bindigit )*
|
||||
|
||||
INT_LIT ::= HEX_LIT
|
||||
| DEC_LIT
|
||||
| OCT_LIT
|
||||
| BIN_LIT
|
||||
|
||||
INT8_LIT ::= INT_LIT '\'' ('i' | 'I' ) '8'
|
||||
INT16_LIT ::= INT_LIT '\'' ('i' | 'I' ) '16'
|
||||
INT32_LIT ::= INT_LIT '\'' ('i' | 'I' ) '32'
|
||||
INT64_LIT ::= INT_LIT '\'' ('i' | 'I' ) '64'
|
||||
INT8_LIT ::= INT_LIT ['\''] ('i' | 'I') '8'
|
||||
INT16_LIT ::= INT_LIT ['\''] ('i' | 'I') '16'
|
||||
INT32_LIT ::= INT_LIT ['\''] ('i' | 'I') '32'
|
||||
INT64_LIT ::= INT_LIT ['\''] ('i' | 'I') '64'
|
||||
|
||||
UINT8_LIT ::= INT_LIT ['\''] ('u' | 'U')
|
||||
UINT8_LIT ::= INT_LIT ['\''] ('u' | 'U') '8'
|
||||
UINT16_LIT ::= INT_LIT ['\''] ('u' | 'U') '16'
|
||||
UINT32_LIT ::= INT_LIT ['\''] ('u' | 'U') '32'
|
||||
UINT64_LIT ::= INT_LIT ['\''] ('u' | 'U') '64'
|
||||
|
||||
exponent ::= ('e' | 'E' ) ['+' | '-'] digit ( ['_'] digit )*
|
||||
FLOAT_LIT ::= digit (['_'] digit)* ('.' (['_'] digit)* [exponent] |exponent)
|
||||
FLOAT32_LIT ::= ( FLOAT_LIT | INT_LIT ) '\'' ('f' | 'F') '32'
|
||||
FLOAT64_LIT ::= ( FLOAT_LIT | INT_LIT ) '\'' ('f' | 'F') '64'
|
||||
FLOAT32_LIT ::= HEX_LIT '\'' ('f'|'F') '32'
|
||||
| (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] ('f'|'F') '32'
|
||||
FLOAT64_LIT ::= HEX_LIT '\'' ('f'|'F') '64'
|
||||
| (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] ('f'|'F') '64'
|
||||
|
||||
|
||||
As can be seen in the productions, numerical constants can contain underscores
|
||||
@@ -328,7 +341,10 @@ There exists a literal for each numerical type that is
|
||||
defined. The suffix starting with an apostrophe ('\'') is called a
|
||||
`type suffix`:idx:. Literals without a type suffix are of the type ``int``,
|
||||
unless the literal contains a dot or ``E|e`` in which case it is of
|
||||
type ``float``.
|
||||
type ``float``. For notational convenience the apostrophe of a type suffix
|
||||
is optional if it is not ambiguous (only hexadecimal floating point literals
|
||||
can be ambiguous).
|
||||
|
||||
|
||||
The type suffixes are:
|
||||
|
||||
@@ -338,7 +354,12 @@ The type suffixes are:
|
||||
``'i8`` int8
|
||||
``'i16`` int16
|
||||
``'i32`` int32
|
||||
``'i64`` int64
|
||||
``'i64`` int64
|
||||
``'u`` uint
|
||||
``'u8`` uint8
|
||||
``'u16`` uint16
|
||||
``'u32`` uint32
|
||||
``'u64`` uint64
|
||||
``'f32`` float32
|
||||
``'f64`` float64
|
||||
================= =========================
|
||||
@@ -3114,6 +3135,10 @@ arguments. If none of its parameters have the type ``var T``
|
||||
or ``ref T`` or ``ptr T`` this means no locations are modified. It is a static
|
||||
error to mark a proc/iterator to have no side effect if the compiler cannot
|
||||
verify this.
|
||||
|
||||
As a special semantic rule, the built-in ``echo`` pretends to be free of
|
||||
side effects, so that it can be used for debugging routines marked as
|
||||
``noSideEffect``.
|
||||
|
||||
**Future directions**: ``func`` may become a keyword and syntactic sugar for a
|
||||
proc with no side effects:
|
||||
|
||||
@@ -1662,6 +1662,10 @@ proc echo*[Ty](x: openarray[Ty]) {.magic: "Echo", noSideEffect.}
|
||||
## available for the ECMAScript target too.
|
||||
## Unlike other IO operations this is guaranteed to be thread-safe as
|
||||
## ``echo`` is very often used for debugging convenience.
|
||||
##
|
||||
## As a special semantic rule, ``echo`` pretends to be free of
|
||||
## side effects, so that it can be used for debugging routines marked as
|
||||
## ``noSideEffect``.
|
||||
|
||||
template newException*(exceptn: typeDesc, message: string): expr =
|
||||
## creates an exception object of type ``exceptn`` and sets its ``msg`` field
|
||||
|
||||
3
todo.txt
3
todo.txt
@@ -1,6 +1,8 @@
|
||||
version 0.9.0
|
||||
=============
|
||||
|
||||
- finish support for unsigned ints
|
||||
|
||||
Debug GC session:
|
||||
- test sequence of closures; especially that the GC does not leak for those!
|
||||
|
||||
@@ -23,7 +25,6 @@ New pragmas:
|
||||
- implement "closure tuple consists of a single 'ref'" optimization
|
||||
|
||||
- document 'do' notation
|
||||
- finish support for unsigned ints
|
||||
- rethink the syntax: distinction between expr and stmt is unfortunate;
|
||||
indentation handling is quite complex too; problem with exception handling
|
||||
is that often the scope of ``try`` is wrong and apart from that ``try`` is
|
||||
|
||||
@@ -119,6 +119,7 @@ Language Additions
|
||||
allowing for *sigil-like* operators.
|
||||
- Stand-alone ``finally`` and ``except`` blocks are now supported.
|
||||
- Macros and templates can now be invoked as pragmas.
|
||||
- The apostrophe in type suffixes for numerical literal is now optional.
|
||||
|
||||
|
||||
2012-02-09 Version 0.8.14 released
|
||||
|
||||
Reference in New Issue
Block a user