Markdown parser fork with extended syntax for personal use.
1use crate::unist::{Point, Position};
2use alloc::{boxed::Box, fmt, string::String};
3
4#[derive(Clone, Debug, PartialEq)]
5pub struct Message {
6 /// Place of message.
7 pub place: Option<Box<Place>>,
8 /// Reason for message (should use markdown).
9 pub reason: String,
10 /// Category of message.
11 pub rule_id: Box<String>,
12 /// Namespace of message.
13 pub source: Box<String>,
14}
15
16impl fmt::Display for Message {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 if let Some(ref place) = self.place {
19 write!(f, "{}: ", place)?;
20 }
21
22 write!(f, "{} ({}:{})", self.reason, self.source, self.rule_id)
23 }
24}
25
26/// Somewhere.
27#[derive(Clone, Debug, PartialEq)]
28pub enum Place {
29 /// Between two points.
30 Position(Position),
31 /// At a point.
32 Point(Point),
33}
34
35impl fmt::Display for Place {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Place::Position(position) => write!(
39 f,
40 "{}:{}-{}:{}",
41 position.start.line, position.start.column, position.end.line, position.end.column
42 ),
43 Place::Point(point) => write!(f, "{}:{}", point.line, point.column),
44 }
45 }
46}