0.11.0
New face, rehauled API
Logos has a new cute logo π€.
There is a number of breaking changes this release, aimed at reducing API surface and being more idiomatic, while adding some long awaited features, like the ability to put slices of the source or arbitrary values returned from callbacks directly into a token.
Most of the changes related to the #[derive]
macro will trigger a compile error message with an explanation to aid migration from 0.10. Those will be removed in the future.
API changes
- π¨ [breaking] LOGOS NO LONGER HANDLES WHITESPACE BY DEFAULT. The
#[trivia]
attribute has been removed. Whitespace handling is easily added by defining#[regex(r"[ \n\t\f]+", logos::skip)]
on any token enum variant. Putting it along#[error]
is recommended. - π¨ [breaking]
Lexer
no longer has theadvance
method, or publicly visibletoken
field. InsteadLexer
now implements theIterator
trait and has anext
method that returns anOption
of a token. - π¨ [breaking]
#[end]
attribute was removed since it became obsolete. - π¨ [breaking]
#[regex = "..."]
and#[token = "..."]
definitions are no longer valid syntax and will error when used in this way. Those need to be transformed to#[regex("...")]
or#[token("...")]
respectively. - π¨ [breaking] Callbacks are now defined as a second parameter to either
#[regex]
or#[token]
. Those can be either paths to functions defined elsewhere (#[token("...", my_callback)]
), or inlined directly into the attribute using closure syntax (#[token("...", |lex| { ... })]
). - π¨ [breaking]
Extras
trait has been removed. You can still associate a custom struct to theLexer
using#[logos(extras = MyExtras)]
with any type that implementsDefault
, and manipulate it using callbacks. - π¨ [breaking]
#[callback]
attribute was removed since it was just polluting attribute namespace while offering no advantages over attaching callbacks to#[regex]
or#[token]
. - π¨ [breaking]
Lexer::range
has been renamed tospan
.span
andslice
methods continue to return information for the most recently returned token. - β¨ [new]
Lexer
has a newspanned
method takes the ownership ofLexer
and returns an interator over(Token, Span)
tuples. - β¨ [new] Callbacks can return arbitrary values (or
Option
s/Result
s of values) that can be put into token enum variants. Currently only a single value in a tuple-like variants is supported (Token::Variant(T)
). - β¨ [new] Logos will automatically populate
Token::Variant(&str)
with a matchingstr
slice if no callback is provided. - β¨ [new] Callback return values can be used to skip matches using the
Skip
type. It's also possible to dynamically skip matches using theFilter
type.
Internals
- π Generated code is now more likely to produce optimized jump tables for complex branches.
- π Logos can now stack multiple boolean lookup tables into a single table, reducing the memory cost of using the tables by a factor of 8, and improving cache locality.
- π For narrow range boolean branches Logos can now produce a lookup table packed into a single
u64
.