ifcparse: give the tokenizer a compile-time policy for what it decodes

spf_lexer::next() becomes next<Policy>(). full_tokens, the default, is
what the parser has always had. index_tokens is what the lazy index
needs: a string is ended but not decoded, and a number, enumeration or
binary comes back as Token_LITERAL with only its position; names,
keywords and operators are read as before. Each policy compiles to its
own loop from the one implementation, so there is no second tokenizer.

character_decoder gains skip(): the same state machine as the
conversion with the collection compiled out, so an escape such as \S\'
(an apostrophe as the page character) ends the string at the same byte
under both policies. A byte-level scan would have ended it early.

Also fixes a comment that follows a token without whitespace, ",/* x */",
which skip_comment() never saw because the slash had been consumed.

TXG (58 MB), single thread: tokenizing the whole file 194 MB/s with
full_tokens, 249 MB/s with index_tokens; through 64 KB pages 196 and
205 MB/s. The parse itself is unchanged.

This commit was written by an AI coding tool and has not been verified by
a human.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013wcN7XquTfUi4vsKQ4KchL
This commit is contained in:
Dion Moult
2026-09-14 07:08:48 +10:00
parent a026fc698c
commit 9829ebf001
6 changed files with 150 additions and 9 deletions
+7 -1
View File
@@ -157,7 +157,10 @@ namespace ifcopenshell {
Token_INT,
Token_BOOL,
Token_FLOAT,
Token_BINARY
Token_BINARY,
// A number, enumeration, binary or string the tokenizer policy
// passed over without decoding; only its position is known.
Token_LITERAL
};
size_t start_pos;
@@ -173,6 +176,9 @@ namespace ifcopenshell {
token() : start_pos(0),
type(Token_NONE) {}
token(size_t start_position, token_type token_kind)
: start_pos(start_position), type(token_kind), value_int(0) {}
token(size_t start_position, token_type token_kind, const std::string& string_value)
: start_pos(start_position), type(token_kind), value_string(&string_value) {}