pub trait CodeGen: Debug + Clone {
    type Context;
    type Options;
    type SymbolTable;

    // Required method
    fn to_rust(
        self,
        ctx: Self::Context,
        options: Self::Options,
        symbols: Self::SymbolTable
    ) -> Result<TokenStream, Box<dyn Error>>;

    // Provided methods
    fn find_symbols(self, symbols_in: Self::SymbolTable) -> Self::SymbolTable { ... }
    fn get_docstring(&self) -> Option<String> { ... }
}
Expand description

Reexport the CodeGen from to_tokenstream A trait for an object that can be converted to Rust code. Any data structure implementing this trait can be converted into a proc_macro2::TokenStream.

Required Associated Types§

source

type Context

A type, generally an enum, that passes the code generator the context of the node.

source

type Options

A struct representing the set of compilation options.

source

type SymbolTable

A trait for a symbol table

Required Methods§

source

fn to_rust( self, ctx: Self::Context, options: Self::Options, symbols: Self::SymbolTable ) -> Result<TokenStream, Box<dyn Error>>

A trait method to output Rust code in a general sense. The output should be stream of Rust tokens, however, it is not guaranteed that it will fully compile because of scoping errors and other checks that don’t occur until later.

Provided Methods§

source

fn find_symbols(self, symbols_in: Self::SymbolTable) -> Self::SymbolTable

A default implementation for find_symbols(), which simply returns the input. Language nodes that modify the symbol table should override this method.

source

fn get_docstring(&self) -> Option<String>

A trait method for extracting a docstring from an object that can have a docstring.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl CodeGen for ClassDef

source§

impl CodeGen for Constant

source§

impl CodeGen for Import

An Import (or FromImport) statement causes 2 things to occur:

  1. Declares the imported object within the existing scope.
  2. Causes the referenced module to be compiled into the program (only once).
source§

impl CodeGen for ImportFrom

source§

impl CodeGen for Parameter

source§

impl<'a> CodeGen for Arg

source§

impl<'a> CodeGen for ExprType

source§

impl<'a> CodeGen for StatementType

source§

impl<'a> CodeGen for Assign

source§

impl<'a> CodeGen for BinOp

source§

impl<'a> CodeGen for BoolOp

source§

impl<'a> CodeGen for Call

source§

impl<'a> CodeGen for Compare

source§

impl<'a> CodeGen for Expr

source§

impl<'a> CodeGen for FunctionDef

source§

impl<'a> CodeGen for Keyword

source§

impl<'a> CodeGen for List<'a>

source§

impl<'a> CodeGen for Name

source§

impl<'a> CodeGen for ParameterList

source§

impl<'a> CodeGen for Statement

source§

impl<'a> CodeGen for Module

source§

impl<'a> CodeGen for UnaryOp