Skip to content
This repository has been archived by the owner on Aug 12, 2018. It is now read-only.

Commit

Permalink
Update Scintilla to d887fc
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed May 19, 2013
1 parent f3c286f commit a73c531
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 82 deletions.
1 change: 1 addition & 0 deletions scintilla/include/Scintilla.iface
Original file line number Diff line number Diff line change
Expand Up @@ -2578,6 +2578,7 @@ val SCLEX_AVS=104
val SCLEX_ECL=105
val SCLEX_OSCRIPT=106
val SCLEX_VISUALPROLOG=107
val SCLEX_LITERATEHASKELL=108
## notepad2 custom code for the AHK lexer - start
val SCLEX_AHK=200
## notepad2 custom code for the AHK lexer - end
Expand Down
166 changes: 87 additions & 79 deletions scintilla/lexers/LexHaskell.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
using namespace Scintilla;
#endif

#define INDENT_OFFSET 1

static int u_iswalpha(int);
static int u_iswalnum(int);
static int u_iswupper(int);
Expand Down Expand Up @@ -141,10 +139,63 @@ static inline bool IsExternalStyle(int style) {
|| style == SCE_HA_LITERATE_CODEDELIM);
}

inline int CommentBlockStyleFromNestLevel(const unsigned int nestLevel) {
static inline int CommentBlockStyleFromNestLevel(const unsigned int nestLevel) {
return SCE_HA_COMMENTBLOCK + (nestLevel % 3);
}

// Mangled version of lexlib/Accessor.cxx IndentAmount.
// Modified to treat comment blocks as whitespace
// plus special case for commentline/preprocessor.
static int HaskellIndentAmount(Accessor &styler, const int line) {

// Determines the indentation level of the current line
// Comment blocks are treated as whitespace

int pos = styler.LineStart(line);
int eol_pos = styler.LineStart(line + 1) - 1;

char ch = styler[pos];
int style = styler.StyleAt(pos);

int indent = 0;
bool inPrevPrefix = line > 0;

int posPrev = inPrevPrefix ? styler.LineStart(line-1) : 0;

while (( ch == ' ' || ch == '\t'
|| IsCommentBlockStyle(style)
|| style == SCE_HA_LITERATE_CODEDELIM)
&& (pos < eol_pos)) {
if (inPrevPrefix) {
char chPrev = styler[posPrev++];
if (chPrev != ' ' && chPrev != '\t') {
inPrevPrefix = false;
}
}
if (ch == '\t') {
indent = (indent / 8 + 1) * 8;
} else { // Space or comment block
indent++;
}
pos++;
ch = styler[pos];
style = styler.StyleAt(pos);
}

indent += SC_FOLDLEVELBASE;
// if completely empty line or the start of a comment or preprocessor...
if ( styler.LineStart(line) == styler.Length()
|| ch == ' '
|| ch == '\t'
|| ch == '\n'
|| ch == '\r'
|| IsCommentStyle(style)
|| style == SCE_HA_PREPROCESSOR)
return indent | SC_FOLDLEVELWHITEFLAG;
else
return indent;
}

struct OptionsHaskell {
bool magicHash;
bool allowQuotes;
Expand Down Expand Up @@ -224,6 +275,7 @@ struct OptionSetHaskell : public OptionSet<OptionsHaskell> {
class LexerHaskell : public ILexer {
bool literate;
int firstImportLine;
int firstImportIndent;
WordList keywords;
WordList ffi;
WordList reserved_operators;
Expand Down Expand Up @@ -310,7 +362,8 @@ class LexerHaskell : public ILexer {
style = styler.StyleAt(currentPos);

if (ch == ' ' || ch == '\t'
|| IsCommentBlockStyle(style)) {
|| IsCommentBlockStyle(style)
|| style == SCE_HA_LITERATE_CODEDELIM) {
currentPos++;
} else {
break;
Expand All @@ -324,8 +377,26 @@ class LexerHaskell : public ILexer {
}
}

inline int IndentAmountWithOffset(Accessor &styler, const int line) const {
const int indent = HaskellIndentAmount(styler, line);
const int indentLevel = indent & SC_FOLDLEVELNUMBERMASK;
return indentLevel <= ((firstImportIndent - 1) + SC_FOLDLEVELBASE)
? indent
: (indentLevel + firstImportIndent) | (indent & ~SC_FOLDLEVELNUMBERMASK);
}

inline int IndentLevelRemoveIndentOffset(const int indentLevel) const {
return indentLevel <= ((firstImportIndent - 1) + SC_FOLDLEVELBASE)
? indentLevel
: indentLevel - firstImportIndent;
}

public:
LexerHaskell(const bool literate_) : literate(literate_), firstImportLine(-1) {}
LexerHaskell(bool literate_)
: literate(literate_)
, firstImportLine(-1)
, firstImportIndent(0)
{}
virtual ~LexerHaskell() {}

void SCI_METHOD Release() {
Expand Down Expand Up @@ -893,80 +964,20 @@ void SCI_METHOD LexerHaskell::Lex(unsigned int startPos, int length, int initSty
sc.Complete();
}

// Mangled version of lexlib/Accessor.cxx IndentAmount.
// Modified to treat comment blocks as whitespace
// plus special case for commentline/preprocessor.
static int HaskellIndentAmount(Accessor &styler, int line) {

// Determines the indentation level of the current line
// Comment blocks are treated as whitespace

int pos = styler.LineStart(line);
int eol_pos = styler.LineStart(line + 1) - 1;

char ch = styler[pos];
int style = styler.StyleAt(pos);

int indent = 0;
bool inPrevPrefix = line > 0;

int posPrev = inPrevPrefix ? styler.LineStart(line-1) : 0;

while (( ch == ' ' || ch == '\t'
|| IsCommentBlockStyle(style)
|| style == SCE_HA_LITERATE_CODEDELIM)
&& (pos < eol_pos)) {
if (inPrevPrefix) {
char chPrev = styler[posPrev++];
if (chPrev != ' ' && chPrev != '\t') {
inPrevPrefix = false;
}
}
if (ch == '\t') {
indent = (indent / 8 + 1) * 8;
} else { // Space or comment block
indent++;
}
pos++;
ch = styler[pos];
style = styler.StyleAt(pos);
}

indent += SC_FOLDLEVELBASE;
// if completely empty line or the start of a comment or preprocessor...
if ( styler.LineStart(line) == styler.Length()
|| ch == ' '
|| ch == '\t'
|| ch == '\n'
|| ch == '\r'
|| IsCommentStyle(style)
|| style == SCE_HA_PREPROCESSOR)
return indent | SC_FOLDLEVELWHITEFLAG;
else
return indent;
}

static inline int IndentAmountWithOffset(Accessor &styler, int line) {
int indent = HaskellIndentAmount(styler, line);
int indentLevel = indent & SC_FOLDLEVELNUMBERMASK;
return indentLevel == (SC_FOLDLEVELBASE & SC_FOLDLEVELNUMBERMASK)
? indent
: (indentLevel + INDENT_OFFSET) | (indent & ~SC_FOLDLEVELNUMBERMASK);
}

static inline int RemoveIndentOffset(int indentLevel) {
return indentLevel == (SC_FOLDLEVELBASE & SC_FOLDLEVELNUMBERMASK)
? indentLevel
: indentLevel - INDENT_OFFSET;
}

void SCI_METHOD LexerHaskell::Fold(unsigned int startPos, int length, int // initStyle
,IDocument *pAccess) {
if (!options.fold)
return;

Accessor styler(pAccess, NULL);

int lineCurrent = styler.GetLine(startPos);

if (lineCurrent <= firstImportLine) {
firstImportLine = -1; // readjust first import position
firstImportIndent = 0;
}

const int maxPos = startPos + length;
const int maxLines =
maxPos == styler.Length()
Expand All @@ -978,7 +989,6 @@ void SCI_METHOD LexerHaskell::Fold(unsigned int startPos, int length, int // ini
// for any white space lines
// and so we can fix any preceding fold level (which is why we go back
// at least one line in all cases)
int lineCurrent = styler.GetLine(startPos);
bool importHere = LineContainsImport(lineCurrent, styler);
int indentCurrent = IndentAmountWithOffset(styler, lineCurrent);

Expand All @@ -992,15 +1002,12 @@ void SCI_METHOD LexerHaskell::Fold(unsigned int startPos, int length, int // ini

int indentCurrentLevel = indentCurrent & SC_FOLDLEVELNUMBERMASK;

if (lineCurrent <= firstImportLine) {
firstImportLine = -1; // readjust first import position
}

if (importHere) {
indentCurrentLevel = IndentLevelRemoveIndentOffset(indentCurrentLevel);
if (firstImportLine == -1) {
firstImportLine = lineCurrent;
firstImportIndent = (1 + indentCurrentLevel) - SC_FOLDLEVELBASE;
}
indentCurrentLevel = RemoveIndentOffset(indentCurrentLevel);
if (firstImportLine != lineCurrent) {
indentCurrentLevel++;
}
Expand Down Expand Up @@ -1040,10 +1047,11 @@ void SCI_METHOD LexerHaskell::Fold(unsigned int startPos, int length, int // ini
int indentNextLevel = indentNext & SC_FOLDLEVELNUMBERMASK;

if (importHere) {
indentNextLevel = IndentLevelRemoveIndentOffset(indentNextLevel);
if (firstImportLine == -1) {
firstImportLine = lineNext;
firstImportIndent = (1 + indentNextLevel) - SC_FOLDLEVELBASE;
}
indentNextLevel = RemoveIndentOffset(indentNextLevel);
if (firstImportLine != lineNext) {
indentNextLevel++;
}
Expand Down
4 changes: 2 additions & 2 deletions scintilla/src/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4147,7 +4147,7 @@ void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) {
if (treatAsDBCS) {
NotifyChar((static_cast<unsigned char>(s[0]) << 8) |
static_cast<unsigned char>(s[1]));
} else {
} else if (len > 0) {
int byte = static_cast<unsigned char>(s[0]);
if ((byte < 0xC0) || (1 == len)) {
// Handles UTF-8 characters between 0x01 and 0x7F and single byte
Expand Down Expand Up @@ -7149,7 +7149,7 @@ void Editor::FoldAll(int action) {
}
}
if (expanding) {
cs.SetVisible(0, maxLine, true);
cs.SetVisible(0, maxLine-1, true);
for (int line = 0; line < maxLine; line++) {
int levelLine = pdoc->GetLevel(line);
if (levelLine & SC_FOLDLEVELHEADERFLAG) {
Expand Down
1 change: 0 additions & 1 deletion scintilla/src/PositionCache.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ BreakFinder::BreakFinder(LineLayout *ll_, int lineStart_, int lineEnd_, int posL
saeNext(0),
subBreak(-1),
pdoc(pdoc_) {
selAndEdge.resize(1);

// Search for first visible break
// First find the first visible character
Expand Down

0 comments on commit a73c531

Please sign in to comment.