Open-Source Wikis

/

Helix

/

Packages

/

helix-parsec

helix-editor/helix

helix-parsec

A small, dependency-free parser-combinator library. ~575 lines of Rust in a single file. Used to parse LSP-style snippets in helix-core.

Purpose

The crate is a faithful (and intentionally small) implementation of the parser-combinator pattern from Bodil Stokke's Learning Parser Combinators With Rust post, plus a few additional combinators borrowed from a Lua snippet parser referenced in the source comments. It exists so the snippet parser in helix-core does not need to pull in a heavier crate like nom or pest.

Directory layout

helix-parsec/src/lib.rs

That's the entire crate.

Key abstractions

Item Purpose
Parser<'a> (trait) Anything that takes &'a str input and returns ParseResult<'a, Output>.
ParseResult<'a, Output> Result<(&'a str, Output), &'a str> — on success, the unconsumed tail and a value; on failure, the input that didn't match.
&'static str: Parser Literal strings are parsers. "foo".parse("foobar") == Ok(("bar", "foo")).
or, and, right, left Sequencing and alternative combinators.
map, pred (filter) Transform/filter the output of a parser.
one_or_more, zero_or_more Kleene-star equivalents producing Vec.
seq! (macro) Tuple-style sequencing of N parsers.
take_until, delimited, whitespace Common string-shape parsers.

Use site

The only consumer is the snippet parser in helix-core/src/snippets/parser.rs. LSP snippets are little expressions like ${1:default} or ${2|opt1,opt2|} and parsing them with combinators is more readable than a hand-rolled state machine.

Entry points for modification

  • Adding new combinators: extend lib.rs and add doc tests.
  • The snippet language is the only consumer; if you change a combinator's semantics, run cargo test -p helix-core --doc to ensure snippet tests still pass.

This crate is small and stable — it rarely needs touching. If your problem is bigger than what these combinators express, consider using a different parser strategy (a hand-rolled pratt parser for instance) rather than expanding helix-parsec into a general parsing framework.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

helix-parsec – Helix wiki | Factory