TRISTATE CTextParser::GetIdentifierCharacter(char* pc, BOOL bFirst) { char cCurrent; if (!mbOutsideText) { cCurrent = mszParserPos[0]; *pc = cCurrent; //The first character of an identifier must be one of these... if (((cCurrent >= 'a') && (cCurrent <= 'z')) || ((cCurrent >= 'A') && (cCurrent <= 'Z')) || (cCurrent == '_')) { StepRight(); return TRITRUE; } //Additional characters can also be... if (!bFirst) { if ((cCurrent >= '0') && (cCurrent <= '9')) { StepRight(); return TRITRUE; } } return TRIFALSE; } else { SetErrorEndOfFile(); return TRIERROR; } }
TRISTATE CTextParser::GetSign(int* pi) { char cCurrent; if (!mbOutsideText) { *pi = 1; cCurrent = mszParserPos[0]; if (cCurrent == '-') { *pi = -1; StepRight(); return TRITRUE; } else if (cCurrent == '+') { StepRight(); return TRITRUE; } else return TRIFALSE; } else { SetErrorEndOfFile(); return TRIERROR; } }
void CTextParser::SkipWhiteSpace(void) { char cCurrent; for (;;) { if (mbOutsideText) { return; } cCurrent = mszParserPos[0]; //Nice clean white space... if (IsWhiteSpace(cCurrent)) { StepRight(); } //Possibly nasty comments... else if (cCurrent == '/') { StepRight(); if (!mbOutsideText) { cCurrent = mszParserPos[0]; if (cCurrent == '*') { //Put the parser back where it was. StepLeft(); SkipCStyleComment(); } else if (cCurrent == '/') { //Put the parser back where it was. StepLeft(); if (!SkipCPPStyleComment()) { break; } } else { //Was something other than white-space starting with / StepLeft(); break; } } } else { //Was not white-space at all. break; } } }
TRISTATE CTextParser::GetDigit(int* pi, int iBase) { char cCurrent; if (!mbOutsideText) { cCurrent = mszParserPos[0]; if (iBase <= 10) { if ((cCurrent >= '0') && (cCurrent <= ('0' + iBase - 1))) { *pi = (int)(cCurrent - '0'); StepRight(); return TRITRUE; } else { return TRIFALSE; } } else { cCurrent = ToUpper(cCurrent); if ((cCurrent >= '0') && (cCurrent <= '9')) { *pi = (int)(cCurrent - '0'); StepRight(); return TRITRUE; } else if ((cCurrent >= 'A') && (cCurrent <= ('A' + iBase - 11))) { *pi = (int)(cCurrent - 'A' + 10); StepRight(); return TRITRUE; } else { return TRIFALSE; } } } else { SetErrorEndOfFile(); return TRIERROR; } }
TRISTATE CTextParser::GetExactCaseInsensitiveCharacter(char c, BOOL bSkipWhiteSpace) { char c1, c2; if (bSkipWhiteSpace) { SkipWhiteSpace(); } if (!mbOutsideText) { c1 = ToUpper(mszParserPos[0]); c2 = ToUpper(c); if (c1 == c2) { StepRight(); return TRITRUE; } return TRIFALSE; } else { SetErrorEndOfFile(); return TRIERROR; } }
TRISTATE CTextParser::FindExactCharacterSequence(char* szSequence) { char* szPosition; TRISTATE result; PushPosition(); for (;;) { szPosition = mszParserPos; result = GetExactCharacterSequence(szSequence); if (result == TRIERROR) { //We've reached the end of the file without finding the identifier. PopPosition(); return TRIFALSE; } else if (result == TRIFALSE) { //Try the next actual character along. StepRight(); SkipWhiteSpace(); } else if (result == TRITRUE) { mszParserPos = szPosition; PassPosition(); return TRITRUE; } } }
TRISTATE CTextParser::GetEscapeCode(char* c) { char cReturn; if (!mbOutsideText) { cReturn = ::GetEscapeCode(mszParserPos[0]); if (cReturn == '@') { SetErrorSyntaxError(); return TRIERROR; } else { *c = cReturn; } StepRight(); return TRITRUE; } else { SetErrorEndOfFile(); return TRIERROR; } }
TRISTATE CTextParser::GetExactIdentifier(char* szIdentifier) { char cCurrent; int iPos; TRISTATE tResult; iPos = 0; PushPosition(); SkipWhiteSpace(); //Make sure we're not off the end of the file. if (mbOutsideText) { PopPosition(); SetErrorEndOfFile(); return TRIERROR; } for (;;) { if (szIdentifier[iPos] == 0) { //Got all the way to the NULL character. //If there are additional identifier characters then we do not have the right identifier. if (!mbOutsideText) { tResult = GetIdentifierCharacter(&cCurrent, iPos == 0); if (tResult == TRITRUE) { //Put the parser back where it was. PopPosition(); return TRIFALSE; } } PassPosition(); return TRITRUE; } if (!mbOutsideText) { cCurrent = mszParserPos[0]; if (cCurrent == szIdentifier[iPos]) { StepRight(); iPos++; } else { //Put the parser back where it was. PopPosition(); return TRIFALSE; } } else { //Put the parser back where it was. PopPosition(); return TRIFALSE; } } }
TRISTATE CTextParser::FindStartOfLine(void) { char cCurrent; BOOL bInQuotes; PushPosition(); //If we're off the end of the file we can't return the beginning of the line. if (mbOutsideText) { PopPosition(); SetErrorEndOfFile(); return TRIERROR; } bInQuotes = FALSE; for (;;) { cCurrent = mszParserPos[0]; if (cCurrent == '"') { bInQuotes = !bInQuotes; } if (!bInQuotes) { SkipLeftCStyleComment(); } StepLeft(); //If we have no more text then the start of the line is the start of the text. if (mbOutsideText) { mszParserPos = mszStartOfText; miColumn = 0; PassPosition(); return TRITRUE; } if (!bInQuotes) { //Get the current character. cCurrent = mszParserPos[0]; //If we get find an end of line character we've gone to far, go right again. if (cCurrent == '\n') { StepRight(); PassPosition(); return TRITRUE; } } } }
void CTextParser::SkipNewLine(void) { char cCurrent; if (mbOutsideText) { return; } cCurrent = mszParserPos[0]; //Nice clean white space... if (cCurrent == '\n') { StepRight(); } else if (mszParserPos == mszEndOfText) { StepRight(); } }
TRISTATE CTextParser::GetCharacter(char* pc) { if (!mbOutsideText) { *pc = mszParserPos[0]; StepRight(); return TRITRUE; } else { SetErrorEndOfFile(); return TRIERROR; } }
TRISTATE CTextParser::GetExactCaseInsensitiveCharacterSequence(char* szSequence) { int iPos; char c1, c2; PushPosition(); SkipWhiteSpace(); iPos = 0; //Make sure we're not off the end of the file. if (mbOutsideText) { PopPosition(); SetErrorEndOfFile(); return TRIERROR; } for (;;) { if (szSequence[iPos] == 0) { //Got all the way to the NULL character. PassPosition(); return TRITRUE; } if (!mbOutsideText) { c1 = ToUpper(mszParserPos[0]); c2 = ToUpper(szSequence[iPos]); if (c1 == c2) { StepRight(); iPos++; } else { //Put the parser back where it was. PopPosition(); return TRIFALSE; } } else { //Put the parser back where it was. PopPosition(); return TRIFALSE; } } }
/*获取鼠标消息并根据鼠标点击位置进行相应操作*/ void GetMessage(MOUSEMSG m) { //鼠标循环 switch(m.uMsg) { case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: if(m.x>440&&m.x<460&&m.y>60&&m.y<80) StepUp(); if(m.x>420&&m.x<440&&m.y>80&&m.y<100) StepLeft(); if(m.x>460&&m.x<480&&m.y>80&&m.y<100) StepRight(); if(m.x>440&&m.x<460&&m.y>100&&m.y<120) StepDown(); break; default: break; } return ; }
TRISTATE CTextParser::GetExactCharacter(char c, BOOL bSkipWhiteSpace) { if (bSkipWhiteSpace) { SkipWhiteSpace(); } if (!mbOutsideText) { if (mszParserPos[0] == c) { StepRight(); return TRITRUE; } return TRIFALSE; } else { SetErrorEndOfFile(); return TRIERROR; } }
TRISTATE CTextParser::FindWhiteSpace(void) { char cCurrent; BOOL bStartOfComment; bStartOfComment = FALSE; for (;;) { if (mbOutsideText) { return TRIFALSE; } cCurrent = mszParserPos[0]; if (IsWhiteSpace(cCurrent)) { return TRITRUE; } if (bStartOfComment) { if ((cCurrent == '/') || (cCurrent == '*')) { StepLeft(); return TRITRUE; } } if (cCurrent = '/') { bStartOfComment = TRUE; } else { bStartOfComment = FALSE; } StepRight(); } }
TRISTATE CTextParser::GetCharacterSequence(char* szSequence, int* piLength) { char c; BOOL bFirst; int iPos; bFirst = TRUE; iPos = 0; PushPosition(); SkipWhiteSpace(); //Make sure we're not off the end of the file. if (mbOutsideText) { PopPosition(); SetErrorEndOfFile(); return TRIERROR; } for (;;) { if (!mbOutsideText) { c = mszParserPos[0]; StepRight(); if (IsWhiteSpace(c)) { if (bFirst) { if (szSequence) szSequence[iPos] = 0; PopPosition(); return TRIFALSE; } else { if (szSequence) szSequence[iPos] = 0; if (szSequence) PassPosition(); else PopPosition(); SafeAssign(piLength, iPos); return TRITRUE; } } else { if (szSequence) szSequence[iPos] = c; } } else { if (bFirst) { PopPosition(); SetErrorEndOfFile(); return TRIERROR; } else { if (szSequence) szSequence[iPos] = 0; if (szSequence) PassPosition(); else PopPosition(); SafeAssign(piLength, iPos); return TRITRUE; } } bFirst = FALSE; iPos++; } }
TRISTATE CTextParser::FindEndOfLine(void) { char cCurrent; BOOL bInQuotes; char cPrev; BOOL bInCppComment; PushPosition(); //If we're off the end of the file we can't go to the end of the line. if (mbOutsideText) { PopPosition(); SetErrorEndOfFile(); return TRIERROR; } bInCppComment = FALSE; bInQuotes = FALSE; cCurrent = 0; for (;;) { cPrev = cCurrent; cCurrent = mszParserPos[0]; if ((cPrev == '/') && (cCurrent == '/')) { bInCppComment = TRUE; } if (!bInCppComment) { if (cCurrent == '"') { bInQuotes = !bInQuotes; } if (!bInQuotes) { SkipCStyleComment(); } } //If we have no more text then ... blah, blah, blah if (mbOutsideText) { mszParserPos = mszEndOfText; miColumn--; //This might work. PassPosition(); return TRITRUE; } if ((!bInQuotes) || (bInCppComment)) //Note: (NOT in quotes) OR (in Cpp comment). { //If we get find an end of line character we've gone to far, go right again. cCurrent = mszParserPos[0]; if (cCurrent == '\n') { PassPosition(); return TRITRUE; } } StepRight(); } }
BOOL CTextParser::SkipCPPStyleComment(void) { char cCurrent; int iCount; if (mbOutsideText) { return TRUE; } PushPosition(); cCurrent = mszParserPos[0]; if (cCurrent == '/') { StepRight(); if (!mbOutsideText) { cCurrent = mszParserPos[0]; if (cCurrent == '/') { for (iCount = 0;; iCount++) { StepRight(); if (!mbOutsideText) { cCurrent = mszParserPos[0]; if (cCurrent == '\n') { //This is the end of the line and the end of the comment. StepRight(); PassPosition(); return TRUE; } if (mbAnnotated) { if (cCurrent == '@') { //Wasn't a comment, was an annotation. PopPosition(); return FALSE; } } } else { PassPosition(); return TRUE; } } } else { PopPosition(); return TRUE; } } else { //Wasn't a comment. StepLeft(); return TRUE; } } PopPosition(); return TRUE; }
void CTextParser::SkipLeftCStyleComment(void) { char cCurrent; int iDepth; iDepth = 0; PushPosition(); for (;;) { if (mbOutsideText) { PassPosition(); return; } cCurrent = mszParserPos[0]; if (cCurrent == '/') { StepLeft(); if (!mbOutsideText) { cCurrent = mszParserPos[0]; if (cCurrent == '*') { iDepth++; } else { //Wasn't a comment start... step back. StepRight(); } } else { PassPosition(); return; } } else if (cCurrent == '*') { StepLeft(); if (!mbOutsideText) { cCurrent = mszParserPos[0]; if (cCurrent == '/') { iDepth--; } else { //Wasn't the end of a comment... step back... StepRight(); } } else { PassPosition(); return; } } if (iDepth == 0) { //No more nested comments... bail.. return; } StepLeft(); } }
TRISTATE CTextParser::GetQuotedCharacterSequence(char cOpenQuote, char cCloseQuote, char* szString, int* piLength, BOOL bPassOnTest, BOOL bSkipWhiteSpace) { int iPos; char cCurrent; TRISTATE tReturn; char cEscape; PushPosition(); if (bSkipWhiteSpace) { SkipWhiteSpace(); } if (!mbOutsideText) { if (GetExactCharacter(cOpenQuote, FALSE)) { iPos = 0; for (;;) { if (!mbOutsideText) { cCurrent = mszParserPos[0]; if (cCurrent == cCloseQuote) { if (szString) szString[iPos] = 0; StepRight(); if (szString || bPassOnTest) PassPosition(); else PopPosition(); SafeAssign(piLength, iPos); return TRITRUE; } //We have an escape character... else if (cCurrent == '\\') { StepRight(); tReturn = GetEscapeCode(&cEscape); if (szString) szString[iPos] = cEscape; iPos++; if (tReturn == TRIFALSE) { PopPosition(); SetErrorSyntaxError(); return TRIERROR; } else if (tReturn == TRIERROR) { PopPosition(); //Don't set the error here, it's already been set by GetEscapeCode return TRIERROR; } } else if (cCurrent == '\n') { //Just ignore new lines. StepRight(); } else { if (szString) szString[iPos] = cCurrent; iPos++; StepRight(); } } else { //This has never been tested. PopPosition(); SetErrorSyntaxError(); return TRIERROR; } } } else { //No quote so not a string. PopPosition(); return TRIFALSE; } } else { PopPosition(); SetErrorEndOfFile(); return TRIERROR; } }