codeparser.h

来自「语法检查程序」· C头文件 代码 · 共 55 行

H
55
字号
/***************************************************************************/
/* 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   */
/***************************************************************************/

#ifndef CODE_PARSER_H
#define CODE_PARSER_H

class CodeState; // defines how the parser responds to data of a specific language

class CodeParser {
public:
    typedef char Datum;
    static const Datum cDefaultDatum;
    typedef int Position;

    class Context // base class for users of the parser
    {
    public:
        virtual void BegString(Position pos) = 0;
        virtual void EndString(Position pos) = 0;
        virtual void BegChar(Position pos) = 0;
        virtual void EndChar(Position pos) = 0;
        virtual void BegLineComment(Position pos) = 0;
        virtual void EndLineComment(Position pos) = 0;
        virtual void BegBlockComment(Position pos) = 0;
        virtual void EndBlockComment(Position pos) = 0;
        virtual ~Context() {}
    };

    CodeParser(
        const CodeState* initialState, // from a state map of a specific language
        Context* c = 0);

    void Process(Datum d);
    void Process(const Datum* data, Position length);
    void ResetPosition(Position newPosition = 0);
    void ResetState(const CodeState* newState = 0);

#ifndef NDEBUG
    const char* CurrentState();
#endif // NDEBUG

private:
    const CodeState*    itsInitialState;
    const CodeState*    itsState;
    Context*            itsContext;
    Position            itsPosition;
    Position            itsMarkedPosition;
};

#endif // CODE_PARSER_H

⌨️ 快捷键说明

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