Skip to content

Commit

Permalink
feat(#10): transpiler
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Sep 25, 2024
1 parent f946311 commit 3c19162
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ FSL.
#[allow(unused_imports)]
#[macro_use]
extern crate hamcrest;
/// FSL Compiler.
pub mod compiler;
/// FSL Transpiler.
pub mod transpiler;
/// FSL Parser.
pub mod parser;
34 changes: 17 additions & 17 deletions src/compiler/fsl_compiler.rs → src/transpiler/fsl_transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@ use log::info;
use std::fs;
use std::path::Path;

/// FSL compiler.
/// FSL transpiler.
/// ```
/// use fsl::compiler::fsl_compiler::Fslc;
/// let output = Fslc::program(String::from("me: @jeff\n +repo me/foo")).out();
/// use fsl::transpiler::fsl_transpiler::Fslt;
/// let output = Fslt::program(String::from("me: @jeff\n +repo me/foo")).out();
/// ```
pub struct Fslc {
/// Program to compile.
pub struct Fslt {
/// Program to transpiler.
pub program: String,
/// Parser.
pub parser: FslParser,
}

impl Fslc {
/// New compiler for program.
pub fn program(program: String) -> Fslc {
Fslc {
impl Fslt {
/// New transpiler for program.
pub fn program(program: String) -> Fslt {
Fslt {
program,
parser: FslParser {},
}
}

/// New compiler for program in file.
pub fn file(path: &Path) -> Fslc {
Fslc {
/// New transpiler for program in file.
pub fn file(path: &Path) -> Fslt {
Fslt {
program: fs::read_to_string(path).unwrap_or_else(|_| {
panic!("Failed to read path: {}", path.display())
}),
Expand All @@ -63,16 +63,16 @@ impl Fslc {

#[cfg(test)]
mod tests {
use crate::compiler::fsl_compiler::Fslc;
use crate::transpiler::fsl_transpiler::Fslt;
use anyhow::Result;
use log::Level;
use std::path::Path;
extern crate testing_logger;

#[test]
fn compiles_program_as_string() -> Result<()> {
fn transpiles_program_as_string() -> Result<()> {
testing_logger::setup();
Fslc::program(String::from("me: @jeff +repo me/foo")).out();
Fslt::program(String::from("me: @jeff +repo me/foo")).out();
testing_logger::validate(|logs| {
assert_eq!(logs.len(), 1);
assert_eq!(logs[0].body, "Done!");
Expand All @@ -82,9 +82,9 @@ mod tests {
}

#[test]
fn compiles_program_from_file() -> Result<()> {
fn transpiles_program_from_file() -> Result<()> {
testing_logger::setup();
Fslc::file(Path::new("resources/programs/me.fsl")).out();
Fslt::file(Path::new("resources/programs/me.fsl")).out();
testing_logger::validate(|logs| {
assert_eq!(logs.len(), 1);
assert_eq!(logs[0].body, "Done!");
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/mod.rs → src/transpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/// FSL Compiler.
pub mod fsl_compiler;
/// FSL to FakeHub types (Rust) transpiler.
pub mod fsl_transpiler;

0 comments on commit 3c19162

Please sign in to comment.