4 releases

0.2.2 Aug 25, 2024
0.2.1 Jul 20, 2024
0.2.0 Jul 6, 2024
0.1.0 Jul 4, 2024

#2346 in Parser implementations

Download history 1312/week @ 2024-11-16 2480/week @ 2024-11-23 5021/week @ 2024-11-30 4874/week @ 2024-12-07 4721/week @ 2024-12-14 1886/week @ 2024-12-21 2190/week @ 2024-12-28 4465/week @ 2025-01-04 4656/week @ 2025-01-11 4517/week @ 2025-01-18 4359/week @ 2025-01-25 4211/week @ 2025-02-01 4382/week @ 2025-02-08 3673/week @ 2025-02-15 4986/week @ 2025-02-22 4472/week @ 2025-03-01

18,085 downloads per month
Used in 4 crates (via pretty_yaml)

MIT license

84KB
2.5K SLoC

yaml_parser

Crates.io docs.rs

Semi-tolerant YAML concrete syntax tree parser.

Usage

match yaml_parser::parse(&code) {
    Ok(tree) => println!("{tree:#?}"),
    Err(err) => eprintln!("{err}"),
};

It produces rowan tree if succeeded. For consuming the tree, see rowan's docs.

If you need to build AST from CST, use ast module:

let root = yaml_parser::ast::Root::cast(tree).unwrap();
dbg!(root);

Tests

Tests come from official test suite.

License

MIT License

Copyright (c) 2024-present Pig Fang


lib.rs:

Semi-tolerant YAML concrete syntax tree parser.

Usage

let code = "";
match yaml_parser::parse(code) {
    Ok(tree) => println!("{tree:#?}"),
    Err(err) => eprintln!("{err}"),
};

It produces rowan tree if succeeded. For consuming the tree, see rowan's docs.

To build AST from CST:

use yaml_parser::{ast::{AstNode, Root}, parse};

let code = "";
let tree = parse(code).unwrap();
let ast = Root::cast(tree);
assert!(matches!(ast, Some(Root { .. })));

Dependencies

~2MB
~41K SLoC