OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
parser.hpp
Go to the documentation of this file.
1 #ifndef COMPILER_PARSER_H_INCLUDED
2 #define COMPILER_PARSER_H_INCLUDED
3 
4 #include <string>
5 
6 namespace Compiler
7 {
8  class Scanner;
9  struct TokenLoc;
10  class ErrorHandler;
11  class Context;
12 
16 
17  class Parser
18  {
20  const Context& mContext;
21  bool mOptional;
22  bool mEmpty;
23 
24  protected:
25 
26  void reportSeriousError (const std::string& message, const TokenLoc& loc);
28 
29  void reportWarning (const std::string& message, const TokenLoc& loc);
31 
32  void reportEOF();
34 
37 
38  const Context& getContext() const;
40 
41  static std::string toLower (const std::string& name);
42 
43  public:
44 
45  Parser (ErrorHandler& errorHandler, const Context& context);
47 
48  virtual ~Parser();
50 
51  virtual bool parseInt (int value, const TokenLoc& loc, Scanner& scanner);
56 
57  virtual bool parseFloat (float value, const TokenLoc& loc, Scanner& scanner);
62 
63  virtual bool parseName (const std::string& name, const TokenLoc& loc,
64  Scanner& scanner);
69 
70  virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
75 
76  virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
81 
82  virtual bool parseComment (const std::string& comment, const TokenLoc& loc,
83  Scanner& scanner);
88 
89  virtual void parseEOF (Scanner& scanner);
93 
94  virtual void reset();
96 
97  void setOptional (bool optional);
100 
101  void start();
103 
104  bool isEmpty() const;
106  };
107 }
108 
109 #endif
virtual bool parseFloat(float value, const TokenLoc &loc, Scanner &scanner)
Definition: parser.cpp:87
void message(CodeContainer &code, Literals &literals, const std::string &message, int buttons)
Definition: generator.cpp:537
virtual bool parseKeyword(int keyword, const TokenLoc &loc, Scanner &scanner)
Definition: parser.cpp:118
virtual void reset()
Reset parser to clean state.
Definition: parser.cpp:157
void setOptional(bool optional)
Definition: parser.cpp:163
Definition: context.hpp:10
Location of a token in a source file.
Definition: tokenloc.hpp:10
static std::string toLower(const std::string &name)
Definition: parser.cpp:52
Error handling.
Definition: errorhandler.hpp:14
void reportEOF()
Report an unexpected EOF condition.
Definition: parser.cpp:32
virtual void parseEOF(Scanner &scanner)
Definition: parser.cpp:152
virtual bool parseName(const std::string &name, const TokenLoc &loc, Scanner &scanner)
Definition: parser.cpp:102
bool mOptional
Definition: parser.hpp:21
ErrorHandler & getErrorHandler()
Return error handler.
Definition: parser.cpp:40
ErrorHandler & mErrorHandler
Definition: parser.hpp:19
virtual bool parseSpecial(int code, const TokenLoc &loc, Scanner &scanner)
Definition: parser.cpp:133
Parser(ErrorHandler &errorHandler, const Context &context)
constructor
Definition: parser.cpp:59
const Context & getContext() const
Return context.
Definition: parser.cpp:47
const Context & mContext
Definition: parser.hpp:20
virtual ~Parser()
destructor
Definition: parser.cpp:65
int code
Definition: crashcatcher.cpp:70
void reportSeriousError(const std::string &message, const TokenLoc &loc)
Report the error and throw a exception.
Definition: parser.cpp:17
virtual bool parseComment(const std::string &comment, const TokenLoc &loc, Scanner &scanner)
Definition: parser.cpp:143
virtual bool parseInt(int value, const TokenLoc &loc, Scanner &scanner)
Definition: parser.cpp:72
Parser base class.
Definition: parser.hpp:17
bool isEmpty() const
Has anything been parsed?
Definition: parser.cpp:173
bool mEmpty
Definition: parser.hpp:22
void reportWarning(const std::string &message, const TokenLoc &loc)
Report the warning without throwing an exception.
Definition: parser.cpp:25
void start()
Mark parser as non-empty (at least one token has been parser).
Definition: parser.cpp:168
Scanner.
Definition: scanner.hpp:21
const char * name
Definition: crashcatcher.cpp:59