mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-27 13:54:55 +00:00
Fine-tune int types
This commit is contained in:
parent
455bcc01a0
commit
6fa3d0f90a
15 changed files with 27 additions and 42 deletions
|
@ -24,6 +24,10 @@ builtin_type_mapping = {
|
|||
}
|
||||
assert builtin_type_mapping.keys() == asdl.builtin_types
|
||||
|
||||
builtin_int_mapping = {
|
||||
"simple": "bool",
|
||||
"is_async": "bool",
|
||||
}
|
||||
|
||||
def rust_type_name(name):
|
||||
"""Return a string for the C name of the type.
|
||||
|
@ -31,7 +35,8 @@ def rust_type_name(name):
|
|||
This function special cases the default types provided by asdl.
|
||||
"""
|
||||
if name in asdl.builtin_types:
|
||||
return builtin_type_mapping[name]
|
||||
builtin = builtin_type_mapping[name]
|
||||
return builtin
|
||||
elif name.islower():
|
||||
return "".join(part.capitalize() for part in name.split("_"))
|
||||
else:
|
||||
|
@ -355,6 +360,8 @@ class StructVisitor(EmitVisitor):
|
|||
typ = f"Option<{typ}>"
|
||||
if field.seq:
|
||||
typ = f"Vec<{typ}>"
|
||||
if typ == "Int":
|
||||
typ = builtin_int_mapping.get(field.name, typ)
|
||||
name = rust_field(field.name)
|
||||
self.emit(f"{vis}{name}: {typ},", depth)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue