Skip to content

Commit

Permalink
Parse directives that end with EOF (#185)
Browse files Browse the repository at this point in the history
- closes #184
- handle eof in parser after directive
- add unit test for 184
- changelog update
  • Loading branch information
jlchmura authored Jan 21, 2025
1 parent 88bada4 commit b901145
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.1.24

- Fix: [Adjust handling of array of arrays #180](https://github.com/jlchmura/lpc-language-server/issues/180)
- Fix: [Parser errors when last last is an include directive without a newline #184](https://github.com/jlchmura/lpc-language-server/issues/184)
- Fix: Import will null text can crash program file load
- Improved efun definitions:
- FluffOS [`shutdown`](https://github.com/jlchmura/lpc-language-server/pull/182)
Expand Down
13 changes: 11 additions & 2 deletions server/src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,15 @@ export namespace LpcParser {
return withJSDoc(finishNode(factory.createEmptyStatement(), pos), hasJSDoc);
}

function parseValidDirectiveEnd() {
if (token() == SyntaxKind.NewLineTrivia || token() == SyntaxKind.EndOfFileToken) {
return true;
} else {
parseErrorAtCurrentToken(Diagnostics.Expected_newline_after_directive);
return false;
}
}

function parseDirective(): PreprocessorDirective {
scanner.setReportLineBreak(true);

Expand Down Expand Up @@ -1873,8 +1882,8 @@ export namespace LpcParser {
nextToken();
}
}

let scanNextToken = parseExpected(SyntaxKind.NewLineTrivia, Diagnostics.Expected_newline_after_directive, false);
let scanNextToken = parseValidDirectiveEnd();
scanner.setReportLineBreak(false);

if (directive?.kind === SyntaxKind.IncludeDirective) {
Expand Down
2 changes: 2 additions & 0 deletions server/src/tests/__snapshots__/compiler.spec.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions server/src/tests/cases/compiler/include2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @files: includeFile.h

test() {}

// this include does not have a newline after it, which is legal
// https://github.com/jlchmura/lpc-language-server/issues/184

#include "includeFile.h"

0 comments on commit b901145

Please sign in to comment.