ESP_IOT v2.5
IOT ESP Coding
TokenParser.cpp File Reference
#include "TokenParser.h"
Include dependency graph for TokenParser.cpp:

Go to the source code of this file.

Classes

struct  identifierStruct
 

Typedefs

typedef struct identifierStruct IdentifierStruct
 

Enumerations

enum  TokensEnum {
  notModifier_enum , wildcardAny_enum , booleanOr_enum , booleanAnd_enum ,
  identifier_enum , null_enum
}
 retrieves the parsed values More...
 

Functions

void pushToken (TokensEnum token)
 pushes token onto token stack More...
 
TokensEnum topOfTokenStack ()
 get the current top of stack token More...
 
TokensEnum popTokenStack ()
 get the current top of stack token, and move the token stack pointer More...
 
void pushIdentifier (char *identifier)
 pushes identifier onto identifier stack, while also inserting a token for identifier More...
 
int numTokens ()
 how many tokens More...
 
int numIdentifiers ()
 how many identifiers More...
 
TokensEnum getToken (int num)
 get the nth token More...
 
char * getIdentifier (int num)
 the nth identifier More...
 
IdentifierStruct getIdentifierStruct (int num)
 grab full identifier struct (Pointer?) More...
 
void addIdentifierChar (char c)
 adds a valie character to an identifier More...
 
void initIdentifier (char c)
 initi for each new identifier More...
 
void doneParsingIdentifier ()
 finished parsing an identifier More...
 
boolean validIdentifierChar (char c)
 
void processIdentifier ()
 
void initParser ()
 initialize the parser More...
 
void parseQueryLine_mainModule (char *line)
 parses a line of text, returning the number of tokens.. More...
 
boolean nameMatchesWildcardQuery (char *name, IdentifierStruct idQueryStruct)
 
boolean stringIsQuery_mainModule (char *line)
 whether the stirng is a potential query More...
 
boolean queryMatchesName_mainModule (char *name)
 
void setup_tokenParser_mainModule ()
 setup a test .. More...
 

Variables

const int _identifierMaxLen = 30
 max length of an identifier.. More...
 
char _identifier [_identifierMaxLen]
 storage for the current identifier More...
 
int _identifierIndex
 
const int _identifierStructsMax = 3
 so now a query is { IdentifierStruct <booleanAnd/Or> } More...
 
int _identifierStructsIndex = 0
 index into _identifiers array More...
 
IdentifierStruct _identifierStructs [_identifierStructsMax]
 array of identifiers .. More...
 
const int _tokensMax = 10
 
TokensEnum _tokens [_tokensMax]
 
int _tokensStackPointer
 index into _tokens array More...
 
boolean _parsingIdentifier
 whether in an identifier parsing More...
 

Typedef Documentation

◆ IdentifierStruct

Enumeration Type Documentation

◆ TokensEnum

enum TokensEnum

retrieves the parsed values

the tokens in the token array

Enumerator
notModifier_enum 
wildcardAny_enum 
booleanOr_enum 
booleanAnd_enum 
identifier_enum 
null_enum 

Definition at line 29 of file TokenParser.cpp.

Function Documentation

◆ addIdentifierChar()

void addIdentifierChar ( char  c)

adds a valie character to an identifier

Definition at line 149 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ doneParsingIdentifier()

void doneParsingIdentifier ( )

finished parsing an identifier

Definition at line 163 of file TokenParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIdentifier()

char * getIdentifier ( int  num)

the nth identifier

Definition at line 137 of file TokenParser.cpp.

◆ getIdentifierStruct()

IdentifierStruct getIdentifierStruct ( int  num)

grab full identifier struct (Pointer?)

Definition at line 143 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ getToken()

TokensEnum getToken ( int  num)

get the nth token

Definition at line 132 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ initIdentifier()

void initIdentifier ( char  c)

initi for each new identifier

Definition at line 156 of file TokenParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initParser()

void initParser ( )

initialize the parser

Definition at line 238 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ nameMatchesWildcardQuery()

boolean nameMatchesWildcardQuery ( char *  name,
IdentifierStruct  idQueryStruct 
)

These are CASE SENSITIVE matches ... matches name with wildcards and the idToMatch name is what is being queried, the idQueryStruct is the QUERY

See also
https://legacy.cplusplus.com/reference/cstring/strncmp/ eg. idToMatch == M5 and wildcard after and before, then just search for idToMatch in name If not before, then starts with ... if non, then strmatch

see if there was a NOT (!)

Definition at line 358 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ numIdentifiers()

int numIdentifiers ( )

how many identifiers

Definition at line 127 of file TokenParser.cpp.

◆ numTokens()

int numTokens ( )

how many tokens

Definition at line 122 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ parseQueryLine_mainModule()

void parseQueryLine_mainModule ( char *  line)

parses a line of text, returning the number of tokens..

parses a line of text, The caller then uses queryMatchesName() to see if their name matches

initialize the variables for parsing this line

if no query params, then make it an identifier and exit

if parsing still then add to identifier

start a new identifier..

init the identifier

else not valid identifier (so a follow..)

done parsing if not a valid identifier character

finishIdNeeded is before pushing another token, unless a not or wildcard

now classify this char if an identifier modifier

! and * belong to the identifier object if a modifier of ident (~ or *) then push the token, and process the identifier

an operator or space if inside an identifier, finish it first

process the token

& and | are expression modifiers

if end of line, and was parsing an identifier .. then finish

Definition at line 254 of file TokenParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ popTokenStack()

TokensEnum popTokenStack ( )

get the current top of stack token, and move the token stack pointer

else pop

Definition at line 95 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ processIdentifier()

void processIdentifier ( )

push identifier .. looks at the stack and fills in the identifier object called after seeing a & or | (the follow set of the identifier, after a *)*

the index is already 1 past..

look at stack

replace the stack with our filled out identifier

Definition at line 187 of file TokenParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pushIdentifier()

void pushIdentifier ( char *  identifier)

pushes identifier onto identifier stack, while also inserting a token for identifier

now save Identifier

Definition at line 112 of file TokenParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pushToken()

void pushToken ( TokensEnum  token)

pushes token onto token stack

Definition at line 72 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ queryMatchesName_mainModule()

boolean queryMatchesName_mainModule ( char *  name)

now need to process the token tree to see if name1 and name2 match the query eg. ! name & name2 ... wildcards after name make it slightly complicated SO: look for wildcards before and after, and the id. then decide if that matches before the boolean and notmodifier applied

basically for each identifier in the query, the names (1&2) have to be compared each time..

what the last boolean_enum was..

the result of A <> B

Definition at line 419 of file TokenParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_tokenParser_mainModule()

void setup_tokenParser_mainModule ( )

setup a test ..

setup for the token parser (really just for testing)

Definition at line 654 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ stringIsQuery_mainModule()

boolean stringIsQuery_mainModule ( char *  line)

whether the stirng is a potential query

whether the stirng is a potential query. This can be used, but it is also used by the parseQueryLine to optimize out the original dev:name query.

Definition at line 407 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ topOfTokenStack()

TokensEnum topOfTokenStack ( )

get the current top of stack token

otherwise grab the top

Definition at line 85 of file TokenParser.cpp.

Here is the caller graph for this function:

◆ validIdentifierChar()

boolean validIdentifierChar ( char  c)

Definition at line 170 of file TokenParser.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ _identifier

char _identifier[_identifierMaxLen]

storage for the current identifier

Definition at line 42 of file TokenParser.cpp.

◆ _identifierIndex

int _identifierIndex

Definition at line 44 of file TokenParser.cpp.

◆ _identifierMaxLen

const int _identifierMaxLen = 30

max length of an identifier..

Definition at line 40 of file TokenParser.cpp.

◆ _identifierStructs

array of identifiers ..

Definition at line 61 of file TokenParser.cpp.

◆ _identifierStructsIndex

int _identifierStructsIndex = 0

index into _identifiers array

Definition at line 59 of file TokenParser.cpp.

◆ _identifierStructsMax

const int _identifierStructsMax = 3

so now a query is { IdentifierStruct <booleanAnd/Or> }

the max number of identifiers

Definition at line 57 of file TokenParser.cpp.

◆ _parsingIdentifier

boolean _parsingIdentifier

whether in an identifier parsing

Definition at line 69 of file TokenParser.cpp.

◆ _tokens

Definition at line 64 of file TokenParser.cpp.

◆ _tokensMax

const int _tokensMax = 10

Definition at line 63 of file TokenParser.cpp.

◆ _tokensStackPointer

int _tokensStackPointer

index into _tokens array

Definition at line 66 of file TokenParser.cpp.