@@ -272,15 +272,13 @@ annotation as a "suffix", instead of prepending it between `(` and `)`. This
272272makes it possible to, for example, write `10px`, `10.5%`, `512GiB`, etc., which
273273are equivalent to `(px)10`, `(%)5`, and `(GiB)512`, respectively.
274274
275- Most suffixes can be appended directly to the number
276- (a ({{bare-suffix-type-annotation}})),
277- as shown in the previous paragraph.
278- To avoid parsing ambiguity, there are some restrictions on this;
279- an ({{explicit-suffix-type-annotation}}) avoids all these restrictions
280- by using an additional `#` to explicitly indicate it.
281- For example, `10.0u8` is invalid, but `10.0#u8` is valid
282- and equivalent to `(u8)10.0`.
283- See the "Bare Suffix Type Annotation" section for the full list of restrictions.
275+ Most suffixes can be appended directly to the number (a
276+ ({{bare-suffix-type-annotation}})), as shown in the previous paragraph. To avoid
277+ parsing ambiguity, there are some restrictions on this; an
278+ ({{explicit-suffix-type-annotation}}) avoids all these restrictions by using an
279+ additional `#` to explicitly indicate it. For example, `10.0u8` is invalid, but
280+ ` 10.0#u8` is valid and equivalent to `(u8)10.0`. See
281+ ({{bare-suffix-type-annotation}}) for the full list of restrictions.
284282
285283An implementation that finds BOTH a parenthesized and a suffix
286284({{type-annotation}}) on the same ({{number}}) MUST yield a syntax error.
@@ -294,8 +292,9 @@ There are two kinds of ({{suffix-type-annotation}}) available:
294292# ### Bare Suffix Type Annotation
295293
296294When a ({{value}}) is a decimal ({{number}}) WITHOUT exponential syntax (`1e+5`
297- etc) (and ONLY a decimal), it's possible to attach the type annotation as a
298- suffix directly to the number, without any additional syntax.
295+ etc) (and ONLY a decimal : that is, numbers which do NOT have a `0b`/`0o`/`0x`
296+ prefix), it's possible to attach the type annotation as a suffix directly to the
297+ number, without any additional syntax.
299298
300299They also come with some additional rules (like only being available for
301300decimals), in order to prevent potential ambiguity or footguns with the syntax.
@@ -305,16 +304,17 @@ designing this feature, it was determined that the value for various real-world
305304DSLs outweighed the complexity of the following rules.
306305
307306As such, to remove ambiguity, the suffix ({{identifier-string}}) MUST NOT start
308- with any of the following patterns, all of which MUST yield syntax errors
309- (if they can be distinguished from other syntaxes at all) :
307+ with any of the following patterns, all of which MUST yield syntax errors (if
308+ they can be distinguished from other syntaxes at all) :
310309
311310* `.`, `,`, or `_`
312- * `[a-zA-Z][0-9_]` (to disambiguate all non-decimals, with breathing room)
313311* `[eE][+-]?[0-9]` (to disambiguate exponentials)
314- * `[xX][a-fA-F]` (to disambiguate hexadecimals)
315312
316- For example, `10,000` is illegal, as is `10u16` . `10e0n` is illegal, but `10e0` is a legal
313+ For example, `10,000` is illegal. `10e0n` is illegal, but `10e0` is a legal
317314*decimal number using exponential syntax*, __not__ equivalent to `(e0)10`.
315+ Additionally, note that since bare suffixes are only legal on _decimals_, `0u8`
316+ is legal, but `0xs` is _not_, since hexadecimals are determined by their
317+ prefixes. Similarly, `1xs` _is_ legal, and equivalent to `(xs)1`.
318318
319319All other ({{identifier-string}})s can be safely appended to decimal numbers, so
320320long as the decimal does not include an exponential component.
@@ -329,11 +329,11 @@ Any ({{number}}) may have a `#` appended to it, followed by any valid
329329({{identifier-string}}). This is an explicit ({{suffix-type-annotation}}) syntax
330330without any of the relatively complex requirements of
331331({{bare-suffix-type-annotation}}), which can be a useful escape hatch. For
332- example : ` 10.0#u8 ` is invalid syntax without the `#` prefix.
332+ example : `0 #b1 ` is invalid syntax without the `#` prefix.
333333
334334Note again that, unlike ({{bare-suffix-type-annotation}})s, Explicit Suffixes
335335may be used with ALL ({{number}}) formats (hexadecimal, decimal, octal, and
336- binary). For example, `0x1234#u16 ` is valid.
336+ binary). For example, `0x1234#u32 ` is valid.
337337
338338# ## Reserved Type Annotations for Numbers Without Decimals
339339
@@ -1022,8 +1022,9 @@ node-children := '{' nodes final-node? '}'
10221022node-terminator := single-line-comment | newline | ';' | eof
10231023
10241024prop := string node-space* '=' node-space* value
1025- value := type? node-space* (string | number | keyword)
1025+ value := normal-value | suffixed-decimal
10261026type := '(' node-space* string node-space* ')'
1027+ normal-value := type? node-space* (string | number | keyword)
10271028
10281029// Strings
10291030string := identifier-string | quoted-string | raw-string ¶
@@ -1084,24 +1085,25 @@ multi-line-raw-string-body :=
10841085// Numbers
10851086number := keyword-number | hex | octal | binary | decimal
10861087
1087- decimal := sign? integer ('.' integer)? (
1088- // NOTE : This grammar does not explicitly guard against having both
1089- // parenthesized and type suffixes.
1090- bare-type-suffix |
1091- explicit-type-suffix |
1092- (exponent explicit-type-suffix?)
1093- )?
1088+ decimal := significand exponent?
1089+ suffixed-decimal := significand (
1090+ bare-type-suffix
1091+ | (exponent? explicit-type-suffix)
1092+ )
1093+ significand := sign? significand-initial integer? ('.' integer)?
10941094exponent := ('e' | 'E') sign? integer
10951095integer := digit (digit | '_')*
1096+ significand-initial = digit
1097+ - ' 0b'
1098+ - ' 0o'
1099+ - ' 0x'
10961100digit := [0-9]
10971101sign := '+' | '-'
10981102
10991103bare-type-suffix := bare-type-suffix-initial identifier-char*
11001104bare-type-suffix-initial := identifier-char
11011105 - ' .' - ',' - '_'
1102- - ([a-zA-Z] [0-9_])
11031106 - (('e' | 'E') sign? digit)
1104- - (('x' | 'X') [a-fA-F])
11051107explicit-type-suffix := '#' identifier-string
11061108
11071109hex := sign? '0x' hex-digit (hex-digit | '_')*
0 commit comments