Skip to content

Releases: maciejhirsz/logos

v0.15 - 2024 edition, improved callback, fixes and better docs!

07 Dec 11:35
ec8b6d5
Compare
Choose a tag to compare

This is a small release, but it contains two important fixes:

  • Fix for big-endian platforms in #431
  • Support for Rust 2024 edition in #435

But it also contains a breaking change:

  • MSRV has been bumped to 1.74

As well as a nice new feature for callback to support returning Result<Skip>!

Moreover, the documentation has received very nice additions.

Many thanks to all the contributors!

What's Changed

New Contributors

Full Changelog: v0.14.2...v0.15

v0.14.3 - YANKED - 2024 edition, improved callback, fixes and better docs!

02 Dec 08:54
04ff39e
Compare
Choose a tag to compare

Important

This version was yanked as it bumped the MSRV, and we should have change the minor (not the patch) part of the version to reflect this.

This is a small release, but it contains two important fixes:

  • Fix for big-endian platforms in #431
  • Support for Rust 2024 edition in #435

As well as a nice new feature for callback to support returning Result<Skip>!

Moreover, the documentation has received very nice additions.

Many thanks to all the contributors!

What's Changed

New Contributors

Full Changelog: v0.14.2...v0.14.3

v0.14.2 - Optional `forbid_unsafe` feature, fuzzing, book, and more!

18 Sep 09:34
196c8c0
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.14.1...v0.14.2

0.14.1 - Debug feature and fixes

02 Aug 10:06
feb8406
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.14...v0.14.1

0.14 - Let's make Logos active again!

07 Feb 10:54
171422c
Compare
Choose a tag to compare

After months without any new release, 0.14 is finally out!

Short summary

  • Logos now provides a very useful handbook;
  • Bug fixes and continuous-integration tools via GitHub workflows;
  • ⚠️ BREAKING priority of classes was changed from 1 to 2, see #320, as a result of bump regex-syntax. This bump actually improves so performances, but only slightly (see below). The documentation about token disambiguation reflects that changes too.

Performance changes from #320:

group                                         before                                 changes
-----                                         ------                                 -------
count_ok/identifiers                          1.04    869.2±6.09ns   854.7 MB/sec    1.00   832.9±14.13ns   891.9 MB/sec
count_ok/keywords_operators_and_punctators    1.04      2.6±0.02µs   784.4 MB/sec    1.00      2.5±0.08µs   811.9 MB/sec
count_ok/strings                              1.03    597.6±5.73ns  1389.9 MB/sec    1.00    582.6±6.94ns  1425.8 MB/sec
iterate/identifiers                           1.05   883.7±23.22ns   840.7 MB/sec    1.00   838.2±12.23ns   886.3 MB/sec
iterate/keywords_operators_and_punctators     1.01      2.6±0.03µs   768.0 MB/sec    1.00      2.6±0.03µs   778.2 MB/sec
iterate/strings                               1.02    595.7±7.48ns  1394.5 MB/sec    1.00    583.6±4.39ns  1423.3 MB/sec

The detailed list of patches can be found below, many thanks to all contributors!

Longer story and help needed

As mentioned in 0.13, the author of Logos, @maciejhirsz,
is reducing his time on GitHub. A few months ago, I was granted collaborator rights, so I can help to maintain this project by reviewing and merging PRs.

As a result, please tag me, @jeertmans, whenever you need help or else (if I did not give any sign of life for a few days).

From now on, I will be able to publish new versions to crates.io, which I hope to do more frequently than in the past months (or years) of this project.

However, I do not master this project at all, and I welcome any help from the community to make this project grow!
I tried to setup a nice working environment, with many tests and guides, to facilitate first time contributors' life!

What's Changed

New Contributors

Full Changelog: v0.13...v0.14

0.13

10 Apr 11:12
cd6d40a
Compare
Choose a tag to compare

This is a long overdue release that includes a bunch of community provided PRs over the last months:

  • ⚠️ BREAKING: @agluszak did the heroic feat of making the Lexer produce a Result<Token, Token::Error> which removes, the need for the #[error] variant. More on that below. (#273)
  • @jannik4 implemented support for #[logos(crate = path::to::logos)]. (#268)
  • @Plaba added the support for {n,m} regex ranges. (#278)
  • SpannedIter now derefs into Lexer, so all Lexer methods are available on it, based on work started by @simvux. (#283, #231)
  • Added new #[logos(skip ...)] attribute to help declare whitespace now that #[error] variant is gone. (#284)
  • Updated syn dependency to 2.0. (#289)

Migrating from 0.12

In 0.12 interacting with Logos would look like:

use logos::Logos;

#[derive(Logos, Debug, PartialEq)]
enum Token {
    #[token("Hello")]
    Hello,

    #[token("Logos")]
    Logos,

    // This variant will be emitted if an error is encountered
    #[error]
    // By convention we also add an attribute to skip whitespace here
    #[regex(r"[ \t\n\f]+", logos::skip)]
    Error,
}

fn main() {
    let mut lex = Token::lexer("Hello Logos");

    // `Lexer` is an iterator of `Token`:
    assert_eq!(lex.next(), Some(Token::Hello));
    assert_eq!(lex.next(), Some(Token::Logos));
    assert_eq!(lex.next(), None);
}

In 0.13 the #[error] variant is gone, this is the updated code:

use logos::Logos;

#[derive(Logos, Debug, PartialEq)]
#[logos(skip r"[ \t\n\f]+")] // new way to annotate whitespace
enum Token {
    #[token("Hello")]
    Hello,

    #[token("Logos")]
    Logos,
}

fn main() {
    let mut lex = Token::lexer("Hello Logos");

    // `Lexer` is an iterator of `Result<Token, Token::Error>`:
    assert_eq!(lex.next(), Some(Ok(Token::Hello)));
    assert_eq!(lex.next(), Some(Ok(Token::Logos)));
    assert_eq!(lex.next(), None);
}

By default the associated Token::Error type is just () and holds no data. Originally I've put the #[error] variant on the token because having one flat enum to make a match on seemed like a performance win. Upon some scrutiny however there is no performance cost to matching on Result<Token, ()> vs flat Token due to Rust's ability to optimize enums: if your Token is a simple enumeration with only unit variants (holds no data), and the number of variants doesn't exceed 254, then Result<Token, ()> and Option<Result<Token, ()>> will be represented by a single byte at runtime, and matching for pattern Ok(Token::Hello) in 0.13 should compile to the same code as plain Token::Hello would be in 0.12. See the full discussion in #104.

Future of Logos

If you've been using Logos for a while now and you've been fighting with some compile-time bugs, you might have been expecting a bunch of fixes here. Alas, as much as it pains me, there are none. There are two main reasons for this, one being me taking a really long coding break last year well into this year:

image

This is including public and private repos, I simply wrote no code at all in any capacity, not personal projects, not professional, nothing at all. I really needed that time.

While I'm back and active now, a lot of my time currently is spent on Kobold.

The derive macro hell

The elephant in the room is that the derive macro is simply unfixable in the current state and requires a complete rewrite. Last time this happened was 3 years ago in 0.10. That rewrite improved things considerably and allowed me to fix numerous outstanding bugs at the time. It took me about two weeks of pretty intense work, and I reckon this time it would be no smaller task.

The main issue is that I've chosen to implement different states of the state machine as separate functions. This made it impossible for the these functions to share common variables on stack, but being really clever I got it to work for the existing test suite. A fatal mistake. Douglas Crockford once said, paraphrasing from memory:

Debugging is harder than writing code. If you write code as cleverly as you possibly can, you are by definition not smart enough to debug it.

The good news is I know how to fix things in a way that basically avoids nearly all pitfalls of current implementation. Instead of functions all states of the state machine should be just unit variants of a single enum with some code in their corresponding match expression arms stuck in a loop.

There are pros and cons to that. When it comes to performance lookup tables that currently use fn pointers would become much smaller (by a factor of 8 for most projects compiled on 64bit architecture), making it much less demanding on CPU cache. On the flip side the generated code would lose automatic inlining of nested function calls, and while that can be done manually as an optimization rolled into the macro itself, it might be a new source of bugs if not done right, and it will almost definitely bloat out the amount of code produced (though it might be sensible to have some feature flags to disable this, particularly for targets like wasm32).

The rewrite in principle should also make it possible to make Logos use ropes such as ropey.

Phasing out #[regex]

Not as much of a nightmare, but something I feel has been a problem for users is relying on a subset of regex syntax, particularly limiting backtracking and look-ahead features for the sake of both simplicity and performance. While it is possible to express pretty much any common programming language syntax necessary with that subset, often enough people find it confusing that you can't just do things like x*?.

What I'd like to do eventually is expand on the #[token] attribute with more DSL-y features, using string literals as means of escaping characters, backwards compatible with current use of the attribute to denote a simple byte sequence. Consider a simple block comment /* ... */, I would like that to be declared as:

#[derive(Logos)]
enum Token {
    #[token("/*" ... "*/")]
    BlockComment,

    // ...
}

The equivalent regex rules for that today would be #[regex(r"\/\*([^*]|\*[^/])*\*\/")]... I think. The fact that I'm not able to write this out of the top of my head without being sure it works should be a testament enough of how clunky it can be. Not to mention this one example kind of breaks one of the main promises of Logos, and that is of making the generated code faster than anything you could write by hand. You do not want to see the codegen for that particular regex.

When?

I've no idea.

In the next few weeks I'd like to get Kobold to 1.0. I also want to get Ramhorns to 1.0 sometime soon, that carte honestly should have been marked 1.0 since last year. I've been guilty of not pushing my crates to 1.0 fast enough, and by not fast enough I mean I've been on noughty versions for most of my projects for years, even though most of them really are production ready and I'm just too much of a chicken to stabilize the API.

With the changes done in 0.13 now I believe the last two issues standing ahead of Logos going 1.0 are the two mentioned above: derive rewrite to fix bugs, and #[token] syntax expansion / phasing out of #[regex] to make the API nicer to use. The former is something I'm best suited to do alone, although the latter could be done by community (though realistically only after the rewrite is done).

If there is a living soul willing to undertake the big rewrite and help push this along faster, do reach out. I can at very least help explain what the hell current codegen is doing. I'd be also happy to give a person or two the ability to review and merge community PRs.

0.12.1

08 Jun 09:31
5dd386a
Compare
Choose a tag to compare

This is a long overdue patch release that includes a number of fixes from community:

  • Subpattern definitions now accept nesting other subpatterns within them (#237 by @Jezza)
  • Callbacks can now use a new FilterResult type where emitting an error or skipping would be necessary (#236 by @Jeremy-Stafford)
  • Chunk is now implemented for all array sizes via const generics, which fixes issues with long regex patterns (#221 by @icewind1991)

0.12.0

01 Feb 19:55
3f9239a
Compare
Choose a tag to compare
  • Added case insensitive flags via ignore(case) and ignore(ascii_case) (by @gymore-io #198).
  • Removed the lookup! macro.
  • Updated dependency in logos-derive that had a security alert on it.

0.11.4

27 Apr 10:41
Compare
Choose a tag to compare
  • Expanded the maximum amount of bytes Logos can read in a single chunk from 16 to 32. This fixes compile errors for longer literal string matches (by @Luro02, #141, #142).

0.11.3

26 Apr 18:41
Compare
Choose a tag to compare
  • Fixed a bug that caused the derive macro to panic when attempting to merge regex definitions with overlapping asymmetric loops (#132).
  • Fixed a bug where a lexing error at first byte of a token could slice into a char boundary (#138).