#grammar #language #expression #dot #pest #excellent #underpinning

polka

A dot language parser for Rust; based on Parser Expression Grammar (PEG) using the excellent pest crate as the underpinning

2 releases

0.1.2 Jun 25, 2019
0.1.1 Jun 18, 2019

#2 in #excellent

MIT license

47KB
1.5K SLoC

Polka

A dot language parser for Rust; based on Parser Expression Grammar (PEG) using the excellent pest crate as the underpinning.


Usage (as a Rust Library)

  1. Add this to your Cargo.toml:
  [dependencies]
  rand = "0.6"
  1. Call the parser function by passing an input String
  extern crate polka;
  use polka::parse;

  fn main() {
    let input = "digraph { a -> b -> c }".to_string();
    println!("Polka AST\n: {:?}", parse(input).unwrap());
  }

  // Polka AST: 
  // Graph {
  //     strict: false,
  //     graph_type: Some(
  //         Digraph,
  //     ),
  //     id: None,
  //     statements: [
  //         EdgeStatement(
  //             EdgeStatement {
  //                 edge: NodeId(
  //                     NodeId {
  //                         node_id: "a",
  //                         port: None,
  //                     },
  //                 ),
  //                 edge_rhs_list: [
  //                     EdgeRhs {
  //                         edge_op: Arrow,
  //                         edge: NodeId(
  //                             NodeId {
  //                                 node_id: "b",
  //                                 port: None,
  //                             },
  //                         ),
  //                     },
  //                     EdgeRhs {
  //                         edge_op: Arrow,
  //                         edge: NodeId(
  //                             NodeId {
  //                                 node_id: "c",
  //                                 port: None,
  //                             },
  //                         ),
  //                     },
  //                 ],
  //                 attributes: None,
  //             },
  //         ),
  //     ],
  // }

Known Limitations:

  1. HTML ids are currently not supported.

License

MIT

Dependencies

~795KB
~10K SLoC