forked from katzen-cafe/iowo
40 lines
1.4 KiB
Rust
40 lines
1.4 KiB
Rust
|
#![feature(iter_collect_into)]
|
||
|
pub mod parser {
|
||
|
pub mod input {
|
||
|
use enumset::{EnumSet, EnumSetType};
|
||
|
|
||
|
struct Input<'src, 'toks, SyntaxKind: EnumSetType + Into<rowan::SyntaxKind>> {
|
||
|
raw: &'toks Vec<(SyntaxKind, &'src str)>,
|
||
|
// enumset of meaningless tokens
|
||
|
semantically_meaningless: EnumSet<SyntaxKind>,
|
||
|
// indices of non-meaningless tokens
|
||
|
meaningful_toks: Vec<usize>,
|
||
|
}
|
||
|
|
||
|
impl<'src, 'toks, SyntaxKind: EnumSetType + Into<rowan::SyntaxKind>>
|
||
|
Input<'src, 'toks, SyntaxKind>
|
||
|
{
|
||
|
pub fn new(
|
||
|
raw_toks: &'toks Vec<(SyntaxKind, &'src str)>,
|
||
|
meaningless: Option<EnumSet<SyntaxKind>>,
|
||
|
) -> Self {
|
||
|
let mut meaningful_toks = Vec::new();
|
||
|
|
||
|
if let Some(meaningless) = meaningless {
|
||
|
let meaningful_toks = raw_toks
|
||
|
.iter()
|
||
|
.enumerate()
|
||
|
.filter_map(|(i, tok)| (!meaningless.contains(tok.0)).then_some(i))
|
||
|
.collect_into(&mut meaningful_toks);
|
||
|
}
|
||
|
|
||
|
Self {
|
||
|
raw: raw_toks,
|
||
|
semantically_meaningless: meaningless.unwrap_or_default(),
|
||
|
meaningful_toks,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|