Update visitor methods to return a Result<(), Box<dyn Error>>
Visitors for AST members may be fallible now Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -53,7 +53,7 @@ def define_visitor(wr: FileWriter, base: str, type_lines: list[str]):
|
|||||||
|
|
||||||
for type, members in types:
|
for type, members in types:
|
||||||
wr.line(
|
wr.line(
|
||||||
f" fn visit_{type.lower()}_{base.lower()}(&mut self, {base.lower()}: &{type}{base});"
|
f" fn visit_{type.lower()}_{base.lower()}(&mut self, {base.lower()}: &{type}{base}) -> Result<(), Box<dyn std::error::Error>>;"
|
||||||
)
|
)
|
||||||
wr.line("}")
|
wr.line("}")
|
||||||
wr.line()
|
wr.line()
|
||||||
@@ -69,7 +69,9 @@ def define_ast(wr: FileWriter, base: str, type_lines: list[str]):
|
|||||||
visitor = f"{base}Visitor"
|
visitor = f"{base}Visitor"
|
||||||
|
|
||||||
wr.line(f"pub trait {base}: Debug + Any " + "{")
|
wr.line(f"pub trait {base}: Debug + Any " + "{")
|
||||||
wr.line(f" fn accept(&self, visitor: &mut dyn {visitor});")
|
wr.line(
|
||||||
|
f" fn accept(&self, visitor: &mut dyn {visitor}) -> Result<(), Box<dyn std::error::Error>>;"
|
||||||
|
)
|
||||||
wr.line(" fn as_any(self: Box<Self>) -> Box<dyn Any>;")
|
wr.line(" fn as_any(self: Box<Self>) -> Box<dyn Any>;")
|
||||||
wr.line(" fn as_any_ref(&self) -> &dyn Any;")
|
wr.line(" fn as_any_ref(&self) -> &dyn Any;")
|
||||||
wr.line("}")
|
wr.line("}")
|
||||||
@@ -85,8 +87,11 @@ def define_ast(wr: FileWriter, base: str, type_lines: list[str]):
|
|||||||
wr.line("}")
|
wr.line("}")
|
||||||
wr.line()
|
wr.line()
|
||||||
wr.line(f"impl {base} for {type}{base} " + "{")
|
wr.line(f"impl {base} for {type}{base} " + "{")
|
||||||
wr.line(f" fn accept(&self, visitor: &mut dyn {visitor})" + "{")
|
wr.line(
|
||||||
wr.line(f" visitor.visit_{type.lower()}_{base.lower()}(self);")
|
f" fn accept(&self, visitor: &mut dyn {visitor}) -> Result<(), Box<dyn std::error::Error>>"
|
||||||
|
+ "{"
|
||||||
|
)
|
||||||
|
wr.line(f" visitor.visit_{type.lower()}_{base.lower()}(self)")
|
||||||
wr.line(" }")
|
wr.line(" }")
|
||||||
wr.line()
|
wr.line()
|
||||||
wr.line(" fn as_any(self: Box<Self>) -> Box<dyn Any> {")
|
wr.line(" fn as_any(self: Box<Self>) -> Box<dyn Any> {")
|
||||||
@@ -111,10 +116,12 @@ def main():
|
|||||||
|
|
||||||
wr = FileWriter(path)
|
wr = FileWriter(path)
|
||||||
|
|
||||||
|
# File headers
|
||||||
wr.line(
|
wr.line(
|
||||||
"// This is an auto-generated file. Any changes made to this file may be overwritten."
|
"// This is an auto-generated file. Any changes made to this file may be overwritten."
|
||||||
)
|
)
|
||||||
wr.line("// This file was created at: " + time.strftime("%Y-%m-%d %H:%M:%S"))
|
wr.line("// This file was created at: " + time.strftime("%Y-%m-%d %H:%M:%S"))
|
||||||
|
wr.line("#![allow(dead_code)]")
|
||||||
|
|
||||||
# Imports
|
# Imports
|
||||||
wr.line("use std::fmt::Debug;")
|
wr.line("use std::fmt::Debug;")
|
||||||
|
|||||||
Reference in New Issue
Block a user