|
1 | 1 | # # Macros and expression interpolation
|
2 | 2 |
|
3 |
| -using JuliaSyntax: SourceFile, SyntaxNode, parse_all, child, setchild! |
| 3 | +using JuliaSyntax: SourceFile, SyntaxNode, parseall, child, setchild! |
4 | 4 |
|
5 | 5 | # The following shows that SyntaxNode works nicely for simple macros which
|
6 | 6 | # just interpolate expressions into one another. In particular it shows how
|
@@ -31,7 +31,7 @@ function at_show2(ex::SyntaxNode)
|
31 | 31 | # The following emulates the expression interpolation lowering which is
|
32 | 32 | # usually done by the compiler.
|
33 | 33 | # 1. Extract the expression literal as `block`
|
34 |
| - tree = parse_all(SyntaxNode, SourceFile(String(read(@__FILE__)), filename=@__FILE__)) |
| 34 | + tree = parseall(SyntaxNode, String(read(@__FILE__)), filename=@__FILE__) |
35 | 35 | block = child(tree, 3, 2, 2, 1)
|
36 | 36 | # 2. Interpolate local variables into the block at positions of $'s
|
37 | 37 | # Interpolating a SyntaxNode `ex` is simple:
|
|
48 | 48 |
|
49 | 49 | # Let's have some simple expression to pass to at_show2. This will be
|
50 | 50 | # attributed to a different file foo.jl
|
51 |
| -s2 = child(parse_all(SyntaxNode, SourceFile("foo +\n42", filename="foo.jl")), 1) |
| 51 | +s2 = parseall(SyntaxNode, "foo +\n42", filename="foo.jl", rule=:statement) |
52 | 52 |
|
53 | 53 | # Calling at_show2, we see that the precise source information is preserved for
|
54 | 54 | # both the surrounding expression and the interpolated fragments.
|
|
0 commit comments