Skip to content

Commit

Permalink
add SCE_JULIA_TYPEOPERATOR
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Jun 27, 2021
1 parent 692b5bd commit 779dcbf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions include/LexicalStyles.iface
Expand Up @@ -1071,6 +1071,7 @@ val SCE_JULIA_COMMANDLITERAL=17
val SCE_JULIA_TYPEANNOT=18
val SCE_JULIA_LEXERROR=19
val SCE_JULIA_KEYWORD4=20
val SCE_JULIA_TYPEOPERATOR=21
# Lexical states for SCLEX_MSSQL
lex MSSQL=SCLEX_MSSQL SCE_MSSQL_
val SCE_MSSQL_DEFAULT=0
Expand Down
1 change: 1 addition & 0 deletions include/SciLexer.h
Expand Up @@ -954,6 +954,7 @@
#define SCE_JULIA_TYPEANNOT 18
#define SCE_JULIA_LEXERROR 19
#define SCE_JULIA_KEYWORD4 20
#define SCE_JULIA_TYPEOPERATOR 21
#define SCE_MSSQL_DEFAULT 0
#define SCE_MSSQL_COMMENT 1
#define SCE_MSSQL_LINE_COMMENT 2
Expand Down
28 changes: 13 additions & 15 deletions lexers/LexJulia.cxx
Expand Up @@ -84,7 +84,7 @@ struct OptionSetJulia : public OptionSet<OptionsJulia> {
"Set this property to 0 to disable syntax based folding.");

DefineProperty("lexer.julia.highlight.typeannotation", &OptionsJulia::highlightTypeannotation,
"This option enables highlighting of type after :: as type annotation instead of parsing from the keyword lists.");
"This option enables highlighting of the type identifier after `::`.");

DefineProperty("lexer.julia.highlight.lexerror", &OptionsJulia::highlightLexerror,
"This option enables highlighting of syntax error int character or number definition.");
Expand All @@ -110,12 +110,13 @@ LexicalClass juliaLexicalClasses[] = {
12, "SCE_JULIA_MACRO", "macro preprocessor", "Macro",
13, "SCE_JULIA_STRINGINTERP", "literal string interpolated", "String interpolation",
14, "SCE_JULIA_DOCSTRING", "literal string documentation", "Docstring",
15, "SCE_JULIA_STRINGLITERAL", "literal string prefix", "String literal prefix",
15, "SCE_JULIA_STRINGLITERAL", "literal string", "String literal prefix",
16, "SCE_JULIA_COMMAND", "literal string command", "Command",
17, "SCE_JULIA_COMMANDLITERAL", "literal string command prefix", "Command literal prefix",
18, "SCE_JULIA_TYPEANNOT", "operator type identifier", "Type annotation",
17, "SCE_JULIA_COMMANDLITERAL", "literal string command", "Command literal prefix",
18, "SCE_JULIA_TYPEANNOT", "identifier type", "Type annotation identifier",
19, "SCE_JULIA_LEXERROR", "lexer error", "Lexing error",
20, "SCE_JULIA_KEYWORD4", "identifier", "Builtin function names",
21, "SCE_JULIA_TYPEOPERATOR", "operator type", "Type annotation operator",
};

const int sizeJuliaLexicalClasses = static_cast<int>(std::size(juliaLexicalClasses));
Expand Down Expand Up @@ -897,13 +898,11 @@ void SCI_METHOD LexerJulia::Lex(Sci_PositionU startPos, Sci_Position length, int
case SCE_JULIA_OPERATOR:
resumeOperator(sc);
break;
case SCE_JULIA_TYPEOPERATOR:
sc.SetState(SCE_JULIA_DEFAULT);
break;
case SCE_JULIA_TYPEANNOT:
// Highlight the next identifier, if option is set
if (options.highlightTypeannotation) {
if (! IsIdentifierCharacter(sc.ch)) {
sc.SetState(SCE_JULIA_DEFAULT);
}
} else {
if (! IsIdentifierCharacter(sc.ch)) {
sc.SetState(SCE_JULIA_DEFAULT);
}
break;
Expand Down Expand Up @@ -1062,13 +1061,12 @@ void SCI_METHOD LexerJulia::Lex(Sci_PositionU startPos, Sci_Position length, int

// Several parsing of operators, should keep the order of `if` blocks
} else if ((sc.ch == ':' || sc.ch == '<' || sc.ch == '>') && sc.chNext == ':') {
sc.SetState(SCE_JULIA_TYPEANNOT);
sc.SetState(SCE_JULIA_TYPEOPERATOR);
sc.Forward();
// Highlight the next identifier, if option is set
if (options.highlightTypeannotation) {
if (IsIdentifierFirstCharacter(sc.chNext)) {
sc.Forward();
}
if (options.highlightTypeannotation &&
IsIdentifierFirstCharacter(sc.chNext)) {
sc.ForwardSetState(SCE_JULIA_TYPEANNOT);
}
} else if (sc.ch == ':') {
// TODO: improve detection of range
Expand Down
2 changes: 1 addition & 1 deletion test/examples/julia/x.jl.styled
Expand Up @@ -6,7 +6,7 @@
test_fun(a::Int)
For test only
"""{0}
{3}function{0} {9}test_fun{8}({9}a{18}::{4}Int{7},{0} {9}b{18}::{9}T{8}){0} {3}where{0} {9}T{0} {18}<:{0} {4}Number{0}
{3}function{0} {9}test_fun{8}({9}a{21}::{4}Int{7},{0} {9}b{21}::{9}T{8}){0} {3}where{0} {9}T{0} {21}<:{0} {4}Number{0}
{9}println{8}({9}a{8}){0}
{9}println{8}({10}"foo {13}$(bar){10}"{8}){0}
{3}end{0}
Expand Down

0 comments on commit 779dcbf

Please sign in to comment.