|
8 | 8 | from argparse import ArgumentParser
|
9 | 9 | from pathlib import Path
|
10 | 10 | from typing import Optional, Dict
|
11 |
| -from attr import dataclass |
12 | 11 |
|
13 | 12 | import asdl
|
14 | 13 |
|
|
18 | 17 | builtin_type_mapping = {
|
19 | 18 | "identifier": "Ident",
|
20 | 19 | "string": "String",
|
21 |
| - "int": "usize", |
| 20 | + "int": "u32", |
22 | 21 | "constant": "Constant",
|
23 | 22 | }
|
24 | 23 | assert builtin_type_mapping.keys() == asdl.builtin_types
|
@@ -391,7 +390,18 @@ def visitModule(self, mod, depth):
|
391 | 390 | depth + 1,
|
392 | 391 | )
|
393 | 392 | self.emit(
|
394 |
| - "fn map_located<T>(&mut self, located: Attributed<T, U>) -> Result<Attributed<T, Self::TargetU>, Self::Error> { let custom = self.map_user(located.custom)?; Ok(Attributed { range: located.range, custom, node: located.node }) }", |
| 393 | + """ |
| 394 | + fn map_located<T>(&mut self, located: Attributed<T, U>) -> Result<Attributed<T, Self::TargetU>, Self::Error> { |
| 395 | + let custom = self.map_user(located.custom)?; |
| 396 | + Ok(Attributed { range: located.range, custom, node: located.node }) |
| 397 | + }""", |
| 398 | + depth + 1, |
| 399 | + ) |
| 400 | + self.emit( |
| 401 | + """ |
| 402 | + fn fold<X: Foldable<U, Self::TargetU>>(&mut self, node: X) -> Result<X::Mapped, Self::Error> { |
| 403 | + node.fold(self) |
| 404 | + }""", |
395 | 405 | depth + 1,
|
396 | 406 | )
|
397 | 407 | for dfn in mod.dfns:
|
@@ -761,11 +771,15 @@ def gen_construction(self, cons_path, cons, name, depth):
|
761 | 771 | def extract_location(self, typename, depth):
|
762 | 772 | row = self.decode_field(asdl.Field("int", "lineno"), typename)
|
763 | 773 | column = self.decode_field(asdl.Field("int", "col_offset"), typename)
|
764 |
| - self.emit(f"""let _location = {{ |
765 |
| - let row = try_location_field({row}, _vm)?; |
766 |
| - let column = try_location_field({column}, _vm)?; |
767 |
| - SourceLocation {{ row, column }} |
768 |
| - }};""", depth) |
| 774 | + self.emit( |
| 775 | + f""" |
| 776 | + let _location = {{ |
| 777 | + let row = {row}; |
| 778 | + let column = {column}; |
| 779 | + try_location(row, column, _vm)? |
| 780 | + }};""", |
| 781 | + depth, |
| 782 | + ) |
769 | 783 |
|
770 | 784 | def decode_field(self, field, typename):
|
771 | 785 | name = json.dumps(field.name)
|
@@ -805,7 +819,7 @@ def write_located_def(typeinfo, f):
|
805 | 819 | f.write(
|
806 | 820 | textwrap.dedent(
|
807 | 821 | """
|
808 |
| - use crate::location::SourceRange; |
| 822 | + use rustpython_parser_core::source_code::SourceRange; |
809 | 823 |
|
810 | 824 | pub type Located<T> = super::generic::Attributed<T, SourceRange>;
|
811 | 825 | """
|
|
0 commit comments