3#ifdef WILDCARD_DEVICE_NAME_SUPPORT
78 SerialMin.println(
" *** Over the token max ***");
114 SerialLots.printf(
"\nPushId %s\n", identifier);
174 boolean valid =
false;
177 else if (c >=
'A' && c <=
'Z')
179 else if (c >=
'a' && c <=
'z')
181 else if (c >=
'0' && c <=
'9')
195 SerialLots.printf(
"\nprocessIdentifier[%d]\n", identifierStructsIndex);
201 SerialLots.printf(
"wildcardAny_enum\n");
209 SerialMin.printf(
"*** Syntax error: expected identifier, found: %d\n", top);
213 SerialLots.printf(
"identifier_enum\n");
221 SerialLots.printf(
"wildcardAny_enum\n");
229 SerialLots.printf(
"notModifier_enum\n");
233 SerialLots.printf(
"token = %d\n", top);
262 SerialTemp.printf(
"\nDevQuery: %s\n", line);
269 SerialLots.println(
"*** Not a query, so optimze to just identifier");
295 boolean finishIdNeeded =
false;
300 finishIdNeeded =
true;
305 if (c ==
'!' || c ==
'*')
342 SerialTemp.println(
" *** INVALID CHAR ***");
365 char *queryIdToMatch = idQueryStruct.
identifier;
370 boolean match =
false;
372 SerialLots.printf(
"%s - idQuery(%s), before=%d,after=%d,not=%d\n", name, queryIdToMatch, wildcardBefore, wildcardAfter, wildcardNot);
377 if (wildcardBefore && wildcardAfter)
379 match = (strstr(name, queryIdToMatch)!=NULL);
380 else if (wildcardAfter)
382 match = (strncmp(name, queryIdToMatch, strlen(queryIdToMatch))==0);
383 else if (wildcardBefore)
385 int queryIdLen = strlen(queryIdToMatch);
386 int nameLen = strlen(name);
393 if (nameLen >= queryIdLen)
396 char *startInName = name + nameLen - queryIdLen;
397 match = strcmp(startInName, queryIdToMatch) == 0;
402 match = strcmp(name, queryIdToMatch)==0;
415 boolean isQuery = strpbrk(line, (
char*)
"|*&!") != NULL;
427 boolean match =
true;
435 boolean thisMatch =
false;
456 match = match && thisMatch;
463 match = match || thisMatch;
465 match = match && thisMatch;
469 SerialLots.printf(
"thisMatch = %d, match = %d\n", thisMatch, match);
486 SerialTemp.println(
"TOKEN TREE..");
493 SerialTemp.printf(
"Token [%d]= ", tokensIndex);
498 SerialTemp.println(
"notModifier_enum");
501 SerialTemp.println(
"wildcardAny_enum");
504 SerialTemp.println(
"booleanOr_enum");
507 SerialTemp.println(
"booleanAnd_enum");
513 SerialTemp.printf(
"identifier_enum: %s%s%s%s\n",
526void testMatchResult(
char*query,
boolean expectedBool)
529 SerialTemp.printf(
"query '%s' ", query);
530 if (match != expectedBool)
531 SerialTemp.printf(
"!= expected: ");
533 SerialTemp.printf(
"== matched : ");
534 SerialTemp.printf(
"%s\n", expectedBool?(
char*)
"MATCH":(
char*)
"NO-MATCH");
538boolean _firstTimeParserTest =
true;
541void testParser_mainModule()
547 testMatchResult((
char*)
"M5WRR",
false);
548 testMatchResult((
char*)
"M5Rainier",
true);
552 testMatchResult((
char*)
"M5WRR",
false);
553 testMatchResult((
char*)
"DukeGEN3",
false);
554 testMatchResult((
char*)
"ScoobyDoo",
true);
555 testMatchResult((
char*)
"ScottyGEN3",
true);
558 testMatchResult((
char*)
"M5Scooby",
true);
559 testMatchResult((
char*)
"DukeGEN3",
true);
563 testMatchResult((
char*)
"M5Scooby",
true);
564 testMatchResult((
char*)
"DukeGEN3",
false);
567 testMatchResult((
char*)
"M5Scooby",
false);
568 testMatchResult((
char*)
"DukeGEN3",
true);
571 testMatchResult((
char*)
"M5Scooby",
false);
572 testMatchResult((
char*)
"DukeGEN3",
false);
573 testMatchResult((
char*)
"M5DukeGEN3",
false);
574 testMatchResult((
char*)
"M5DukeGEN3",
true);
577 testMatchResult((
char*)
"M5Scooby",
false);
578 testMatchResult((
char*)
"DukeGEN3",
true);
579 testMatchResult((
char*)
"M5DukeGEN3",
false);
582 testMatchResult((
char*)
"M5WRR",
false);
583 testMatchResult((
char*)
"DukeGEN3",
true);
586 testMatchResult((
char*)
"M5WRR",
false);
587 testMatchResult((
char*)
"M5Scooby",
true);
590 testMatchResult((
char*)
"M5Scooby",
true);
591 testMatchResult((
char*)
"GEN3Scott",
true);
592 testMatchResult((
char*)
"ScoobyDoo",
true);
593 testMatchResult((
char*)
"Duke",
false);
594 testMatchResult((
char*)
"M5Duke",
true);
597 testMatchResult((
char*)
"ScoobyDoo",
true);
598 testMatchResult((
char*)
"Duke",
false);
601 testMatchResult((
char*)
"ScoobyDoo",
true);
602 testMatchResult((
char*)
"M5WRR",
false);
603 testMatchResult((
char*)
"GEN3Scott",
true);
606 testMatchResult((
char*)
"ScoobyDoo",
true);
607 testMatchResult((
char*)
"M5WRR",
false);
608 testMatchResult((
char*)
"GEN3Scott",
true);
612 testMatchResult((
char*)
"Room1_M5Scooby",
true);
613 testMatchResult((
char*)
"Room1_GEN3",
false);
614 testMatchResult((
char*)
"Room2_GEN3",
false);
615 testMatchResult((
char*)
"M5WRR",
false);
619 testMatchResult((
char*)
"Room1_M5Scooby",
true);
620 testMatchResult((
char*)
"Room1_GEN3",
true);
621 testMatchResult((
char*)
"Room2_GEN3",
false);
622 testMatchResult((
char*)
"Room2_M5",
true);
623 testMatchResult((
char*)
"M5WRR",
true);
627 testMatchResult((
char*)
"Room1_M5Scooby",
true);
628 testMatchResult((
char*)
"Room1_GEN3",
true);
629 testMatchResult((
char*)
"Room2_GEN3",
false);
633 testMatchResult((
char*)
"Scooby_Room1",
true);
634 testMatchResult((
char*)
"Scooby_Room1_GEN3",
false);
635 testMatchResult((
char*)
"Room1",
true);
636 testMatchResult((
char*)
"Room2",
false);
640 testMatchResult((
char*)
"Scooby_GEN3",
true);
641 testMatchResult((
char*)
"Scooby_GEN3_Room1",
false);
642 testMatchResult((
char*)
"GEN3",
true);
643 testMatchResult((
char*)
"GEN2",
false);
647 testMatchResult((
char*)
"Scooby_GEN3",
false);
648 testMatchResult((
char*)
"Scooby_GEN3_Room1",
true);
649 testMatchResult((
char*)
"GEN3",
false);
650 testMatchResult((
char*)
"GEN2",
true);
651 testMatchResult((
char*)
"M5Scooby",
true);
652 testMatchResult((
char*)
"DukeGEN3",
false);
653 testMatchResult((
char*)
"M5DukeGEN3",
false);
662 if (_firstTimeParserTest)
664 _firstTimeParserTest =
false;
665 testParser_mainModule();
737 SerialLots.printf(
"\nTokens for: %s\n",semanticMarker);
748 int setDeviceFlag = -1;
753 for (
char *token= strtok(semanticMarker,
"/"); token!= NULL; token= strtok(NULL,
"/"))
760 if (strcmp(token,
"setdevice")==0)
762 else if (strcmp(token,
"cmddevice")==0)
774 sprintf(buffer,
"'dev':'%s',\n", token);
782 sprintf(buffer,
"'%s':'%s',\n",
"set",token);
783 else if (setDeviceFlag == 0)
784 sprintf(buffer,
"'%s':'%s'\n",
"cmd",token);
790 sprintf(buffer,
"'val':'%s'\n", token);
797 int indexLen = arrayIndex - 1;
798 SerialLots.printf(
"#IndexLen= %d\n", indexLen);
799 switch (setDeviceFlag)
804 SerialDebug.printf(
" *** Wrong syntax setDevice *** \n");
810 SerialDebug.printf(
" *** Wrong syntax sendDevice *** \n");
818 if (setDeviceFlag >= 0)
861 char _flowString[40];
863 strcpy(_flowString,
"");
867 strcpy(str,semanticMarker);
871 for (
char *token= strtok(str,
"/"); token!= NULL; token= strtok(NULL,
"/"))
873 SerialLots.printf(
"Token[%d] = %s\n", arrayIndex, token);
889 char *smartIndex = strstr(token,
"smart?");
891 smartIndex += strlen(
"smart?");
894 for (
char*amper = strtok(smartIndex,
"&"); amper!=NULL; amper=strtok(NULL,
"&"))
896 char *equalIndex = strchr(amper,
'=');
898 char queryString[100];
899 int len = equalIndex - amper;
900 strncpy(queryString, amper, len);
901 queryString[len] =
'\0';
902 SerialLots.printf(
"%s - %d\n", queryString, len);
906 if (strcmp(queryString,
"uuid")==0)
910 else if (strcmp(queryString,
"flow")==0)
912 strcpy(_flowString, equalIndex);
914 SerialLots.printf(
"query ={%s,%s}\n", queryString, equalIndex);
920 if (strlen(
_uuidString) > 0 && strlen(_flowString) > 0)
void initParser()
initialize the parser
TokensEnum topOfTokenStack()
get the current top of stack token
const int _identifierStructsMax
so now a query is { IdentifierStruct <booleanAnd/Or> }
boolean stringIsQuery_mainModule(char *line)
whether the stirng is a potential query
struct identifierStruct IdentifierStruct
const int _identifierMaxLen
max length of an identifier..
TokensEnum _tokens[_tokensMax]
boolean nameMatchesWildcardQuery(char *name, IdentifierStruct idQueryStruct)
void addIdentifierChar(char c)
adds a valie character to an identifier
boolean _parsingIdentifier
whether in an identifier parsing
boolean queryMatchesName_mainModule(char *name)
void initIdentifier(char c)
initi for each new identifier
IdentifierStruct _identifierStructs[_identifierStructsMax]
array of identifiers ..
TokensEnum getToken(int num)
get the nth token
void parseQueryLine_mainModule(char *line)
parses a line of text, returning the number of tokens..
void setup_tokenParser_mainModule()
setup a test ..
void pushToken(TokensEnum token)
pushes token onto token stack
boolean validIdentifierChar(char c)
int numTokens()
how many tokens
void pushIdentifier(char *identifier)
pushes identifier onto identifier stack, while also inserting a token for identifier
char _sm_for_UUID_Flownum[100]
global for returning..
char * getIdentifier(int num)
the nth identifier
int _identifierStructsIndex
index into _identifiers array
int numIdentifiers()
how many identifiers
char * semanticMarkerToJSON_TokenParser(char *semanticMarker)
TokensEnum popTokenStack()
get the current top of stack token, and move the token stack pointer
int _tokensStackPointer
index into _tokens array
char _JSON_String_mainModule[300]
storage for the current identifier
char * parseSM_For_UUID_Flownum(char *semanticMarker)
void doneParsingIdentifier()
finished parsing an identifier
char _identifier[_identifierMaxLen]
storage for the current identifier
TokensEnum
retrieves the parsed values
IdentifierStruct getIdentifierStruct(int num)
grab full identifier struct (Pointer?)
char identifier[_identifierMaxLen]