/* * Copyright 2017 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/
#ifndef SKSL_NFASTATE #define SKSL_NFASTATE
#include <string> #include <vector>
#include"src/sksl/lex/LexUtil.h"
struct NFAState { enum Kind { // represents an accept state - if the NFA ends up in this state, we have successfully // matched the token indicated by fData[0]
kAccept_Kind, // matches the single character fChar
kChar_Kind, // the regex '.'; matches any char but '\n'
kDot_Kind, // a state which serves as a placeholder for the states indicated in fData. When we // transition to this state, we instead transition to all of the fData states.
kRemapped_Kind, // contains a list of true/false values in fData. fData[c] tells us whether we accept the // character c.
kTable_Kind
};
bool accept(char c) const { switch (fKind) { case kAccept_Kind: returnfalse; case kChar_Kind: return c == fChar; case kDot_Kind: return c != '\n'; case kTable_Kind: { bool value; if ((size_t) c < fData.size()) {
value = fData[c];
} else {
value = false;
} return value != fInverse;
} default:
SkUNREACHABLE;
}
}
#ifdef SK_DEBUG
std::string description() const { switch (fKind) { case kAccept_Kind: return"Accept(" + std::to_string(fData[0]) + ")"; case kChar_Kind: {
std::string result = "Char('" + std::string(1, fChar) + "'"; for (int v : fNext) {
result += ", ";
result += std::to_string(v);
}
result += ")"; return result;
} case kDot_Kind: {
std::string result = "Dot("; constchar* separator = ""; for (int v : fNext) {
result += separator;
result += std::to_string(v);
separator = ", ";
}
result += ")"; return result;
} case kRemapped_Kind: {
std::string result = "Remapped("; constchar* separator = ""; for (int v : fData) {
result += separator;
result += std::to_string(v);
separator = ", ";
}
result += ")"; return result;
} case kTable_Kind: {
std::string result = std::string("Table(") + (fInverse ? "true" : "false") + ", ["; constchar* separator = ""; for (int v : fData) {
result += separator;
result += v ? "true" : "false";
separator = ", ";
}
result += "]"; for (int n : fNext) {
result += ", ";
result += std::to_string(n);
}
result += ")"; return result;
} default:
SkUNREACHABLE;
}
} #endif
Kind fKind;
char fChar = 0;
bool fInverse = false;
std::vector<int> fData;
// states we transition to upon a succesful match from this state
std::vector<int> fNext;
};
#endif
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.