language change: change how the experimental dot operators work

This commit is contained in:
Andreas Rumpf 2017-11-29 13:31:31 +01:00
commit 33814cf63e
5 changed files with 25 additions and 19 deletions

View file

@ -17,8 +17,8 @@ or dynamic file formats such as JSON or XML.
When Nim encounters an expression that cannot be resolved by the
standard overload resolution rules, the current scope will be searched
for a dot operator that can be matched against a re-written form of
the expression, where the unknown field or proc name is converted to
an additional static string parameter:
the expression, where the unknown field or proc name is passed to
an ``untyped`` parameter:
.. code-block:: nim
a.b # becomes `.`(a, "b")
@ -28,7 +28,7 @@ The matched dot operators can be symbols of any callable kind (procs,
templates and macros), depending on the desired effect:
.. code-block:: nim
proc `.` (js: PJsonNode, field: string): JSON = js[field]
template `.` (js: PJsonNode, field: untyped): JSON = js[astToStr(field)]
var js = parseJson("{ x: 1, y: 2}")
echo js.x # outputs 1