Skip to content

Commit

Permalink
1. preliminary attempt to use #[no_std]
Browse files Browse the repository at this point in the history
  • Loading branch information
denisandroid committed May 16, 2024
1 parent 32cd2a0 commit c69efeb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/exprs/literal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

use std::{ops::Deref, fmt::{Debug, Display}, borrow::Borrow};
use core::{ops::Deref, fmt::{Debug, Display}, borrow::Borrow};
use alloc::{borrow::ToOwned, string::String};
use proc_macro2::{Span, TokenStream as TokenStream2};
use crate::sg_err;

Expand Down Expand Up @@ -63,14 +64,14 @@ impl Deref for ExprLit {

impl Debug for ExprLit {
#[inline(always)]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Debug::fmt(&self as &str, f)
}
}

impl Display for ExprLit {
#[inline(always)]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Display::fmt(&self as &str, f)
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ use std::fmt::Write;
```
*/

// #![no_std] TODO, impossible without: [std::io::Error, std::{io::Read, fs::File}, std::fs::read_to_string]
#![allow(clippy::redundant_field_names)]
#![allow(clippy::redundant_pattern_matching)]
#![allow(clippy::needless_return)]
#![allow(clippy::tabs_in_doc_comments)]

extern crate proc_macro;
extern crate alloc;

use std::slice::IterMut;
use core::slice::IterMut;
use alloc::string::ToString;
use proc_macro2::{TokenTree as TokenTree2, TokenStream as TokenStream2, Group};
use proc_macro::TokenStream;
use trees::sg_err;
Expand Down
1 change: 1 addition & 0 deletions src/macros/include.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

use std::{io::Read, fs::File};
use alloc::string::String;
use proc_macro2::{TokenTree as TokenTree2, Group, TokenStream as TokenStream2, Delimiter, Span, Literal};
use crate::{trees::{sg_err, result::TreeResult, loader::{load_file_and_automake_tree_with_fns, LoadFileAndAutoMakeTreeErr}, ttry, group::g_stringify}, exprs::literal::{ExprLit, ExprLitTryNewErr}};

Expand Down
4 changes: 2 additions & 2 deletions src/trees/group.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

use std::slice::IterMut;
use core::slice::IterMut;
use proc_macro2::{Group, Delimiter, TokenTree as TokenTree2};
use crate::{TreeResult, trees::sg_err, trees::ttry, exprs::literal::ExprLit};
use std::fmt::Write;
use alloc::{fmt::Write, format, string::{String, ToString}};

/// This function allows you to correctly end a group with
/// a delimiter () and skip ';' if it is needed.
Expand Down
1 change: 1 addition & 0 deletions src/trees/loader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

use alloc::{format, string::String};
use proc_macro2::{TokenStream as TokenStream2, Span};
use std::io::Error as IOError;
use syn::Error as SynError;
Expand Down
7 changes: 4 additions & 3 deletions src/trees/replace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

use std::slice::IterMut;
use core::slice::IterMut;
use proc_macro2::{Group, TokenTree as TokenTree2, TokenStream as TokenStream2};
use alloc::vec::Vec;

/*
TODO, At the moment this is not optimally done :(.
Expand Down Expand Up @@ -38,14 +39,14 @@ pub fn support_replace_tree_in_group<R>(
/// A small function that provides the ability
/// to iterate and replace trees in place.
///
/// For a group, use the `replace_tree_in_group` function.
/// For a group, use the `support_replace_tree_in_group` function.
pub fn support_replace_tree_in_stream<R>(
stream: &mut TokenStream2,

next: impl FnOnce(IterMut<TokenTree2>) -> R
) -> R {
let mut allts: Vec<TokenTree2> =
std::mem::take(stream)
core::mem::take(stream)
.into_iter()
.collect();

Expand Down

0 comments on commit c69efeb

Please sign in to comment.