From ae5d7705bbd9e873562f02f6132205342d462763 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 14 May 2021 17:14:44 +0200 Subject: [PATCH] allow correct parsing of source files that don't end in a EOL character. Fixes #40 --- compilerAst/src/prog8/parser/ModuleParsing.kt | 5 ++++- docs/source/todo.rst | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compilerAst/src/prog8/parser/ModuleParsing.kt b/compilerAst/src/prog8/parser/ModuleParsing.kt index 87eba5d40..4c0b0a8ef 100644 --- a/compilerAst/src/prog8/parser/ModuleParsing.kt +++ b/compilerAst/src/prog8/parser/ModuleParsing.kt @@ -44,7 +44,10 @@ class ModuleImporter(private val program: Program, if(!Files.isReadable(filePath)) throw ParsingFailedError("No such file: $filePath") - val content = filePath.toFile().readText().replace("\r\n", "\n") + var content = filePath.toFile().readText().replace("\r\n", "\n") // normalize line endings + if(content.last()!='\n') + content+='\n' // grammar requires blocks (and thus module files) to end in an EOL + return importModule(CharStreams.fromString(content), filePath, false) } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index b46914cfd..12084c221 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -4,8 +4,9 @@ TODO - possible idea: option to mark vardecls 'shared' to indicate they should not be optimized away because they're shared with assembly code? However: who even needs variables declared in prog8 code that are only used by assembly??? -- github issue: make strings no longer immutable? Deduplication selectable via command line switch? - IMPROVE DOCUMENTATION ABOUT STRINGS AND DEDUP. +- github issue about strings and their immutability: + StatementOptimizer line 60: only optimize when it's a known constant literal + IMPROVE DOCUMENTATION ABOUT STRINGS AND DEDUP and (NON)IMMUTABILITY. - test all examples before release of the new version