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)
837char _sm_for_UUID_Flownum[100];
870 char _flowString[40];
872 strcpy(_flowString,
"");
876 strcpy(str,semanticMarker);
877 strcpy(_sm_for_UUID_Flownum,
"");
880 for (
char *token= strtok(str,
"/"); token!= NULL; token= strtok(NULL,
"/"))
882 SerialLots.printf(
"Token[%d] = %s\n", arrayIndex, token);
898 char *smartIndex = strstr(token,
"smart?");
900 smartIndex += strlen(
"smart?");
903 for (
char*amper = strtok(smartIndex,
"&"); amper!=NULL; amper=strtok(NULL,
"&"))
905 char *equalIndex = strchr(amper,
'=');
907 char queryString[100];
908 int len = equalIndex - amper;
909 strncpy(queryString, amper, len);
910 queryString[len] =
'\0';
911 SerialLots.printf(
"%s - %d\n", queryString, len);
915 if (strcmp(queryString,
"uuid")==0)
919 else if (strcmp(queryString,
"flow")==0)
921 strcpy(_flowString, equalIndex);
923 SerialLots.printf(
"query ={%s,%s}\n", queryString, equalIndex);
929 if (strlen(
_uuidString) > 0 && strlen(_flowString) > 0)
931 sprintf(_sm_for_UUID_Flownum,
"%s.%s",
_uuidString, _flowString);
932 SerialDebug.printf(
"SemanticMarker: %s\n", _sm_for_UUID_Flownum);
934 return _sm_for_UUID_Flownum;
937 return _sm_for_UUID_Flownum;
951 SerialDebug.printf(
"ParseSM: %s\n", str);
956 char* paren = index(str,
'(');
963 SerialLots.printf(
"sm. %s\n", b);
969 char *comma = index(paren,
',');
973 b[comma-paren] =
'\0';
975 SerialLots.printf(
"str. %s\n", b);
981 comma = index(paren,
',');
985 b[comma-paren] =
'\0';
987 SerialLots.printf(
"val. %s\n", b);
998 char *rparen = index(paren,
')');
1002 b[rparen-paren] =
'\0';
1004 SerialLots.printf(
"dev. %s\n", b);
1022 char *uuidIndex = strstr(str,
"uuid=");
1027 uuidIndex += strlen(
"uuid=");
1029 while (uuidIndex[i] !=
'&')
1038 char *flowIndex = strstr(str,
"flow=");
1041 flowIndex += strlen(
"flow=");
1045 while (flowIndex[j] !=
'&' && flowIndex[j] !=
'}' && flowIndex[j] !=
'\0')
char * createCopy(char *stringA)
void initParser()
initialize the parser
char _smBuffer_chain[100]
storage for sm parsin
TokensEnum topOfTokenStack()
get the current top of stack token
const int _identifierStructsMax
so now a query is { IdentifierStruct <booleanAnd/Or> }
char * parseDOCFOLLOW(char *str)
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 * 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)
before 1355313 now 1355169
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?)
SMStruct parseSMAddress(char *str)
2.11.26 moved here from ChainButtonClassType
char identifier[_identifierMaxLen]