Commits

Andreas Tscharner committed 4926625

Make embedded code a little bit larger

Due to this change a lot a newlines had to be inserted to make the whole code
readable

Comments (0)

Files changed (1)

Scintilla-var'aq-Tutorial.tex

 
 \usepackage{listings}
 \lstset{language=C++,
-basicstyle=\tiny \ttfamily,
+basicstyle=\small \ttfamily,
 keywordstyle=,
 identifierstyle=\color{blue},
 commentstyle=\color{lightgrey},
     virtual int SCI_METHOD PropertySet(const char *key, const char *val) = 0;
     virtual const char * SCI_METHOD DescribeWordListSets() = 0;
     virtual int SCI_METHOD WordListSet(int n, const char *wl) = 0;
-    virtual void SCI_METHOD Lex(unsigned int startPos, int lengthDoc, int initStyle, IDocument *pAccess) = 0;
-    virtual void SCI_METHOD Fold(unsigned int startPos, int lengthDoc, int initStyle, IDocument *pAccess) = 0;
+    virtual void SCI_METHOD Lex(unsigned int startPos, int lengthDoc,
+	  int initStyle, IDocument *pAccess) = 0;
+    virtual void SCI_METHOD Fold(unsigned int startPos, int lengthDoc,
+	  int initStyle, IDocument *pAccess) = 0;
     virtual void * SCI_METHOD PrivateCall(int operation, void *pointer) = 0;
 };
 \end{lstlisting}
  ** Used for the Scintilla-var'aq-Tutorial
  **/
 // Copyright 2013-2014 by Andreas Tscharner <andy@vis.ethz.ch>
-// The License.txt file describes the conditions under which this software may be distributed.
+// The License.txt file describes the conditions under which this
+// software may be distributed.
 
 
 #include "ILexer.h"
 			return -1;
 		}
 
-		void SCI_METHOD Lex(unsigned int startPos, int lengthDoc, int initStyle, IDocument *pAccess);
-		void SCI_METHOD Fold(unsigned int startPos, int lengthDoc, int initStyle, IDocument *pAccess) {}
+		void SCI_METHOD Lex(unsigned int startPos, int lengthDoc,
+		  int initStyle, IDocument *pAccess);
+		void SCI_METHOD Fold(unsigned int startPos, int lengthDoc,
+		  int initStyle, IDocument *pAccess) {}
 
 		void * SCI_METHOD PrivateCall(int operation, void *pointer) {
 			return NULL;
 So we start to find such tokens in the document and add the \verb+COMMENT+{}
 style to the range from start to the end.
 \begin{lstlisting}
-void SCI_METHOD LexerVaraq::Lex(unsigned int startPos, int lengthDoc, int initStyle, IDocument *pAccess)
+void SCI_METHOD LexerVaraq::Lex(unsigned int startPos, int lengthDoc,
+  int initStyle, IDocument *pAccess)
 {
 	LexAccessor styler(pAccess);
 	StyleContext scCTX(startPos, lengthDoc, initStyle, styler);
 \emph{var'aq} default block to switch to \emph{var'aq} string style:
 
 \begin{lstlisting}
-				if (scCTX.Match('\"')) {
-					scCTX.SetState(SCE_VARAQ_STRING);
-					break;
-				};
+if (scCTX.Match('\"')) {
+	scCTX.SetState(SCE_VARAQ_STRING);
+	break;
+};
 \end{lstlisting}
 
 and we add a new block in case of a string and switch back to the default
 style:
 
 \begin{lstlisting}
-			case SCE_VARAQ_STRING :
-				if (scCTX.Match('\"')) {
-					scCTX.ForwardSetState(SCE_VARAQ_DEFAULT);
-				};
-				break;
+case SCE_VARAQ_STRING :
+	if (scCTX.Match('\"')) {
+		scCTX.ForwardSetState(SCE_VARAQ_DEFAULT);
+	};
+	break;
 \end{lstlisting}
 
 That's all to get the strings highlighted:
 check for a negative sign followed by a digit or just for a digit:
 
 \begin{lstlisting}
-				if (IsADigit(scCTX.ch) || (scCTX.Match('-') && IsADigit(scCTX.chNext))) {
-					scCTX.SetState(SCE_VARAQ_NUMBER);
-					pointInNumberUsed = false;
-					break;
-				};
+if (IsADigit(scCTX.ch) || (scCTX.Match('-') && IsADigit(scCTX.chNext))) {
+	scCTX.SetState(SCE_VARAQ_NUMBER);
+	pointInNumberUsed = false;
+	break;
+};
 \end{lstlisting}
 
 We can keep the number style as long as digits follow or at maximum one
 is a variable of type \lstinline[basicstyle=\small]+bool+:
 
 \begin{lstlisting}
-			case SCE_VARAQ_NUMBER :
-				if (scCTX.Match('.')) {
-					if (pointInNumberUsed) {
-						scCTX.SetState(SCE_VARAQ_DEFAULT);
-					} else {
-						pointInNumberUsed = true;
-					};
-				} else {
-					if (!IsADigit(scCTX.ch)) {
-						scCTX.SetState(SCE_VARAQ_DEFAULT);
-					};
-				};
-				break;
+case SCE_VARAQ_NUMBER :
+	if (scCTX.Match('.')) {
+		if (pointInNumberUsed) {
+			scCTX.SetState(SCE_VARAQ_DEFAULT);
+		} else {
+			pointInNumberUsed = true;
+		};
+	} else {
+		if (!IsADigit(scCTX.ch)) {
+			scCTX.SetState(SCE_VARAQ_DEFAULT);
+		};
+	};
+	break;
 \end{lstlisting}
 
 As usual the new style (the numbers) is red; the strings have become green:
 
 \begin{lstlisting}
 static const char *const VaraqKeywords = {
-	"woD latlh tam chImmoH qaw qawHa\' Hotlh pong cher HIja\'chugh ghobe\'chugh wIv"
-	"chov nargh vangqa\' SIj muv ghorqu\' chIm\'a\' tlheghrar naQmoH tlheghrap\'a\'"
-	"tlheghpe\' tlheghjuv jor boq boqHa\' boq\'egh boqHa\'\'egh HabboqHa\'\'egh"
-	"chuv boqHa\'qa\' loS\'ar wa\'boq wa\'boqHa\' joq joqHa\' qojmI\' qojHa\'"
-	"ghurtaH maHghurtaH wejghurtaH poD Hab \'ar mIScher mIS HeHmI\' ghurmI\'"
-	"HabmI\'\'a\' mI\'\'a\' mI\'moH mobmoH DuD tlhoch Qo\'moH nIHghoS poSghoS"
-	"law\'\'a\' puS\'a\' rap\'a\' law\'rap\'a\' puSrap\'a\' rapbe\'a\' pagh\'a\'"
-	"taH\'a\' je joq ghap ghobe\' cha\' \'Ij bep chu\'DonwI\' chu\'tut nuqDaq_jIH"
-	"pongmI\' taghDe\'"
+  "woD latlh tam chImmoH qaw qawHa\' Hotlh pong cher HIja\'chugh ghobe\'chugh wIv"
+  "chov nargh vangqa\' SIj muv ghorqu\' chIm\'a\' tlheghrar naQmoH tlheghrap\'a\'"
+  "tlheghpe\' tlheghjuv jor boq boqHa\' boq\'egh boqHa\'\'egh HabboqHa\'\'egh"
+  "chuv boqHa\'qa\' loS\'ar wa\'boq wa\'boqHa\' joq joqHa\' qojmI\' qojHa\'"
+  "ghurtaH maHghurtaH wejghurtaH poD Hab \'ar mIScher mIS HeHmI\' ghurmI\'"
+  "HabmI\'\'a\' mI\'\'a\' mI\'moH mobmoH DuD tlhoch Qo\'moH nIHghoS poSghoS"
+  "law\'\'a\' puS\'a\' rap\'a\' law\'rap\'a\' puSrap\'a\' rapbe\'a\' pagh\'a\'"
+  "taH\'a\' je joq ghap ghobe\' cha\' \'Ij bep chu\'DonwI\' chu\'tut nuqDaq_jIH"
+  "pongmI\' taghDe\'"
 };
 \end{lstlisting}
 
 helping state \lstinline[basicstyle=\small]+SCE_VARAQ_IDENTIFIER+:
 
 \begin{lstlisting}
-		switch (scCTX.state) {
-			case SCE_VARAQ_DEFAULT :
-				if (setKeywordChars.Contains(scCTX.ch)) {
-					scCTX.SetState(SCE_VARAQ_IDENTIFIER);
-					break;
-				};
+switch (scCTX.state) {
+	case SCE_VARAQ_DEFAULT :
+		if (setKeywordChars.Contains(scCTX.ch)) {
+			scCTX.SetState(SCE_VARAQ_IDENTIFIER);
+			break;
 		};
+};
 \end{lstlisting}
 
 Now all possible words have the \lstinline[basicstyle=\small]+SCE_VARAQ_IDENTIFIER+
 state again.
 
 \begin{lstlisting}
-			case SCE_VARAQ_IDENTIFIER :
-				if (!setKeywordChars.Contains(scCTX.ch)) {
-					tmpStr = new char[MAX_STR_LEN];
-					memset(tmpStr, 0, sizeof(char)*MAX_STR_LEN);
-					scCTX.GetCurrent(tmpStr, MAX_STR_LEN);
+case SCE_VARAQ_IDENTIFIER :
+	if (!setKeywordChars.Contains(scCTX.ch)) {
+		tmpStr = new char[MAX_STR_LEN];
+		memset(tmpStr, 0, sizeof(char)*MAX_STR_LEN);
+		scCTX.GetCurrent(tmpStr, MAX_STR_LEN);
 
-					if (vqKeywords.InList(tmpStr)) {
-						scCTX.ChangeState(SCE_VARAQ_KEYWORD);
-					};
-					scCTX.SetState(SCE_VARAQ_DEFAULT);
+		if (vqKeywords.InList(tmpStr)) {
+			scCTX.ChangeState(SCE_VARAQ_KEYWORD);
+		};
+		scCTX.SetState(SCE_VARAQ_DEFAULT);
 
-					delete[] tmpStr;
-				};
-				break;
+		delete[] tmpStr;
+	};
+	break;
 \end{lstlisting}
 
 Finally, our program is almost completely highlighted (keywords are red):
 curly braces (\{ and \}). The code is a little bit different as there is no
 StyleContext this time.
 \begin{lstlisting}
-void SCI_METHOD LexerVaraq::Fold(unsigned int startPos, int lengthDoc, int initStyle, IDocument *pAccess)
+void SCI_METHOD LexerVaraq::Fold(unsigned int startPos, int lengthDoc,
+  int initStyle, IDocument *pAccess)
 {
 	LexAccessor styler(pAccess);
 	unsigned int endPos = startPos + lengthDoc;
 What is left now? We also have to set up some stuff in the controlling
 application:
 \begin{lstlisting}
-	#define MARGIN_SCRIPT_FOLD_INDEX 1
+#define MARGIN_SCRIPT_FOLD_INDEX 1
 
 
-	SSM(SCI_SETMARGINTYPEN, MARGIN_SCRIPT_FOLD_INDEX, SC_MARGIN_SYMBOL);
-	SSM(SCI_SETMARGINMASKN, MARGIN_SCRIPT_FOLD_INDEX, SC_MASK_FOLDERS);
-	SSM(SCI_SETMARGINWIDTHN, MARGIN_SCRIPT_FOLD_INDEX, 20);
-	SSM(SCI_SETMARGINSENSITIVEN, MARGIN_SCRIPT_FOLD_INDEX, 1);
+SSM(SCI_SETMARGINTYPEN, MARGIN_SCRIPT_FOLD_INDEX, SC_MARGIN_SYMBOL);
+SSM(SCI_SETMARGINMASKN, MARGIN_SCRIPT_FOLD_INDEX, SC_MASK_FOLDERS);
+SSM(SCI_SETMARGINWIDTHN, MARGIN_SCRIPT_FOLD_INDEX, 20);
+SSM(SCI_SETMARGINSENSITIVEN, MARGIN_SCRIPT_FOLD_INDEX, 1);
 
-	SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS);
-	SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS);
-	SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY);
-	SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY);
-	SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY);
-	SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY);
-	SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_EMPTY);
+SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS);
+SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS);
+SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY);
+SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY);
+SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY);
+SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY);
+SSM(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_EMPTY);
 
-	SSM(SCI_SETFOLDFLAGS, SC_FOLDFLAG_LINEAFTER_CONTRACTED, 0);
+SSM(SCI_SETFOLDFLAGS, SC_FOLDFLAG_LINEAFTER_CONTRACTED, 0);
 \end{lstlisting}
 
 These calls set up a margin for symbols which is 20 pixels wide, and defines
 sensitive for mouse clicks. Therefore a callback function for Scintilla
 notifications has to be set up...
 \begin{lstlisting}
-static void scintilla_notify(GtkWidget *sciWidget, gint ctrlID, struct SCNotification *notifyData, gpointer userData)
+static void scintilla_notify(GtkWidget *sciWidget, gint ctrlID,
+  struct SCNotification *notifyData, gpointer userData)
 {
-	int lineNr = scintilla_send_message(SCINTILLA(sciWidget), SCI_LINEFROMPOSITION, (uptr_t)notifyData->position, 0);
+	int lineNr = scintilla_send_message(SCINTILLA(sciWidget),
+		SCI_LINEFROMPOSITION, (uptr_t)notifyData->position, 0);
 
 
 	switch (notifyData->margin) {
 		case MARGIN_SCRIPT_FOLD_INDEX:
-			scintilla_send_message(SCINTILLA(sciWidget), SCI_TOGGLEFOLD, lineNr, 0);
+			scintilla_send_message(SCINTILLA(sciWidget),
+			  SCI_TOGGLEFOLD, lineNr, 0);
 			break;
 	};
 }
 
 ... and connected:
 \begin{lstlisting}
-		gtk_signal_connect(GTK_OBJECT(editor), "sci-notify", G_CALLBACK(scintilla_notify), editor);
+gtk_signal_connect(GTK_OBJECT(editor), "sci-notify",
+  G_CALLBACK(scintilla_notify), editor);
 \end{lstlisting}
 
 
 \appendix
 \section{The complete \emph{var'aq} lexing and folding code}
 
+\lstset{basicstyle=\tiny \ttfamily}
 \begin{lstlisting}
 // Scintilla source code edit control
 /** @file LexVaraq.cxx