From 31a2d84483f331821c3152346279a0c9d675c11a Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 11 Aug 2022 18:34:02 -0500 Subject: [PATCH] Removed erroneous indentation from indent test file Need to find a more controlled and accurate way to test erroneous indentation. Possibly by analyzing the returned error object. --- lexer/lexer.go | 15 ++++++++------- tests/lexer/indent | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lexer/lexer.go b/lexer/lexer.go index c8eeebe..9703759 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -101,16 +101,17 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) { // indent level previousToken := lexer.tokens[len(lexer.tokens) - 1] - if !previousToken.Is(TokenKindNewline) || - !previousToken.Is(TokenKindNewline) { - + if !previousToken.Is(TokenKindNewline) { + err = lexer.nextRune() + file.NewError ( lexer.file.Location(), 1, "tab not used as indent", - file.ErrorKindWarn) - break + file.ErrorKindWarn).Print() + return } + // eat up tabs while increasing the indent level indentLevel := 0 for lexer.char == '\t' { indentLevel ++ @@ -124,11 +125,12 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) { }) case '\n': // line break + + // if the last line is empty, discard it lastLineEmpty := true tokenIndex := len(lexer.tokens) - 1 for lexer.tokens[tokenIndex].kind != TokenKindNewline { if lexer.tokens[tokenIndex].kind != TokenKindIndent { - lastLineEmpty = false break } @@ -139,7 +141,6 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) { lexer.tokens = lexer.tokens[:tokenIndex] } - // TODO: if last line was blank, (ony whitespace) discard. lexer.addToken (Token { kind: TokenKindNewline, }) diff --git a/tests/lexer/indent b/tests/lexer/indent index 1f9d311..309c335 100644 --- a/tests/lexer/indent +++ b/tests/lexer/indent @@ -1,7 +1,7 @@ line1 - line2 + line2 line3 - + line4 line5