#parser #syntax-tree #yaml

yaml_parser

Semi-tolerant YAML concrete syntax tree parser

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

#1372 in Parser implementations

Download history 278/week @ 2024-07-04 10/week @ 2024-07-11 126/week @ 2024-07-18 283/week @ 2024-07-25 355/week @ 2024-08-01 688/week @ 2024-08-08 434/week @ 2024-08-15 1352/week @ 2024-08-22 1354/week @ 2024-08-29 1293/week @ 2024-09-05 880/week @ 2024-09-12 1007/week @ 2024-09-19 1073/week @ 2024-09-26 1664/week @ 2024-10-03 1653/week @ 2024-10-10 1206/week @ 2024-10-17

5,837 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

~1.5MB
~30K SLoC