Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw canonical ast separation #10

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod node;
pub mod sexpr_parser;
pub mod sexpr_tokenizer;
pub mod sexpr_tokenizer_2;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put these modules into a separate directory?

26 changes: 26 additions & 0 deletions src/sexpr_tokenizer_2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use core::iter::*;
use crate::sexpr_tokenizer::Token;
use crate::sexpr_tokenizer::Whitespace;

pub fn tokenize(input: String) -> Vec<Token> {
let lines = input.split('\n').collect::<Vec<&str>>().iter().enumerate();
return lines.flat_map(|(lineNumber, line)| {
return line.chars().enumerate().fold(vec![], |tokens, (columnNumber, character)| {
let token = to_token(character);
match tokens.last() {
Some(lastToken) => match (lastToken, token) {
(Token::Whitespace, Token::Whitespace) =>
[&tokens[0..lineNumber]].concat(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the concat is not needed here.

},
None => vec![token]
}
})
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: return { .. }; vs { .. }

}

fn to_token(c: char) -> Token {
match c {
' ' => Token::Whitespace(Whitespace::Space),
_ => unimplemented!()
}
}