Crate plantuml_parser

source ·
Expand description

The parser for plantuml-server-client

Examples

use anyhow::Result;
use plantuml_parser::{IncludesCollections, PlantUmlFileData};
use std::collections::HashMap;

fn main() -> Result<()> {
    // Multiple PlantUml contents
    let data = r#"
        @startuml diagram_0
        Alice -> Bob: Hello
        @enduml

        @startuml
        !include foo.puml!diagram_0
        Bob -> Alice: Hi
        @enduml
    "#;

    // Parses string
    let parsed = PlantUmlFileData::parse_from_str(data)?;

    // Parsed 1st content
    let parsed0 = parsed.get(0).unwrap();
    let empty = IncludesCollections::new(HashMap::new());
    assert_eq!(
        parsed0.construct(".".into(), &empty)?,
        concat!(
            "        @startuml diagram_0\n",
            "        Alice -> Bob: Hello\n",
            "        @enduml\n",
        )
    );
    assert_eq!(parsed0.inner(), "        Alice -> Bob: Hello\n");
    // Parsed 2nd content
    let parsed1 = parsed.get(1).unwrap();
    assert_eq!(
        parsed1.inner(),
        concat!(
            "        !include foo.puml!diagram_0\n",
            "        Bob -> Alice: Hi\n",
        )
    );

    // Embeds 1st content in 2nd content's `!include` line.
    let includes = IncludesCollections::new(HashMap::from([("foo.puml".into(), parsed.clone())]));
    let constructed = parsed1.construct("base.puml".into(), &includes)?;
    assert_eq!(
        constructed,
        concat!(
            "        @startuml\n",
            "        Alice -> Bob: Hello\n",
            "        Bob -> Alice: Hi\n",
            "        @enduml\n",
        )
    );

    Ok(())
}

Structs

  • A token sequence of ID included in the around of start keyword (like "@startuml ID" or "@startuml(id=ID)")
  • A token sequence that is an empty line. (like " \t \n", "' comment\n")
  • A token sequence that is a line containing a end keyword ("@endXYX"). (like "@enduml\n".)
  • A token sequence that is a line containing a FooterToken. (like "\tfooter EXAMPLE FOOTER \n".)
  • A token sequence that is around the footer keyword. (like "footer EXAMPLE FOOTER".)
  • A token sequence that is a line containing a HeaderToken. (like "\theader EXAMPLE HEADER \n".)
  • A token sequence that is around the header keyword. (like "header EXAMPLE HEADER".)
  • A token sequence that is a line containing a IncludeToken. (like "\t!include foo.puml \n" or "\r!include bar.iuml!buz \n".)
  • A token sequence that is the include specifier (DiagramIdToken) around the include keyword. (like "foo.puml" or "bar.iuml!buz".)
  • A token sequence with IncludeSpecifierToken that is around the include keyword. (like "!include foo.puml" or "!include bar.iuml!buz" , "!include_many foo.puml" or "!include_many bar.iuml!buz".)
  • Data collected on the file path and PlantUML diagrams in the file for the include process.
  • An intermediate representation to parse.
  • The error type to fail to parse.
  • A resolver that keeps relative paths on a stack for recursive include process.
  • A token sequence that is a single PlantUML diagram, that is, from the StartLine to the EndLine (lines inclusive).
  • PlantUML diagrams in the file.
  • A line of PlantUML
  • A token sequence that is around the start keyword ("@startXYZ"). (like "@startuml" or "@startuml ID", "@startuml(id=ID)".)
  • A token sequence that is a line containing a start keyword ("@startXYZ") parsed by StartDiagramToken. (like "@startuml\n".)
  • A token sequence that is a line containing a TitleToken. (like "\ttitle EXAMPLE TITLE \n".)
  • A token sequence that is around the title keyword. (like "title EXAMPLE TITLE".)

Enums

Constants

Type Aliases