2018-02-23 17:07:12 +00:00
|
|
|
#ifndef __KF_PARSER_H__
|
|
|
|
#define __KF_PARSER_H__
|
|
|
|
|
|
|
|
#include "defs.h"
|
2018-02-24 03:19:29 +00:00
|
|
|
#include "stack.h"
|
2018-02-23 17:07:12 +00:00
|
|
|
|
|
|
|
struct Token {
|
|
|
|
char *token;
|
|
|
|
uint8_t length;
|
|
|
|
};
|
|
|
|
|
2018-02-23 22:01:52 +00:00
|
|
|
typedef enum _PARSE_RESULT_ : uint8_t {
|
|
|
|
PARSE_OK = 0,
|
|
|
|
PARSE_EOB = 1, // end of buffer
|
|
|
|
PARSE_LEN = 2, // token is too long
|
|
|
|
PARSE_FAIL = 3 // catch-all error
|
|
|
|
} PARSE_RESULT;
|
|
|
|
|
|
|
|
bool match_token(const char *, const size_t, const char *, const size_t);
|
|
|
|
PARSE_RESULT parse_next(const char *, const size_t, size_t *, struct Token *);
|
2018-02-23 17:07:12 +00:00
|
|
|
|
2018-02-24 03:19:29 +00:00
|
|
|
// TODO(kyle): investigate a better return value, e.g. to differentiate between
|
|
|
|
// stack failures and parse failures.
|
|
|
|
bool parse_num(struct Token *, Stack<KF_INT> &);
|
|
|
|
|
2018-02-23 17:07:12 +00:00
|
|
|
|
|
|
|
#endif // __KF_PARSER_H__
|