#[repr(C)]
#[derive(Debug,Clone)]
pub enum Word {
Untracked(String),
Ignored(String),
Tracked(String, String, f32, Option<&'static str>),
}
impl Word {
pub fn set_stemmed(&mut self, s: String) {
if let Word::Tracked(_, ref mut stemmed, _, _) = *self {
*stemmed = s;
}
}
pub fn set_count(&mut self, x: f32) {
if let Word::Tracked(_, _, ref mut v, _) = *self {
*v = x;
}
}
}
#[repr(C)]
#[derive(Debug,Clone)]
pub struct Ast {
pub words: Vec<Word>,
pub begin_head: Option<usize>,
pub begin_body: Option<usize>,
pub end_body: Option<usize>,
}
impl Ast {
pub fn new() -> Ast {
Ast {
words: vec![],
begin_head: None,
begin_body: None,
end_body: None,
}
}
pub fn mark_begin_head(&mut self) {
if self.begin_head.is_some() {
return;
}
let i = self.words.len();
self.begin_head = Some(i);
}
pub fn mark_begin_body(&mut self) {
if self.begin_body.is_some() {
return;
}
let i = self.words.len();
self.begin_body = Some(i);
}
pub fn mark_end_body(&mut self) {
let i = self.words.len();
self.end_body = Some(i);
}
pub fn get_body(&self) -> &[Word] {
if let Some(begin) = self.begin_body {
if let Some(end) = self.end_body {
if begin < end {
return &self.words[begin + 1..end];
}
}
}
&self.words
}
pub fn get_body_mut(&mut self) -> &mut [Word] {
if let Some(begin) = self.begin_body {
if let Some(end) = self.end_body {
if begin < end {
return &mut self.words[begin + 1..end];
}
}
}
&mut self.words
}
}