Skip to content

Commit 45bc92e

Browse files
committed
Improve directive name parsing in cases without trailing whitespace
1 parent 90ffd70 commit 45bc92e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Include "found" and "expected" values for issues messages in `LowercaseKeyword`.
1717
- Exclude `J` and `K` by default in `ShortIdentifier`.
18+
- Improve compiler directive parsing in cases where the directive name is not followed by whitespace.
1819

1920
### Fixed
2021

delphi-frontend/src/main/java/au/com/integradev/delphi/preprocessor/directive/CompilerDirectiveParserImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ private String readName() {
238238
StringBuilder name = new StringBuilder();
239239
char character = currentChar();
240240

241-
while (Character.isLetter(character) || Character.isDigit(character) || character == '_') {
241+
while ((character >= 'a' && character <= 'z')
242+
|| (character >= 'A' && character <= 'Z')
243+
|| Character.isDigit(character)
244+
|| character == '_') {
242245
name.append(character);
243246
character = nextChar();
244247
}

delphi-frontend/src/test/java/au/com/integradev/delphi/preprocessor/directive/CompilerDirectiveParserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ void testCreateSwitchDirective() {
239239
assertThat(((SwitchDirective) directive).isActive()).isTrue();
240240
}
241241

242+
@Test
243+
void testDirectiveNameWithTrailingSymbol() {
244+
CompilerDirective directive = parse("{$if%01010 <> 123}");
245+
assertThat(directive).isInstanceOf(IfDirective.class);
246+
}
247+
248+
@Test
249+
void testDirectiveNameWithTrailingNonAsciiCharacter() {
250+
CompilerDirective directive = parse("{$ifǣ <> 123}");
251+
assertThat(directive).isInstanceOf(IfDirective.class);
252+
}
253+
242254
@Test
243255
void testCreateUnsupportedDirectives() {
244256
CompilerDirective directive = parse("{$FOO}");

0 commit comments

Comments
 (0)