ijzer_lib/
lib.rs

1//! This crate provides the implementation of the IJzer language.
2//! It defines a parser for the IJzer language, a syntax tree for the IJzer language, and a transpiler for the IJzer language to Rust code.
3//! For documentation of the language itself and how you can use this see the documentation of the `ijzer` crate.
4
5use anyhow::Result;
6use proc_macro2::TokenStream;
7
8pub mod ast_node;
9pub mod comparison_funcs;
10pub mod compiler;
11pub mod function_enums;
12pub mod operations;
13pub mod parser;
14pub mod syntax_error;
15pub mod tensor;
16pub mod tokens;
17pub mod types;
18
19/// Compiles a string of IJzer code into a Rust `TokenStream`.
20pub fn compile(input: &str) -> Result<TokenStream> {
21    let mut ast_context = ast_node::ASTContext::new();
22    let tokens = tokens::lexer(input)?;
23    let parsed_lines = parser::parse_lines(tokens, &mut ast_context)?;
24
25    parsed_lines
26        .into_iter()
27        .map(|(root, has_semicolon)| compiler::compile_line_from_node(root, has_semicolon))
28        .collect::<Result<TokenStream>>()
29}