Skip to content

Commit

Permalink
fix: ignoring first character
Browse files Browse the repository at this point in the history
  • Loading branch information
xNaCly committed Apr 2, 2023
1 parent 3b4d96e commit 4637d3f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Parser {
let input = fs::read_to_string(file_path).expect("could not read file");
let current_char = input
.chars()
.nth(1)
.nth(0)
.expect("could not get first character of input");
Parser {
input,
Expand Down Expand Up @@ -56,14 +56,23 @@ impl Parser {
let mut token_kind = token::TokenKind::Paragraph;

match self.current_char {
' ' | '\t' | '\r' => {
self.advance();
continue;
}
'\n' => {
self.line += 1;
self.line_pos = 0;
self.advance();
}
'#' => {
// skip over '#' with a counter:
let mut heading_id = 1;
while self.peek_equals('#') {
heading_id += 1;
self.advance();
}
while self.peek() != '\n' {
while !self.peek_equals('\n') {
token_value.push(self.current_char);
self.advance();
}
Expand All @@ -81,7 +90,7 @@ impl Parser {
}

res.push(Token {
pos: self.pos,
pos: self.pos - token_value.len(),
kind: token_kind,
content: token_value.to_owned(),
});
Expand Down
12 changes: 11 additions & 1 deletion test.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# This is a heading
# Heading 1

## Heading 2

### Heading 3

#### Heading 4

##### Heading 5

###### Heading 6

0 comments on commit 4637d3f

Please sign in to comment.