⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lexclw.cxx

📁 robocup rcssserver 运行防真机器人足球比赛所用的服务器端
💻 CXX
📖 第 1 页 / 共 2 页
字号:
// Scintilla source code edit control/** @file LexClw.cxx ** Lexer for Clarion. ** 2004/12/17 Updated Lexer **/// Copyright 2003-2004 by Ron Schofield <ron@schofieldcomputer.com>// The License.txt file describes the conditions under which this software may be distributed.#include <stdlib.h>#include <string.h>#include <stdio.h>#include <stdarg.h>#include <ctype.h>#include "Platform.h"#include "PropSet.h"#include "Accessor.h"#include "StyleContext.h"#include "KeyWords.h"#include "Scintilla.h"#include "SciLexer.h"// Is an end of line characterinline bool IsEOL(const int ch) {	return(ch == '\n');}// Convert character to uppercasestatic char CharacterUpper(char chChar) {	if (chChar < 'a' || chChar > 'z') {		return(chChar);	}	else {		return(static_cast<char>(chChar - 'a' + 'A'));	}}// Convert string to uppercasestatic void StringUpper(char *szString) {	while (*szString) {		*szString = CharacterUpper(*szString);		szString++;	}}// Is a label start characterinline bool IsALabelStart(const int iChar) {	return(isalpha(iChar) || iChar == '_');}// Is a label characterinline bool IsALabelCharacter(const int iChar) {	return(isalnum(iChar) || iChar == '_' || iChar == ':'); }// Is the character is a ! and the the next character is not a ! inline bool IsACommentStart(const int iChar) {	return(iChar == '!');}// Is the character a Clarion hex character (ABCDEF)inline bool IsAHexCharacter(const int iChar, bool bCaseSensitive) {	// Case insensitive.	if (!bCaseSensitive) {		if (strchr("ABCDEFabcdef", iChar) != NULL) {			return(true);		}	}	// Case sensitive	else {		if (strchr("ABCDEF", iChar) != NULL) {			return(true);		}	}	return(false);}// Is the character a Clarion base character (B=Binary, O=Octal, H=Hex)inline bool IsANumericBaseCharacter(const int iChar, bool bCaseSensitive) {	// Case insensitive.	if (!bCaseSensitive) {		// If character is a numeric base character		if (strchr("BOHboh", iChar) != NULL) {			return(true);		}	}	// Case sensitive	else {		// If character is a numeric base character		if (strchr("BOH", iChar) != NULL) {			return(true);		}	}	return(false);}// Set the correct numeric constant stateinline bool SetNumericConstantState(StyleContext &scDoc) {	int iPoints = 0;			// Point counter	char cNumericString[512];	// Numeric string buffer	// Buffer the current numberic string	scDoc.GetCurrent(cNumericString, sizeof(cNumericString));	// Loop through the string until end of string (NULL termination)	for (int iIndex = 0; cNumericString[iIndex] != '\0'; iIndex++) {		// Depending on the character		switch (cNumericString[iIndex]) {			// Is a . (point)			case '.' :				// Increment point counter				iPoints++;				break;			default :				break;		}		}	// If points found (can be more than one for improper formatted number	if (iPoints > 0) {		return(true);	}	// Else no points found	else {		return(false);	}}// Get the next word in uppercase from the current position (keyword lookahead)inline bool GetNextWordUpper(Accessor &styler, unsigned int uiStartPos, int iLength, char *cWord) {	unsigned int iIndex = 0;		// Buffer Index	// Loop through the remaining string from the current position	for (int iOffset = uiStartPos; iOffset < iLength; iOffset++) {		// Get the character from the buffer using the offset		char cCharacter = styler[iOffset];		if (IsEOL(cCharacter)) {			break;		}		// If the character is alphabet character		if (isalpha(cCharacter)) {			// Add UPPERCASE character to the word buffer			cWord[iIndex++] = CharacterUpper(cCharacter);		}	}	// Add null termination	cWord[iIndex] = '\0';	// If no word was found	if (iIndex == 0) {		// Return failure		return(false);	}	// Else word was found	else {		// Return success		return(true);	}}// Clarion Language Colouring Procedurestatic void ColouriseClarionDoc(unsigned int uiStartPos, int iLength, int iInitStyle, WordList *wlKeywords[], Accessor &accStyler, bool bCaseSensitive) {	int iParenthesesLevel = 0;		// Parenthese Level	int iColumn1Label = false;		// Label starts in Column 1	WordList &wlClarionKeywords = *wlKeywords[0];			// Clarion Keywords	WordList &wlCompilerDirectives = *wlKeywords[1];		// Compiler Directives	WordList &wlRuntimeExpressions = *wlKeywords[2];		// Runtime Expressions	WordList &wlBuiltInProcsFuncs = *wlKeywords[3];			// Builtin Procedures and Functions	WordList &wlStructsDataTypes = *wlKeywords[4];			// Structures and Data Types	WordList &wlAttributes = *wlKeywords[5];				// Procedure Attributes	WordList &wlStandardEquates = *wlKeywords[6];			// Standard Equates	WordList &wlLabelReservedWords = *wlKeywords[7];		// Clarion Reserved Keywords (Labels)	WordList &wlProcLabelReservedWords = *wlKeywords[8];	// Clarion Reserved Keywords (Procedure Labels)	const char wlProcReservedKeywordList[] = 	"PROCEDURE FUNCTION";	WordList wlProcReservedKeywords;	wlProcReservedKeywords.Set(wlProcReservedKeywordList);	const char wlCompilerKeywordList[] = 	"COMPILE OMIT";	WordList wlCompilerKeywords;	wlCompilerKeywords.Set(wlCompilerKeywordList);	const char wlLegacyStatementsList[] =	"BOF EOF FUNCTION POINTER SHARE";	WordList wlLegacyStatements;	wlLegacyStatements.Set(wlLegacyStatementsList);	StyleContext scDoc(uiStartPos, iLength, iInitStyle, accStyler);	// lex source code    for (; scDoc.More(); scDoc.Forward())	{		//		// Determine if the current state should terminate.		//		// Label State Handling		if (scDoc.state == SCE_CLW_LABEL) {			// If the character is not a valid label			if (!IsALabelCharacter(scDoc.ch)) {				// If the character is a . (dot syntax)				if (scDoc.ch == '.') {					// Turn off column 1 label flag as label now cannot be reserved work					iColumn1Label = false;					// Uncolour the . (dot) to default state, move forward one character,					// and change back to the label state.					scDoc.SetState(SCE_CLW_DEFAULT);					scDoc.Forward();					scDoc.SetState(SCE_CLW_LABEL);				}				// Else check label				else {					char cLabel[512];		// Label buffer					// Buffer the current label string					scDoc.GetCurrent(cLabel,sizeof(cLabel));					// If case insensitive, convert string to UPPERCASE to match passed keywords.					if (!bCaseSensitive) {						StringUpper(cLabel);					}					// Else if UPPERCASE label string is in the Clarion compiler keyword list					if (wlCompilerKeywords.InList(cLabel) && iColumn1Label){						// change the label to error state						scDoc.ChangeState(SCE_CLW_COMPILER_DIRECTIVE);					}					// Else if UPPERCASE label string is in the Clarion reserved keyword list					else if (wlLabelReservedWords.InList(cLabel) && iColumn1Label){						// change the label to error state						scDoc.ChangeState(SCE_CLW_ERROR);					}					// Else if UPPERCASE label string is 					else if (wlProcLabelReservedWords.InList(cLabel) && iColumn1Label) {						char cWord[512];	// Word buffer						// Get the next word from the current position						if (GetNextWordUpper(accStyler,scDoc.currentPos,uiStartPos+iLength,cWord)) {							// If the next word is a procedure reserved word							if (wlProcReservedKeywords.InList(cWord)) {								// Change the label to error state								scDoc.ChangeState(SCE_CLW_ERROR);							}						}					}					// Else if label string is in the compiler directive keyword list					else if (wlCompilerDirectives.InList(cLabel)) {						// change the state to compiler directive state						scDoc.ChangeState(SCE_CLW_COMPILER_DIRECTIVE);					}					// Terminate the label state and set to default state					scDoc.SetState(SCE_CLW_DEFAULT);				}			}		}		// Keyword State Handling		else if (scDoc.state == SCE_CLW_KEYWORD) {			// If character is : (colon)			if (scDoc.ch == ':') {				char cEquate[512];		// Equate buffer				// Move forward to include : (colon) in buffer				scDoc.Forward();				// Buffer the equate string				scDoc.GetCurrent(cEquate,sizeof(cEquate));				// If case insensitive, convert string to UPPERCASE to match passed keywords.				if (!bCaseSensitive) {					StringUpper(cEquate);				}				// If statement string is in the equate list				if (wlStandardEquates.InList(cEquate)) {					// Change to equate state					scDoc.ChangeState(SCE_CLW_STANDARD_EQUATE);				}			}			// If the character is not a valid label character			else if (!IsALabelCharacter(scDoc.ch)) {				char cStatement[512];		// Statement buffer				// Buffer the statement string				scDoc.GetCurrent(cStatement,sizeof(cStatement));				// If case insensitive, convert string to UPPERCASE to match passed keywords.				if (!bCaseSensitive) {					StringUpper(cStatement);				}				// If statement string is in the Clarion keyword list				if (wlClarionKeywords.InList(cStatement)) {					// Change the statement string to the Clarion keyword state					scDoc.ChangeState(SCE_CLW_KEYWORD);				}				// Else if statement string is in the compiler directive keyword list				else if (wlCompilerDirectives.InList(cStatement)) {					// Change the statement string to the compiler directive state					scDoc.ChangeState(SCE_CLW_COMPILER_DIRECTIVE);				}				// Else if statement string is in the runtime expressions keyword list				else if (wlRuntimeExpressions.InList(cStatement)) {					// Change the statement string to the runtime expressions state					scDoc.ChangeState(SCE_CLW_RUNTIME_EXPRESSIONS);				}				// Else if statement string is in the builtin procedures and functions keyword list				else if (wlBuiltInProcsFuncs.InList(cStatement)) {					// Change the statement string to the builtin procedures and functions state					scDoc.ChangeState(SCE_CLW_BUILTIN_PROCEDURES_FUNCTION);				}				// Else if statement string is in the tructures and data types keyword list				else if (wlStructsDataTypes.InList(cStatement)) {					// Change the statement string to the structures and data types state					scDoc.ChangeState(SCE_CLW_STRUCTURE_DATA_TYPE);				}				// Else if statement string is in the procedure attribute keyword list				else if (wlAttributes.InList(cStatement)) {					// Change the statement string to the procedure attribute state					scDoc.ChangeState(SCE_CLW_ATTRIBUTE);				}				// Else if statement string is in the standard equate keyword list				else if (wlStandardEquates.InList(cStatement)) {					// Change the statement string to the standard equate state					scDoc.ChangeState(SCE_CLW_STANDARD_EQUATE);				}				// Else if statement string is in the deprecated or legacy keyword list				else if (wlLegacyStatements.InList(cStatement)) {					// Change the statement string to the standard equate state					scDoc.ChangeState(SCE_CLW_DEPRECATED);				}				// Else the statement string doesn't match any work list				else {					// Change the statement string to the default state					scDoc.ChangeState(SCE_CLW_DEFAULT);				}				// Terminate the keyword state and set to default state				scDoc.SetState(SCE_CLW_DEFAULT);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -