aboutsummaryrefslogtreecommitdiff
path: root/src/tokenizer
AgeCommit message (Collapse)Author
2023-09-28break!: move offsets out of TokenMartin Fischer
Previously the Token enum contained the offsets using the O generic type parameter, which could be a usize if you're tracking offsets or a zero-sized type if you didn't care about offsets. This commit moves all the byte offset and syntax information to a new Trace enum, which has several advantages: * Traces can now easily be stored separately, while the tokens are fed to the tree builder. (The tree builder only has to keep track of which tree nodes originate from which tokens.) * No needless generics for functions that take a token but don't care about offsets (a tree construction implementation is bound to have many of such functions). * The FromIterator<(String, String)> impl for AttributeMap no longer has to specify arbitrary values for the spans and the value_syntax). * The PartialEq implementation of Token is now much more useful (since it no longer includes all the offsets). * The Debug formatting of Token is now more readable (since it no longer includes all the offsets). * Function pointers to functions accepting tokens are possible. (Since function pointer types may not have generic parameters.)
2023-09-28break!: emit chars instead of stringsMartin Fischer
The HTML spec specifies that the tokenizer emits character tokens. That html5gum always emitted strings instead was probably just done to make the token consumption more convenient. When it comes to tree construction character tokens are however actually more convenient than string tokens since the spec defines that specific character tokens should be ignored in specific states (and character tokens let us avoid string manipulation for these conditions). This should also make the DefaultEmitter more performant for cases where you don't actually need the strings at all (or only a few) since it avoids string allocations. Though I haven't benchmarked it.
2023-09-28refactor: proxy emit_string calls through utilsMartin Fischer
This is done separately so that the next commit has a cleaner diff.
2023-09-28refactor: move machine impl details to machine moduleMartin Fischer
This commit separates the public API (the "Tokenizer") from the internal implementation (the "Machine") to make the code more readable.
2023-09-28refactor: move utils module under tokenizer::machineMartin Fischer
2023-09-28refactor: only use InternalState re-export for feature-gated internal APIMartin Fischer
2023-09-28refactor: move machine module under tokenizerMartin Fischer