Skip to content

Commit d370a89

Browse files
committed
preserve source location info of dialect-import in example dialects
Any code coming in from the template will be marked as if it came from the line containing the dialect-import statement. (Invoke the `mcpyrate.debug.StepExpansion` dialect before any other dialects to see the line numbers.) Preserving the source location info requires `mcpyrate` 3.6.0 or later. This will also run on earlier versions, without preserving the source location info, just like before; then it will look like all dialect template code came from the beginning of the unexpanded user code.
1 parent 6ba8309 commit d370a89

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

unpythonic/dialects/lispython.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ def transform_ast(self, tree): # tree is an ast.Module
3939
from unpythonic import cons, car, cdr, ll, llist, nil, prod, dyn, Values # noqa: F401, F811
4040
with autoreturn, quicklambda, multilambda, namedlambda, tco:
4141
__paste_here__ # noqa: F821, just a splicing marker.
42-
tree.body = splice_dialect(tree.body, template, "__paste_here__")
42+
43+
# Beginning with 3.6.0, `mcpyrate` makes available the source location info
44+
# of the dialect-import that imported this dialect.
45+
if hasattr(self, "lineno"): # mcpyrate 3.6.0+
46+
tree.body = splice_dialect(tree.body, template, "__paste_here__",
47+
lineno=self.lineno, col_offset=self.col_offset)
48+
else:
49+
tree.body = splice_dialect(tree.body, template, "__paste_here__")
50+
4351
return tree
4452

4553

@@ -68,5 +76,13 @@ def transform_ast(self, tree): # tree is an ast.Module
6876
# of the template.
6977
with autoreturn, quicklambda, multilambda, namedlambda, tco:
7078
__paste_here__ # noqa: F821, just a splicing marker.
71-
tree.body = splice_dialect(tree.body, template, "__paste_here__")
79+
80+
# Beginning with 3.6.0, `mcpyrate` makes available the source location info
81+
# of the dialect-import that imported this dialect.
82+
if hasattr(self, "lineno"): # mcpyrate 3.6.0+
83+
tree.body = splice_dialect(tree.body, template, "__paste_here__",
84+
lineno=self.lineno, col_offset=self.col_offset)
85+
else:
86+
tree.body = splice_dialect(tree.body, template, "__paste_here__")
87+
7288
return tree

unpythonic/dialects/listhell.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,13 @@ def transform_ast(self, tree): # tree is an ast.Module
2323
from unpythonic import composerc as compose # compose from Right, Currying # noqa: F401
2424
with prefix, autocurry:
2525
__paste_here__ # noqa: F821, just a splicing marker.
26-
tree.body = splice_dialect(tree.body, template, "__paste_here__")
26+
27+
# Beginning with 3.6.0, `mcpyrate` makes available the source location info
28+
# of the dialect-import that imported this dialect.
29+
if hasattr(self, "lineno"): # mcpyrate 3.6.0+
30+
tree.body = splice_dialect(tree.body, template, "__paste_here__",
31+
lineno=self.lineno, col_offset=self.col_offset)
32+
else:
33+
tree.body = splice_dialect(tree.body, template, "__paste_here__")
34+
2735
return tree

unpythonic/dialects/pytkell.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,13 @@ def transform_ast(self, tree): # tree is an ast.Module
3939
from unpythonic import cons, car, cdr, ll, llist, nil # noqa: F401
4040
with lazify, autocurry:
4141
__paste_here__ # noqa: F821, just a splicing marker.
42-
tree.body = splice_dialect(tree.body, template, "__paste_here__")
42+
43+
# Beginning with 3.6.0, `mcpyrate` makes available the source location info
44+
# of the dialect-import that imported this dialect.
45+
if hasattr(self, "lineno"): # mcpyrate 3.6.0+
46+
tree.body = splice_dialect(tree.body, template, "__paste_here__",
47+
lineno=self.lineno, col_offset=self.col_offset)
48+
else:
49+
tree.body = splice_dialect(tree.body, template, "__paste_here__")
50+
4351
return tree

0 commit comments

Comments
 (0)