Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Tokenize 'done' at end of lines #18

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Changes from all commits
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
14 changes: 13 additions & 1 deletion src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@ export function tokenize(sentence: string): Token[] {
throw new Error(prettyPrintError(message, sentence, { line, column }));
};

function isAtEndOfLine() {
let j = i;

while (j < sentence.length) {
const char = sentence[j];

if (char === ' ' || char === '\t') {
j++;
} else return char === '\n';
}
}

function pushToken() {
if (currentToken === '') {
return;
}

let kind: Token['kind'] = 'generic';

if (currentToken === 'done' && isAtStartOfLine) {
if (currentToken === 'done' && (isAtStartOfLine || isAtEndOfLine())) {
kind = 'done';
} else if (currentToken === '-' && isAtStartOfLine) {
kind = 'bullet';
Expand Down