void CBPythonStyler::Scan ( istream& input, const TokenExtra& initData ) { BeginScan(input); const JString& text = GetText(); Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if (token.type == kID || token.type == kReservedKeyword || token.type == kString || token.type == kComment) { SaveTokenStart(TokenExtra()); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFontStyle(); } else if (token.type == kComment || token.type == kString) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else if (token.type > kError) // misc { if (!GetWordStyle(text.GetSubstring(token.range), &style)) { style = GetDefaultFontStyle(); } } else { style = GetStyle(typeIndex, text.GetSubstring(token.range)); } } while (SetStyle(token.range, style)); }
void CBHTMLStyler::Scan ( istream& input, const TokenExtra& initData ) { BeginScan(input, initData.lexerState); itsLatestTagName.Clear(); const JString& text = GetText(); JBoolean keepGoing; Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if ((yy_start_stack_ptr == 0 && (token.type == kHTMLText || token.type == kHTMLComment || token.type == kJSPComment || (token.type == kHTMLTag && text.GetCharacter(token.range.first) == '<'))) || (yy_start_stack_ptr > 0 && yy_top_state() == 0 && (token.type == kPHPID || token.type == kPHPVariable || token.type == kPHPReservedKeyword || token.type == kPHPBuiltInDataType || token.type == kPHPSingleQuoteString || token.type == kPHPDoubleQuoteString || token.type == kPHPHereDocString || token.type == kPHPExecString || token.type == kJavaID || token.type == kJavaReservedKeyword || token.type == kJavaBuiltInDataType || token.type == kJavaString || token.type == kJSID || token.type == kJSReservedKeyword || token.type == kComment))) { TokenExtra data; data.lexerState = GetCurrentLexerState(); SaveTokenStart(data); // const JString s = text.GetSubstring(token.range); // cout << yy_top_state() << ' ' << yy_start_stack_ptr << ": " << s << endl; } // handle special cases if (token.type == kPHPDoubleQuoteString || token.type == kPHPExecString) { ExtendCheckRangeForString(token.range); } else if (token.type == kPHPStartEnd) { ExtendCheckRangeForPHPStartEnd(token.range); } else if (token.type == kJSPStartEnd) { ExtendCheckRangeForJSPStartEnd(token.range); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFontStyle(); } else if ((token.type == kHTMLNamedCharacter || token.type == kHTMLInvalidNamedCharacter) && GetCurrentLexerState() != 0) { style = GetStyle(kHTMLTag - kWhitespace, itsLatestTagName); if (token.type == kHTMLInvalidNamedCharacter) { style.strike = !style.strike; } else { style.underlineCount++; } } else if (token.type == kHTMLText || token.type == kHTMLComment || token.type == kCDATABlock || token.type == kMustacheCommand || token.type == kPHPStartEnd || token.type == kPHPSingleQuoteString || token.type == kPHPDoubleQuoteString || token.type == kPHPHereDocString || token.type == kPHPExecString || token.type == kJSPStartEnd || token.type == kJSPComment || token.type == kJavaString || token.type == kJSString || token.type == kJSRegexSearch || token.type == kComment) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else if (token.type == kHTMLTag) { style = GetTagStyle(token.range, typeIndex); } else if (token.type == kHTMLScript) { style = GetStyle(typeIndex, *(token.language)); } else if (token.type == kHTMLNamedCharacter) { JIndexRange r = token.range; r.first++; if (text.GetCharacter(r.last) == ';') { r.last--; } style = GetStyle(typeIndex, text.GetSubstring(r)); } else { if (token.type == kDocCommentHTMLTag || token.type == kDocCommentSpecialTag) { if (!(token.docCommentRange).IsEmpty()) { SetStyle(token.docCommentRange, GetTypeStyle(kComment - kWhitespace)); } ExtendCheckRange(token.range.last+1); } style = GetStyle(typeIndex, text.GetSubstring(token.range)); } keepGoing = SetStyle(token.range, style); if (token.type == kPHPDoubleQuoteString || token.type == kPHPHereDocString || token.type == kPHPExecString) { StyleEmbeddedVariables(token); } } while (keepGoing); }
//--------------------------------------------------------------------------- // ParseCommandLine // // This routine parses the command line given. If the command line is valid, // then it is assumed that the user's intention is to execute the test given // and then exit -- without using the UI for anything. Else, we display the // usage message box (if the cmdline wasn't valid), and return. // // RETURNS: NULL if cmdline was valid (script run made, or attempted), // or if command line was invalid and usage was given, // OR pointer to script to load if /RUN not present given. // // NOTE: If no script was given, this function returns a ptr // to a null string. //--------------------------------------------------------------------------- HANDLE *ParseCommandLine (LPSTR cmdline) { CHAR *tok, *scr; INT doit = 0, scriptfound = 0; static HANDLE hScr[9] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; #ifdef DEBUG fDiags = 0; #endif // We always return at least one file name, so allocate it now //----------------------------------------------------------------------- listflag = 0; if (!(hScr[0] = LocalAlloc (LHND, 128))) { MPError (NULL, MB_OK | MB_ICONEXCLAMATION, IDS_OUTOFMEM); return (NULL); } scr = LocalLock (hScr[0]); // Return now if no cmdline args given //----------------------------------------------------------------------- scr[0] = 0; tok = GetCmdToken(cmdline); if (!tok) return (hScr); do { // Check here for the /T (testmode) switch and get its parameter //------------------------------------------------------------------- if (!_stricmp (tok, "/T") || !_stricmp (tok, "-T")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } lstrcpy (tmbuf, tok); } // Here we check for /C (command) switch //------------------------------------------------------------------- else if (!_stricmp (tok, "/C") || !_stricmp (tok, "-C")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } lstrcpy (cmdbuf, tok); } // /NOE (no error dialog) //------------------------------------------------------------------- else if (!_stricmp (tok, "/NOE") || !_stricmp (tok, "-NOE")) { NOERRDLG = 1; } // /A (filename) switch (produce assembly listing/diagnostics) //------------------------------------------------------------------- else if (!_stricmp (tok, "/A") || !_stricmp (tok, "-A")) { tok = GetCmdToken (cmdline); if (!tok) { Usage(); return (NULL); } SetAssemblyListFile (tok); } // /RUN switch //------------------------------------------------------------------- else if (!_stricmp (tok, "/RUN") || !_stricmp (tok, "-RUN")) { doit = 1; } #ifdef DEBUG else if (!_stricmp (tok, "/DIAG") || !_stricmp (tok, "-DIAG")) { fDiags = 1; } #endif // /D (define) switch //------------------------------------------------------------------- else if (!_stricmp (tok, "/D") || !_stricmp (tok, "-D")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } if (SymCount == 16) { MPError (NULL, MB_OK | MB_ICONSTOP, IDS_MANYSYMBOLS); return (NULL); } _fstrncpy (DefSym[SymCount], tok, MAXSYMLEN); DefSym[SymCount++][MAXSYMLEN] = 0; } // If this was nothing above, we assume it's a script name //------------------------------------------------------------------- else if (scriptfound < 8) { if (!hScr[scriptfound]) { if (!(hScr[scriptfound] = LocalAlloc (LHND, 128))) { MPError (NULL, MB_OK | MB_ICONEXCLAMATION, IDS_OUTOFMEM); return (NULL); } scr = LocalLock (hScr[scriptfound]); } lstrcpy (scr, tok); LocalUnlock (hScr[scriptfound]); scriptfound += 1; } // Must have given too many script names //------------------------------------------------------------------- else { Usage (); return (NULL); } } while (tok = GetCmdToken(cmdline)); // No error dialog gets nullified if we're running the environment //----------------------------------------------------------------------- if (NOERRDLG && (!doit)) NOERRDLG = 0; // Return a pointer to the scripts given if no /RUN switch given //----------------------------------------------------------------------- if (!doit) return (hScr); // Give an error if no script name found, or more than one //----------------------------------------------------------------------- if (scriptfound != 1) { Usage (); return (NULL); } // Okay, we got a valid cmdline and we need to run. Send the script to // the parsing engine. // // NEW: Create a simple window which stays minimized and behind every // NEW: other window. The window text for this will contain the name // NEW: of the script running. //----------------------------------------------------------------------- EnsureExt (scr, 80); AnsiUpper (scr); Command = cmdbuf; TestMode = tmbuf; // KLUDGE: Call peekmessage to yield once... { MSG msg; CHAR buf[256], fmt[40]; PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE); // Change the window text of the viewport for this guy... //----------------------------------------------------------------------- if (LoadString (hInst, IDS_VPRUNTITLE, fmt, sizeof(fmt))) { wsprintf (buf, fmt, (LPSTR)scr); SetWindowText (hwndViewPort, buf); } } // Here's where we create the dummy window //----------------------------------------------------------------------- hwndDummy = CreateWindow (szRBRun, (LPSTR)scr, WS_OVERLAPPED|WS_SYSMENU, 0, 0, 0, 0, NULL, NULL, hInst, NULL); SetWindowPos (hwndDummy, (HWND)1, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); ShowWindow (hwndDummy, SW_SHOWMINNOACTIVE); // Okay, here we go. //----------------------------------------------------------------------- if (InitParser ()) { // HACKHACK: ntbldrus (kenhia) - on x86, complains about uninit var // 41 lines below (in final else WITHIN this if block) HCURSOR hOld = 0; // Initialize the scanner //------------------------------------------------------------------- if (BeginScan (scr, CBLoaderImmediate, SymCount, DefPtrs)) { #ifdef DEBUG if (fDiags) OpenDiagFile (scr); #endif hOld = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (!PcodeCompile()) { if (PcodeFixup(0)) { SetCursor (hOld); PcodeExecute(PE_RUN, NULL); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (ExitVal); } else { SetCursor (hOld); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (1); } } else { SetCursor (hOld); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (1); } EndScan (); } else { SetCursor (hOld); AbortParser(); MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTREAD, (LPSTR)scr); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (1); } } else MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTINIT); DestroyWindow (hwndViewPort); DestroyWindow (hwndDummy); exit (1); }
//--------------------------------------------------------------------------- // ParseCommandLine // // This routine parses the command line given. If the command line is valid, // then it is assumed that the user's intention is to execute the test given // and then exit -- without using the UI for anything. Else, we display the // usage message box (if the cmdline wasn't valid), and return. // // RETURNS: NULL if cmdline was valid (script run made, or attempted), // or if command line was invalid and usage was given, // OR pointer to script to load if /RUN not present given. // // NOTE: If no script was given, this function returns a ptr // to a null string. //--------------------------------------------------------------------------- CHAR *ParseCommandLine (LPSTR cmdline) { CHAR *tok; INT scriptfound = 0; static CHAR tm[80], cmd[80], scr[128]; // Return now if no cmdline args given //----------------------------------------------------------------------- scr[0] = 0; while (tok = GetCmdToken(cmdline)) { if (!_stricmp (tok, "/T") || !_stricmp (tok, "-T")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } lstrcpy (tm, tok); } else if (!_stricmp (tok, "/C") || !_stricmp (tok, "-C")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } lstrcpy (cmd, tok); } else if (!_stricmp (tok, "/RUN") || !_stricmp (tok, "-RUN")) { // Here only for compatibility with wattdrvr } else if (!_stricmp (tok, "/D") || !_stricmp (tok, "-D")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } if (SymCount == 16) { MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTINIT); return (NULL); } lstrcpy (DefSym[SymCount++], tok); } else if (!scriptfound) { lstrcpy (scr, tok); scriptfound = -1; } else { Usage (); return (NULL); } } // If no script name was given, create one using the module file name and // replacing its extension with .WTD //----------------------------------------------------------------------- if (!scriptfound) { INT l, i; GetModuleFileName (hInst, scr, sizeof(scr)); l = lstrlen (scr); for (i=0; i<=4; i++) if (scr[l-i] == '.') { strcpy (scr+l-i, ".MST"); break; } } // Okay, we got a valid cmdline and we need to run. Send the script to // the parsing engine. //----------------------------------------------------------------------- EnsureExt (scr, 80); Command = cmd; TestMode = tm; if (InitParser ()) { // Initialize the scanner, and start the compilation. //------------------------------------------------------------------- if (BeginScan (scr, CBLoaderImmediate, SymCount, DefPtrs)) { if (!PcodeCompile()) { if (PcodeFixup(0)) { PcodeExecute(PE_RUN, NULL); } } } else { AbortParser(); MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTREAD, (LPSTR)scr); } } else MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTINIT); return (NULL); }
void CBJavaStyler::Scan ( istream& input, const TokenExtra& initData ) { BeginScan(input); const JString& text = GetText(); Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if (token.type == kID || token.type == kReservedKeyword || token.type == kBuiltInDataType || token.type == kString) { SaveTokenStart(TokenExtra()); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFontStyle(); } else if (token.type == kComment || token.type == kString) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else { if (token.type == kDocCommentHTMLTag || token.type == kDocCommentSpecialTag) { if (!(token.docCommentRange).IsEmpty()) { SetStyle(token.docCommentRange, GetTypeStyle(kComment - kWhitespace)); } ExtendCheckRange(token.range.last+1); } style = GetStyle(typeIndex, text.GetSubstring(token.range)); } } while (SetStyle(token.range, style)); }
void CBTCLStyler::Scan ( std::istream& input, const TokenExtra& initData ) { BeginScan(input); const JString& text = GetText(); JBoolean keepGoing; Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if (token.type == kPredefinedWord || token.type == kOtherWord || token.type == kVariable || token.type == kString || token.type == kComment) { SaveTokenStart(TokenExtra()); } // handle special cases if (token.type == kString || token.type == kUnterminatedString) { ExtendCheckRangeForString(token.range); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFont().GetStyle(); } else if (token.type == kComment || token.type == kString || token.type == kBrace || token.type == kSquareBracket || token.type == kParenthesis) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else { style = GetStyle(typeIndex, text.GetSubstring(token.range)); } keepGoing = SetStyle(token.range, style); if (token.type == kString) { StyleEmbeddedVariables(token); } } while (keepGoing); }
void CBCShellStyler::Scan ( istream& input, const TokenExtra& initData ) { BeginScan(input); const JString& text = GetText(); JBoolean keepGoing; Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if (token.type == kID || token.type == kVariable || token.type == kReservedWord || token.type == kSingleQuoteString || token.type == kDoubleQuoteString || token.type == kExecString || token.type == kComment) { SaveTokenStart(TokenExtra()); } // handle special cases if (token.type == kDoubleQuoteString || token.type == kExecString) { ExtendCheckRangeForString(token.range); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFontStyle(); } else if (token.type == kSingleQuoteString || token.type == kDoubleQuoteString || token.type == kExecString || token.type == kComment) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else if (token.type > kError) // misc { if (!GetWordStyle(text.GetSubstring(token.range), &style)) { style = GetDefaultFontStyle(); } } else { style = GetStyle(typeIndex, text.GetSubstring(token.range)); } keepGoing = SetStyle(token.range, style); if (token.type == kDoubleQuoteString || token.type == kExecString) { StyleEmbeddedVariables(token); } } while (keepGoing); }