- Timestamp:
- Jun 4, 2012 12:57:02 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/err.h
r41558 r41559 2122 2122 /** Syntax error - too many arguments for static storage. */ 2123 2123 #define VERR_DBGC_PARSE_ARGUMENT_OVERFLOW (VERR_DBGC_PARSE_LOWEST + 2) 2124 /** Syntax error - expected binary operator. */ 2125 #define VERR_DBGC_PARSE_EXPECTED_BINARY_OP (VERR_DBGC_PARSE_LOWEST + 3) 2124 2126 2125 2127 /** Syntax error - the argument does not allow a range to be specified. */ -
trunk/src/VBox/Debugger/DBGCEval.cpp
r41558 r41559 549 549 unsigned cBinaryOps = 0; 550 550 unsigned cPar = 0; 551 unsigned cchWord = 0; 551 552 char chQuote = '\0'; 552 553 char chPrev = ' '; … … 557 558 while ((ch = *psz) != '\0') 558 559 { 559 //Log2(("ch=%c cPar=%d fBinary=%d\n", ch, cPar, fBinary));560 560 /* 561 561 * String quoting. … … 563 563 if (chQuote) 564 564 { 565 if ( ch == chQuote 566 && psz[1] != chQuote) 567 { 568 chQuote = '\0'; 569 fBinary = true; 570 } 565 if (ch == chQuote) 566 { 567 if (psz[1] == chQuote) 568 { 569 psz++; /* escaped quote */ 570 cchWord++; 571 } 572 else 573 { 574 chQuote = '\0'; 575 fBinary = true; 576 cchWord = 0; 577 } 578 } 579 else 580 cchWord++; 571 581 } 572 582 else if (ch == '"' || ch == '\'') 583 { 584 if (fBinary || cchWord) 585 return VERR_DBGC_PARSE_EXPECTED_BINARY_OP; 573 586 chQuote = ch; 587 } 574 588 /* 575 589 * Parentheses. … … 577 591 else if (ch == '(') 578 592 { 593 if (!cPar && (fBinary || cchWord)) /** @todo function call */ 594 return VERR_DBGC_PARSE_EXPECTED_BINARY_OP; 579 595 cPar++; 580 596 fBinary = false; 597 cchWord = 0; 581 598 } 582 599 else if (ch == ')') … … 586 603 cPar--; 587 604 fBinary = true; 605 cchWord = 0; 588 606 } 589 607 /* … … 622 640 psz += pOp->cchName - 1; 623 641 fBinary = false; 624 } 642 cchWord = 0; 643 } 644 else if (fBinary && !cchWord) 645 return VERR_DBGC_PARSE_EXPECTED_BINARY_OP; 625 646 else 647 { 626 648 fBinary = true; 627 } 649 cchWord++; 650 } 651 } 652 else if (cPar == 0 && RT_C_IS_BLANK(ch)) 653 cchWord++; 628 654 629 655 /* next */ … … 974 1000 975 1001 /* 976 * Find the end of the argument. 1002 * Find the end of the argument. This is just rough splitting, 1003 * dbgcEvalSub will do stricter syntax checking later on. 977 1004 */ 978 1005 int cPar = 0; … … 1000 1027 * We use the REXX way of escaping the quotation char, i.e. double occurrence. 1001 1028 */ 1002 else if (ch == '\'' || ch == '"')1003 { 1004 if (ch Quote)1029 else if (chQuote) 1030 { 1031 if (ch == chQuote) 1005 1032 { 1006 /* end quote? */ 1007 if (ch == chQuote) 1033 if (psz[1] == chQuote) 1034 psz++; /* skip the escaped quote char */ 1035 else 1008 1036 { 1009 if (psz[1] == ch) 1010 psz++; /* skip the escaped quote char */ 1011 else 1012 chQuote = '\0'; /* end of quoted string. */ 1037 chQuote = '\0'; /* end of quoted string. */ 1038 fBinary = true; 1013 1039 } 1014 1040 } 1015 else 1016 chQuote = ch; /* open new quote */ 1041 } 1042 else if (ch == '\'' || ch == '"') 1043 { 1044 if (fBinary) 1045 return VERR_DBGC_PARSE_EXPECTED_BINARY_OP; 1046 chQuote = ch; 1017 1047 } 1018 1048 /* 1019 1049 * Parenthesis can of course be nested. 1020 1050 */ 1021 else if (!chQuote && ch == '(') 1022 { 1051 else if (ch == '(') 1052 { 1053 if (!cPar && fBinary) 1054 return VERR_DBGC_PARSE_EXPECTED_BINARY_OP; 1023 1055 cPar++; 1024 1056 fBinary = false; 1025 1057 } 1026 else if ( !chQuote &&ch == ')')1058 else if (ch == ')') 1027 1059 { 1028 1060 if (!cPar) … … 1031 1063 fBinary = true; 1032 1064 } 1033 else if (!c hQuote && !cPar)1065 else if (!cPar) 1034 1066 { 1035 1067 /* 1036 * Encountering blanks may mean the end of it all. A binary operator 1037 * will force continued parsing. 1068 * Encountering a comma is a definite end of parameter. 1038 1069 */ 1039 if ( RT_C_IS_BLANK(*psz))1070 if (ch == ',') 1040 1071 { 1041 pszEnd = psz++; /* just in case. */ 1072 pszEnd = psz++; 1073 break; 1074 } 1075 1076 /* 1077 * Encountering blanks may mean the end of it all. A binary 1078 * operator will force continued parsing. 1079 */ 1080 if (RT_C_IS_BLANK(ch)) 1081 { 1082 pszEnd = psz++; /* in case it's the end. */ 1042 1083 while (RT_C_IS_BLANK(*psz)) 1043 1084 psz++; 1085 1086 if (*psz == ',') 1087 { 1088 psz++; 1089 break; 1090 } 1091 1044 1092 PCDBGCOP pOp = dbgcOperatorLookup(pDbgc, psz, fBinary, ' '); 1045 1093 if (!pOp || pOp->fBinary != fBinary) 1046 1094 break; /* the end. */ 1095 1047 1096 psz += pOp->cchName; 1048 1097 while (RT_C_IS_BLANK(*psz)) /* skip blanks so we don't get here again */ … … 1055 1104 * Look for operators without a space up front. 1056 1105 */ 1057 if (dbgcIsOpChar( *psz))1106 if (dbgcIsOpChar(ch)) 1058 1107 { 1059 1108 PCDBGCOP pOp = dbgcOperatorLookup(pDbgc, psz, fBinary, ' '); -
trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp
r41558 r41559 861 861 tstTry(pDbgc, "cpu @eax\n", VINF_SUCCESS); 862 862 tstTry(pDbgc, "cpu %bad:bad\n", VERR_DBGC_PARSE_CONVERSION_FAILED); 863 tstTry(pDbgc, "cpu '1'\n", VERR_DBGC_PARSE_INVALID_NUMBER); 863 864 } 864 865 … … 872 873 873 874 /* The idea here is that since the prefered input is a string, we 874 definitely won't be mistaking number like beginnings as numbers. */875 definitely won't be confused by the number like beginning. */ 875 876 tstTryEx(pDbgc, "echo 1234567890abcdefghijklmn\n", VINF_SUCCESS, false, "1234567890abcdefghijklmn", -1); 876 877 … … 1127 1128 tstTry(pDbgc, "format \n", VERR_DBGC_PARSE_TOO_FEW_ARGUMENTS); 1128 1129 tstTry(pDbgc, "format 0 1 23 4\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS); 1130 tstTry(pDbgc, "format 'x'\n", VINF_SUCCESS); 1131 tstTry(pDbgc, "format 'x' 'x'\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS); 1132 tstTry(pDbgc, "format 'x''x'\n", VINF_SUCCESS); 1133 tstTry(pDbgc, "format 'x'\"x\"\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP); 1134 tstTry(pDbgc, "format 'x'1\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP); 1135 tstTry(pDbgc, "format (1)1\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP); 1136 tstTry(pDbgc, "format (1)(1)\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP); 1137 tstTry(pDbgc, "format (1)''\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP); 1138 tstTry(pDbgc, "format foo(1)\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP); /** @todo VERR_DBGC_PARSE_FUNCTION_NOT_FOUND */ 1129 1139 tstTry(pDbgc, "sa 3 23 4 'q' \"21123123\" 'b' \n", VINF_SUCCESS); 1140 tstTry(pDbgc, "sa 3,23, 4,'q' ,\"21123123\" , 'b' \n", VINF_SUCCESS); 1130 1141 } 1131 1142
Note:
See TracChangeset
for help on using the changeset viewer.