forked from mightymos/OnbrightFlasher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleParser.h
64 lines (56 loc) · 1.56 KB
/
simpleParser.h
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
/*
* Written 2014 by Bill Westfield (WestfW)
* Refactored 2020
* Released to the public domain.
*/
#include "Arduino.h"
class parserCore {
private:
char *buffer;
char *lastToken;
byte lineLen;
Stream *S;
byte inptr; /* read character into here */
byte parsePtr;
byte termchar;
// Internal functions.
bool IsWhitespace(char c);
bool delim(char c);
char *token(void);
// int8_t KeywordPM (const char *keys);
uint8_t tokcasecmp(const char *tok, const char * target);
public:
parserCore(char *buf, byte buflen, Stream &io) {
buffer = buf;
lineLen = buflen;
S = &io;
}
uint8_t getLine(void); /* Non-blocking read line w/editing*/
uint8_t getLineWait(void); /* wait for a full line of input */
void reset(void); /* reset the parser */
int number(); /* parse a number */
int lastNumber();
boolean eol(); /* check for EOL */
uint8_t termChar(); /* return the terminating char of last token */
int8_t keyword(const char *keys); /* keyword with partial matching */
// int8_t keywordExact(const char *keys); /* keyword exact match */
int tryihex(int16_t *addr, uint8_t * bytes);
uint8_t hexton (uint8_t h);
};
/*
* Constants
*/
#define PARSER_NOMATCH -1
#define PARSER_EOL -2
#define PARSER_AMB -3
#define CMP_PARTIALMATCH 2
#define CMP_NONMATCH 1
#define CMP_MATCH 0
#define CTRL(x) (x-64)
template <size_t maxline=80>
class simpleParser: public parserCore {
private:
char buf[maxline];
public:
simpleParser(Stream &io) : parserCore(buf, sizeof(buf), io) {}
};