From 58ab229671b37589365927180b1badeac06fee5e Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 16 Feb 2018 00:01:23 +0100 Subject: [PATCH 1/8] + add: R-Statistics Code lexer + chg: Registry files lexer to support eolfilled on "Added Keys" --- scintilla/Scintilla.vcxproj | 1 + scintilla/Scintilla.vcxproj.filters | 3 + scintilla/lexers/LexRegistry.cxx | 73 ++++++++++++---------- scintilla/src/Catalogue.cxx | 2 +- src/Notepad3.rc | 5 ++ src/Styles.c | 96 ++++++++++++++++++++++++++++- src/Styles.h | 2 +- 7 files changed, 146 insertions(+), 36 deletions(-) diff --git a/scintilla/Scintilla.vcxproj b/scintilla/Scintilla.vcxproj index 70bbfe9c5..83943f36c 100644 --- a/scintilla/Scintilla.vcxproj +++ b/scintilla/Scintilla.vcxproj @@ -292,6 +292,7 @@ + diff --git a/scintilla/Scintilla.vcxproj.filters b/scintilla/Scintilla.vcxproj.filters index 458cb2b1d..73969f909 100644 --- a/scintilla/Scintilla.vcxproj.filters +++ b/scintilla/Scintilla.vcxproj.filters @@ -444,6 +444,9 @@ lexers + + lexers + diff --git a/scintilla/lexers/LexRegistry.cxx b/scintilla/lexers/LexRegistry.cxx index 779ea2f47..fa4ad4d07 100644 --- a/scintilla/lexers/LexRegistry.cxx +++ b/scintilla/lexers/LexRegistry.cxx @@ -78,16 +78,25 @@ class LexerRegistry : public DefaultLexer { return false; } + static bool AtEndOfLine(LexAccessor& styler, Sci_Position pos) { + //char curr; + //do { + // curr = styler.SafeGetCharAt(pos, '\0'); + // ++pos; + //} while (curr == ' ' || curr == '\t'); + const char curr = styler.SafeGetCharAt(pos, '\0'); + const char next = styler.SafeGetCharAt(pos+1, '\0'); + return (!curr || (curr == '\n') || (curr == '\r' && next != '\n')); + } + static bool IsNextNonWhitespace(LexAccessor &styler, Sci_Position start, char ch) { - Sci_Position i = 0; - while (i < 100) { - i++; - char curr = styler.SafeGetCharAt(start+i, '\0'); - char next = styler.SafeGetCharAt(start+i+1, '\0'); - bool atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); + while (!AtEndOfLine(styler, start + 1)) { + ++start; + char curr = styler.SafeGetCharAt(start, '\0'); + char next = styler.SafeGetCharAt(start+1, '\0'); if (curr == ch) { return true; - } else if (!isspacechar(curr) || atEOL) { + } else if (!isspacechar(curr)) { return false; } } @@ -96,21 +105,18 @@ class LexerRegistry : public DefaultLexer { // Looks for the equal sign at the end of the string static bool AtValueName(LexAccessor &styler, Sci_Position start) { - bool atEOL = false; - Sci_Position i = 0; bool escaped = false; - while (!atEOL) { - i++; - char curr = styler.SafeGetCharAt(start+i, '\0'); - char next = styler.SafeGetCharAt(start+i+1, '\0'); - atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); + while (!AtEndOfLine(styler, start + 1)) { + ++start; + char curr = styler.SafeGetCharAt(start, '\0'); + char next = styler.SafeGetCharAt(start+1, '\0'); if (escaped) { escaped = false; continue; } escaped = curr == '\\'; if (curr == '"') { - return IsNextNonWhitespace(styler, start+i, '='); + return IsNextNonWhitespace(styler, start, '='); } else if (!curr) { return false; } @@ -118,13 +124,12 @@ class LexerRegistry : public DefaultLexer { return false; } - static bool AtKeyPathEnd(LexAccessor &styler, Sci_Position start) { + static bool AtKeyPathEnd(LexAccessor& styler, Sci_Position start) { bool atEOL = false; - Sci_Position i = 0; - while (!atEOL) { - i++; - char curr = styler.SafeGetCharAt(start+i, '\0'); - char next = styler.SafeGetCharAt(start+i+1, '\0'); + while (!AtEndOfLine(styler, start + 1)) { + ++start; + char curr = styler.SafeGetCharAt(start, '\0'); + char next = styler.SafeGetCharAt(start+1, '\0'); atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); if (curr == ']' || !curr) { // There's still at least one or more square brackets ahead @@ -200,6 +205,7 @@ public: Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, @@ -207,9 +213,9 @@ public: }; void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, - Sci_Position length, - int initStyle, - IDocument *pAccess) { + Sci_Position length, + int initStyle, + IDocument *pAccess) { int beforeGUID = SCE_REG_DEFAULT; int beforeEscape = SCE_REG_DEFAULT; CharacterSet setOperators = CharacterSet(CharacterSet::setNone, "-,.=:\\@()"); @@ -217,7 +223,7 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, StyleContext context(startPos, length, initStyle, styler); bool highlight = true; bool afterEqualSign = false; - while (context.More()) { + while (context.More() && context.ch) { if (context.atLineStart) { Sci_Position currPos = static_cast(context.currentPos); bool continued = styler[currPos-3] == '\\'; @@ -270,7 +276,8 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, case SCE_REG_DELETEDKEY: case SCE_REG_ADDEDKEY: { Sci_Position currPos = static_cast(context.currentPos); - if (context.ch == ']' && AtKeyPathEnd(styler, currPos)) { + //if (context.ch == ']' && AtKeyPathEnd(styler, currPos)) { + if (AtEndOfLine(styler, currPos)) { context.ForwardSetState(SCE_REG_DEFAULT); } else if (context.ch == '{') { if (AtGUID(styler, currPos)) { @@ -300,9 +307,9 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, Sci_Position currPos = static_cast(context.currentPos); if (context.ch == '"' && IsStringState(context.state)) { context.ForwardSetState(SCE_REG_DEFAULT); - } else if (context.ch == ']' && - AtKeyPathEnd(styler, currPos) && - IsKeyPathState(context.state)) { + //} else if (context.ch == ']' && AtKeyPathEnd(styler, currPos) && + } else if (AtEndOfLine(styler, currPos) && + IsKeyPathState(context.state)) { context.ForwardSetState(SCE_REG_DEFAULT); } else if (context.ch == '\\' && IsStringState(context.state)) { beforeEscape = context.state; @@ -337,7 +344,7 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, if (wordStart && AtValueType(styler, currPos)) { context.SetState(SCE_REG_VALUETYPE); } - } else if (isxdigit(context.ch) && highlight) { + } else if (isxdigit(context.ch & 0xFF) && highlight) { context.SetState(SCE_REG_HEXDIGIT); } highlight = (context.ch == '@') ? true : highlight; @@ -409,7 +416,7 @@ void SCI_METHOD LexerRegistry::Fold(Sci_PositionU startPos, } LexerModule lmRegistry(SCLEX_REGISTRY, - LexerRegistry::LexerFactoryRegistry, - "registry", - RegistryWordListDesc); + LexerRegistry::LexerFactoryRegistry, + "registry", + RegistryWordListDesc); diff --git a/scintilla/src/Catalogue.cxx b/scintilla/src/Catalogue.cxx index b315f374b..717715644 100644 --- a/scintilla/src/Catalogue.cxx +++ b/scintilla/src/Catalogue.cxx @@ -162,7 +162,7 @@ int Scintilla_LinkLexers() { //LINK_LEXER(lmPS); //LINK_LEXER(lmPureBasic); LINK_LEXER(lmPython); - //LINK_LEXER(lmR); + LINK_LEXER(lmR); //LINK_LEXER(lmREBOL); LINK_LEXER(lmRegistry); LINK_LEXER(lmRuby); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 874c887c9..dc79060c5 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -1718,6 +1718,7 @@ BEGIN 63042 "Coffeescript" 63043 "MATLAB" 63044 "Nim Source Code" + 63045 "R-S-SPlus Statistics Code" END STRINGTABLE @@ -1935,6 +1936,10 @@ BEGIN 63266 "2nd Default Text" 63267 "Variable within String" 63268 "Ordered List" + 63269 "Infix" + 63270 "Infix EOL" + 63271 "Base Package Functions" + 63272 "Other Package Functions" END #endif // English (United States) resources diff --git a/src/Styles.c b/src/Styles.c index ffe14b11a..a680d5e49 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -97,7 +97,7 @@ EDITLEXER lexStandard2nd = { SCLEX_NULL, 63266, L"2nd Default Text", L"txt; text /* 9 */ { SCI_SETCARETFORE + SCI_SETCARETWIDTH, 63121, L"2nd Caret (Color, Size 1-3)", L"", L"" }, /* 10 */ { SCI_SETEDGECOLOUR, 63122, L"2nd Long Line Marker (Colors)", L"fore:#FFC000", L"" }, /* 11 */ { SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT, 63123, L"2nd Extra Line Spacing (Size)", L"", L"" }, - /* 12 */ { SCI_FOLDALL + SCI_MARKERSETALPHA, 63125, L"2nd Bookmarks and Folding (Colors)", L"fore:#000000; back:#00FF00; alpha:80; charset:2; case:U;", L"" }, + /* 12 */ { SCI_FOLDALL + SCI_MARKERSETALPHA, 63125, L"2nd Bookmarks and Folding (Colors)", L"fore:#000000; back:#00FF00; alpha:80; charset:2; case:U", L"" }, /* 13 */ { SCI_MARKERSETBACK + SCI_MARKERSETALPHA, 63263, L"2nd Mark Occurrences (Indicator)", L"fore:#0x00FF00; alpha:100; alpha2:220; indic_box", L"" }, /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, 63265, L"2nd Hyperlink Hotspots", L"bold; fore:#FF0000", L"" }, { -1, 00000, L"", L"", L"" } } }; @@ -2826,6 +2826,99 @@ EDITLEXER lexNimrod = { SCLEX_NIMROD, 63044, L"Nim Source Code", L"nim; nimrod", +KEYWORDLIST KeyWords_R = { + // Language Keywords + "if else repeat while function for in next break " + "TRUE FALSE NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character_", + // Base / Default package function + "abbreviate abline abs acf acos acosh addmargins aggregate agrep alarm alias alist " + "all anova any aov aperm append apply approx approxfun apropos ar args arima array " + "arrows asin asinh assign assocplot atan atanh attach attr attributes autoload autoloader ave axis " + "backsolve barplot basename beta bindtextdomain binomial biplot bitmap bmp body " + "box boxplot bquote break browser builtins bxp by bzfile c call cancor capabilities " + "casefold cat category cbind ccf ceiling character charmatch chartr chol choose " + "chull citation class close cm cmdscale codes coef coefficients col colnames colors " + "colorspaces colours comment complex confint conflicts contour contrasts contributors " + "convolve cophenetic coplot cor cos cosh cov covratio cpgram crossprod cummax cummin " + "cumprod cumsum curve cut cutree cycle data dataentry date dbeta dbinom dcauchy dchisq de " + "debug debugger decompose delay deltat demo dendrapply density deparse deriv det detach " + "determinant deviance dexp df dfbeta dfbetas dffits dgamma dgeom dget dhyper diag diff " + "diffinv difftime digamma dim dimnames dir dirname dist dlnorm dlogis dmultinom dnbinom " + "dnorm dotchart double dpois dput drop dsignrank dt dump dunif duplicated dweibull " + "dwilcox eapply ecdf edit effects eigen emacs embed end environment eval evalq " + "example exists exp expression factanal factor factorial family fft fifo file filter " + "find fitted fivenum fix floor flush for force formals format formula forwardsolve " + "fourfoldplot frame frequency ftable function gamma gaussian gc gcinfo gctorture get " + "getenv geterrmessage gettext gettextf getwd gl glm globalenv gray grep grey grid gsub " + "gzcon gzfile hat hatvalues hcl hclust head heatmap help hist history hsv httpclient " + "iconv iconvlist identical identify if ifelse image influence inherits integer integrate " + "interaction interactive intersect invisible isoreg jitter jpeg julian kappa kernapply " + "kernel kmeans knots kronecker ksmooth labels lag lapply layout lbeta lchoose lcm legend " + "length letters levels lfactorial lgamma library licence license line lines list lm load " + "loadhistory loadings local locator loess log logb logical loglin lowess ls lsfit machine mad " + "mahalanobis makepredictcall manova mapply match matlines matplot matpoints matrix max mean " + "median medpolish menu merge message methods mget min missing mode monthplot months " + "mosaicplot mtext mvfft names napredict naprint naresid nargs nchar ncol next nextn ngettext " + "nlevels nlm nls noquote nrow numeric objects offset open optim optimise optimize options " + "order ordered outer pacf page pairlist pairs palette par parse paste pbeta pbinom pbirthday " + "pcauchy pchisq pdf pentagamma person persp pexp pf pgamma pgeom phyper pi pico pictex pie " + "piechart pipe plclust plnorm plogis plot pmatch pmax pmin pnbinom png pnorm points poisson " + "poly polygon polym polyroot postscript power ppoints ppois ppr prcomp predict preplot " + "pretty princomp print prmatrix prod profile profiler proj promax prompt provide psigamma " + "psignrank pt ptukey punif pweibull pwilcox q qbeta qbinom qbirthday qcauchy qchisq qexp qf " + "qgamma qgeom qhyper qlnorm qlogis qnbinom qnorm qpois qqline qqnorm qqplot qr qsignrank qt " + "qtukey quantile quarters quasi quasibinomial quasipoisson quit qunif quote qweibull qwilcox " + "rainbow range rank raw rbeta rbind rbinom rcauchy rchisq readline real recover rect " + "reformulate regexpr relevel remove reorder rep repeat replace replicate replications require " + "reshape resid residuals restart return rev rexp rf rgamma rgb rgeom rhyper rle rlnorm rlogis rm " + "rmultinom rnbinom rnorm round row rownames rowsum rpois rsignrank rstandard rstudent rt " + "rug runif runmed rweibull rwilcox sample sapply save savehistory scale scan screen screeplot sd " + "search searchpaths seek segments seq sequence serialize setdiff setequal setwd shell sign " + "signif sin single sinh sink smooth solve sort source spectrum spline splinefun split sprintf " + "sqrt stack stars start stderr stdin stdout stem step stepfun stl stop stopifnot str strftime " + "strheight stripchart strptime strsplit strtrim structure strwidth strwrap sub subset " + "substitute substr substring sum summary sunflowerplot supsmu svd sweep switch symbols symnum " + "system t table tabulate tail tan tanh tapply tempdir tempfile termplot terms tetragamma " + "text time title toeplitz tolower topenv toupper trace traceback transform trigamma trunc " + "truncate try ts tsdiag tsp typeof unclass undebug union unique uniroot unix unlink unlist " + "unname unserialize unsplit unstack untrace unz update upgrade url var varimax vcov vector " + "version vi vignette warning warnings weekdays weights which while window windows " + "with write wsbrowser xedit xemacs xfig xinch xor xtabs xyinch yinch zapsmall", + // "Other Package Functions + "acme aids aircondit amis aml banking barchart barley beaver bigcity boot brambles " + "breslow bs bwplot calcium cane capability cav censboot channing city claridge cloth " + "cloud coal condense contourplot control corr darwin densityplot dogs dotplot ducks " + "empinf envelope environmental ethanol fir frets gpar grav gravity grob hirose histogram " + "islay knn larrows levelplot llines logit lpoints lsegments lset ltext lvqinit lvqtest manaus " + "melanoma melanoma motor multiedit neuro nitrofen nodal ns nuclear oneway parallel " + "paulsen poisons polar qq qqmath remission rfs saddle salinity shingle simplex singer " + "somgrid splom stripplot survival tau tmd tsboot tuna unit urine viewport wireframe wool xyplot", + // Unused + "", + // Unused + "", + // --- + "", "", "", "" +}; + + +EDITLEXER lexR = { SCLEX_R, 63045, L"R-S-SPlus Statistics Code", L"R", L"", &KeyWords_R,{ + { STYLE_DEFAULT, 63126, L"Default", L"", L"" }, + //{ SCE_R_DEFAULT, 63126, L"Default", L"", L"" }, + { SCE_R_COMMENT, 63127, L"Comment", L"fore:#008000", L"" }, + { SCE_R_KWORD, 63128, L"Keyword", L"bold; fore:#0A246A", L"" }, + { SCE_R_BASEKWORD, 63271, L"Base Package Functions", L"bold; fore:#7f0000", L"" }, + { SCE_R_OTHERKWORD, 63272, L"Other Package Functions", L"bold; fore:#7f007F", L"" }, + { SCE_R_NUMBER, 63130, L"Number", L"fore:#0000FF", L"" }, + { MULTI_STYLE(SCE_R_STRING,SCE_R_STRING2,0,0), 63131, L"String", L"italic; fore:#3C6CDD", L"" }, + { SCE_R_OPERATOR, 63132, L"Operator", L"bold; fore:#B000B0", L"" }, + { SCE_R_IDENTIFIER, 63129, L"Identifier", L"", L"" }, + { SCE_R_INFIX, 63269, L"Infix", L"fore:#660066", L"" }, + { SCE_R_INFIXEOL, 63270, L"Infix EOL", L"fore:#FF4000; ,back:#E0C0E0; eolfilled", L"" }, + { -1, 00000, L"", L"", L"" } } }; + + + // This array holds all the lexers... // Don't forget to change the number of the lexer for HTML and XML // in Notepad2.c ParseCommandLine() if you change this array! @@ -2865,6 +2958,7 @@ static PEDITLEXER g_pLexArray[NUMLEXERS] = &lexPL, // Perl Script &lexPS, // PowerShell Script &lexPY, // Python Script + &lexR, // R Statistics Code &lexRegistry, // Registry Files &lexRC, // Resource Script &lexRUBY, // Ruby Script diff --git a/src/Styles.h b/src/Styles.h index 6dc77bdfa..6b9eb1afc 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -61,7 +61,7 @@ typedef struct _editlexer // Number of Lexers in pLexArray -#define NUMLEXERS 46 +#define NUMLEXERS 47 #define AVG_NUM_OF_STYLES_PER_LEXER 20 From 13c9ec1026aebf0cbcb0b1b757dc3d9899da7eb4 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 16 Feb 2018 00:01:23 +0100 Subject: [PATCH 2/8] + add: R-Statistics Code lexer + chg: Registry files lexer to support eolfilled on "Added Keys" --- scintilla/Scintilla.vcxproj | 1 + scintilla/Scintilla.vcxproj.filters | 3 + scintilla/lexers/LexRegistry.cxx | 73 ++++++++++++---------- scintilla/src/Catalogue.cxx | 2 +- src/Notepad3.rc | 5 ++ src/Styles.c | 96 ++++++++++++++++++++++++++++- src/Styles.h | 2 +- 7 files changed, 146 insertions(+), 36 deletions(-) diff --git a/scintilla/Scintilla.vcxproj b/scintilla/Scintilla.vcxproj index 70bbfe9c5..83943f36c 100644 --- a/scintilla/Scintilla.vcxproj +++ b/scintilla/Scintilla.vcxproj @@ -292,6 +292,7 @@ + diff --git a/scintilla/Scintilla.vcxproj.filters b/scintilla/Scintilla.vcxproj.filters index 458cb2b1d..73969f909 100644 --- a/scintilla/Scintilla.vcxproj.filters +++ b/scintilla/Scintilla.vcxproj.filters @@ -444,6 +444,9 @@ lexers + + lexers + diff --git a/scintilla/lexers/LexRegistry.cxx b/scintilla/lexers/LexRegistry.cxx index 779ea2f47..fa4ad4d07 100644 --- a/scintilla/lexers/LexRegistry.cxx +++ b/scintilla/lexers/LexRegistry.cxx @@ -78,16 +78,25 @@ class LexerRegistry : public DefaultLexer { return false; } + static bool AtEndOfLine(LexAccessor& styler, Sci_Position pos) { + //char curr; + //do { + // curr = styler.SafeGetCharAt(pos, '\0'); + // ++pos; + //} while (curr == ' ' || curr == '\t'); + const char curr = styler.SafeGetCharAt(pos, '\0'); + const char next = styler.SafeGetCharAt(pos+1, '\0'); + return (!curr || (curr == '\n') || (curr == '\r' && next != '\n')); + } + static bool IsNextNonWhitespace(LexAccessor &styler, Sci_Position start, char ch) { - Sci_Position i = 0; - while (i < 100) { - i++; - char curr = styler.SafeGetCharAt(start+i, '\0'); - char next = styler.SafeGetCharAt(start+i+1, '\0'); - bool atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); + while (!AtEndOfLine(styler, start + 1)) { + ++start; + char curr = styler.SafeGetCharAt(start, '\0'); + char next = styler.SafeGetCharAt(start+1, '\0'); if (curr == ch) { return true; - } else if (!isspacechar(curr) || atEOL) { + } else if (!isspacechar(curr)) { return false; } } @@ -96,21 +105,18 @@ class LexerRegistry : public DefaultLexer { // Looks for the equal sign at the end of the string static bool AtValueName(LexAccessor &styler, Sci_Position start) { - bool atEOL = false; - Sci_Position i = 0; bool escaped = false; - while (!atEOL) { - i++; - char curr = styler.SafeGetCharAt(start+i, '\0'); - char next = styler.SafeGetCharAt(start+i+1, '\0'); - atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); + while (!AtEndOfLine(styler, start + 1)) { + ++start; + char curr = styler.SafeGetCharAt(start, '\0'); + char next = styler.SafeGetCharAt(start+1, '\0'); if (escaped) { escaped = false; continue; } escaped = curr == '\\'; if (curr == '"') { - return IsNextNonWhitespace(styler, start+i, '='); + return IsNextNonWhitespace(styler, start, '='); } else if (!curr) { return false; } @@ -118,13 +124,12 @@ class LexerRegistry : public DefaultLexer { return false; } - static bool AtKeyPathEnd(LexAccessor &styler, Sci_Position start) { + static bool AtKeyPathEnd(LexAccessor& styler, Sci_Position start) { bool atEOL = false; - Sci_Position i = 0; - while (!atEOL) { - i++; - char curr = styler.SafeGetCharAt(start+i, '\0'); - char next = styler.SafeGetCharAt(start+i+1, '\0'); + while (!AtEndOfLine(styler, start + 1)) { + ++start; + char curr = styler.SafeGetCharAt(start, '\0'); + char next = styler.SafeGetCharAt(start+1, '\0'); atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); if (curr == ']' || !curr) { // There's still at least one or more square brackets ahead @@ -200,6 +205,7 @@ public: Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, @@ -207,9 +213,9 @@ public: }; void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, - Sci_Position length, - int initStyle, - IDocument *pAccess) { + Sci_Position length, + int initStyle, + IDocument *pAccess) { int beforeGUID = SCE_REG_DEFAULT; int beforeEscape = SCE_REG_DEFAULT; CharacterSet setOperators = CharacterSet(CharacterSet::setNone, "-,.=:\\@()"); @@ -217,7 +223,7 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, StyleContext context(startPos, length, initStyle, styler); bool highlight = true; bool afterEqualSign = false; - while (context.More()) { + while (context.More() && context.ch) { if (context.atLineStart) { Sci_Position currPos = static_cast(context.currentPos); bool continued = styler[currPos-3] == '\\'; @@ -270,7 +276,8 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, case SCE_REG_DELETEDKEY: case SCE_REG_ADDEDKEY: { Sci_Position currPos = static_cast(context.currentPos); - if (context.ch == ']' && AtKeyPathEnd(styler, currPos)) { + //if (context.ch == ']' && AtKeyPathEnd(styler, currPos)) { + if (AtEndOfLine(styler, currPos)) { context.ForwardSetState(SCE_REG_DEFAULT); } else if (context.ch == '{') { if (AtGUID(styler, currPos)) { @@ -300,9 +307,9 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, Sci_Position currPos = static_cast(context.currentPos); if (context.ch == '"' && IsStringState(context.state)) { context.ForwardSetState(SCE_REG_DEFAULT); - } else if (context.ch == ']' && - AtKeyPathEnd(styler, currPos) && - IsKeyPathState(context.state)) { + //} else if (context.ch == ']' && AtKeyPathEnd(styler, currPos) && + } else if (AtEndOfLine(styler, currPos) && + IsKeyPathState(context.state)) { context.ForwardSetState(SCE_REG_DEFAULT); } else if (context.ch == '\\' && IsStringState(context.state)) { beforeEscape = context.state; @@ -337,7 +344,7 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, if (wordStart && AtValueType(styler, currPos)) { context.SetState(SCE_REG_VALUETYPE); } - } else if (isxdigit(context.ch) && highlight) { + } else if (isxdigit(context.ch & 0xFF) && highlight) { context.SetState(SCE_REG_HEXDIGIT); } highlight = (context.ch == '@') ? true : highlight; @@ -409,7 +416,7 @@ void SCI_METHOD LexerRegistry::Fold(Sci_PositionU startPos, } LexerModule lmRegistry(SCLEX_REGISTRY, - LexerRegistry::LexerFactoryRegistry, - "registry", - RegistryWordListDesc); + LexerRegistry::LexerFactoryRegistry, + "registry", + RegistryWordListDesc); diff --git a/scintilla/src/Catalogue.cxx b/scintilla/src/Catalogue.cxx index b315f374b..717715644 100644 --- a/scintilla/src/Catalogue.cxx +++ b/scintilla/src/Catalogue.cxx @@ -162,7 +162,7 @@ int Scintilla_LinkLexers() { //LINK_LEXER(lmPS); //LINK_LEXER(lmPureBasic); LINK_LEXER(lmPython); - //LINK_LEXER(lmR); + LINK_LEXER(lmR); //LINK_LEXER(lmREBOL); LINK_LEXER(lmRegistry); LINK_LEXER(lmRuby); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 874c887c9..dc79060c5 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -1718,6 +1718,7 @@ BEGIN 63042 "Coffeescript" 63043 "MATLAB" 63044 "Nim Source Code" + 63045 "R-S-SPlus Statistics Code" END STRINGTABLE @@ -1935,6 +1936,10 @@ BEGIN 63266 "2nd Default Text" 63267 "Variable within String" 63268 "Ordered List" + 63269 "Infix" + 63270 "Infix EOL" + 63271 "Base Package Functions" + 63272 "Other Package Functions" END #endif // English (United States) resources diff --git a/src/Styles.c b/src/Styles.c index ffe14b11a..a680d5e49 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -97,7 +97,7 @@ EDITLEXER lexStandard2nd = { SCLEX_NULL, 63266, L"2nd Default Text", L"txt; text /* 9 */ { SCI_SETCARETFORE + SCI_SETCARETWIDTH, 63121, L"2nd Caret (Color, Size 1-3)", L"", L"" }, /* 10 */ { SCI_SETEDGECOLOUR, 63122, L"2nd Long Line Marker (Colors)", L"fore:#FFC000", L"" }, /* 11 */ { SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT, 63123, L"2nd Extra Line Spacing (Size)", L"", L"" }, - /* 12 */ { SCI_FOLDALL + SCI_MARKERSETALPHA, 63125, L"2nd Bookmarks and Folding (Colors)", L"fore:#000000; back:#00FF00; alpha:80; charset:2; case:U;", L"" }, + /* 12 */ { SCI_FOLDALL + SCI_MARKERSETALPHA, 63125, L"2nd Bookmarks and Folding (Colors)", L"fore:#000000; back:#00FF00; alpha:80; charset:2; case:U", L"" }, /* 13 */ { SCI_MARKERSETBACK + SCI_MARKERSETALPHA, 63263, L"2nd Mark Occurrences (Indicator)", L"fore:#0x00FF00; alpha:100; alpha2:220; indic_box", L"" }, /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, 63265, L"2nd Hyperlink Hotspots", L"bold; fore:#FF0000", L"" }, { -1, 00000, L"", L"", L"" } } }; @@ -2826,6 +2826,99 @@ EDITLEXER lexNimrod = { SCLEX_NIMROD, 63044, L"Nim Source Code", L"nim; nimrod", +KEYWORDLIST KeyWords_R = { + // Language Keywords + "if else repeat while function for in next break " + "TRUE FALSE NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character_", + // Base / Default package function + "abbreviate abline abs acf acos acosh addmargins aggregate agrep alarm alias alist " + "all anova any aov aperm append apply approx approxfun apropos ar args arima array " + "arrows asin asinh assign assocplot atan atanh attach attr attributes autoload autoloader ave axis " + "backsolve barplot basename beta bindtextdomain binomial biplot bitmap bmp body " + "box boxplot bquote break browser builtins bxp by bzfile c call cancor capabilities " + "casefold cat category cbind ccf ceiling character charmatch chartr chol choose " + "chull citation class close cm cmdscale codes coef coefficients col colnames colors " + "colorspaces colours comment complex confint conflicts contour contrasts contributors " + "convolve cophenetic coplot cor cos cosh cov covratio cpgram crossprod cummax cummin " + "cumprod cumsum curve cut cutree cycle data dataentry date dbeta dbinom dcauchy dchisq de " + "debug debugger decompose delay deltat demo dendrapply density deparse deriv det detach " + "determinant deviance dexp df dfbeta dfbetas dffits dgamma dgeom dget dhyper diag diff " + "diffinv difftime digamma dim dimnames dir dirname dist dlnorm dlogis dmultinom dnbinom " + "dnorm dotchart double dpois dput drop dsignrank dt dump dunif duplicated dweibull " + "dwilcox eapply ecdf edit effects eigen emacs embed end environment eval evalq " + "example exists exp expression factanal factor factorial family fft fifo file filter " + "find fitted fivenum fix floor flush for force formals format formula forwardsolve " + "fourfoldplot frame frequency ftable function gamma gaussian gc gcinfo gctorture get " + "getenv geterrmessage gettext gettextf getwd gl glm globalenv gray grep grey grid gsub " + "gzcon gzfile hat hatvalues hcl hclust head heatmap help hist history hsv httpclient " + "iconv iconvlist identical identify if ifelse image influence inherits integer integrate " + "interaction interactive intersect invisible isoreg jitter jpeg julian kappa kernapply " + "kernel kmeans knots kronecker ksmooth labels lag lapply layout lbeta lchoose lcm legend " + "length letters levels lfactorial lgamma library licence license line lines list lm load " + "loadhistory loadings local locator loess log logb logical loglin lowess ls lsfit machine mad " + "mahalanobis makepredictcall manova mapply match matlines matplot matpoints matrix max mean " + "median medpolish menu merge message methods mget min missing mode monthplot months " + "mosaicplot mtext mvfft names napredict naprint naresid nargs nchar ncol next nextn ngettext " + "nlevels nlm nls noquote nrow numeric objects offset open optim optimise optimize options " + "order ordered outer pacf page pairlist pairs palette par parse paste pbeta pbinom pbirthday " + "pcauchy pchisq pdf pentagamma person persp pexp pf pgamma pgeom phyper pi pico pictex pie " + "piechart pipe plclust plnorm plogis plot pmatch pmax pmin pnbinom png pnorm points poisson " + "poly polygon polym polyroot postscript power ppoints ppois ppr prcomp predict preplot " + "pretty princomp print prmatrix prod profile profiler proj promax prompt provide psigamma " + "psignrank pt ptukey punif pweibull pwilcox q qbeta qbinom qbirthday qcauchy qchisq qexp qf " + "qgamma qgeom qhyper qlnorm qlogis qnbinom qnorm qpois qqline qqnorm qqplot qr qsignrank qt " + "qtukey quantile quarters quasi quasibinomial quasipoisson quit qunif quote qweibull qwilcox " + "rainbow range rank raw rbeta rbind rbinom rcauchy rchisq readline real recover rect " + "reformulate regexpr relevel remove reorder rep repeat replace replicate replications require " + "reshape resid residuals restart return rev rexp rf rgamma rgb rgeom rhyper rle rlnorm rlogis rm " + "rmultinom rnbinom rnorm round row rownames rowsum rpois rsignrank rstandard rstudent rt " + "rug runif runmed rweibull rwilcox sample sapply save savehistory scale scan screen screeplot sd " + "search searchpaths seek segments seq sequence serialize setdiff setequal setwd shell sign " + "signif sin single sinh sink smooth solve sort source spectrum spline splinefun split sprintf " + "sqrt stack stars start stderr stdin stdout stem step stepfun stl stop stopifnot str strftime " + "strheight stripchart strptime strsplit strtrim structure strwidth strwrap sub subset " + "substitute substr substring sum summary sunflowerplot supsmu svd sweep switch symbols symnum " + "system t table tabulate tail tan tanh tapply tempdir tempfile termplot terms tetragamma " + "text time title toeplitz tolower topenv toupper trace traceback transform trigamma trunc " + "truncate try ts tsdiag tsp typeof unclass undebug union unique uniroot unix unlink unlist " + "unname unserialize unsplit unstack untrace unz update upgrade url var varimax vcov vector " + "version vi vignette warning warnings weekdays weights which while window windows " + "with write wsbrowser xedit xemacs xfig xinch xor xtabs xyinch yinch zapsmall", + // "Other Package Functions + "acme aids aircondit amis aml banking barchart barley beaver bigcity boot brambles " + "breslow bs bwplot calcium cane capability cav censboot channing city claridge cloth " + "cloud coal condense contourplot control corr darwin densityplot dogs dotplot ducks " + "empinf envelope environmental ethanol fir frets gpar grav gravity grob hirose histogram " + "islay knn larrows levelplot llines logit lpoints lsegments lset ltext lvqinit lvqtest manaus " + "melanoma melanoma motor multiedit neuro nitrofen nodal ns nuclear oneway parallel " + "paulsen poisons polar qq qqmath remission rfs saddle salinity shingle simplex singer " + "somgrid splom stripplot survival tau tmd tsboot tuna unit urine viewport wireframe wool xyplot", + // Unused + "", + // Unused + "", + // --- + "", "", "", "" +}; + + +EDITLEXER lexR = { SCLEX_R, 63045, L"R-S-SPlus Statistics Code", L"R", L"", &KeyWords_R,{ + { STYLE_DEFAULT, 63126, L"Default", L"", L"" }, + //{ SCE_R_DEFAULT, 63126, L"Default", L"", L"" }, + { SCE_R_COMMENT, 63127, L"Comment", L"fore:#008000", L"" }, + { SCE_R_KWORD, 63128, L"Keyword", L"bold; fore:#0A246A", L"" }, + { SCE_R_BASEKWORD, 63271, L"Base Package Functions", L"bold; fore:#7f0000", L"" }, + { SCE_R_OTHERKWORD, 63272, L"Other Package Functions", L"bold; fore:#7f007F", L"" }, + { SCE_R_NUMBER, 63130, L"Number", L"fore:#0000FF", L"" }, + { MULTI_STYLE(SCE_R_STRING,SCE_R_STRING2,0,0), 63131, L"String", L"italic; fore:#3C6CDD", L"" }, + { SCE_R_OPERATOR, 63132, L"Operator", L"bold; fore:#B000B0", L"" }, + { SCE_R_IDENTIFIER, 63129, L"Identifier", L"", L"" }, + { SCE_R_INFIX, 63269, L"Infix", L"fore:#660066", L"" }, + { SCE_R_INFIXEOL, 63270, L"Infix EOL", L"fore:#FF4000; ,back:#E0C0E0; eolfilled", L"" }, + { -1, 00000, L"", L"", L"" } } }; + + + // This array holds all the lexers... // Don't forget to change the number of the lexer for HTML and XML // in Notepad2.c ParseCommandLine() if you change this array! @@ -2865,6 +2958,7 @@ static PEDITLEXER g_pLexArray[NUMLEXERS] = &lexPL, // Perl Script &lexPS, // PowerShell Script &lexPY, // Python Script + &lexR, // R Statistics Code &lexRegistry, // Registry Files &lexRC, // Resource Script &lexRUBY, // Ruby Script diff --git a/src/Styles.h b/src/Styles.h index 6dc77bdfa..6b9eb1afc 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -61,7 +61,7 @@ typedef struct _editlexer // Number of Lexers in pLexArray -#define NUMLEXERS 46 +#define NUMLEXERS 47 #define AVG_NUM_OF_STYLES_PER_LEXER 20 From be2ddf00f67ea553c8e28b9877def5ec9e0c69e2 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 16 Feb 2018 00:01:23 +0100 Subject: [PATCH 3/8] + add: R-Statistics Code lexer + chg: Registry files lexer to support eolfilled on "Added Keys" --- scintilla/Scintilla.vcxproj | 1 + scintilla/Scintilla.vcxproj.filters | 3 + scintilla/lexers/LexRegistry.cxx | 73 ++++++++++++---------- scintilla/src/Catalogue.cxx | 2 +- src/Notepad3.rc | 5 ++ src/Styles.c | 96 ++++++++++++++++++++++++++++- src/Styles.h | 2 +- 7 files changed, 146 insertions(+), 36 deletions(-) diff --git a/scintilla/Scintilla.vcxproj b/scintilla/Scintilla.vcxproj index 70bbfe9c5..83943f36c 100644 --- a/scintilla/Scintilla.vcxproj +++ b/scintilla/Scintilla.vcxproj @@ -292,6 +292,7 @@ + diff --git a/scintilla/Scintilla.vcxproj.filters b/scintilla/Scintilla.vcxproj.filters index 458cb2b1d..73969f909 100644 --- a/scintilla/Scintilla.vcxproj.filters +++ b/scintilla/Scintilla.vcxproj.filters @@ -444,6 +444,9 @@ lexers + + lexers + diff --git a/scintilla/lexers/LexRegistry.cxx b/scintilla/lexers/LexRegistry.cxx index 779ea2f47..fa4ad4d07 100644 --- a/scintilla/lexers/LexRegistry.cxx +++ b/scintilla/lexers/LexRegistry.cxx @@ -78,16 +78,25 @@ class LexerRegistry : public DefaultLexer { return false; } + static bool AtEndOfLine(LexAccessor& styler, Sci_Position pos) { + //char curr; + //do { + // curr = styler.SafeGetCharAt(pos, '\0'); + // ++pos; + //} while (curr == ' ' || curr == '\t'); + const char curr = styler.SafeGetCharAt(pos, '\0'); + const char next = styler.SafeGetCharAt(pos+1, '\0'); + return (!curr || (curr == '\n') || (curr == '\r' && next != '\n')); + } + static bool IsNextNonWhitespace(LexAccessor &styler, Sci_Position start, char ch) { - Sci_Position i = 0; - while (i < 100) { - i++; - char curr = styler.SafeGetCharAt(start+i, '\0'); - char next = styler.SafeGetCharAt(start+i+1, '\0'); - bool atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); + while (!AtEndOfLine(styler, start + 1)) { + ++start; + char curr = styler.SafeGetCharAt(start, '\0'); + char next = styler.SafeGetCharAt(start+1, '\0'); if (curr == ch) { return true; - } else if (!isspacechar(curr) || atEOL) { + } else if (!isspacechar(curr)) { return false; } } @@ -96,21 +105,18 @@ class LexerRegistry : public DefaultLexer { // Looks for the equal sign at the end of the string static bool AtValueName(LexAccessor &styler, Sci_Position start) { - bool atEOL = false; - Sci_Position i = 0; bool escaped = false; - while (!atEOL) { - i++; - char curr = styler.SafeGetCharAt(start+i, '\0'); - char next = styler.SafeGetCharAt(start+i+1, '\0'); - atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); + while (!AtEndOfLine(styler, start + 1)) { + ++start; + char curr = styler.SafeGetCharAt(start, '\0'); + char next = styler.SafeGetCharAt(start+1, '\0'); if (escaped) { escaped = false; continue; } escaped = curr == '\\'; if (curr == '"') { - return IsNextNonWhitespace(styler, start+i, '='); + return IsNextNonWhitespace(styler, start, '='); } else if (!curr) { return false; } @@ -118,13 +124,12 @@ class LexerRegistry : public DefaultLexer { return false; } - static bool AtKeyPathEnd(LexAccessor &styler, Sci_Position start) { + static bool AtKeyPathEnd(LexAccessor& styler, Sci_Position start) { bool atEOL = false; - Sci_Position i = 0; - while (!atEOL) { - i++; - char curr = styler.SafeGetCharAt(start+i, '\0'); - char next = styler.SafeGetCharAt(start+i+1, '\0'); + while (!AtEndOfLine(styler, start + 1)) { + ++start; + char curr = styler.SafeGetCharAt(start, '\0'); + char next = styler.SafeGetCharAt(start+1, '\0'); atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); if (curr == ']' || !curr) { // There's still at least one or more square brackets ahead @@ -200,6 +205,7 @@ public: Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, @@ -207,9 +213,9 @@ public: }; void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, - Sci_Position length, - int initStyle, - IDocument *pAccess) { + Sci_Position length, + int initStyle, + IDocument *pAccess) { int beforeGUID = SCE_REG_DEFAULT; int beforeEscape = SCE_REG_DEFAULT; CharacterSet setOperators = CharacterSet(CharacterSet::setNone, "-,.=:\\@()"); @@ -217,7 +223,7 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, StyleContext context(startPos, length, initStyle, styler); bool highlight = true; bool afterEqualSign = false; - while (context.More()) { + while (context.More() && context.ch) { if (context.atLineStart) { Sci_Position currPos = static_cast(context.currentPos); bool continued = styler[currPos-3] == '\\'; @@ -270,7 +276,8 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, case SCE_REG_DELETEDKEY: case SCE_REG_ADDEDKEY: { Sci_Position currPos = static_cast(context.currentPos); - if (context.ch == ']' && AtKeyPathEnd(styler, currPos)) { + //if (context.ch == ']' && AtKeyPathEnd(styler, currPos)) { + if (AtEndOfLine(styler, currPos)) { context.ForwardSetState(SCE_REG_DEFAULT); } else if (context.ch == '{') { if (AtGUID(styler, currPos)) { @@ -300,9 +307,9 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, Sci_Position currPos = static_cast(context.currentPos); if (context.ch == '"' && IsStringState(context.state)) { context.ForwardSetState(SCE_REG_DEFAULT); - } else if (context.ch == ']' && - AtKeyPathEnd(styler, currPos) && - IsKeyPathState(context.state)) { + //} else if (context.ch == ']' && AtKeyPathEnd(styler, currPos) && + } else if (AtEndOfLine(styler, currPos) && + IsKeyPathState(context.state)) { context.ForwardSetState(SCE_REG_DEFAULT); } else if (context.ch == '\\' && IsStringState(context.state)) { beforeEscape = context.state; @@ -337,7 +344,7 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, if (wordStart && AtValueType(styler, currPos)) { context.SetState(SCE_REG_VALUETYPE); } - } else if (isxdigit(context.ch) && highlight) { + } else if (isxdigit(context.ch & 0xFF) && highlight) { context.SetState(SCE_REG_HEXDIGIT); } highlight = (context.ch == '@') ? true : highlight; @@ -409,7 +416,7 @@ void SCI_METHOD LexerRegistry::Fold(Sci_PositionU startPos, } LexerModule lmRegistry(SCLEX_REGISTRY, - LexerRegistry::LexerFactoryRegistry, - "registry", - RegistryWordListDesc); + LexerRegistry::LexerFactoryRegistry, + "registry", + RegistryWordListDesc); diff --git a/scintilla/src/Catalogue.cxx b/scintilla/src/Catalogue.cxx index b315f374b..717715644 100644 --- a/scintilla/src/Catalogue.cxx +++ b/scintilla/src/Catalogue.cxx @@ -162,7 +162,7 @@ int Scintilla_LinkLexers() { //LINK_LEXER(lmPS); //LINK_LEXER(lmPureBasic); LINK_LEXER(lmPython); - //LINK_LEXER(lmR); + LINK_LEXER(lmR); //LINK_LEXER(lmREBOL); LINK_LEXER(lmRegistry); LINK_LEXER(lmRuby); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 874c887c9..dc79060c5 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -1718,6 +1718,7 @@ BEGIN 63042 "Coffeescript" 63043 "MATLAB" 63044 "Nim Source Code" + 63045 "R-S-SPlus Statistics Code" END STRINGTABLE @@ -1935,6 +1936,10 @@ BEGIN 63266 "2nd Default Text" 63267 "Variable within String" 63268 "Ordered List" + 63269 "Infix" + 63270 "Infix EOL" + 63271 "Base Package Functions" + 63272 "Other Package Functions" END #endif // English (United States) resources diff --git a/src/Styles.c b/src/Styles.c index ffe14b11a..a680d5e49 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -97,7 +97,7 @@ EDITLEXER lexStandard2nd = { SCLEX_NULL, 63266, L"2nd Default Text", L"txt; text /* 9 */ { SCI_SETCARETFORE + SCI_SETCARETWIDTH, 63121, L"2nd Caret (Color, Size 1-3)", L"", L"" }, /* 10 */ { SCI_SETEDGECOLOUR, 63122, L"2nd Long Line Marker (Colors)", L"fore:#FFC000", L"" }, /* 11 */ { SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT, 63123, L"2nd Extra Line Spacing (Size)", L"", L"" }, - /* 12 */ { SCI_FOLDALL + SCI_MARKERSETALPHA, 63125, L"2nd Bookmarks and Folding (Colors)", L"fore:#000000; back:#00FF00; alpha:80; charset:2; case:U;", L"" }, + /* 12 */ { SCI_FOLDALL + SCI_MARKERSETALPHA, 63125, L"2nd Bookmarks and Folding (Colors)", L"fore:#000000; back:#00FF00; alpha:80; charset:2; case:U", L"" }, /* 13 */ { SCI_MARKERSETBACK + SCI_MARKERSETALPHA, 63263, L"2nd Mark Occurrences (Indicator)", L"fore:#0x00FF00; alpha:100; alpha2:220; indic_box", L"" }, /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, 63265, L"2nd Hyperlink Hotspots", L"bold; fore:#FF0000", L"" }, { -1, 00000, L"", L"", L"" } } }; @@ -2826,6 +2826,99 @@ EDITLEXER lexNimrod = { SCLEX_NIMROD, 63044, L"Nim Source Code", L"nim; nimrod", +KEYWORDLIST KeyWords_R = { + // Language Keywords + "if else repeat while function for in next break " + "TRUE FALSE NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character_", + // Base / Default package function + "abbreviate abline abs acf acos acosh addmargins aggregate agrep alarm alias alist " + "all anova any aov aperm append apply approx approxfun apropos ar args arima array " + "arrows asin asinh assign assocplot atan atanh attach attr attributes autoload autoloader ave axis " + "backsolve barplot basename beta bindtextdomain binomial biplot bitmap bmp body " + "box boxplot bquote break browser builtins bxp by bzfile c call cancor capabilities " + "casefold cat category cbind ccf ceiling character charmatch chartr chol choose " + "chull citation class close cm cmdscale codes coef coefficients col colnames colors " + "colorspaces colours comment complex confint conflicts contour contrasts contributors " + "convolve cophenetic coplot cor cos cosh cov covratio cpgram crossprod cummax cummin " + "cumprod cumsum curve cut cutree cycle data dataentry date dbeta dbinom dcauchy dchisq de " + "debug debugger decompose delay deltat demo dendrapply density deparse deriv det detach " + "determinant deviance dexp df dfbeta dfbetas dffits dgamma dgeom dget dhyper diag diff " + "diffinv difftime digamma dim dimnames dir dirname dist dlnorm dlogis dmultinom dnbinom " + "dnorm dotchart double dpois dput drop dsignrank dt dump dunif duplicated dweibull " + "dwilcox eapply ecdf edit effects eigen emacs embed end environment eval evalq " + "example exists exp expression factanal factor factorial family fft fifo file filter " + "find fitted fivenum fix floor flush for force formals format formula forwardsolve " + "fourfoldplot frame frequency ftable function gamma gaussian gc gcinfo gctorture get " + "getenv geterrmessage gettext gettextf getwd gl glm globalenv gray grep grey grid gsub " + "gzcon gzfile hat hatvalues hcl hclust head heatmap help hist history hsv httpclient " + "iconv iconvlist identical identify if ifelse image influence inherits integer integrate " + "interaction interactive intersect invisible isoreg jitter jpeg julian kappa kernapply " + "kernel kmeans knots kronecker ksmooth labels lag lapply layout lbeta lchoose lcm legend " + "length letters levels lfactorial lgamma library licence license line lines list lm load " + "loadhistory loadings local locator loess log logb logical loglin lowess ls lsfit machine mad " + "mahalanobis makepredictcall manova mapply match matlines matplot matpoints matrix max mean " + "median medpolish menu merge message methods mget min missing mode monthplot months " + "mosaicplot mtext mvfft names napredict naprint naresid nargs nchar ncol next nextn ngettext " + "nlevels nlm nls noquote nrow numeric objects offset open optim optimise optimize options " + "order ordered outer pacf page pairlist pairs palette par parse paste pbeta pbinom pbirthday " + "pcauchy pchisq pdf pentagamma person persp pexp pf pgamma pgeom phyper pi pico pictex pie " + "piechart pipe plclust plnorm plogis plot pmatch pmax pmin pnbinom png pnorm points poisson " + "poly polygon polym polyroot postscript power ppoints ppois ppr prcomp predict preplot " + "pretty princomp print prmatrix prod profile profiler proj promax prompt provide psigamma " + "psignrank pt ptukey punif pweibull pwilcox q qbeta qbinom qbirthday qcauchy qchisq qexp qf " + "qgamma qgeom qhyper qlnorm qlogis qnbinom qnorm qpois qqline qqnorm qqplot qr qsignrank qt " + "qtukey quantile quarters quasi quasibinomial quasipoisson quit qunif quote qweibull qwilcox " + "rainbow range rank raw rbeta rbind rbinom rcauchy rchisq readline real recover rect " + "reformulate regexpr relevel remove reorder rep repeat replace replicate replications require " + "reshape resid residuals restart return rev rexp rf rgamma rgb rgeom rhyper rle rlnorm rlogis rm " + "rmultinom rnbinom rnorm round row rownames rowsum rpois rsignrank rstandard rstudent rt " + "rug runif runmed rweibull rwilcox sample sapply save savehistory scale scan screen screeplot sd " + "search searchpaths seek segments seq sequence serialize setdiff setequal setwd shell sign " + "signif sin single sinh sink smooth solve sort source spectrum spline splinefun split sprintf " + "sqrt stack stars start stderr stdin stdout stem step stepfun stl stop stopifnot str strftime " + "strheight stripchart strptime strsplit strtrim structure strwidth strwrap sub subset " + "substitute substr substring sum summary sunflowerplot supsmu svd sweep switch symbols symnum " + "system t table tabulate tail tan tanh tapply tempdir tempfile termplot terms tetragamma " + "text time title toeplitz tolower topenv toupper trace traceback transform trigamma trunc " + "truncate try ts tsdiag tsp typeof unclass undebug union unique uniroot unix unlink unlist " + "unname unserialize unsplit unstack untrace unz update upgrade url var varimax vcov vector " + "version vi vignette warning warnings weekdays weights which while window windows " + "with write wsbrowser xedit xemacs xfig xinch xor xtabs xyinch yinch zapsmall", + // "Other Package Functions + "acme aids aircondit amis aml banking barchart barley beaver bigcity boot brambles " + "breslow bs bwplot calcium cane capability cav censboot channing city claridge cloth " + "cloud coal condense contourplot control corr darwin densityplot dogs dotplot ducks " + "empinf envelope environmental ethanol fir frets gpar grav gravity grob hirose histogram " + "islay knn larrows levelplot llines logit lpoints lsegments lset ltext lvqinit lvqtest manaus " + "melanoma melanoma motor multiedit neuro nitrofen nodal ns nuclear oneway parallel " + "paulsen poisons polar qq qqmath remission rfs saddle salinity shingle simplex singer " + "somgrid splom stripplot survival tau tmd tsboot tuna unit urine viewport wireframe wool xyplot", + // Unused + "", + // Unused + "", + // --- + "", "", "", "" +}; + + +EDITLEXER lexR = { SCLEX_R, 63045, L"R-S-SPlus Statistics Code", L"R", L"", &KeyWords_R,{ + { STYLE_DEFAULT, 63126, L"Default", L"", L"" }, + //{ SCE_R_DEFAULT, 63126, L"Default", L"", L"" }, + { SCE_R_COMMENT, 63127, L"Comment", L"fore:#008000", L"" }, + { SCE_R_KWORD, 63128, L"Keyword", L"bold; fore:#0A246A", L"" }, + { SCE_R_BASEKWORD, 63271, L"Base Package Functions", L"bold; fore:#7f0000", L"" }, + { SCE_R_OTHERKWORD, 63272, L"Other Package Functions", L"bold; fore:#7f007F", L"" }, + { SCE_R_NUMBER, 63130, L"Number", L"fore:#0000FF", L"" }, + { MULTI_STYLE(SCE_R_STRING,SCE_R_STRING2,0,0), 63131, L"String", L"italic; fore:#3C6CDD", L"" }, + { SCE_R_OPERATOR, 63132, L"Operator", L"bold; fore:#B000B0", L"" }, + { SCE_R_IDENTIFIER, 63129, L"Identifier", L"", L"" }, + { SCE_R_INFIX, 63269, L"Infix", L"fore:#660066", L"" }, + { SCE_R_INFIXEOL, 63270, L"Infix EOL", L"fore:#FF4000; ,back:#E0C0E0; eolfilled", L"" }, + { -1, 00000, L"", L"", L"" } } }; + + + // This array holds all the lexers... // Don't forget to change the number of the lexer for HTML and XML // in Notepad2.c ParseCommandLine() if you change this array! @@ -2865,6 +2958,7 @@ static PEDITLEXER g_pLexArray[NUMLEXERS] = &lexPL, // Perl Script &lexPS, // PowerShell Script &lexPY, // Python Script + &lexR, // R Statistics Code &lexRegistry, // Registry Files &lexRC, // Resource Script &lexRUBY, // Ruby Script diff --git a/src/Styles.h b/src/Styles.h index 6dc77bdfa..6b9eb1afc 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -61,7 +61,7 @@ typedef struct _editlexer // Number of Lexers in pLexArray -#define NUMLEXERS 46 +#define NUMLEXERS 47 #define AVG_NUM_OF_STYLES_PER_LEXER 20 From 76be9bfd8e203c367ef98a72775d749ff9f6002a Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 16 Feb 2018 12:30:58 +0100 Subject: [PATCH 4/8] + fix: bug in changed "Windows Registry Files" lexer --- scintilla/lexers/LexRegistry.cxx | 33 +++++++++++++++----------------- src/Edit.c | 2 +- src/Notepad3.c | 4 +--- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/scintilla/lexers/LexRegistry.cxx b/scintilla/lexers/LexRegistry.cxx index fa4ad4d07..f16fcb89f 100644 --- a/scintilla/lexers/LexRegistry.cxx +++ b/scintilla/lexers/LexRegistry.cxx @@ -32,7 +32,7 @@ using namespace Scintilla; static const char *const RegistryWordListDesc[] = { - 0 + nullptr }; struct OptionsRegistry { @@ -79,11 +79,6 @@ class LexerRegistry : public DefaultLexer { } static bool AtEndOfLine(LexAccessor& styler, Sci_Position pos) { - //char curr; - //do { - // curr = styler.SafeGetCharAt(pos, '\0'); - // ++pos; - //} while (curr == ' ' || curr == '\t'); const char curr = styler.SafeGetCharAt(pos, '\0'); const char next = styler.SafeGetCharAt(pos+1, '\0'); return (!curr || (curr == '\n') || (curr == '\r' && next != '\n')); @@ -125,13 +120,9 @@ class LexerRegistry : public DefaultLexer { } static bool AtKeyPathEnd(LexAccessor& styler, Sci_Position start) { - bool atEOL = false; while (!AtEndOfLine(styler, start + 1)) { - ++start; - char curr = styler.SafeGetCharAt(start, '\0'); - char next = styler.SafeGetCharAt(start+1, '\0'); - atEOL = (curr == '\r' && next != '\n') || (curr == '\n'); - if (curr == ']' || !curr) { + char curr = styler.SafeGetCharAt(++start, '\0'); + if (curr == ']') { // There's still at least one or more square brackets ahead return false; } @@ -193,7 +184,7 @@ public: return -1; } void *SCI_METHOD PrivateCall(int, void *) override { - return 0; + return nullptr; } static ILexer4 *LexerFactoryRegistry() { return new LexerRegistry; @@ -223,11 +214,16 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, StyleContext context(startPos, length, initStyle, styler); bool highlight = true; bool afterEqualSign = false; + int stateBefore = SCE_REG_DEFAULT; + while (context.More() && context.ch) { if (context.atLineStart) { Sci_Position currPos = static_cast(context.currentPos); bool continued = styler[currPos-3] == '\\'; highlight = continued ? true : false; + if (IsKeyPathState(context.state) && !highlight) { + context.SetState(SCE_REG_DEFAULT); + } } switch (context.state) { case SCE_REG_COMMENT: @@ -276,8 +272,7 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, case SCE_REG_DELETEDKEY: case SCE_REG_ADDEDKEY: { Sci_Position currPos = static_cast(context.currentPos); - //if (context.ch == ']' && AtKeyPathEnd(styler, currPos)) { - if (AtEndOfLine(styler, currPos)) { + if (context.ch == ']' && AtKeyPathEnd(styler, currPos)) { context.ForwardSetState(SCE_REG_DEFAULT); } else if (context.ch == '{') { if (AtGUID(styler, currPos)) { @@ -307,9 +302,7 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, Sci_Position currPos = static_cast(context.currentPos); if (context.ch == '"' && IsStringState(context.state)) { context.ForwardSetState(SCE_REG_DEFAULT); - //} else if (context.ch == ']' && AtKeyPathEnd(styler, currPos) && - } else if (AtEndOfLine(styler, currPos) && - IsKeyPathState(context.state)) { + } else if (context.ch == ']' && AtKeyPathEnd(styler, currPos) && IsKeyPathState(context.state)) { context.ForwardSetState(SCE_REG_DEFAULT); } else if (context.ch == '\\' && IsStringState(context.state)) { beforeEscape = context.state; @@ -347,11 +340,15 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, } else if (isxdigit(context.ch & 0xFF) && highlight) { context.SetState(SCE_REG_HEXDIGIT); } + else if (context.chPrev == ']' && !IsNextNonWhitespace(styler, currPos-1, ';')) { + context.SetState(stateBefore); // continue Reg-Key style for eolfilled + } highlight = (context.ch == '@') ? true : highlight; if (setOperators.Contains(context.ch) && highlight) { context.SetState(SCE_REG_OPERATOR); } } + stateBefore = context.state; context.Forward(); } context.Complete(); diff --git a/src/Edit.c b/src/Edit.c index a97d79065..e27bf1feb 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -4244,7 +4244,7 @@ void EditJumpTo(HWND hwnd, DocLn iNewLine, DocPos iNewCol) // void EditFixPositions(HWND hwnd) { - DocPos iMaxPos = SciCall_GetTextLength();; + DocPos iMaxPos = SciCall_GetTextLength(); DocPos iCurrentPos = SciCall_GetCurrentPos(); DocPos iAnchorPos = SciCall_GetAnchor(); diff --git a/src/Notepad3.c b/src/Notepad3.c index 2088ec8ab..fe7bf7330 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -3503,10 +3503,8 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) case SCLEX_AHK: case SCLEX_NSIS: // # could also be used instead case SCLEX_INNOSETUP: - EditToggleLineComments(g_hwndEdit, L";", TRUE); - break; case SCLEX_REGISTRY: - EditToggleLineComments(g_hwndEdit, L";;", TRUE); + EditToggleLineComments(g_hwndEdit, L";", TRUE); break; case SCLEX_SQL: case SCLEX_LUA: From 164bd4106adb824f1480bc11d041c0a94547b80d Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 16 Feb 2018 12:59:28 +0100 Subject: [PATCH 5/8] + fix: Undo/Redo action w/o selection sets/preserves selection mode (bug) --- src/Notepad3.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index fe7bf7330..c8f5f6980 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -7263,8 +7263,6 @@ void RestoreAction(int token, DoAction doAct) // we are inside undo/redo transaction, so do delayed PostMessage() instead of SendMessage() #define ISSUE_MESSAGE PostMessage - ISSUE_MESSAGE(g_hwndEdit, SCI_CANCEL, 0, 0); // prepare - not needed ? - const DocPos _anchorPos = (doAct == UNDO ? sel.anchorPos_undo : sel.anchorPos_redo); const DocPos _curPos = (doAct == UNDO ? sel.curPos_undo : sel.curPos_redo); @@ -7279,7 +7277,7 @@ void RestoreAction(int token, DoAction doAct) const int selectionMode = (doAct == UNDO ? sel.selMode_undo : sel.selMode_redo); ISSUE_MESSAGE(g_hwndEdit, SCI_SETSELECTIONMODE, (WPARAM)selectionMode, 0); - // independant from selection mode + // independent from selection mode ISSUE_MESSAGE(g_hwndEdit, SCI_SETANCHOR, (WPARAM)_anchorPos, 0); ISSUE_MESSAGE(g_hwndEdit, SCI_SETCURRENTPOS, (WPARAM)_curPos, 0); @@ -7307,8 +7305,7 @@ void RestoreAction(int token, DoAction doAct) // nothing to do here break; } - - //ISSUE_MESSAGE(g_hwndEdit, SCI_CANCEL, 0, 0); + ISSUE_MESSAGE(g_hwndEdit, SCI_CANCEL, 0, 0); #undef ISSUE_MASSAGE } From 7a20c52a172b517da92da06bccac4b2a2900216b Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 16 Feb 2018 15:33:23 +0100 Subject: [PATCH 6/8] + fix: support styler attribute "eolfilled" in any Reg-Key case (Windows Registry Lexer) --- scintilla/lexers/LexRegistry.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scintilla/lexers/LexRegistry.cxx b/scintilla/lexers/LexRegistry.cxx index f16fcb89f..0c14318f6 100644 --- a/scintilla/lexers/LexRegistry.cxx +++ b/scintilla/lexers/LexRegistry.cxx @@ -340,13 +340,13 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, } else if (isxdigit(context.ch & 0xFF) && highlight) { context.SetState(SCE_REG_HEXDIGIT); } - else if (context.chPrev == ']' && !IsNextNonWhitespace(styler, currPos-1, ';')) { - context.SetState(stateBefore); // continue Reg-Key style for eolfilled - } highlight = (context.ch == '@') ? true : highlight; if (setOperators.Contains(context.ch) && highlight) { context.SetState(SCE_REG_OPERATOR); } + if (context.chPrev == ']' && !IsNextNonWhitespace(styler, currPos - 1, ';')) { + context.SetState(stateBefore); // continue Reg-Key style for eolfilled + } } stateBefore = context.state; context.Forward(); From 1e71f4199ad8081b665ccdceafbec6d960ca1b6e Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 16 Feb 2018 17:22:10 +0100 Subject: [PATCH 7/8] + fix: small datatype correction ... --- scintilla/lexers/LexRegistry.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scintilla/lexers/LexRegistry.cxx b/scintilla/lexers/LexRegistry.cxx index 0c14318f6..d2a37740a 100644 --- a/scintilla/lexers/LexRegistry.cxx +++ b/scintilla/lexers/LexRegistry.cxx @@ -64,6 +64,10 @@ class LexerRegistry : public DefaultLexer { return (state == SCE_REG_ADDEDKEY || state == SCE_REG_DELETEDKEY); } + static bool IsByteValue(int value) { + return ((value >= 0) && (value < 256)); + } + static bool AtValueType(LexAccessor &styler, Sci_Position start) { Sci_Position i = 0; while (i < 10) { @@ -337,7 +341,7 @@ void SCI_METHOD LexerRegistry::Lex(Sci_PositionU startPos, if (wordStart && AtValueType(styler, currPos)) { context.SetState(SCE_REG_VALUETYPE); } - } else if (isxdigit(context.ch & 0xFF) && highlight) { + } else if (IsByteValue(context.ch) && isxdigit(context.ch & 0xFF) && highlight) { context.SetState(SCE_REG_HEXDIGIT); } highlight = (context.ch == '@') ? true : highlight; From 16de55821749c5ff815328a49d5c8c006df7ebe1 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 16 Feb 2018 19:49:34 +0100 Subject: [PATCH 8/8] + fix: map Toolbar Labels according to bitmap/settings file --- src/Notepad3.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index c8f5f6980..a5eacd513 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1432,21 +1432,21 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance) pIniSection = LocalAlloc(LPTR,sizeof(WCHAR) * 32 * 1024); cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR); LoadIniSection(L"Toolbar Labels",pIniSection,cchIniSection); - n = 1; for (i = 0; i < COUNTOF(tbbMainWnd); i++) { if (tbbMainWnd[i].fsStyle == TBSTYLE_SEP) continue; - StringCchPrintf(tchIndex,COUNTOF(tchIndex),L"%02i",n++); - - if (IniSectionGetString(pIniSection,tchIndex,L"",tchDesc,COUNTOF(tchDesc))) { + n = tbbMainWnd[i].iBitmap + 1; + StringCchPrintf(tchIndex,COUNTOF(tchIndex),L"%02i",n); + if (IniSectionGetString(pIniSection,tchIndex,L"",tchDesc,COUNTOF(tchDesc))) + { tbbMainWnd[i].iString = SendMessage(g_hwndToolbar,TB_ADDSTRING,0,(LPARAM)tchDesc); tbbMainWnd[i].fsStyle |= BTNS_AUTOSIZE | BTNS_SHOWTEXT; } - - else + else { tbbMainWnd[i].fsStyle &= ~(BTNS_AUTOSIZE | BTNS_SHOWTEXT); + } } LocalFree(pIniSection);