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§

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

Enums§

Error
The error type for plantuml-parser’s operations.
IncludeKind
A kind of include keywords. !include | !include_many | !include_once
PathResolverError
The error type for PathResolver’s operations.
PlantUmlLineKind
A kind of PlantUML lines to be handled by plantuml-parser. A line that cannot be handled is set to Others.

Constants§

PKG_NAME
The package name from Cargo.toml: plantuml-parser
PKG_VERSION
The package version from Cargo.toml

Type Aliases§

ParseResult
The Result type for parsing process.