Writing a Markdown Parser Part 1. Lexing
struct Position {
line: usize;
column: usize;
}
enum Token {
eof,
illegal
}
struct Lexer<'a> {
source: Peekable<Chars<'a>>;
}
impl<'a> Lexer<'a> {
fn new(src: &str) {
let source = src.chars();
Lexer { source }
}
}
impl<'a> Iterator for Lexer<'a> {
type Item = (Token, Position);
fn next(&mut self) -> Self::Item {
match self.source.peek() {
Some(_) => None,
None => None,
}
}
}
Go
package lexer
type Lexer struct{
Source
}
func NewLexer(input str) *Lexer {
source := bufio.NewReader(input)
return &Lexer{
Source: source
}
}