Expand description
§Conventional Commits Parser
This module provides a parser for Conventional Commits, a specification for adding human and machine-readable meaning to commit messages.
The parser consists of three main components:
Token: An enum representing different parts of a conventional commit message.ConventionalCommit: A struct representing a parsed conventional commit.Lexer: A struct that tokenizes the input commit message.
§Usage
To parse a conventional commit message:
use conventional_commit::{parse_commit, Lexer};
fn parse_example() -> Result<(), String> {
let input = "feat(parser): add ability to parse conventional commits".to_string();
let mut lexer = Lexer::new(input);
let tokens = lexer.lex()?;
let commit = parse_commit(tokens)?;
println!("{:?}", commit);
Ok(())
}
// Call the function in the doctest
parse_example().unwrap();§Error Handling
Both the lexing and parsing stages return Result types, allowing for error handling.
Common errors include invalid commit type, missing description, and unclosed scope parentheses.
Structs§
- Conventional
Commit - Represents a parsed conventional commit.
- Lexer
- A lexer for tokenizing conventional commit messages.
Enums§
Functions§
- parse_
commit - Parses a vector of
Tokens into aConventionalCommitstruct.