Crates.io | svg_file_parser |
lib.rs | svg_file_parser |
version | 0.1.0 |
source | src |
created_at | 2023-11-20 10:46:12.248589 |
updated_at | 2023-11-20 10:46:12.248589 |
description | A Rust-based SVG parser designed to interpret scalable vector graphics (SVG) files. |
homepage | |
repository | |
max_upload_size | |
id | 1041955 |
size | 35,629 |
Display help information:
cargo run -- help
Parse a SVG file and output file content.
cargo run -- parse -i input.svg -o src/output.txt
If you don't specify an output file, file content will be written to your command-line interface.
cargo run -- parse -i input.svg
svg_file = { svg_open ~ svg_content ~ svg_close }
svg_open = { "<svg" ~ attribute* ~ ">" ~ NEWLINE }
svg_content = { ((element | text_content ) ~ NEWLINE)* }
svg_close = { "</svg>" }
element = { circle | rect | line | ellipse }
circle = { "<circle" ~ attribute+ ~ "/>" }
rect = { "<rect" ~ attribute+ ~ "/>" }
line = { "<line" ~ attribute+ ~ "/>" }
ellipse = { "<ellipse" ~ attribute+ ~ "/>" }
attribute = { attribute_name ~ "=" ~ "\"" ~ attribute_value ~ "\"" }
attribute_name = { ASCII_ALPHA ~ ASCII_ALPHANUMERIC* }
attribute_value = { ASCII_ALPHANUMERIC* }
text_content = { (PUNCTUATION | ASCII_ALPHANUMERIC)+ ~ (PUNCTUATION | ASCII_ALPHANUMERIC)*}
WHITESPACE = _{ " " }
<svg>
<circle cx="10" cy="10" r="5" />
<rect x="20" y="20" width="10" height="10" />
Some text content
</svg>
Result:
[
Svg(
[],
),
Circle(
[
(
"cx",
"10",
),
(
"cy",
"10",
),
(
"r",
"5",
),
],
),
Rect(
[
(
"x",
"20",
),
(
"y",
"20",
),
(
"width",
"10",
),
(
"height",
"10",
),
],
),
Text(
"Some text content",
),
]