Skip to content

Commit

Permalink
[Ruby] Add styles for %w, %i, %I, %s percent literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Feb 9, 2023
1 parent e9e3e58 commit 39bb296
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 75 deletions.
20 changes: 8 additions & 12 deletions doc/Notepad2 DarkTheme.ini
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ Operator=fore:#A349A4
Number=fore:#F84C4C
Operator=fore:#A349A4
POD=fore:#A46000; back:#424640; eolfilled
Backticks=fore:#8E0D90
Regex=back:#0B4F60
Backticks=fore:#E24000; back:#0F405D
Regex=fore:#006633; back:#0F405D
Variable=fore:#0080FF
Here-doc (Backticks, qx)=fore:#E24000; back:#0F405D
Backticks (qx)=fore:#E24000; back:#0F405D
Regex (qr)=fore:#006633; back:#0F405D
Array (qw)=fore:#0080FF
Here-doc (Backticks)=fore:#E24000; back:#0F405D
String Array=fore:#0080FF
[SQL Query]
Basic Function=fore:#8E0D90
Number=fore:#F84C4C
Expand Down Expand Up @@ -311,13 +309,11 @@ Operator=fore:#A349A4
Scalar $var=fore:#00B050
Array @var=fore:#8E0D90
Hash %var=fore:#A349A4
Regex /re/ or m{re}=fore:#006633; back:#0F405D
Substitution s/re/ore/=fore:#006633; back:#0F405D
Regex=fore:#006633; back:#0F405D
Substitution=fore:#006633; back:#0F405D
Backticks=fore:#E24000; back:#0F405D
Here-doc (Backticks, qx)=fore:#E24000; back:#0F405D
Backticks (qx)=fore:#E24000; back:#0F405D
Regex (qr)=fore:#006633; back:#0F405D
Array (qw)=fore:#0080FF
Here-doc (Backticks)=fore:#E24000; back:#0F405D
String Array=fore:#0080FF
Format Identifier=bold; fore:#648000; back:#0F405D
Format Body=fore:#648000; back:#0F405D
POD (Common)=fore:#A46000; back:#424640; eolfilled
Expand Down
24 changes: 14 additions & 10 deletions scintilla/include/SciLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,20 @@
#define SCE_RB_STRING_QX 26
#define SCE_RB_STRING_QR 27
#define SCE_RB_STRING_QW 28
#define SCE_RB_WORD_DEMOTED 29
#define SCE_RB_STDIN 30
#define SCE_RB_STDOUT 31
#define SCE_RB_STDERR 40
#define SCE_RB_UPPER_BOUND 41
#define SCE_RB_FUNCTION 42
#define SCE_RB_LIKE_MODULE 43
#define SCE_RB_LIKE_CLASS 44
#define SCE_RB_BUILTIN_CONSTANT 45
#define SCE_RB_BUILTIN_FUNCTION 46
#define SCE_RB_STRING_W 29
#define SCE_RB_STRING_I 30
#define SCE_RB_STRING_QI 31
#define SCE_RB_STRING_QS 40
#define SCE_RB_WORD_DEMOTED 41
#define SCE_RB_STDIN 42
#define SCE_RB_STDOUT 43
#define SCE_RB_STDERR 44
#define SCE_RB_FUNCTION 45
#define SCE_RB_LIKE_MODULE 46
#define SCE_RB_LIKE_CLASS 47
#define SCE_RB_BUILTIN_CONSTANT 48
#define SCE_RB_BUILTIN_FUNCTION 49
#define SCE_RB_UPPER_BOUND 50
#define SCE_B_DEFAULT 0
#define SCE_B_COMMENT 1
#define SCE_B_NUMBER 2
Expand Down
14 changes: 9 additions & 5 deletions scintilla/include/SciLexer.iface
Original file line number Diff line number Diff line change
Expand Up @@ -505,16 +505,20 @@ val SCE_RB_STRING_QQ=25
val SCE_RB_STRING_QX=26
val SCE_RB_STRING_QR=27
val SCE_RB_STRING_QW=28
val SCE_RB_WORD_DEMOTED=29
val SCE_RB_STDIN=30
val SCE_RB_STDOUT=31
val SCE_RB_STDERR=40
val SCE_RB_UPPER_BOUND=41
val SCE_RB_STRING_W=
val SCE_RB_STRING_I=
val SCE_RB_STRING_QI=
val SCE_RB_STRING_QS=
val SCE_RB_WORD_DEMOTED=
val SCE_RB_STDIN=
val SCE_RB_STDOUT=
val SCE_RB_STDERR=
val SCE_RB_FUNCTION=
val SCE_RB_LIKE_MODULE=
val SCE_RB_LIKE_CLASS=
val SCE_RB_BUILTIN_CONSTANT=
val SCE_RB_BUILTIN_FUNCTION=
val SCE_RB_UPPER_BOUND=
# Lexical states for SCLEX_VISUALBASIC, SCLEX_VBSCRIPT, SCLEX_POWERBASIC, SCLEX_BLITZBASIC, SCLEX_PUREBASIC, SCLEX_FREEBASIC
lex VisualBasic=SCLEX_VISUALBASIC SCE_B_
lex VBScript=SCLEX_VBSCRIPT SCE_B_
Expand Down
46 changes: 34 additions & 12 deletions scintilla/lexers/LexRuby.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,26 @@ class QuoteCls {
}
};

constexpr bool IsPercentLiteral(int state) noexcept {
return state == SCE_RB_STRING_Q
|| state == SCE_RB_STRING_QQ
// excluded SCE_RB_STRING_QR
|| state == SCE_RB_STRING_W
|| state == SCE_RB_STRING_QW
|| state == SCE_RB_STRING_I
|| state == SCE_RB_STRING_QI
|| state == SCE_RB_STRING_QS
|| state == SCE_RB_STRING_QX;
}

constexpr bool IsInterpolableLiteral(int state) noexcept {
return state != SCE_RB_STRING_Q
&& state != SCE_RB_STRING_W
&& state != SCE_RB_STRING_I
&& state != SCE_RB_STRING_QS
&& state != SCE_RB_STRING_SQ;
}

void enterInnerExpression(int *p_inner_string_types,
int *p_inner_expn_brace_counts,
QuoteCls *p_inner_quotes,
Expand Down Expand Up @@ -706,12 +726,15 @@ void ColouriseRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
styler.StartSegment(startPos);

constexpr uint64_t q_states = SCE_RB_STRING_Q
| ((uint64_t)SCE_RB_STRING_QQ << 8)
| ((uint64_t)SCE_RB_STRING_QR << 16)
| ((uint64_t)SCE_RB_STRING_QQ << 6)
| ((uint64_t)SCE_RB_STRING_QR << 12)
| ((uint64_t)SCE_RB_STRING_W << 18)
| ((uint64_t)SCE_RB_STRING_QW << 24)
| ((uint64_t)SCE_RB_STRING_QW << 32)
| ((uint64_t)SCE_RB_STRING_QX << 48);
constexpr const char* q_chars = "qQrwWx";
| ((uint64_t)SCE_RB_STRING_QX << 30)
| ((uint64_t)SCE_RB_STRING_I << 36)
| ((uint64_t)SCE_RB_STRING_QI << 42)
| ((uint64_t)SCE_RB_STRING_QS << 48);
constexpr const char* q_chars = "qQrwWxiIs";

// In most cases a value of 2 should be ample for the code in the
// Ruby library, and the code the user is likely to enter.
Expand Down Expand Up @@ -1002,7 +1025,7 @@ void ColouriseRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
if (hit && !isSafeWordcharOrHigh(chNext2)) {
Quote.New();
{
state = (int)((q_states >> ((hit - q_chars)*8)) & 0xff);
state = (int)((q_states >> ((hit - q_chars)*6)) & 0x3f);
Quote.Open(chNext2);
i += 2;
ch = chNext2;
Expand Down Expand Up @@ -1425,8 +1448,7 @@ void ColouriseRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
}
}
// Quotes of all kinds...
} else if (state == SCE_RB_STRING_Q || state == SCE_RB_STRING_QQ ||
state == SCE_RB_STRING_QX || state == SCE_RB_STRING_QW ||
} else if (IsPercentLiteral(state) ||
state == SCE_RB_STRING_DQ || state == SCE_RB_STRING_SQ ||
state == SCE_RB_BACKTICKS) {
if (!Quote.Down && !isspacechar(ch)) {
Expand All @@ -1445,8 +1467,7 @@ void ColouriseRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
Quote.Count++;
} else if (ch == '#' && chNext == '{'
&& inner_string_count < INNER_STRINGS_MAX_COUNT
&& state != SCE_RB_STRING_SQ
&& state != SCE_RB_STRING_Q) {
&& IsInterpolableLiteral(state)) {
// process #{ ... }
styler.ColorTo(i, state);
styler.ColorTo(i + 2, SCE_RB_OPERATOR);
Expand Down Expand Up @@ -1787,10 +1808,11 @@ void FoldRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexer
} else if (styleNext == SCE_RB_DEFAULT) {
levelCurrent--;
}
} else if (style == SCE_RB_STRING_QW) {
} else if (style == SCE_RB_STRING_QW || style == SCE_RB_STRING_W) {
if (stylePrev != style) {
levelCurrent++;
} else if (styleNext != style) {
}
if (styleNext != style) {
levelCurrent--;
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/EditLexers/EditStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,14 @@
#define NP2STYLE_ArrayVar 63502
#define NP2STYLE_HashVar 63503
#define NP2STYLE_SymbolTableVar 63504
#define NP2STYLE_Regex_mre 63505
#define NP2STYLE_Substitution_re 63506
// 63507
#define NP2STYLE_SymbolArray 63505

#define NP2STYLE_HeredocDelimiter 63508
#define NP2STYLE_HeredocSingleQuoted 63509
#define NP2STYLE_HeredocDoubleQuoted 63510
#define NP2STYLE_HeredocBackticks 63511
#define NP2STYLE_SingleQuotedString_q 63512
#define NP2STYLE_DoubleQuotedString_qq 63513
#define NP2STYLE_Backticks_qx 63514
#define NP2STYLE_Regex_qr 63515
#define NP2STYLE_Array_qw 63516

#define NP2STYLE_StringArray 63516
#define NP2STYLE_Prototype 63517
#define NP2STYLE_FormatIdentifier 63518
#define NP2STYLE_FormatBody 63519
Expand Down
16 changes: 6 additions & 10 deletions src/EditLexers/EditStyleX.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,14 @@
#define NP2StyleX_ArrayVar EDITSTYLE_HOLE(ArrayVar, L"Array @var")
#define NP2StyleX_HashVar EDITSTYLE_HOLE(HashVar, L"Hash %var")
#define NP2StyleX_SymbolTableVar EDITSTYLE_HOLE(SymbolTableVar, L"Symbol Table *var")
#define NP2StyleX_Regex_mre EDITSTYLE_HOLE(Regex_mre, L"Regex /re/ or m{re}")
#define NP2StyleX_Substitution_re EDITSTYLE_HOLE(Substitution_re, L"Substitution s/re/ore/")
#define NP2STYLEX_SymbolArray EDITSTYLE_HOLE(SymbolArray, L"Symbol Array")

#define NP2StyleX_HeredocDelimiter EDITSTYLE_HOLE(HeredocDelimiter, L"Here-doc (Delimiter)")
#define NP2StyleX_HeredocSingleQuoted EDITSTYLE_HOLE(HeredocSingleQuoted, L"Here-doc (Single Quoted, q)")
#define NP2StyleX_HeredocDoubleQuoted EDITSTYLE_HOLE(HeredocDoubleQuoted, L"Here-doc (Double Quoted, qq)")
#define NP2StyleX_HeredocBackticks EDITSTYLE_HOLE(HeredocBackticks, L"Here-doc (Backticks, qx)")
#define NP2StyleX_SingleQuotedString_q EDITSTYLE_HOLE(SingleQuotedString_q, L"Single Quoted String (Generic, q)")
#define NP2StyleX_DoubleQuotedString_qq EDITSTYLE_HOLE(DoubleQuotedString_qq, L"Double Quoted String (qq)")
#define NP2StyleX_Backticks_qx EDITSTYLE_HOLE(Backticks_qx, L"Backticks (qx)")
#define NP2StyleX_Regex_qr EDITSTYLE_HOLE(Regex_qr, L"Regex (qr)")
#define NP2StyleX_Array_qw EDITSTYLE_HOLE(Array_qw, L"Array (qw)")
#define NP2StyleX_HeredocSingleQuoted EDITSTYLE_HOLE(HeredocSingleQuoted, L"Here-doc (Single Quoted)")
#define NP2StyleX_HeredocDoubleQuoted EDITSTYLE_HOLE(HeredocDoubleQuoted, L"Here-doc (Double Quoted)")
#define NP2StyleX_HeredocBackticks EDITSTYLE_HOLE(HeredocBackticks, L"Here-doc (Backticks)")

#define NP2StyleX_StringArray EDITSTYLE_HOLE(StringArray, L"String Array")
#define NP2StyleX_Prototype EDITSTYLE_HOLE(Prototype, L"Prototype")
#define NP2StyleX_FormatIdentifier EDITSTYLE_HOLE(FormatIdentifier, L"Format Identifier")
#define NP2StyleX_FormatBody EDITSTYLE_HOLE(FormatBody, L"Format Body")
Expand Down
15 changes: 6 additions & 9 deletions src/EditLexers/stlPerl.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,22 @@ static EDITSTYLE Styles_Perl[] = {
EDITSTYLE_DEFAULT,
{ SCE_PL_COMMENTLINE, NP2StyleX_Comment, L"fore:#608060" },
{ SCE_PL_WORD, NP2StyleX_Keyword, L"bold; fore:#FF8000" },
{ MULTI_STYLE(SCE_PL_STRING_DQ, SCE_PL_STRING_SQ, 0, 0), NP2StyleX_String, L"fore:#008000" },
{ MULTI_STYLE(SCE_PL_STRING_SQ, SCE_PL_STRING_Q, 0, 0), NP2StyleX_SingleQuotedString, L"fore:#008000" },
{ MULTI_STYLE(SCE_PL_STRING_DQ, SCE_PL_STRING_QQ, 0, 0), NP2StyleX_DoubleQuotedString, L"fore:#008000" },
{ SCE_PL_NUMBER, NP2StyleX_Number, L"fore:#FF0000" },
{ SCE_PL_OPERATOR, NP2StyleX_Operator, L"fore:#B000B0" },
{ MULTI_STYLE(SCE_PL_SCALAR, SCE_PL_STRING_VAR, 0, 0), NP2StyleX_ScalarVar, L"fore:#0000FF" },
{ SCE_PL_ARRAY, NP2StyleX_ArrayVar, L"fore:#FF0080" },
{ SCE_PL_HASH, NP2StyleX_HashVar, L"fore:#B000B0" },
{ SCE_PL_SYMBOLTABLE, NP2StyleX_SymbolTableVar, L"fore:#3A6EA5" },
{ SCE_PL_REGEX, NP2StyleX_Regex_mre, L"fore:#006633; back:#FFF1A8" },
{ SCE_PL_REGSUBST, NP2StyleX_Substitution_re, L"fore:#006633; back:#FFF1A8" },
{ SCE_PL_BACKTICKS, NP2StyleX_Backticks, L"fore:#E24000; back:#FFF1A8" },
{ MULTI_STYLE(SCE_PL_REGEX, SCE_PL_STRING_QR, 0, 0), NP2StyleX_Regex, L"fore:#006633; back:#FFF1A8" },
{ SCE_PL_REGSUBST, NP2StyleX_Substitution, L"fore:#006633; back:#FFF1A8" },
{ MULTI_STYLE(SCE_PL_BACKTICKS, SCE_PL_STRING_QX, 0, 0), NP2StyleX_Backticks, L"fore:#E24000; back:#FFF1A8" },
{ SCE_PL_HERE_DELIM, NP2StyleX_HeredocDelimiter, L"fore:#648000" },
{ SCE_PL_HERE_Q, NP2StyleX_HeredocSingleQuoted, L"fore:#648000" },
{ SCE_PL_HERE_QQ, NP2StyleX_HeredocDoubleQuoted, L"fore:#648000" },
{ SCE_PL_HERE_QX, NP2StyleX_HeredocBackticks, L"fore:#E24000; back:#FFF1A8" },
{ SCE_PL_STRING_Q, NP2StyleX_SingleQuotedString_q, L"fore:#008000" },
{ SCE_PL_STRING_QQ, NP2StyleX_DoubleQuotedString_qq, L"fore:#008000" },
{ SCE_PL_STRING_QX, NP2StyleX_Backticks_qx, L"fore:#E24000; back:#FFF1A8" },
{ SCE_PL_STRING_QR, NP2StyleX_Regex_qr, L"fore:#006633; back:#FFF1A8" },
{ SCE_PL_STRING_QW, NP2StyleX_Array_qw, L"fore:#003CE6" },
{ SCE_PL_STRING_QW, NP2StyleX_StringArray, L"fore:#003CE6" },
{ SCE_PL_SUB_PROTOTYPE, NP2StyleX_Prototype, L"fore:#800080; back:#FFE2FF" },
{ SCE_PL_FORMAT_IDENT, NP2StyleX_FormatIdentifier, L"bold; fore:#648000; back:#FFF1A8" },
{ SCE_PL_FORMAT, NP2StyleX_FormatBody, L"fore:#648000; back:#FFF1A8" },
Expand Down
16 changes: 7 additions & 9 deletions src/EditLexers/stlRuby.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,19 @@ static EDITSTYLE Styles_Ruby[] = {
{ SCE_RB_NUMBER, NP2StyleX_Number, L"fore:#FF0000" },
{ SCE_RB_OPERATOR, NP2StyleX_Operator, L"fore:#B000B0" },
{ SCE_RB_COMMENTLINE, NP2StyleX_Comment, L"fore:#608060" },
{ MULTI_STYLE(SCE_RB_STRING_DQ, SCE_RB_STRING_SQ, 0, 0), NP2StyleX_String, L"fore:#008000" },
{ MULTI_STYLE(SCE_RB_STRING_SQ, SCE_RB_STRING_Q, 0, 0), NP2StyleX_SingleQuotedString, L"fore:#008000" },
{ MULTI_STYLE(SCE_RB_STRING_DQ, SCE_RB_STRING_QQ, 0, 0), NP2StyleX_DoubleQuotedString, L"fore:#008000" },
{ SCE_RB_POD, NP2StyleX_POD, L"fore:#004000; back:#C0FFC0; eolfilled" },
{ SCE_RB_BACKTICKS, NP2StyleX_Backticks, L"fore:#FF0080" },
{ SCE_RB_REGEX, NP2StyleX_Regex, L"back:#A0FFA0" },
{ SCE_RB_SYMBOL, NP2StyleX_Symbol, L"bold; fore:#FF4F0F" },
{ MULTI_STYLE(SCE_RB_BACKTICKS, SCE_RB_STRING_QX, 0, 0), NP2StyleX_Backticks, L"fore:#E24000; back:#FFF1A8" },
{ MULTI_STYLE(SCE_RB_REGEX, SCE_RB_STRING_QR, 0, 0), NP2StyleX_Regex, L"fore:#006633; back:#FFF1A8" },
{ MULTI_STYLE(SCE_RB_SYMBOL, SCE_RB_STRING_QS, 0, 0), NP2StyleX_Symbol, L"bold; fore:#FF4F0F" },
{ MULTI_STYLE(SCE_RB_CLASS_VAR, SCE_RB_INSTANCE_VAR, SCE_RB_GLOBAL, 0), NP2StyleX_Variable, L"fore:#003CE6" },
{ SCE_RB_HERE_DELIM, NP2StyleX_HeredocDelimiter, L"fore:#648000" },
{ SCE_RB_HERE_Q, NP2StyleX_HeredocSingleQuoted, L"fore:#648000" },
{ SCE_RB_HERE_QQ, NP2StyleX_HeredocDoubleQuoted,L"fore:#648000" },
{ SCE_RB_HERE_QX, NP2StyleX_HeredocBackticks, L"fore:#E24000; back:#FFF1A8" },
{ SCE_RB_STRING_Q, NP2StyleX_SingleQuotedString_q, L"fore:#008000" },
{ SCE_RB_STRING_QQ, NP2StyleX_DoubleQuotedString_qq, L"fore:#008000" },
{ SCE_RB_STRING_QX, NP2StyleX_Backticks_qx, L"fore:#E24000; back:#FFF1A8" },
{ SCE_RB_STRING_QR, NP2StyleX_Regex_qr, L"fore:#006633; back:#FFF1A8" },
{ SCE_RB_STRING_QW, NP2StyleX_Array_qw, L"fore:#003CE6" },
{ MULTI_STYLE(SCE_RB_STRING_QW, SCE_RB_STRING_W, 0, 0), NP2StyleX_StringArray, L"fore:#003CE6" },
{ MULTI_STYLE(SCE_RB_STRING_I, SCE_RB_STRING_QI, 0, 0), NP2STYLEX_SymbolArray, L"fore:#E24000" },
{ SCE_RB_DATASECTION, NP2StyleX_DataSection, L"fore:#600000; back:#FFF0D8; eolfilled" },
};

Expand Down

0 comments on commit 39bb296

Please sign in to comment.