File: lineparser.hpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (104 lines) | stat: -rw-r--r-- 3,149 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef COMPILER_LINEPARSER_H_INCLUDED
#define COMPILER_LINEPARSER_H_INCLUDED

#include <string>
#include <vector>

#include <components/interpreter/types.hpp>
#include <components/misc/messageformatparser.hpp>

#include "exprparser.hpp"
#include "parser.hpp"

namespace Compiler
{
    class Locals;
    class Literals;

    /// \brief Line parser, to be used in console scripts and as part of ScriptParser

    class LineParser : public Parser
    {
        enum State
        {
            BeginState,
            SetState,
            SetLocalVarState,
            SetGlobalVarState,
            SetPotentialMemberVarState,
            SetMemberVarState,
            SetMemberVarState2,
            MessageState,
            MessageButtonState,
            EndState,
            PotentialExplicitState,
            ExplicitState,
            MemberState
        };

        Locals& mLocals;
        Literals& mLiterals;
        std::vector<Interpreter::Type_Code>& mCode;
        State mState;
        std::string mName;
        std::string mMemberName;
        bool mReferenceMember;
        int mButtons;
        std::string mExplicit;
        char mType;
        ExprParser mExprParser;
        bool mAllowExpression;

        void parseExpression(Scanner& scanner, const TokenLoc& loc);

    public:
        LineParser(ErrorHandler& errorHandler, const Context& context, Locals& locals, Literals& literals,
            std::vector<Interpreter::Type_Code>& code, bool allowExpression = false);
        ///< \param allowExpression Allow lines consisting of a naked expression
        /// (result is send to the messagebox interface)

        bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
        ///< Handle an int token.
        /// \return fetch another token?

        bool parseFloat(float value, const TokenLoc& loc, Scanner& scanner) override;
        ///< Handle a float token.
        /// \return fetch another token?

        bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
        ///< Handle a name token.
        /// \return fetch another token?

        bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
        ///< Handle a keyword token.
        /// \return fetch another token?

        bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
        ///< Handle a special character token.
        /// \return fetch another token?

        void reset() override;
        ///< Reset parser to clean state.
    };

    class GetArgumentsFromMessageFormat : public ::Misc::MessageFormatParser
    {
    private:
        std::string mArguments;

    protected:
        void visitedPlaceholder(
            Placeholder placeholder, char padding, int width, int precision, Notation notation) override;
        void visitedCharacter(char c) override {}

    public:
        void process(std::string_view message) override
        {
            mArguments.clear();
            ::Misc::MessageFormatParser::process(message);
        }
        std::string getArguments() const { return mArguments; }
    };
}

#endif