Skip to main content

Crate offsides

Crate offsides 

Source
Expand description

Layout-sensitive (off-side rule) lexer adapter for logos + lalrpop pipelines.

LayoutLexer wraps any Iterator<Item = Result<(usize, T, usize), E>> and splices virtual open/close/separator tokens into the stream based on the indentation of the input. The downstream parser sees a clean brace-and-semicolon shape and never has to think about columns.

ⓘ
use offsides::{LayoutLexer, LayoutConfig, LayoutMode, OpenerRule};

let cfg = LayoutConfig::new(is_layout_opener)
    .with_mode(LayoutMode::Eager)
    .with_opener_rule(OpenerRule::Conditional)
    .with_brackets(is_bracket_open, is_bracket_close);
let layout = LayoutLexer::new(my_logos_lexer, source, cfg);
let ast = MyParser::new().parse(layout)?;

Composes with marginalia::TriviaLexer; see the blocklet example.

Re-exports§

pub use layout::Layout;
pub use layout::LayoutConfig;
pub use layout::LayoutMode;
pub use layout::OpenerRule;

Modules§

layout
Public configuration types for layout-sensitive lexing.

Structs§

LayoutLexer
Iterator adapter that inserts virtual open/close/separator tokens into a stream from a logos lexer (or any compatible token iterator), driven by an off-side / indentation rule.