summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorLeon <github@adigitoleo.dissimulo.com>2022-04-10 01:51:44 +1000
committerGitHub <noreply@github.com>2022-04-09 17:51:44 +0200
commit152dab09838adc5a4ab8dc220c5017c868563467 (patch)
tree028ea601bd12af106028d5e9c7f1a556e7ce6dac
parentded8b0e5410518ffed24b46565eb6e42f18a63f1 (diff)
downloadNim-152dab09838adc5a4ab8dc220c5017c868563467.tar.gz
fix: Fix introductory macro examples (#19706)
Co-authored-by: adigitoleo <adigitoleo@dissimulo.com>
-rw-r--r--doc/tut3.rst20
1 files changed, 17 insertions, 3 deletions
diff --git a/doc/tut3.rst b/doc/tut3.rst
index 1c497f1f5..c2c956107 100644
--- a/doc/tut3.rst
+++ b/doc/tut3.rst
@@ -188,21 +188,35 @@ Backticks are used to insert code from `NimNode` symbols into the
 generated expression.
 
 .. code-block:: nim
-    macro a(i) = quote do: let `i` = 0
+    :test: "nim c $1"
+    import std/macros
+    macro a(i) = quote do:
+      let `i` = 0
+
     a b
+    doAssert b == 0
 
 A custom prefix operator can be defined whenever backticks are needed.
 
 .. code-block:: nim
-    macro a(i) = quote("@") do: assert @i == 0
+    :test: "nim c $1"
+    import std/macros
+    macro a(i) = quote("@") do:
+      assert @i == 0
+
     let b = 0
     a b
 
 The injected symbol needs accent quoted when it resolves to a symbol.
 
 .. code-block:: nim
-    macro a(i) = quote("@") do: let `@i` == 0
+    :test: "nim c $1"
+    import std/macros
+    macro a(i) = quote("@") do:
+      let `@i` = 0
+
     a b
+    doAssert b == 0
 
 Make sure to inject only symbols of type `NimNode` into the generated syntax
 tree. You can use `newLit` to convert arbitrary values into