Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Copy link
Copy Markdown

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(),

Copy link
Copy Markdown

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]
}
})
});

Copy link
Copy Markdown

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!()
}
}