From 2e41f8ffe30912200f84701c3a93bfe55a962aa7 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 2 Mar 2018 02:57:04 -0800 Subject: [PATCH] SOme work WIP --- src/schala_lang/tokenizing.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/schala_lang/tokenizing.rs b/src/schala_lang/tokenizing.rs index ba12cdc..55e8a95 100644 --- a/src/schala_lang/tokenizing.rs +++ b/src/schala_lang/tokenizing.rs @@ -1,8 +1,8 @@ use itertools::Itertools; use std::collections::HashMap; use std::rc::Rc; -use std::iter::{Enumerate, Peekable}; -use std::str::Chars; +use std::iter::{Iterator, Enumerate, Peekable, FlatMap}; +use std::str::{Lines, Chars}; #[derive(Debug, PartialEq, Clone)] pub enum TokenType { @@ -89,8 +89,27 @@ fn is_operator(c: &char) -> bool { type CharIter<'a> = Peekable>>; +struct LineCharIter<'a> { source: &'a str } +impl<'a> Iterator for LineCharIter<'a> { + type Item = (usize, usize, char); + fn next(&mut self) -> Option { + None + } +} + pub fn tokenize(input: &str) -> Vec { let mut tokens: Vec = Vec::new(); + + let b = input.clone(); + + //ound type `std::iter::Peekable>, std::iter::Map>, [closure@src/schala_lang +// tokenizing.rs:99:40: 99:82 line_idx:_]>, [closure@src/schala_lang/tokenizing.rs:98:17: 100:8]>>` + + let mut input2 = b.lines().enumerate() + .flat_map(|(line_idx, ref line)| { + line.chars().enumerate().map(move |(ch_idx, ch)| (line_idx, ch_idx, ch)) + }).peekable(); + let mut input: CharIter = input.chars().enumerate().peekable(); while let Some((idx, c)) = input.next() {