diff --git a/examples/gmt-building-out.mo b/examples/gmt-building-out.mo index e6158ad..35f8cdf 100644 --- a/examples/gmt-building-out.mo +++ b/examples/gmt-building-out.mo @@ -187,3 +187,4 @@ First implementation. ")); end building; +/* trailing comment */ diff --git a/examples/gmt-building.mo b/examples/gmt-building.mo index 63e4bd6..ca6c717 100644 --- a/examples/gmt-building.mo +++ b/examples/gmt-building.mo @@ -221,4 +221,5 @@ First implementation. ")); -end building; \ No newline at end of file +end building; +/* trailing comment */ \ No newline at end of file diff --git a/modelicafmt.go b/modelicafmt.go index 0894891..55c15c1 100644 --- a/modelicafmt.go +++ b/modelicafmt.go @@ -423,5 +423,13 @@ func processFile(filename string, out io.Writer) error { defer listener.close() antlr.ParseTreeWalkerDefault.Walk(listener, sd) + // add any remaining comments and handle newline at end of file + for _, comment := range listener.commentTokens { + listener.writeComment(comment) + } + if !listener.onNewLine { + listener.writeNewline() + } + return nil }