Consteval converter to ascii keywords
This commit is contained in:
parent
dfe4a58973
commit
b96926f5a0
@ -1,5 +1,7 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
|
||||||
use crate::{AsciiChar, AsciiCharConvertable};
|
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::{
|
use source_stream_0_converter_0::{
|
||||||
ConvertedSourceStream, StreamConverter, StreamConverter_Char, StreamConverter_Pos,
|
ConvertedSourceStream, StreamConverter, StreamConverter_Char, StreamConverter_Pos,
|
||||||
StreamConverter_Pos_Noop, StreamConverter_Substring,
|
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 source_stream_0_default_streams_0::pos::IndexPosCounter;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use crate::asciiLiteral;
|
||||||
#[cfg(test)]
|
|
||||||
|
|
||||||
struct ConverterImpl {}
|
struct ConverterImpl {}
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ fn printAscii(a: Option<AsciiChar>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sandbox() {
|
fn sandbox() {
|
||||||
let src8 = SourceStreamOverIterator::wrap(StrSourceIterator::start(
|
let src8 = SourceStreamOverIterator::wrap(StrSourceIterator::start(
|
||||||
@ -55,9 +57,23 @@ fn sandbox() {
|
|||||||
let cvt = ConverterImpl {};
|
let cvt = ConverterImpl {};
|
||||||
let mut src = ConvertedSourceStream::convert(src8, cvt);
|
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 {
|
for _ in 0..10 {
|
||||||
// println!("{}", src.pos());
|
// println!("{}", src.pos());
|
||||||
printAscii(src.currentChar());
|
printAscii(src.currentChar());
|
||||||
src.nextChar();
|
src.nextChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
19
ascii/src/keyword.rs
Normal file
19
ascii/src/keyword.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#![feature(const_for)]
|
||||||
|
|
||||||
|
use crate::{AsciiChar};
|
||||||
|
|
||||||
|
pub const fn asciiLiteral<const S: usize>(
|
||||||
|
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;
|
||||||
|
}
|
||||||
@ -1,6 +1,8 @@
|
|||||||
|
mod _sandbox;
|
||||||
mod char;
|
mod char;
|
||||||
mod converters;
|
mod converters;
|
||||||
mod _sandbox;
|
mod keyword;
|
||||||
|
|
||||||
pub use crate::char::AsciiChar;
|
pub use crate::char::AsciiChar;
|
||||||
pub use crate::converters::AsciiCharConvertable;
|
pub use crate::converters::AsciiCharConvertable;
|
||||||
|
pub use crate::keyword::asciiLiteral;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user