From b96926f5a08ade9ed2d0daf0ef2008d3a1e3a326 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Tue, 18 Nov 2025 17:30:01 +0300 Subject: [PATCH] Consteval converter to ascii keywords --- ascii/src/_sandbox.rs | 22 +++++++++++++++++++--- ascii/src/keyword.rs | 19 +++++++++++++++++++ ascii/src/lib.rs | 4 +++- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 ascii/src/keyword.rs diff --git a/ascii/src/_sandbox.rs b/ascii/src/_sandbox.rs index d9a067d..0d63c76 100644 --- a/ascii/src/_sandbox.rs +++ b/ascii/src/_sandbox.rs @@ -1,5 +1,7 @@ +#[cfg(test)] + use crate::{AsciiChar, AsciiCharConvertable}; -use source_stream_0::{CollectedSubstring, Pos, SourceStream}; +use source_stream_0::{CollectResult, CollectedSubstring, Pos, SourceStream}; use source_stream_0_converter_0::{ ConvertedSourceStream, StreamConverter, StreamConverter_Char, StreamConverter_Pos, StreamConverter_Pos_Noop, StreamConverter_Substring, @@ -10,8 +12,7 @@ use source_stream_0_default_streams_0::iterators::{ }; use source_stream_0_default_streams_0::pos::IndexPosCounter; use std::marker::PhantomData; - -#[cfg(test)] +use crate::asciiLiteral; struct ConverterImpl {} @@ -45,6 +46,7 @@ fn printAscii(a: Option) { } } + #[test] fn sandbox() { let src8 = SourceStreamOverIterator::wrap(StrSourceIterator::start( @@ -55,9 +57,23 @@ fn sandbox() { let cvt = ConverterImpl {}; let mut src = ConvertedSourceStream::convert(src8, cvt); + /* let cs = src.collect(); + + + match cs { + CollectResult::EOF => {} + CollectResult::NotMatches => {} + CollectResult::Matches(z) => { + z.compareKeyword(&asciiLiteral(b"azboba")); + (); + } + } +*/ for _ in 0..10 { // println!("{}", src.pos()); printAscii(src.currentChar()); src.nextChar(); } + + } diff --git a/ascii/src/keyword.rs b/ascii/src/keyword.rs new file mode 100644 index 0000000..885c42c --- /dev/null +++ b/ascii/src/keyword.rs @@ -0,0 +1,19 @@ +#![feature(const_for)] + +use crate::{AsciiChar}; + +pub const fn asciiLiteral( + str: &[u8; S], +) -> [AsciiChar; S] { + let mut out: [AsciiChar; S] = [AsciiChar::NOT_ASCII; S]; + let mut i = 0usize; + while i < S { + let a = str[i] as u32; + if (a >= 128) { + panic!("Not ascii char in literal"); + } + out[i] = AsciiChar::ASCII(a as u8); + i += 1; + } + return out; +} diff --git a/ascii/src/lib.rs b/ascii/src/lib.rs index 9139b6f..d8c1622 100644 --- a/ascii/src/lib.rs +++ b/ascii/src/lib.rs @@ -1,6 +1,8 @@ +mod _sandbox; mod char; mod converters; -mod _sandbox; +mod keyword; pub use crate::char::AsciiChar; pub use crate::converters::AsciiCharConvertable; +pub use crate::keyword::asciiLiteral;