pub struct Transpiler {
    pub cfg: ErgConfig,
    /* private fields */
}
Expand description

Generates a PyScript from an String or other File inputs.

Fields§

§cfg: ErgConfig

Implementations§

Examples found in repository?
transpile.rs (line 148)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    fn exec(&mut self) -> Result<i32, Self::Errs> {
        let path = self.cfg.dump_path().replace(".er", ".py");
        let artifact = self
            .transpile(self.input().read(), "exec")
            .map_err(|eart| {
                eart.warns.fmt_all_stderr();
                eart.errors
            })?;
        artifact.warns.fmt_all_stderr();
        let mut f = File::create(path).unwrap();
        f.write_all(artifact.object.code.as_bytes()).unwrap();
        Ok(0)
    }

    fn eval(&mut self, src: String) -> Result<String, CompileErrors> {
        let artifact = self.transpile(src, "eval").map_err(|eart| {
            eart.warns.fmt_all_stderr();
            eart.errors
        })?;
        artifact.warns.fmt_all_stderr();
        Ok(artifact.object.code)
    }
}

impl ContextProvider for Transpiler {
    fn dir(&self) -> Vec<(&VarName, &VarInfo)> {
        self.builder.dir()
    }

    fn get_receiver_ctx(&self, receiver_name: &str) -> Option<&Context> {
        self.builder.get_receiver_ctx(receiver_name)
    }

    fn get_var_info(&self, name: &str) -> Option<(&VarName, &VarInfo)> {
        self.builder.get_var_info(name)
    }
}

impl Buildable<PyScript> for Transpiler {
    fn build(
        &mut self,
        src: String,
        mode: &str,
    ) -> Result<CompleteArtifact<PyScript>, IncompleteArtifact<PyScript>> {
        self.transpile(src, mode)
            .map_err(|err| IncompleteArtifact::new(None, err.errors, err.warns))
    }

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Erase all but immutable information.
Erase information that will no longer be meaningful in the next iteration

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.