Parser is finished (or very nearly so)!!! :-)

+ Added support for extended notation floating point numbers,
as well as signed (+ and -) floats.
+ Finished up parsing code
+ Moved Err class into it's own header/source pair, since I
started using it all over the place in the sniffer code.
+ Did my darndest to make sure I wasn't leaking memory
anywhere.
+ Matched up error messages as best as possible with R5's
error message. Some couldn't be matched, some were improved.

There *are* a few things left to do. I don't think priorities are
verified to be valid (0.0 <= x <= 1.0). More tests also need to
be written. Things have solidified enough now that documentation
is a reasonable thing to start considering as well.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@608 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-08-06 08:37:14 +00:00
parent 01293d6ed7
commit 390dce8da6
2 changed files with 405 additions and 185 deletions
+27 -25
View File
@@ -10,23 +10,21 @@
#define _sk_sniffer_parser_h_
#include <SupportDefs.h>
#include <sniffer/Err.h>
#include <sniffer/Range.h>
#include <sniffer/Rule.h>
#include <List.h>
#include <string>
#include <vector>
class BString;
namespace Sniffer {
class Rule;
class Expr;
class Range;
class RPattern;
class Pattern;
typedef std::vector<Expr*> ExprList;
//------------------------------------------------------------------------------
// The mighty parsing function ;-)
@@ -38,21 +36,6 @@ status_t parse(const char *rule, Rule *result, BString *parseError = NULL);
// Classes used internally by the parser
//------------------------------------------------------------------------------
class Err {
public:
Err(const char *msg, const ssize_t pos);
Err(const std::string &msg, const ssize_t pos);
Err(const Err &ref);
Err& operator=(const Err &ref);
const char* Msg() const;
ssize_t Pos() const;
private:
void SetMsg(const char *msg);
char *fMsg;
ssize_t fPos;
};
class CharStream {
public:
CharStream(const char *string = NULL);
@@ -63,6 +46,7 @@ public:
status_t InitCheck() const;
bool IsEmpty() const;
ssize_t Pos() const;
const char *String() const;
char Get();
void Unget();
@@ -102,7 +86,7 @@ public:
virtual int32 Int() const;
virtual double Float() const;
ssize_t Pos() const;
bool operator==(Token &ref);
bool operator==(Token &ref) const;
protected:
TokenType fType;
ssize_t fPos;
@@ -143,10 +127,16 @@ public:
void Unset();
status_t InitCheck() const;
Token* Get();
void Unget(Token *token);
const Token* Get();
void Unget();
bool IsEmpty();
void Read(TokenType type);
bool CondRead(TokenType type);
ssize_t Pos() const;
ssize_t EndPos() const;
bool IsEmpty() const;
private:
void AddToken(TokenType type, ssize_t pos);
@@ -154,9 +144,12 @@ private:
void AddInt(const char *str, ssize_t pos);
void AddFloat(const char *str, ssize_t pos);
BList fTokenList;
std::vector<Token*> fTokenList;
int fPos;
int fStrLen;
status_t fCStatus;
TokenStream(const TokenStream &ref);
TokenStream& operator=(const TokenStream &ref);
};
@@ -164,22 +157,31 @@ private:
class Parser {
public:
Parser();
~Parser();
status_t Parse(const char *rule, Rule *result, BString *parseError = NULL);
private:
std::string ErrorMessage(Err *err, const char *rule);
// Things that get done a lot :-)
void ThrowEndOfStreamError();
inline void ThrowOutOfMemError(ssize_t pos);
void ThrowUnexpectedTokenError(TokenType expected, const Token *found);
void ThrowUnexpectedTokenError(TokenType expected1, TokenType expected2, const Token *found);
// Parsing functions
void ParseRule(Rule *result);
double ParsePriority();
ExprList* ParseExprList();
std::vector<Expr*>* ParseExprList();
Expr* ParseExpr();
Range ParseRange();
Expr* ParsePatternList();
Expr* ParsePatternList(Range range);
Expr* ParseRPatternList();
RPattern* ParseRPattern();
Pattern* ParsePattern();
TokenStream stream;
Err *fOutOfMemErr;
};
} // namespace Sniffer