|
8 | 8 | from .ast_node import * |
9 | 9 | from .eval_literal import eval_number, eval_string |
10 | 10 | from .errors import LocatedAstError |
11 | | -from ..common import region_union, RegionUnionArgT, HasRegion |
| 11 | +from ..common import region_union, RegionUnionArgT, HasRegion, StrRegion |
12 | 12 | from ..cst.base_node import AnyNode, Node, Leaf |
13 | 13 | from ..cst.named_node import NamedLeafCls, NamedNodeCls, NamedSizedNodeCls |
14 | 14 | from ..cst.nodes import * |
@@ -138,11 +138,17 @@ def _walk_var_decl(self, smt: DeclNode): |
138 | 138 | else VarDeclScope.GLOBAL) |
139 | 139 | tp = (VarType.LIST if isinstance(smt.decl_type, DeclType_List) |
140 | 140 | else VarType.VARIABLE) |
141 | | - return [self._walk_single_decl(d, scope, tp) for d in smt.decl_list.decls] |
142 | | - |
143 | | - def _walk_single_decl(self, d: DeclItemNode, scope: VarDeclScope, tp: VarType): |
| 141 | + # Add the region from the keywords to first decl (to make single-var |
| 142 | + # decls a more sensible .region that includes the `let` keyword as well) |
| 143 | + extra_region_first = region_union(smt.decl_scope, smt.decl_type) |
| 144 | + return [self._walk_single_decl(d, scope, tp, |
| 145 | + extra_region_first if i == 0 else None) |
| 146 | + for i, d in enumerate(smt.decl_list.decls)] |
| 147 | + |
| 148 | + def _walk_single_decl(self, d: DeclItemNode, scope: VarDeclScope, |
| 149 | + tp: VarType, extra_region: StrRegion | None): |
144 | 150 | return AstDeclNode( |
145 | | - region_union(d.ident, d.value), |
| 151 | + region_union(d.ident, d.value, extra_region), |
146 | 152 | scope, tp, self._walk_ident(d.ident), |
147 | 153 | None if d.value is None else self._walk_expr(d.value)) |
148 | 154 |
|
|
0 commit comments