dtd-macro

Crates.iodtd-macro
lib.rsdtd-macro
version0.1.0-alpha2
sourcesrc
created_at2021-08-08 08:59:11.715001
updated_at2021-08-10 07:32:33.17498
descriptionA DTD file parser.
homepagehttps://github.com/songww/dtd-rs
repository
max_upload_size
id433063
size26,344
songww (songww)

documentation

https://docs.rs/dtd-parser

README

DTD Parser

Install

cargo add dtd-rs --allow-prerelease

Usage

use dtd::dtd;

// parse dtd elements.
dtd! {
    "<!ELEMENT note (to,from,heading,body)>
    <!ELEMENT to (#PCDATA)>
    <!ELEMENT from (#PCDATA)>
    <!ELEMENT heading (#PCDATA)>
    <!ELEMENT body (#PCDATA)>"
}

// Generated:
//    pub struct Body(pub String);
//    #[derive(Clone, Debug)]
//    pub struct Body(pub String);
//    #[derive(Clone, Debug)]
//    pub struct Heading(pub String);
//    #[derive(Clone, Debug)]
//    pub struct From(pub String);
//    #[derive(Clone, Debug)]
//    pub struct To(pub String);
//    #[derive(Clone, Debug)]
//    pub struct TupleToFromHeadingBody {
//        pub to: To,
//        pub from: From,
//        pub heading: Heading,
//        pub body: Body,
//    }
//    pub type Note = TupleToFromHeadingBody;

let note = Note {
    to: To(String::From("to somewhere")),
    from: From(String::From("from somewhere")),
    heading: Heading(String::From("this is heading")),
    body: Body(String::From("Some Body"))
}

println!("{:?}", note);

// Or parse from file:
//
// content of `path/to/file.dtd`
//    <!ELEMENT note (to,from,heading,body)>
//    <!ELEMENT to (#PCDATA)>
//    <!ELEMENT from (#PCDATA)>
//    <!ELEMENT heading (#PCDATA)>
//    <!ELEMENT body (#PCDATA)>
// parse from file
dtd!("path/to/file.dtd");
Commit count: 0

cargo fmt