Advance immediately upon evaluating a character
This commit is contained in:
parent
099bb1afef
commit
e6762f9b48
|
@ -7,10 +7,10 @@ namespace logger {
|
|||
static constexpr const char * DASHES = "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
|
||||
|
||||
static constexpr const bool LOG_ENABLED = false;
|
||||
static constexpr const int LOG_EVENT_LEN = 30;
|
||||
static constexpr const int LOG_BUFFER_LEN = 20;
|
||||
static constexpr const int LOG_DETAIL_LEN = 50;
|
||||
static constexpr const int LOG_INDEX_LEN = 10;
|
||||
static constexpr const int LOG_EVENT_LEN = 20;
|
||||
static constexpr const int LOG_BUFFER_LEN = 10;
|
||||
static constexpr const int LOG_SMALL_BUFFER_LEN = 10;
|
||||
static constexpr const int LOG_INDEX_LEN = 5;
|
||||
|
||||
static int log_depth; // Not threadsafe. Log only.
|
||||
|
||||
|
@ -28,8 +28,8 @@ namespace logger {
|
|||
if (LOG_ENABLED) {
|
||||
log_depth = 0;
|
||||
printf("\n");
|
||||
printf("| %-*s | %-*s | %*s | %*s | %*s | %-*s | %-*s | %-*s |\n", LOG_EVENT_LEN, "Event", LOG_BUFFER_LEN, "Buffer", 4, "Curr", 4, "Next", 5, "Next#", 5, "Tape#", LOG_DETAIL_LEN, "Detail", LOG_INDEX_LEN, "index");
|
||||
printf("|%.*s|%.*s|%.*s|%.*s|%.*s|%.*s|%.*s|%.*s|\n", LOG_EVENT_LEN+2, DASHES, LOG_BUFFER_LEN+2, DASHES, 4+2, DASHES, 4+2, DASHES, 5+2, DASHES, 5+2, DASHES, LOG_DETAIL_LEN+2, DASHES, LOG_INDEX_LEN+2, DASHES);
|
||||
printf("| %-*s | %-*s | %-*s | %-*s | %-*s | Detail |\n", LOG_EVENT_LEN, "Event", LOG_BUFFER_LEN, "Buffer", LOG_SMALL_BUFFER_LEN, "Next", 5, "Next#", 5, "Tape#");
|
||||
printf("|%.*s|%.*s|%.*s|%.*s|%.*s|--------|\n", LOG_EVENT_LEN+2, DASHES, LOG_BUFFER_LEN+2, DASHES, LOG_SMALL_BUFFER_LEN+2, DASHES, 5+2, DASHES, 5+2, DASHES);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,22 +44,35 @@ namespace logger {
|
|||
static really_inline void log_line(S &structurals, const char *title_prefix, const char *title, const char *detail) {
|
||||
if (LOG_ENABLED) {
|
||||
printf("| %*s%s%-*s ", log_depth*2, "", title_prefix, LOG_EVENT_LEN - log_depth*2 - int(strlen(title_prefix)), title);
|
||||
auto current_index = structurals.at_beginning() ? nullptr : structurals.next_structural-1;
|
||||
auto next_index = structurals.next_structural;
|
||||
auto current = current_index ? &structurals.buf[*current_index] : (const uint8_t*)" ";
|
||||
auto next = &structurals.buf[*next_index];
|
||||
{
|
||||
// Print the next N characters in the buffer.
|
||||
printf("| ");
|
||||
// Otherwise, print the characters starting from the buffer position.
|
||||
// Print spaces for unprintable or newline characters.
|
||||
for (int i=0;i<LOG_BUFFER_LEN;i++) {
|
||||
printf("%c", printable_char(structurals.current()[i]));
|
||||
printf("%c", printable_char(current[i]));
|
||||
}
|
||||
printf(" ");
|
||||
// Print the next N characters in the buffer.
|
||||
printf("| ");
|
||||
// Otherwise, print the characters starting from the buffer position.
|
||||
// Print spaces for unprintable or newline characters.
|
||||
for (int i=0;i<LOG_SMALL_BUFFER_LEN;i++) {
|
||||
printf("%c", printable_char(next[i]));
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
printf("| %c ", printable_char(structurals.current_char()));
|
||||
printf("| %c ", printable_char(structurals.peek_next_char()));
|
||||
printf("| %5u ", structurals.parser.structural_indexes[*(structurals.current_structural+1)]);
|
||||
printf("| %5u ", structurals.next_tape_index());
|
||||
printf("| %-*s ", LOG_DETAIL_LEN, detail);
|
||||
printf("| %*u ", LOG_INDEX_LEN, *structurals.current_structural);
|
||||
if (current_index) {
|
||||
printf("| %*u ", LOG_INDEX_LEN, *current_index);
|
||||
} else {
|
||||
printf("| %-*s ", LOG_INDEX_LEN, "");
|
||||
}
|
||||
printf("| %*u ", LOG_INDEX_LEN, structurals.next_tape_index());
|
||||
printf("| %-s ", detail);
|
||||
printf("|\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,44 +5,45 @@ namespace stage2 {
|
|||
class structural_iterator {
|
||||
public:
|
||||
const uint8_t* const buf;
|
||||
uint32_t *current_structural;
|
||||
uint32_t *next_structural;
|
||||
dom_parser_implementation &parser;
|
||||
|
||||
// Start a structural
|
||||
really_inline structural_iterator(dom_parser_implementation &_parser, size_t start_structural_index)
|
||||
: buf{_parser.buf},
|
||||
current_structural{&_parser.structural_indexes[start_structural_index]},
|
||||
next_structural{&_parser.structural_indexes[start_structural_index]},
|
||||
parser{_parser} {
|
||||
}
|
||||
// Get the buffer position of the current structural character
|
||||
really_inline const uint8_t* current() {
|
||||
return &buf[*current_structural];
|
||||
return &buf[*(next_structural-1)];
|
||||
}
|
||||
// Get the current structural character
|
||||
really_inline char current_char() {
|
||||
return buf[*current_structural];
|
||||
return buf[*(next_structural-1)];
|
||||
}
|
||||
// Get the next structural character without advancing
|
||||
really_inline char peek_next_char() {
|
||||
return buf[*(current_structural+1)];
|
||||
return buf[*next_structural];
|
||||
}
|
||||
really_inline const uint8_t* peek() {
|
||||
return &buf[*next_structural];
|
||||
}
|
||||
really_inline const uint8_t* advance() {
|
||||
current_structural++;
|
||||
return &buf[*current_structural];
|
||||
return &buf[*(next_structural++)];
|
||||
}
|
||||
really_inline char advance_char() {
|
||||
current_structural++;
|
||||
return buf[*current_structural];
|
||||
return buf[*(next_structural++)];
|
||||
}
|
||||
really_inline size_t remaining_len() {
|
||||
return parser.len - *current_structural;
|
||||
return parser.len - *(next_structural-1);
|
||||
}
|
||||
|
||||
really_inline bool at_end() {
|
||||
return current_structural == &parser.structural_indexes[parser.n_structural_indexes];
|
||||
return next_structural == &parser.structural_indexes[parser.n_structural_indexes];
|
||||
}
|
||||
really_inline bool at_beginning() {
|
||||
return current_structural == parser.structural_indexes.get();
|
||||
return next_structural == parser.structural_indexes.get();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ struct structural_parser : structural_iterator {
|
|||
|
||||
WARN_UNUSED really_inline error_code finish() {
|
||||
end_document();
|
||||
parser.next_structural_index = uint32_t(current_structural + 1 - &parser.structural_indexes[0]);
|
||||
parser.next_structural_index = uint32_t(next_structural - &parser.structural_indexes[0]);
|
||||
|
||||
if (depth != 0) {
|
||||
log_error("Unclosed objects or arrays!");
|
||||
|
@ -279,7 +279,7 @@ WARN_UNUSED static really_inline error_code parse_structurals(dom_parser_impleme
|
|||
// Read first value
|
||||
//
|
||||
{
|
||||
switch (parser.current_char()) {
|
||||
switch (parser.advance_char()) {
|
||||
case '{': {
|
||||
if (parser.empty_object()) { goto document_end; }
|
||||
SIMDJSON_TRY( parser.start_object() );
|
||||
|
|
Loading…
Reference in New Issue