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§
- Block
Comment - Lines that are representation as block comment. (like
"/' begin \n end '/\n"
.) - Block
Comment Close Line - A token sequence that is an close
BlockComment
line. - Block
Comment Open Line - A token sequence that is an open
BlockComment
line. - Diagram
IdToken - A token sequence of
ID
included in the around of start keyword (like"@startuml ID"
or"@startuml(id=ID)"
) - Empty
Line - A token sequence that is an empty line. (like
" \t \n"
,"' comment\n"
," /' oneline block comment '/ "
.) - EndLine
- A token sequence that is a line containing a end keyword (
"@endXYX"
). (like"@enduml\n"
.) - Footer
Line - A token sequence that is a line containing a
FooterToken
. (like"\tfooter EXAMPLE FOOTER \n"
.) - Footer
Token - A token sequence that is around the footer keyword. (like
"footer EXAMPLE FOOTER"
.) - Header
Line - A token sequence that is a line containing a
HeaderToken
. (like"\theader EXAMPLE HEADER \n"
.) - Header
Token - A token sequence that is around the header keyword. (like
"header EXAMPLE HEADER"
.) - Include
Line - A token sequence that is a line containing a
IncludeToken
. (like"\t!include foo.puml \n"
or"\r!include bar.iuml!buz \n"
.) - Include
Specifier Token - A token sequence that is the include specifier (
DiagramIdToken
) around the include keyword. (like"foo.puml"
or"bar.iuml!buz"
.) - Include
Token - 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"
.) - Includes
Collections - Data collected on the file path and PlantUML diagrams in the file for the include process.
- Inline
Block Comment Token - A token sequence that is an inline block comment. (like
"/' comment '/"
. not like"/' one '/ /' two '/"
) - Parse
Container - An intermediate representation to parse.
- Parse
Error - The error type to fail to parse.
- Path
Resolver - A resolver that keeps relative paths on a stack for recursive include process.
- Plant
UmlBlock - A block of PlantUML
- Plant
UmlContent - A token sequence that is a single PlantUML diagram, that is, from the
StartLine
to theEndLine
(lines inclusive). - Plant
UmlFile Data - PlantUML diagrams in the file.
- Plant
UmlLine - A line of PlantUML
- Start
Diagram Token - A token sequence that is around the start keyword (
"@startXYZ"
). (like"@startuml"
or"@startuml ID"
,"@startuml(id=ID)"
.) - Start
Line - A token sequence that is a line containing a start keyword (
"@startXYZ"
) parsed byStartDiagramToken
. (like"@startuml\n"
.) - Title
Line - A token sequence that is a line containing a
TitleToken
. (like"\ttitle EXAMPLE TITLE \n"
.) - Title
Token - A token sequence that is around the title keyword. (like
"title EXAMPLE TITLE"
.)
Enums§
- Error
- The error type for
plantuml-parser
’s operations. - Include
Kind - A kind of include keywords.
!include
|!include_many
|!include_once
- Path
Resolver Error - The error type for
PathResolver
’s operations. - Plant
UmlBlock Kind - A kind of PlantUML blocks to be handled by
plantuml-parser
. - Plant
UmlLine Kind - A kind of PlantUML lines to be handled by
plantuml-parser
. A line that cannot be handled is set toOthers
.
Constants§
- PKG_
NAME - The package name from Cargo.toml:
plantuml-parser
- PKG_
VERSION - The package version from Cargo.toml
Type Aliases§
- Parse
Result - The
Result
type for parsing process.