+ Added priority verification (0.0 <= valid priority <= 1.0)

+ Fixed a stupid bug in my hexToChar() function
+ Added code to actually return the parsed in priority to ParsePriority()...
+ Added code to actually SetTo() the result in ParseRule()...
+ Changed most "Sniffer scanner error" messages to "Sniffer
  pattern error" messages.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@630 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder 2002-08-07 07:48:30 +00:00
parent cc3a5fd2c2
commit ef88abd1be

View File

@ -340,7 +340,7 @@ int q = 0;
if (stream.IsEmpty()) if (stream.IsEmpty())
keepLooping = false; keepLooping = false;
else else
throw new Err(std::string("Sniffer scanner error: invalid character '") + ch + "'", pos); throw new Err(std::string("Sniffer pattern error: invalid character '") + ch + "'", pos);
break; break;
case '\t': case '\t':
@ -404,7 +404,7 @@ int q = 0;
case '|': AddToken(Divider, pos); break; case '|': AddToken(Divider, pos); break;
default: default:
throw new Err(std::string("Sniffer scanner error: invalid character '") + ch + "'", pos); throw new Err(std::string("Sniffer pattern error: invalid character '") + ch + "'", pos);
} }
break; break;
@ -420,7 +420,7 @@ int q = 0;
break; break;
case 0x3: case 0x3:
if (stream.IsEmpty()) if (stream.IsEmpty())
throw new Err(std::string("Sniffer scanner error: unterminated single-quoted string"), pos); throw new Err(std::string("Sniffer pattern error: unterminated single-quoted string"), pos);
else else
charStr += ch; charStr += ch;
break; break;
@ -442,7 +442,7 @@ int q = 0;
break; break;
case 0x3: case 0x3:
if (stream.IsEmpty()) if (stream.IsEmpty())
throw new Err(std::string("Sniffer scanner error: unterminated single-quoted string"), pos); throw new Err(std::string("Sniffer pattern error: unterminated single-quoted string"), pos);
else else
charStr += ch; charStr += ch;
break; break;
@ -477,7 +477,7 @@ int q = 0;
lastChar = ch; lastChar = ch;
state = tsssOneHex; state = tsssOneHex;
} else } else
throw new Err(std::string("Sniffer scanner error: incomplete hex code"), pos); throw new Err(std::string("Sniffer pattern error: incomplete hex code"), pos);
break; break;
case tsssOneHex: case tsssOneHex:
@ -539,7 +539,7 @@ int q = 0;
charStr += ch; charStr += ch;
state = tsssFloat; state = tsssFloat;
} else } else
throw new Err(std::string("Sniffer scanner error: incomplete floating point number"), pos); throw new Err(std::string("Sniffer pattern error: incomplete floating point number"), pos);
break; break;
case tsssLonelyMinusOrPlus: case tsssLonelyMinusOrPlus:
@ -550,7 +550,7 @@ int q = 0;
charStr += ch; charStr += ch;
state = tsssLonelyDecimalPoint; state = tsssLonelyDecimalPoint;
} else } else
throw new Err(std::string("Sniffer scanner error: incomplete signed number"), pos); throw new Err(std::string("Sniffer pattern error: incomplete signed number"), pos);
break; break;
case tsssLonelyFloatExtension: case tsssLonelyFloatExtension:
@ -595,7 +595,7 @@ int q = 0;
stream.Unget(); // In case it's punctuation, let tsssStart handle it stream.Unget(); // In case it's punctuation, let tsssStart handle it
state = tsssStart; state = tsssStart;
} else if (ch == '\'' || ch == '"') { } else if (ch == '\'' || ch == '"') {
throw new Err(std::string("Sniffer scanner error: illegal unquoted character '") + ch + "'", pos); throw new Err(std::string("Sniffer pattern error: illegal unquoted character '") + ch + "'", pos);
} else if (ch == 0x3 && stream.IsEmpty()) { } else if (ch == 0x3 && stream.IsEmpty()) {
AddString(charStr.c_str(), startPos); AddString(charStr.c_str(), startPos);
keepLooping = false; keepLooping = false;
@ -611,7 +611,7 @@ int q = 0;
} else { } else {
// Check for a true end-of-text marker // Check for a true end-of-text marker
if (ch == 0x3 && stream.IsEmpty()) if (ch == 0x3 && stream.IsEmpty())
throw new Err(std::string("Sniffer scanner error: incomplete escape sequence"), pos); throw new Err(std::string("Sniffer pattern error: incomplete escape sequence"), pos);
else { else {
charStr += escapeChar(ch); charStr += escapeChar(ch);
state = escapedState; // Return to the state we were in before the escape state = escapedState; // Return to the state we were in before the escape
@ -624,7 +624,7 @@ int q = 0;
lastChar = ch; lastChar = ch;
state = tsssEscapeOneHex; state = tsssEscapeOneHex;
} else } else
throw new Err(std::string("Sniffer scanner error: incomplete hex code"), pos); throw new Err(std::string("Sniffer pattern error: incomplete hex code"), pos);
break; break;
case tsssEscapeOneOctal: case tsssEscapeOneOctal:
@ -663,7 +663,7 @@ int q = 0;
charStr += hexToChar(lastChar, ch); charStr += hexToChar(lastChar, ch);
state = escapedState; state = escapedState;
} else } else
throw new Err(std::string("Sniffer scanner error: incomplete escaped hex code"), pos); throw new Err(std::string("Sniffer pattern error: incomplete escaped hex code"), pos);
break; break;
} }
@ -825,7 +825,7 @@ hexToChar(char hex) {
else if ('a' <= hex && hex <= 'f') else if ('a' <= hex && hex <= 'f')
return hex-'a'+10; return hex-'a'+10;
else if ('A' <= hex && hex <= 'F') else if ('A' <= hex && hex <= 'F')
return hex-'a'+10; return hex-'A'+10;
else else
throw new Err(std::string("Sniffer parser error: invalid hex digit '") + hex + "' passed to hexToChar()", -1); throw new Err(std::string("Sniffer parser error: invalid hex digit '") + hex + "' passed to hexToChar()", -1);
} }
@ -843,7 +843,10 @@ octalToChar(char hi, char low) {
char char
octalToChar(char hi, char mid, char low) { octalToChar(char hi, char mid, char low) {
if (isOctalChar(hi) && isOctalChar(mid) && isOctalChar(low)) { if (isOctalChar(hi) && isOctalChar(mid) && isOctalChar(low)) {
return ((hi-'0') << 6) | ((mid-'0') << 3) | (low-'0'); if ((hi-'0') <= 3)
return ((hi-'0') << 6) | ((mid-'0') << 3) | (low-'0');
else
throw new Err("Sniffer pattern error: invalid octal literal (octals must be between octal 0 and octal 377 inclusive)", -1);
} else } else
throw new Err(std::string("Sniffer parser error: invalid octal digit passed to hexToChar()"), -1); throw new Err(std::string("Sniffer parser error: invalid octal digit passed to hexToChar()"), -1);
} }
@ -977,19 +980,29 @@ Parser::ErrorMessage(Err *err, const char *rule) {
void void
Parser::ParseRule(Rule *result) { Parser::ParseRule(Rule *result) {
if (!result)
throw new Err("Sniffer parser error: NULL Rule object passed to Parser::ParseRule()", -1);
// Priority // Priority
double priority = ParsePriority(); double priority = ParsePriority();
// Expression List // Expression List
std::vector<Expr*>* list = ParseExprList(); std::vector<Expr*>* list = ParseExprList();
result->SetTo(priority, list);
} }
double double
Parser::ParsePriority() { Parser::ParsePriority() {
double result;
const Token *t = stream.Get(); const Token *t = stream.Get();
if (t->Type() == FloatingPoint || t->Type() == Integer) if (t->Type() == FloatingPoint || t->Type() == Integer) {
result = t->Float(); double result = t->Float();
else if (0.0 <= result && result <= 1.0)
return result;
else {
cout << "(priority == " << result << ")" << endl;
throw new Err("Sniffer pattern error: invalid priority", t->Pos());
}
} else
throw new Err("Sniffer pattern error: match level expected", t->Pos()); // Same as R5 throw new Err("Sniffer pattern error: match level expected", t->Pos()); // Same as R5
} }