3
3
// File: LexMetapost.cxx - general context conformant metapost coloring scheme
4
4
// Author: Hans Hagen - PRAGMA ADE - Hasselt NL - www.pragma-ade.com
5
5
// Version: September 28, 2003
6
// Modified by instanton: July 10, 2007
7
// Folding based on keywordlists[]
7
9
// Copyright: 1998-2003 by Neil Hodgson <neilh@scintilla.org>
8
10
// The License.txt file describes the conditions under which this software may be distributed.
320
LexerModule lmMETAPOST(SCLEX_METAPOST, ColouriseMETAPOSTDoc, "metapost", 0, metapostWordListDesc);
326
static int classifyFoldPointMetapost(const char* s,WordList *keywordlists[]) {
327
WordList& keywordsStart=*keywordlists[3];
328
WordList& keywordsStop1=*keywordlists[4];
330
if (keywordsStart.InList(s)) {return 1;}
331
else if (keywordsStop1.InList(s)) {return -1;}
336
static int ParseMetapostWord(unsigned int pos, Accessor &styler, char *word)
339
char ch=styler.SafeGetCharAt(pos);
342
while(isMETAPOSTidentifier(ch) && isalpha(ch) && length<100){
345
ch=styler.SafeGetCharAt(pos+length);
351
static void FoldMetapostDoc(unsigned int startPos, int length, int, WordList *keywordlists[], Accessor &styler)
353
bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
354
unsigned int endPos = startPos+length;
356
int lineCurrent=styler.GetLine(startPos);
357
int levelPrev=styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
358
int levelCurrent=levelPrev;
359
char chNext=styler[startPos];
363
for (unsigned int i=startPos; i < endPos; i++) {
365
chNext=styler.SafeGetCharAt(i+1);
366
char chPrev=styler.SafeGetCharAt(i-1);
367
bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
369
if(i==0 || chPrev == '\r' || chPrev=='\n'|| chPrev==' '|| chPrev=='(' || chPrev=='$')
371
ParseMetapostWord(i, styler, buffer);
372
levelCurrent += classifyFoldPointMetapost(buffer,keywordlists);
377
if (visibleChars == 0 && foldCompact)
378
lev |= SC_FOLDLEVELWHITEFLAG;
379
if ((levelCurrent > levelPrev) && (visibleChars > 0))
380
lev |= SC_FOLDLEVELHEADERFLAG;
381
if (lev != styler.LevelAt(lineCurrent)) {
382
styler.SetLevel(lineCurrent, lev);
385
levelPrev = levelCurrent;
389
if (!isspacechar(ch))
392
// Fill in the real level of the next line, keeping the current flags as they will be filled in later
393
int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
394
styler.SetLevel(lineCurrent, levelPrev | flagsNext);
399
LexerModule lmMETAPOST(SCLEX_METAPOST, ColouriseMETAPOSTDoc, "metapost", FoldMetapostDoc, metapostWordListDesc);