mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-06 03:44:14 +00:00
removed 'strong spaces' from the manual because some people on reddit who never actually tried the feature are afraid that they could be confused (TM). Boo, we like to learn crazy precedence tables instead and check they adhere with the spacing.
This commit is contained in:
@@ -70,48 +70,6 @@ Whether an operator is used a prefix operator is also affected by preceeding whi
|
||||
echo($foo)
|
||||
|
||||
|
||||
Strong spaces
|
||||
-------------
|
||||
|
||||
The number of spaces preceding a non-keyword operator affects precedence
|
||||
if the experimental parser directive ``#?strongSpaces`` is used. Indentation
|
||||
is not used to determine the number of spaces. If 2 or more operators have the
|
||||
same number of preceding spaces the precedence table applies, so ``1 + 3 * 4``
|
||||
is still parsed as ``1 + (3 * 4)``, but ``1+3 * 4`` is parsed as ``(1+3) * 4``:
|
||||
|
||||
.. code-block:: nim
|
||||
#? strongSpaces
|
||||
if foo+4 * 4 == 8 and b&c | 9 ++
|
||||
bar:
|
||||
echo ""
|
||||
# is parsed as
|
||||
if ((foo+4)*4 == 8) and (((b&c) | 9) ++ bar): echo ""
|
||||
|
||||
|
||||
Furthermore whether an operator is used a prefix operator is affected by the
|
||||
number of spaces:
|
||||
|
||||
.. code-block:: nim
|
||||
#? strongSpaces
|
||||
echo $foo
|
||||
# is parsed as
|
||||
echo($foo)
|
||||
|
||||
This also affects whether ``[]``, ``{}``, ``()`` are parsed as constructors
|
||||
or as accessors:
|
||||
|
||||
.. code-block:: nim
|
||||
#? strongSpaces
|
||||
echo (1,2)
|
||||
# is parsed as
|
||||
echo((1,2))
|
||||
|
||||
Only 0, 1, 2, 4 or 8 spaces are allowed to specify precedence and it is
|
||||
enforced that infix operators have the same amount of spaces before and after
|
||||
them. This rules does not apply when a newline follows after the operator,
|
||||
then only the preceding spaces are considered.
|
||||
|
||||
|
||||
Grammar
|
||||
-------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user