// Currently there's only three discrete words: DIS (for disadvantage),
// ADV (for advantage) and D. This will need to be made more complex if 
// additional or arbitrary words (functions or labels, for example) are
// added.
Currently there's only three discrete words: DIS (for disadvantage),
ADV (for advantage) and D. This will need to be made more complex if
additional or arbitrary words (functions or labels, for example) are
added.
Currently there ' s only three discrete words : DIS ( for disadvantage ) ADV ( for advantage ) and D . This will need to be made more complex if additional or arbitrary words ( functions or labels for example ) are added .
fn tokenize_word(tokens: &mut Vec<Token>, iter: &mut std::str::Chars, prev: char) {
    let curr = iter.next();
    match curr {
        Some(c) => {
            match c {
                'i' | 'I' => {
                    if prev == 'd' || prev == 'D' {
                        return tokenize_word(tokens, iter, c);
                    }
                },
                's' | 'S' => {
                    if prev == 'i' || prev == 'I' {
                        let curr = iter.next();
                        tokens.push(Token::Op('D'));
                        return tokenize(tokens, iter, &curr);
                    }
                },
                'd' | 'D' => {
                    if prev == 'a' || prev == 'A' {
                        return tokenize_word(tokens, iter, c);
                    }
                },
                'v' | 'V' => {
                    if prev == 'd' || prev == 'D' {
                        let curr = iter.next();
                        tokens.push(Token::Op('A'));
                        return tokenize(tokens, iter, &curr);
                    }
                },
                _ => (),        
            }
        }
        None => println!("No work char: prev={}", prev),
    }
    if prev == 'd' || prev == 'D' {
        tokens.push(Token::D);
        return tokenize(tokens, iter, &curr);
    }
}
fn tokenize_word ( tokens : & mut Vec < Token > , iter : & mut std :: str :: Chars , prev : char ) { let curr = iter . next ( ) ; match curr { Some ( c ) => { match c { 'i' | 'I' => { if prev == 'd' || prev == 'D' { return tokenize_word ( tokens , iter , c ) ; } } , 's' | 'S' => { if prev == 'i' || prev == 'I' { let curr = iter . next ( ) ; tokens . push ( Token :: Op ( 'D' ) ) ; return tokenize ( tokens , iter , & curr ) ; } } , 'd' | 'D' => { if prev == 'a' || prev == 'A' { return tokenize_word ( tokens , iter , c ) ; } } , 'v' | 'V' => { if prev == 'd' || prev == 'D' { let curr = iter . next ( ) ; tokens . push ( Token :: Op ( 'A' ) ) ; return tokenize ( tokens , iter , & curr ) ; } } , _ => ( ) , } } None => println ! ( " " prev ) , } if prev == 'd' || prev == 'D' { tokens . push ( Token :: D ) ; return tokenize ( tokens , iter , & curr ) ; } }
Currently there's only three discrete words: DIS (for disadvantage),
ADV (for advantage) and D. This will need to be made more complex if
additional or arbitrary words (functions or labels, for example) are
added.
Currently there ' s only three discrete words : DIS ( for disadvantage ) ADV ( for advantage ) and D . This will need to be made more complex if additional or arbitrary words ( functions or labels for example ) are added .
tokens
&mut Vec<Token>
iter
&mut std::str::Chars
prev
char