File: parser.hpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (105 lines) | stat: -rw-r--r-- 3,256 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
105
#ifndef COMPILER_PARSER_H_INCLUDED
#define COMPILER_PARSER_H_INCLUDED

#include <string>

namespace Compiler
{
    class Scanner;
    struct TokenLoc;
    class ErrorHandler;
    class Context;

    /// \brief Parser base class
    ///
    /// This class defines a callback-parser.

    class Parser
    {
        ErrorHandler& mErrorHandler;
        const Context& mContext;
        bool mOptional;
        bool mEmpty;

    protected:
        [[noreturn]] void reportSeriousError(const std::string& message, const TokenLoc& loc);
        ///< Report the error and throw a exception.

        void reportWarning(const std::string& message, const TokenLoc& loc);
        ///< Report the warning without throwing an exception.

        [[noreturn]] void reportEOF();
        ///< Report an unexpected EOF condition.

        ErrorHandler& getErrorHandler();
        ///< Return error handler

        const Context& getContext() const;
        ///< Return context

        static std::string toLower(const std::string& name);

    public:
        Parser(ErrorHandler& errorHandler, const Context& context);
        ///< constructor

        virtual ~Parser();
        ///< destructor

        virtual bool parseInt(int value, const TokenLoc& loc, Scanner& scanner);
        ///< Handle an int token.
        /// \return fetch another token?
        ///
        /// - Default-implementation: Report an error.

        virtual bool parseFloat(float value, const TokenLoc& loc, Scanner& scanner);
        ///< Handle a float token.
        /// \return fetch another token?
        ///
        /// - Default-implementation: Report an error.

        virtual bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner);
        ///< Handle a name token.
        /// \return fetch another token?
        ///
        /// - Default-implementation: Report an error.

        virtual bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner);
        ///< Handle a keyword token.
        /// \return fetch another token?
        ///
        /// - Default-implementation: Report an error.

        virtual bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner);
        ///< Handle a special character token.
        /// \return fetch another token?
        ///
        /// - Default-implementation: Report an error.

        virtual bool parseComment(const std::string& comment, const TokenLoc& loc, Scanner& scanner);
        ///< Handle comment token.
        /// \return fetch another token?
        ///
        /// - Default-implementation: ignored (and return true).

        virtual void parseEOF(Scanner& scanner);
        ///< Handle EOF token.
        ///
        /// - Default-implementation: Report an error.

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

        void setOptional(bool optional);
        ///< Optional mode: If nothign has been parsed yet and an unexpected token is delivered, stop
        /// parsing without raising an exception (after a reset the parser is in non-optional mode).

        void start();
        ///< Mark parser as non-empty (at least one token has been parser).

        bool isEmpty() const;
        ///< Has anything been parsed?
    };
}

#endif