Skip to content

Commit

Permalink
fix windows line ending (\r\n) parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Apr 4, 2021
1 parent 374e2b3 commit b4700af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions compilerAst/src/prog8/parser/ModuleParsing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class ModuleImporter {
if(!Files.isReadable(filePath))
throw ParsingFailedError("No such file: $filePath")

val input = CharStreams.fromPath(filePath)
return importModule(program, input, filePath, false, encoder, compilationTargetName)
val content = Files.readAllBytes(filePath).toString(Charsets.UTF_8).replace("\r\n", "\n")
return importModule(program, CharStreams.fromString(content), filePath, false, encoder, compilationTargetName)
}

fun importLibraryModule(program: Program, name: String,
Expand Down Expand Up @@ -122,7 +122,8 @@ class ModuleImporter {
val (resource, resourcePath) = rsc
resource.use {
println("importing '$moduleName' (library)")
importModule(program, CharStreams.fromStream(it), Paths.get("@embedded@/$resourcePath"),
val content = it.readAllBytes().toString(Charsets.UTF_8).replace("\r\n", "\n")
importModule(program, CharStreams.fromString(content), Paths.get("@embedded@/$resourcePath"),
true, encoder, compilationTargetName)
}
} else {
Expand Down
7 changes: 4 additions & 3 deletions parser/antlr/prog8.g4
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ NOTES:
- whitespace is ignored. (tabs/spaces)
- every position can be empty, be a comment, or contain ONE statement.
- input is assumed to be a text file with UNIX line endings (\n).
*/

Expand All @@ -14,10 +15,10 @@ grammar prog8;
package prog8.parser;
}

LINECOMMENT : [\r\n][ \t]* COMMENT -> channel(HIDDEN);
COMMENT : ';' ~[\r\n]* -> channel(HIDDEN) ;
LINECOMMENT : [\n][ \t]* COMMENT -> channel(HIDDEN);
COMMENT : ';' ~[\n]* -> channel(HIDDEN) ;
WS : [ \t] -> skip ;
EOL : [\r\n]+ ;
EOL : [\n]+ ;
// WS2 : '\\' EOL -> skip;
VOID: 'void';
NAME : [a-zA-Z][a-zA-Z0-9_]* ;
Expand Down

0 comments on commit b4700af

Please sign in to comment.