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
|
#pragma once
#include "InfoErrors.h"
#include "Compiler/Package.h"
#include "Compiler/Exception.h"
#include "Compiler/Syntax/Rule.h"
#include "Compiler/Syntax/Production.h"
#include "Compiler/Syntax/Node.h"
#include "Compiler/Syntax/InfoNode.h"
namespace storm {
namespace syntax {
STORM_PKG(lang.bnf);
#ifdef DEBUG
extern bool parserDebug;
#define PARSER_PLN(x) if (parserDebug) { PLN(x); }
#define PARSER_PVAR(x) if (parserDebug) { PVAR(x); }
#else
#define PARSER_PLN(x)
#define PARSER_PVAR(x)
#endif
/**
* Represents one of the available parser backends.
*
* Most of the API is protected and only accessible to the Parser class to ensure
* type-safety.
*/
class ParserBackend : public ObjectOn<Compiler> {
STORM_CLASS;
protected:
friend class ParserBase;
STORM_CTOR ParserBackend();
// Add syntax rules or productions.
virtual void add(Rule *rule);
virtual void add(ProductionType *prod);
// Does this parser contain the same syntax as 'o'?
virtual Bool sameSyntax(ParserBackend *o);
// Parse a string. Returns 'true' if we found some match.
virtual Bool parse(Rule *root, Str *str, Url *file, Str::Iter start, Str::Iter end);
// Parse a string, doing error recovery. Only call 'infoTree' after parsing in this
// manner, as the resulting syntax tree is not neccessarily complete.
virtual InfoErrors parseApprox(Rule *root, Str *str, Url *file,
Str::Iter start, Str::Iter end, MAYBE(InfoInternal *) ctx);
// Clear all parse-related information. Included packages are retained.
virtual void clear();
/**
* Operations on the last parse.
*/
// Found any errors? If Str::Iter is not end, this is always true. Note that even if we
// have an error, it could be possible to extract a tree!
virtual Bool hasError() const;
// Is it possible to extract a syntax tree? (equivalent to the return value of 'parse').
virtual Bool hasTree() const;
// Return an iterator after the last matched character, or the start of the string if no
// match could be made.
virtual Str::Iter matchEnd() const;
// Get the error message.
virtual Str *errorMsg() const;
// Get the error position.
virtual SrcPos errorPos() const;
// Get the syntax tree. Only for C++, in Storm we know the exact subtype we will generate!
virtual Node *tree() const;
// Get the generic syntax tree.
virtual InfoNode *infoTree() const;
/**
* Performance inspection:
*/
// Get the number of states used.
virtual Nat stateCount() const;
// Get the number of bytes used.
virtual Nat byteCount() const;
};
}
}
|