From d02ec80c21e8e6ed217c86ab4bdc981505c9f402 Mon Sep 17 00:00:00 2001 From: Claes Norreen <105717036+Claes65@users.noreply.github.com> Date: Sat, 30 Sep 2023 08:32:39 +0200 Subject: [PATCH] Adding missing attributes (#390) --- .../KeywordAsIdentifierAnalyzerShould.java | 2 +- .../amshove/natparse/lexing/KeywordTable.java | 4 ++ .../amshove/natparse/lexing/SyntaxKind.java | 39 +++++++++++++++++- .../LexerForAttributeControlsShould.java | 40 ++++++++++++++++++- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/libs/natlint/src/test/java/org/amshove/natlint/analyzers/KeywordAsIdentifierAnalyzerShould.java b/libs/natlint/src/test/java/org/amshove/natlint/analyzers/KeywordAsIdentifierAnalyzerShould.java index 0d586639d..8f9becfe7 100644 --- a/libs/natlint/src/test/java/org/amshove/natlint/analyzers/KeywordAsIdentifierAnalyzerShould.java +++ b/libs/natlint/src/test/java/org/amshove/natlint/analyzers/KeywordAsIdentifierAnalyzerShould.java @@ -24,7 +24,7 @@ Stream reportADiagnosticForKeywordsThatCanBeIdentifiers() return Arrays.stream(SyntaxKind.values()) .filter(SyntaxKind::canBeIdentifier) .filter(sk -> sk != SyntaxKind.IDENTIFIER) - .map(sk -> dynamicTest("%s should be discouraged as identifier".formatted(sk), () -> + .map(sk -> dynamicTest("%s should be discouraged as identifier, but was not. Is it defined in the KeywordTable?".formatted(sk), () -> { testDiagnostics( """ diff --git a/libs/natparse/src/main/java/org/amshove/natparse/lexing/KeywordTable.java b/libs/natparse/src/main/java/org/amshove/natparse/lexing/KeywordTable.java index bc04e5d23..5ebc51151 100644 --- a/libs/natparse/src/main/java/org/amshove/natparse/lexing/KeywordTable.java +++ b/libs/natparse/src/main/java/org/amshove/natparse/lexing/KeywordTable.java @@ -142,6 +142,7 @@ public static SyntaxKind getKeyword(String possibleKeyword) case "eject" -> SyntaxKind.EJECT; case "else" -> SyntaxKind.ELSE; case "em" -> SyntaxKind.EM; + case "emu" -> SyntaxKind.EMU; case "encoded" -> SyntaxKind.ENCODED; case "end" -> SyntaxKind.END; case "end-all" -> SyntaxKind.END_ALL; @@ -260,6 +261,7 @@ public static SyntaxKind getKeyword(String possibleKeyword) case "hw" -> SyntaxKind.HW; case "ia" -> SyntaxKind.IA; case "ic" -> SyntaxKind.IC; + case "icu" -> SyntaxKind.ICU; case "id" -> SyntaxKind.ID; case "identical" -> SyntaxKind.IDENTICAL; case "if" -> SyntaxKind.IF; @@ -309,6 +311,7 @@ public static SyntaxKind getKeyword(String possibleKeyword) case "language" -> SyntaxKind.LANGUAGE; case "last" -> SyntaxKind.LAST; case "lc" -> SyntaxKind.LC; + case "lcu" -> SyntaxKind.LCU; case "le" -> SyntaxKind.LE; case "leading" -> SyntaxKind.LEADING; case "leave" -> SyntaxKind.LEAVE; @@ -555,6 +558,7 @@ public static SyntaxKind getKeyword(String possibleKeyword) case "system" -> SyntaxKind.SYSTEM; case "tan" -> SyntaxKind.TAN; case "tc" -> SyntaxKind.TC; + case "tcu" -> SyntaxKind.TCU; case "terminate" -> SyntaxKind.TERMINATE; case "text" -> SyntaxKind.TEXT; case "textarea" -> SyntaxKind.TEXTAREA; diff --git a/libs/natparse/src/main/java/org/amshove/natparse/lexing/SyntaxKind.java b/libs/natparse/src/main/java/org/amshove/natparse/lexing/SyntaxKind.java index 708f1317d..e288873a2 100644 --- a/libs/natparse/src/main/java/org/amshove/natparse/lexing/SyntaxKind.java +++ b/libs/natparse/src/main/java/org/amshove/natparse/lexing/SyntaxKind.java @@ -401,6 +401,7 @@ public enum SyntaxKind EDITED(true, false, false), EJ(true, false, false), EM(true, false, false), // EDITOR MASK + EMU(true, false, false), ENCODED(true, false, false), END_CLASS(true, false, false), END_DEFINE(true, false, false), @@ -475,6 +476,7 @@ public enum SyntaxKind HW(true, false, false), IA(true, false, false), IC(true, false, false), + ICU(true, false, false), ID(true, false, false), IDENTICAL(true, false, false), IM(true, false, false), @@ -512,6 +514,7 @@ public enum SyntaxKind KEYS(true, false, false), LAST(true, false, false), LC(true, false, false), + LCU(true, false, false), LE(true, false, false), LEAVE(true, false, false), LEAVING(true, false, false), @@ -529,7 +532,6 @@ public enum SyntaxKind LISTED(true, false, false), LOCAL(true, false, false), LOCKS(true, false, false), - // LOG(true,false, false), sadly this is used my natunit as a subroutine name :( LOG_LS(true, false, false), LOG_PS(true, false, false), LOGICAL(true, false, false), @@ -693,6 +695,7 @@ public enum SyntaxKind SYNC(true, false, false), SYSTEM(true, false, false), TC(true, false, false), + TCU(true, false, false), TEXT(true, false, false), TEXTAREA(true, false, false), TEXTVARIABLE(true, false, false), @@ -783,6 +786,38 @@ public boolean canBeIdentifier() public boolean isAttribute() { - return this == AD || this == DY || this == CD || this == EM || this == NL || this == AL || this == DF || this == PM || this == IP || this == IS || this == CV || this == ZP || this == SG || this == ES || this == SB; + return this == AD || + this == AL || + this == CC || + this == CD || + this == CV || + this == DF || + this == DL || + this == DY || + this == EM || this == EMU || + this == ES || + this == FC || + this == FL || + this == GC || + this == HC || + this == HW || + this == IC || this == ICU || + this == IP || + this == IS || + this == KD || + this == LC || this == LCU || + this == LS || + this == MC || + this == MP || + this == MS || + this == NL || + this == PC || + this == PM || + this == PS || + this == SB || + this == SG || + this == TC || this == TCU || + this == UC || + this == ZP; } } diff --git a/libs/natparse/src/test/java/org/amshove/natparse/lexing/LexerForAttributeControlsShould.java b/libs/natparse/src/test/java/org/amshove/natparse/lexing/LexerForAttributeControlsShould.java index 9b3012c9d..f2eee3ba7 100644 --- a/libs/natparse/src/test/java/org/amshove/natparse/lexing/LexerForAttributeControlsShould.java +++ b/libs/natparse/src/test/java/org/amshove/natparse/lexing/LexerForAttributeControlsShould.java @@ -16,7 +16,45 @@ class LexerForAttributeControlsShould extends AbstractLexerTest @TestFactory Stream recognizeAttributes() { - var attributes = List.of(SyntaxKind.AD, SyntaxKind.DY, SyntaxKind.CD, SyntaxKind.EM, SyntaxKind.NL, SyntaxKind.AL, SyntaxKind.DF, SyntaxKind.PM, SyntaxKind.IP, SyntaxKind.IS, SyntaxKind.CV, SyntaxKind.ZP, SyntaxKind.SG, SyntaxKind.ES, SyntaxKind.SG, SyntaxKind.SB); + var attributes = List.of( + SyntaxKind.AD, + SyntaxKind.AL, + SyntaxKind.CC, + SyntaxKind.CD, + SyntaxKind.CV, + SyntaxKind.DF, + SyntaxKind.DL, + SyntaxKind.DY, + SyntaxKind.EM, + SyntaxKind.EMU, + SyntaxKind.ES, + SyntaxKind.FC, + SyntaxKind.FL, + SyntaxKind.GC, + SyntaxKind.HC, + SyntaxKind.HW, + SyntaxKind.IC, + SyntaxKind.ICU, + SyntaxKind.IP, + SyntaxKind.IS, + SyntaxKind.KD, + SyntaxKind.LC, + SyntaxKind.LCU, + SyntaxKind.LS, + SyntaxKind.MC, + SyntaxKind.MP, + SyntaxKind.MS, + SyntaxKind.NL, + SyntaxKind.PC, + SyntaxKind.PM, + SyntaxKind.PS, + SyntaxKind.SB, + SyntaxKind.SG, + SyntaxKind.TC, + SyntaxKind.TCU, + SyntaxKind.UC, + SyntaxKind.ZP + ); var shouldBeAttributes = attributes.stream() .map(a -> dynamicTest("%s should be attribute".formatted(a), () -> assertThat(a.isAttribute()).isTrue()));