Crate logosky

Crate logosky 

Source
Expand description

LogoSky

A seamless integration layer between Logos and Chumsky parser combinator, providing zero-copy TokenStream adapter and Parseable trait for building robust parsers

github LoC Build codecov

docs.rs crates.io crates.io license

English | 简体中文

§Overview

LogoSky is a Rust library that bridges Logos and Chumsky, combining the speed of Logos’ lexical analysis with the expressiveness of Chumsky’s parser combinators. It provides a seamless integration layer that allows you to use Logos for tokenization and Chumsky for parsing in a unified, type-safe manner.

§Features

  • 🚀 High-performance tokenization with Logos
  • 🎯 Expressive parser combinators with Chumsky
  • 🔗 Seamless integration via TokenStream adapter
  • 📍 Rich span tracking with Span and Spanned types
  • 🎨 Flexible parseable trait for building composable parsers
  • 🔧 No-std support with optional allocator
  • 🧩 Multiple source types support (str, [u8], Bytes, BStr, HipStr)
  • Zero-cost abstractions for efficient parsing

§Installation

Add this to your Cargo.toml:

[dependencies]
logosky = "0.2"

§Feature Flags

  • std (default) - Enable standard library support
  • alloc - Enable allocator support for no-std environments
  • bytes - Support for bytes::Bytes as token source
  • bstr - Support for bstr::BStr as token source
  • hipstr - Support for hipstr::HipStr as token source
  • either - Enable Either<L, R> parseable support
  • among - Enable Among<L, M, R> parseable support
  • smallvec - Enable small vector optimization utilities

§Core Components

  • TokenStream<'a, T>

    An zero-copy adapter that bridges Logos lexer output to Chumsky parser input. Implements Chumsky’s Input, ValueInput, SliceInput, and ExactSizeInput traits.

  • Token<'a> Trait

    The core trait for defining tokens. Requires:

    • Char: Character type (usually char or u8)
    • Kind: Token kind discriminator
    • Logos: Associated Logos token enum
  • LosslessToken<'a> Trait

    Extends Token<'a> for tokens that preserve all source information, including trivia (whitespace, comments).

    • Provides is_trivia() method to identify non-semantic tokens
    • Essential for building formatters, linters, and language servers that need to preserve formatting
    • Works seamlessly with Tokenizer trivia handling utilities
  • Tokenizer<'a, T> Trait

    Provides parser combinators for working with token streams:

    • skip_trivias(): Skip over trivia tokens (whitespace, comments)
    • collect_trivias(): Collect trivia tokens into a container for later processing
  • Parseable<'a, I, T, Error> Trait

    A trait for types that can be parsed from a token stream. Implement this to create composable parsers.

  • Span and Spanned<T>

    • Span: Lightweight span tracking (start/end positions)
    • Spanned<T>: Wraps a value with its source span
  • Utility Traits

    • IsAsciiChar: ASCII character checking utilities
    • AsSpan / IntoSpan: Span access traits
    • IntoComponents: Destructure parsed elements

§Who uses logosky?

  • smear: Blazing fast, fully spec-compliant, reusable parser combinators for standard GraphQL and GraphQL-like DSLs.

§License

logosky is dual-licensed under:

You may choose either license for your purposes.

Copyright (c) 2025 Al Liu.

Re-exports§

pub use chumsky;
pub use logos;

Modules§

iter
Iterators for TokenStream
source
The source related structures and traits
token
The token related structures and traits
utils
Common utilities for working with tokens and lexers.

Structs§

TokenStream
A zero-copy token stream adapter that bridges Logos and Chumsky.

Enums§

Lexed
The result of lexing a single token: either a successful token or an error.

Traits§

Lexable
A trait for types that can be lexed from the input.
Logos
Trait implemented for an enum representing all tokens. You should never have to implement it manually, use the #[derive(Logos)] attribute on your enum.
LosslessToken
A token trait for tokens that preserve all source information during lexing, including trivia.
Parseable
A trait for types that can be parsed from a token stream using Chumsky parsers.
Source
Trait for types the Lexer can read from.
State
The state trait for lexers
Token
The core trait for token types used with LogoSky.
TokenExt
The token extension trait.
Tokenizer
Tokenizer trait providing utilities for working with token streams.

Derive Macros§

Logos