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

📄 basiccodestate.cpp

📁 语法检查程序
💻 CPP
字号:
/***************************************************************************/
/* NOTE:                                                                   */
/* This document is copyright (c) by Oz Solomon and Yonat Sharon, and is   */
/* bound by the MIT open source license.                                   */ 
/* See License.txt or visit www.opensource.org/licenses/mit-license.html   */
/***************************************************************************/

#include "CodeState.h"

const CodeState* BasicCodeState()
{
    // states
    enum {
        cNormal,
        cString,
        cLineComment,
        cStatesNum
    };
    static CodeState states[cStatesNum];
    static bool initialized = false;

    if (initialized)
        return &states[0];

#ifndef NDEBUG
    states[cNormal].itsName = "Normal";
    states[cString].itsName = "String";
    states[cLineComment].itsName = "LineComment";
#endif // NDEBUG

    CodeEffect e;
    e.markPosition = true; // in all cases
    
    // begin string
    e.action = CodeParser::Context::BegString;
    e.next = &states[cString];
    states[cNormal]['"'] = e;

    // begin line comment
    e.action = CodeParser::Context::BegLineComment;
    e.next = &states[cLineComment];
    states[cNormal]['\''] = e;

    // end string
    e.action = CodeParser::Context::EndString;
    e.next = &states[cNormal];
    states[cString]['"'] = e;

    // end line comment
    e.action = CodeParser::Context::EndLineComment;
    states[cLineComment]['\n'] = e;

    initialized = true;

    return &states[0];
}


#ifdef TEST_BASIC_CODE_STATE

#include "TestContext.h"

char str[] =
    "Sub CommentOut ()\n"
    "'DESCRIPTION: Comments out a selected block of text.\n"
    "	Dim win\n"
    "	set win = ActiveWindow\n"
    "	if win.type <> \"Text\" Then\n"
    "	  MsgBox \"This macro can only be run when a text editor window is active.\"\n"
    "	else\n"
    "		TypeOfFile = FileType(ActiveDocument)  \n"
    "		If TypeOfFile > 1 And TypeOfFile < 5 Then    'C & Java use the same \n"
    "														'style of comments.\n"
    "			ActiveDocument.Selection = \"/*\" + ActiveDocument.Selection + \"*/\"\n"
    "		ElseIf TypeOfFile = 5 Then\n"
    "			ActiveDocument.Selection = \"<!-- \" + ActiveDocument.Selection + \" -->\"\n";


int main()
{
    TestContext t(str);
    CodeParser cp(BasicCodeState(), &t);
    cp.Process(str, sizeof(str));

    return 0;
}

#endif // TEST_BASIC_CODE_STATE

⌨️ 快捷键说明

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