Skip to content

Commit

Permalink
+ add: Kotlin Source Lexer based on Zufuliu's Kotlin Lexer code base
Browse files Browse the repository at this point in the history
  • Loading branch information
RaiKoHoff committed Dec 22, 2020
1 parent 3a2165e commit 6c79ce1
Show file tree
Hide file tree
Showing 25 changed files with 1,257 additions and 70 deletions.
4 changes: 4 additions & 0 deletions language/common_res.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@
#define IDS_LEX_TOML_CFG 63049
#define IDS_LEX_PRISM_CSV 63050
#define IDS_LEX_DART_SRC 63051
#define IDS_LEX_KOTLIN_SRC 63052

#define IDS_LEX_STD_STYLE 63100
#define IDS_LEX_STD_MARGIN 63101
Expand Down Expand Up @@ -1120,6 +1121,9 @@
#define IDS_LEX_STR_63366 63366
#define IDS_LEX_STR_63367 63367
#define IDS_LEX_STR_63368 63368
#define IDS_LEX_STR_63369 63369
#define IDS_LEX_STR_63370 63370
#define IDS_LEX_STR_63371 63371

#define IDS_LEX_CSV_COL_0 63400
#define IDS_LEX_CSV_COL_1 63401
Expand Down
4 changes: 4 additions & 0 deletions language/np3_en_us/lexer_en_us.rc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ BEGIN
IDS_LEX_TEXT_FILES "Text Files"
IDS_LEX_TOML_CFG "TOML"
IDS_LEX_DART_SRC "Dart Source Code"
IDS_LEX_KOTLIN_SRC "Kotlin Source Code"
END

STRINGTABLE
Expand Down Expand Up @@ -467,6 +468,9 @@ BEGIN
IDS_LEX_STR_63366 "ESC Sequence"
IDS_LEX_STR_63367 "Unicode-Point Hover"
IDS_LEX_STR_63368 "2nd Unicode-Point Hover"
IDS_LEX_STR_63369 "Interface"
IDS_LEX_STR_63370 "Annotation"
IDS_LEX_STR_63371 "Comment Doc Word"
END

STRINGTABLE
Expand Down
1 change: 1 addition & 0 deletions lexilla/Lexilla.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<ClCompile Include="src\lexers_x\LexAHKL.cxx" />
<ClCompile Include="src\lexers_x\LexCSV.cxx" />
<ClCompile Include="src\lexers_x\LexDart.cxx" />
<ClCompile Include="src\lexers_x\LexKotlin.cxx" />
<ClCompile Include="src\lexers_x\LexTOML.cxx" />
<ClCompile Include="src\Lexilla.cxx" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions lexilla/Lexilla.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
<ClCompile Include="src\lexers_x\LexDart.cxx">
<Filter>lexers_x</Filter>
</ClCompile>
<ClCompile Include="src\lexers_x\LexKotlin.cxx">
<Filter>lexers_x</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="src\LexillaVersion.rc">
Expand Down
2 changes: 2 additions & 0 deletions lexilla/src/Lexilla.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ using namespace Scintilla;
extern LexerModule lmAHKL;
extern LexerModule lmCSV;
extern LexerModule lmDart;
extern LexerModule lmKotlin;
extern LexerModule lmTOML;


Expand Down Expand Up @@ -314,6 +315,7 @@ void AddEachLexer() {
catalogueLexilla.AddLexerModule(&lmAHKL);
catalogueLexilla.AddLexerModule(&lmCSV);
catalogueLexilla.AddLexerModule(&lmDart);
catalogueLexilla.AddLexerModule(&lmKotlin);
catalogueLexilla.AddLexerModule(&lmTOML);

}
Expand Down
10 changes: 9 additions & 1 deletion lexilla/src/lexers_x/CharSetX.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ inline bool EqualsAny(const char* s, Args... args) noexcept {
//- IsUpperOrLowerCase(int ch);
//- IsAlphaNumeric(int ch);

constexpr int abs_i(const int i) noexcept
{
return ((i < 0) ? (0 - i) : (0 + i));
}

constexpr bool IsWordCharEx(int ch) noexcept {
return Scintilla::iswordchar(ch) || ch >= 0x80;
}

constexpr bool IsASpaceX(const int ch) noexcept
{
return ((ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)));
Expand Down Expand Up @@ -85,7 +94,6 @@ constexpr bool IsIdentifierStartEx(int ch) noexcept {
return IsIdentifierStart(ch) || ch >= 0x80;
}


constexpr int IsNumber(const Scintilla::StyleContext& sc)
{
return ((sc.ch >= '0') && (sc.ch <= '9')) ||
Expand Down
2 changes: 1 addition & 1 deletion lexilla/src/lexers_x/LexAHKL.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -815,4 +815,4 @@ void SCI_METHOD LexerAHKL::Fold(Sci_PositionU startPos, Sci_Position lengthDoc,

}

LexerModule lmAHKL(SCLEX_AHKL, LexerAHKL::LexerFactoryAHKL, "ahkl", ahklWordLists);
LexerModule lmAHKL(SCLEX_AHKL, LexerAHKL::LexerFactoryAHKL, "AHKL", ahklWordLists);
9 changes: 1 addition & 8 deletions lexilla/src/lexers_x/LexCSV.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,6 @@ Sci_Position SCI_METHOD LexerCSV::WordListSet(int n, const char* wl)
}
// ----------------------------------------------------------------------------

constexpr int abs_i(const int i) noexcept
{
return ((i < 0) ? (0 - i) : (0 + i));
}

// ----------------------------------------------------------------------------

constexpr bool IsSingleQuoteChar(const int ch) noexcept
{
return (ch == '\'');
Expand Down Expand Up @@ -423,7 +416,7 @@ void SCI_METHOD LexerCSV::Fold(Sci_PositionU startPos, Sci_Position length, int,
}
// ----------------------------------------------------------------------------

LexerModule lmCSV(SCLEX_CSV, LexerCSV::LexerFactoryCSV, "csv", csvWordLists);
LexerModule lmCSV(SCLEX_CSV, LexerCSV::LexerFactoryCSV, "CSV", csvWordLists);

// ----------------------------------------------------------------------------

31 changes: 12 additions & 19 deletions lexilla/src/lexers_x/LexDart.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ LexicalClass lexicalClasses[] =
class LexerDart : public DefaultLexer
{

CharacterSet validKey;
CharacterSet validKeyWord;
CharacterSet validNumberEnd;
CharacterSet chDateTime;
//CharacterSet validKey;
//CharacterSet validKeyWord;
//CharacterSet validNumberEnd;
//CharacterSet chDateTime;

WordList wl_keywords;
WordList wl_types;
Expand All @@ -135,10 +135,10 @@ class LexerDart : public DefaultLexer
public:
LexerDart()
: DefaultLexer("Dart", SCLEX_DART, lexicalClasses, ELEMENTS(lexicalClasses))
, validKey(CharacterSet::setAlphaNum, R"(-_.)", 0x80, false)
, validKeyWord(CharacterSet::setAlphaNum, "_+-", 0x80, false)
, validNumberEnd(CharacterSet::setNone, " \t\n\v\f\r#,)}]", 0x80, false)
, chDateTime(CharacterSet::setNone, "-+.:TZ", 0x80, false)
//, validKey(CharacterSet::setAlphaNum, R"(-_.)", 0x80, false)
//, validKeyWord(CharacterSet::setAlphaNum, "_+-", 0x80, false)
//, validNumberEnd(CharacterSet::setNone, " \t\n\v\f\r#,)}]", 0x80, false)
//, chDateTime(CharacterSet::setNone, "-+.:TZ", 0x80, false)
{ }

virtual ~LexerDart() { }
Expand Down Expand Up @@ -260,13 +260,6 @@ Sci_Position SCI_METHOD LexerDart::WordListSet(int n, const char* wl)
}
// ----------------------------------------------------------------------------

constexpr int abs_i(const int i) noexcept
{
return ((i < 0) ? (0 - i) : (0 + i));
}

// ----------------------------------------------------------------------------

struct EscapeSequence {

int outerState = SCE_DART_DEFAULT;
Expand Down Expand Up @@ -318,11 +311,11 @@ constexpr int UnpackState(int state) noexcept {
}
}

int PackNestedState(const std::vector<int>& nestedState) noexcept {
inline static int PackNestedState(const std::vector<int>& nestedState) noexcept {
return PackLineState<3, MaxDartNestedStateCount, PackState>(nestedState) << 16;
}

void UnpackNestedState(int lineState, int count, std::vector<int>& nestedState) {
inline static void UnpackNestedState(int lineState, int count, std::vector<int>& nestedState) {
UnpackLineState<3, MaxDartNestedStateCount, UnpackState>(lineState, count, nestedState);
}

Expand Down Expand Up @@ -415,7 +408,7 @@ void SCI_METHOD LexerDart::Lex(Sci_PositionU startPos, Sci_Position length, int
sc.ChangeState(kwType);
}
else {
//@@@const int chNext = GetNextNSChar();
//?const int chNext = GetNextNSChar();
while (IsASpace(sc.ch)){ sc.Forward(); };
if (sc.ch == '(') {
sc.ChangeState(SCE_DART_FUNCTION);
Expand Down Expand Up @@ -788,7 +781,7 @@ void SCI_METHOD LexerDart::Fold(Sci_PositionU startPos, Sci_Position length, int
}
// ----------------------------------------------------------------------------

LexerModule lmDart(SCLEX_DART, LexerDart::LexerFactoryDart, "dart", dartWordLists);
LexerModule lmDart(SCLEX_DART, LexerDart::LexerFactoryDart, "Dart", dartWordLists);

// ----------------------------------------------------------------------------

Loading

0 comments on commit 6c79ce1

Please sign in to comment.