Skip to content

Commit

Permalink
Update Julia syntax to Julia 1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Sep 6, 2018
1 parent 3643de3 commit 103263f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 21 deletions.
2 changes: 2 additions & 0 deletions scintilla/include/SciLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@
#define SCE_MAT_REGEX 17
#define SCE_MAT_VARIABLE 18
#define SCE_MAT_FUNCTION 19
#define SCE_MAT_TRIPLE_STRING2 20
#define SCE_MAT_RAW_STRING2 21
#define SCE_FSHARP_DEFAULT 0
#define SCE_FSHARP_COMMENT 1
#define SCE_FSHARP_COMMENTLINE 2
Expand Down
2 changes: 2 additions & 0 deletions scintilla/include/SciLexer.iface
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ val SCE_MAT_BACKTICK=16
val SCE_MAT_REGEX=17
val SCE_MAT_VARIABLE=18
val SCE_MAT_FUNCTION=19
val SCE_MAT_TRIPLE_STRING2=20
val SCE_MAT_RAW_STRING2=21
# Lexical states for SCLEX_FSHARP
lex FSharp=SCLEX_FSHARP SCE_FSHARP_
val SCE_FSHARP_DEFAULT=0
Expand Down
82 changes: 63 additions & 19 deletions scintilla/lexers/LexMatlab.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ static bool IsNestedCommentEnd(int lexType, int ch, int chNext, int visibleChars

static bool IsBlockCommentStart(int lexType, int ch, int chNext, int visibleChars, LexAccessor &styler, Sci_PositionU currentPos) noexcept {
return IsNestedCommentStart(lexType, ch, chNext, visibleChars, styler, currentPos)
|| (lexType == LEX_JULIA && (ch == '#' && chNext == '='))
|| (ch == '/' && chNext == '*'); // Scilab
}

static bool IsBlockCommentEnd(int lexType, int ch, int chNext, int visibleChars, LexAccessor &styler, Sci_PositionU currentPos) noexcept {
return IsNestedCommentEnd(lexType, ch, chNext, visibleChars, styler, currentPos)
|| (lexType == LEX_JULIA && (ch == '=' && chNext == '#'))
|| (ch == '*' && chNext == '/'); // Scilab
}

Expand Down Expand Up @@ -120,8 +122,8 @@ static void ColouriseMatlabDoc(Sci_PositionU startPos, Sci_Position length, int
bool hasTest = false; // Octave test/demo: %!demo %!test %testif %!assert %!error %!fail %!share %!function

for (; sc.More(); sc.Forward()) {

if (sc.state == SCE_MAT_OPERATOR) {
switch (sc.state) {
case SCE_MAT_OPERATOR:
sc.SetState(SCE_MAT_DEFAULT);
if (sc.chPrev == '.') {
if (sc.ch == '*' || sc.ch == '/' || sc.ch == '\\' || sc.ch == '^') {
Expand All @@ -130,19 +132,23 @@ static void ColouriseMatlabDoc(Sci_PositionU startPos, Sci_Position length, int
isTransposeOperator = true;
}
}
} else if (sc.state == SCE_MAT_NUMBER) {
break;
case SCE_MAT_NUMBER:
if (!IsMatNumber(sc.ch, sc.chPrev)) {
if ((lexType == LEX_JULIA) && sc.ch == 'm' && sc.chPrev == 'i')
if ((lexType == LEX_JULIA) && sc.ch == 'm' && sc.chPrev == 'i') {
sc.Forward();
}
sc.SetState(SCE_MAT_DEFAULT);
isTransposeOperator = true;
}
} else if (sc.state == SCE_MAT_HEXNUM) {
break;
case SCE_MAT_HEXNUM:
if (!IsHexNum(sc.ch)) {
sc.SetState(SCE_MAT_DEFAULT);
isTransposeOperator = true;
}
} else if (sc.state == SCE_MAT_IDENTIFIER) {
break;
case SCE_MAT_IDENTIFIER:
_label_identifier:
if (!iswordstart(sc.ch)) {
char s[128]; // Matlab max indentifer length = 63, Octave unlimited
Expand All @@ -169,20 +175,24 @@ static void ColouriseMatlabDoc(Sci_PositionU startPos, Sci_Position length, int
}
sc.SetState(SCE_MAT_DEFAULT);
}
} else if (sc.state == SCE_MAT_CALLBACK || sc.state == SCE_MAT_VARIABLE) {
break;
case SCE_MAT_CALLBACK:
case SCE_MAT_VARIABLE:
if (!iswordstart(sc.ch)) {
if (sc.ch == '@') {
sc.SetState(SCE_MAT_OPERATOR);
sc.Forward();
}
sc.SetState(SCE_MAT_DEFAULT);
}
} else if (sc.state == SCE_MAT_COMMAND) {
break;
case SCE_MAT_COMMAND:
if (IsInvalidFileName(sc.ch)) {
sc.SetState(SCE_MAT_DEFAULT);
isTransposeOperator = false;
}
} else if (sc.state == SCE_MAT_STRING) {
break;
case SCE_MAT_STRING:
if ((lexType == LEX_JULIA) && sc.ch == '\\') {
if (sc.chNext == '\"' || sc.chNext == '\'' || sc.chNext == '\\') {
sc.Forward();
Expand All @@ -194,7 +204,10 @@ static void ColouriseMatlabDoc(Sci_PositionU startPos, Sci_Position length, int
sc.ForwardSetState(SCE_MAT_DEFAULT);
}
}
} else if (sc.state == SCE_MAT_DOUBLEQUOTESTRING || sc.state == SCE_MAT_REGEX) {
break;
case SCE_MAT_DOUBLEQUOTESTRING:
case SCE_MAT_REGEX:
case SCE_MAT_RAW_STRING2:
if (sc.ch == '\\') {
if (sc.chNext == '\"' || sc.chNext == '\'' || sc.chNext == '\\') {
sc.Forward();
Expand All @@ -207,10 +220,19 @@ static void ColouriseMatlabDoc(Sci_PositionU startPos, Sci_Position length, int
}
sc.ForwardSetState(SCE_MAT_DEFAULT);
}
} else if (sc.state == SCE_MAT_BACKTICK) {
if (sc.ch == '`')
break;
case SCE_MAT_TRIPLE_STRING2:
if (sc.Match("\"\"\"")) {
sc.Forward(2);
sc.ForwardSetState(SCE_MAT_DEFAULT);
}
break;
case SCE_MAT_BACKTICK:
if (sc.ch == '`') {
sc.ForwardSetState(SCE_MAT_DEFAULT);
} else if (sc.state == SCE_MAT_COMMENTBLOCK) {
}
break;
case SCE_MAT_COMMENTBLOCK:
if (IsBlockCommentEnd(lexType, sc, visibleChars)) {
if (IsMatlabOctave(lexType)) {
--commentLevel;
Expand All @@ -226,21 +248,26 @@ static void ColouriseMatlabDoc(Sci_PositionU startPos, Sci_Position length, int
++commentLevel;
sc.Forward();
}
} else if (sc.state == SCE_MAT_COMMENT) {
break;
case SCE_MAT_COMMENT:
if (sc.atLineStart) {
visibleChars = 0;
sc.SetState(SCE_MAT_DEFAULT);
isTransposeOperator = false;
}
break;
}

if (sc.state == SCE_MAT_DEFAULT) {
if ((lexType == LEX_JULIA) && sc.Match('r', '\"')) { // regex
sc.SetState(SCE_MAT_REGEX);
sc.Forward();
} else if ((lexType == LEX_JULIA) && (sc.ch == 'b' || sc.ch == 'L' || sc.ch == 'I' || sc.ch == 'E') && sc.chNext == '\"') {
} else if ((lexType == LEX_JULIA) && (sc.ch == 'b' || sc.ch == 'L' || sc.ch == 'I' || sc.ch == 'E' || sc.ch == 'v') && sc.chNext == '\"') {
sc.SetState(SCE_MAT_DOUBLEQUOTESTRING);
sc.Forward();
} else if (sc.Match("raw\"")) {
sc.SetState(SCE_MAT_RAW_STRING2);
sc.Forward(3);
} else if (IsBlockCommentStart(lexType, sc, visibleChars)) {
if (IsMatlabOctave(lexType)) {
++commentLevel;
Expand All @@ -260,17 +287,21 @@ static void ColouriseMatlabDoc(Sci_PositionU startPos, Sci_Position length, int
}
if (hasTest) {
sc.Forward(2);
if (iswordstart(sc.ch))
if (iswordstart(sc.ch)) {
sc.SetState(SCE_MAT_IDENTIFIER);
else
} else {
sc.SetState(SCE_MAT_DEFAULT);
}
}
} else if (sc.ch == '.') {
sc.Forward(2);
}
}
} else if (IsMatlabOctave(lexType) && visibleChars == 0 && sc.ch == '!') {
sc.SetState(SCE_MAT_COMMAND);
} else if (sc.Match("\"\"\"")) {
sc.SetState(SCE_MAT_TRIPLE_STRING2);
sc.Forward(2);
} else if (sc.ch == '\'') { // Octave allows whitespace before transpose operator
if (isTransposeOperator) {
sc.SetState(SCE_MAT_OPERATOR);
Expand All @@ -296,10 +327,11 @@ static void ColouriseMatlabDoc(Sci_PositionU startPos, Sci_Position length, int
sc.SetState(SCE_MAT_IDENTIFIER);
} else if (IsMatOperator(static_cast<char>(sc.ch))) {
sc.SetState(SCE_MAT_OPERATOR);
if (sc.ch == ')' || sc.ch == ']' || sc.ch == '}')
if (sc.ch == ')' || sc.ch == ']' || sc.ch == '}') {
isTransposeOperator = true;
else
} else {
isTransposeOperator = false;
}
} else {
isTransposeOperator = false;
}
Expand Down Expand Up @@ -332,6 +364,10 @@ static constexpr bool IsStreamCommentStyle(int style) noexcept {
return style == SCE_MAT_COMMENTBLOCK;
}

static constexpr bool IsSripleStringStyle(int style) noexcept {
return style == SCE_MAT_TRIPLE_STRING2;
}

#define IsCommentLine(line) IsLexCommentLine(line, styler, SCE_MAT_COMMENT)
#define StrEqu(str1, str2) (strcmp(str1, str2) == 0)

Expand Down Expand Up @@ -386,6 +422,13 @@ static void FoldMatlabDoc(Sci_PositionU startPos, Sci_Position length, int initS
else if (IsCommentLine(lineCurrent - 1) && !IsCommentLine(lineCurrent + 1))
levelNext--;
}
if (foldComment && IsSripleStringStyle(style)) {
if (!IsSripleStringStyle(stylePrev)) {
levelNext++;
} else if (!IsSripleStringStyle(styleNext) && !atEOL) {
levelNext--;
}
}

if (style == SCE_MAT_KEYWORD && stylePrev != SCE_MAT_KEYWORD && numBrace == 0 && chPrev != '.' && chPrev != ':') {
char word[32];
Expand All @@ -400,6 +443,7 @@ static void FoldMatlabDoc(Sci_PositionU startPos, Sci_Position length, int initS
|| ((lexType == LEX_SCILAB) && StrEqu(word, "select"))
|| ((lexType == LEX_JULIA) && (StrEqu(word, "type") || StrEqu(word, "quote")
|| StrEqu(word, "let") || StrEqu(word, "macro") || StrEqu(word, "do")
|| StrEqu(word, "struct")
|| StrEqu(word, "begin") || StrEqu(word, "module"))
)
) {
Expand Down
6 changes: 4 additions & 2 deletions src/EditLexers/stlJulia.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

static KEYWORDLIST Keywords_Julia = {{
"abstract begin bitstype break catch continue const do else elseif end export for function global if in import "
"let local macro module quote return try type typealias using while "
"true false nothing ans Inf NaN Inf32 NaN32 Inf16 NaN16"
"let local macro module mutable primitive quote return struct try type typealias using where while "
"true false nothing missing ans Inf NaN Inf32 NaN32 Inf16 NaN16"

, // 1 Type Keyword
"ANY Any Void Exception String Number Real Float Integer Signed Unsigned "
Expand Down Expand Up @@ -44,6 +44,8 @@ EDITLEXER lexJulia = { SCLEX_MATLAB, NP2LEX_JULIA, L"Julia Script", L"jl", L"",
{ SCE_MAT_FUNCTION, NP2STYLE_Function, L"Function", L"fore:#A46000", L"" },
{ MULTI_STYLE(SCE_MAT_COMMENT, SCE_MAT_COMMENTBLOCK, 0, 0), NP2STYLE_Comment, L"Comment", L"fore:#008000", L"" },
{ MULTI_STYLE(SCE_MAT_STRING, SCE_MAT_DOUBLEQUOTESTRING, 0, 0), NP2STYLE_String, L"String", L"fore:#008000", L"" },
{ SCE_MAT_RAW_STRING2, NP2STYLE_RawString, L"Raw String", L"fore:#008080", L"" },
{ SCE_MAT_TRIPLE_STRING2, NP2STYLE_TripleString, L"Triple Quoted String", L"fore:#F08000", L"" },
{ MULTI_STYLE(SCE_MAT_NUMBER, SCE_MAT_HEXNUM, 0, 0), NP2STYLE_Number, L"Number", L"fore:#FF0000", L"" },
{ SCE_MAT_BACKTICK, NP2STYLE_Backticks, L"Backticks", L"fore:#FF0080", L"" },
{ SCE_MAT_REGEX, NP2STYLE_Regex, L"Regex", L"fore:#006633; back:#FFF1A8", L"" },
Expand Down

0 comments on commit 103263f

Please sign in to comment.