1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Location {
pub path: PathBuf,
pub line: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Target {
Stable {
id: String,
letter: Option<String>,
},
#[allow(dead_code)]
Display {
note: String,
section: u32,
clause: Option<String>,
letter: Option<char>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Clause {
pub stable_id: Option<String>,
pub letter: Option<String>,
pub text: String,
/// The lettered line plus the content attached under it (continuation, table, fence).
pub body: String,
/// For a row of a table that letters its rows, the rows of that table before its first
/// lettered row, through which the row reads. Empty for an item.
pub header: String,
/// The last line of the clause and its attached body, 1-based.
pub end: usize,
pub struck: bool,
/// Written `(x)?`, or under a draft law: it owes no marker and no marker may name it.
pub draft: bool,
pub loc: Location,
}
impl Clause {
/// The text a clause pin is bound to: its body, after the header of its table.
pub fn pin_body(&self) -> String {
if self.header.is_empty() {
self.body.clone()
} else {
format!("{}\n{}", self.header, self.body)
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Law {
pub id: String,
pub name: String,
/// Content attached under the head before any clause or prose paragraph.
pub body: String,
/// The last line of the head and the content attached under it, 1-based.
pub end: usize,
/// The lines between the head and its last clause that neither holds: context, which binds
/// nothing and no pin hashes.
pub context: String,
/// Ids this law carried before an `accept`, kept as empty anchors in the head.
pub aliases: Vec<String>,
pub loc: Location,
pub clauses: Vec<Clause>,
pub struck: bool,
/// Written `§?`: it and every clause of it owe no marker.
pub draft: bool,
/// Written `§!`: a promise of the public documentation, which owes a documentation marker.
pub public: bool,
}
impl Law {
/// The text a law-grain pin is bound to.
pub fn pin_text(&self) -> String {
if self.body.is_empty() {
self.name.clone()
} else {
format!("{}\n{}", self.name, self.body)
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum PointerKind {
Cite,
Implements,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Pointer {
pub kind: PointerKind,
/// The project path of a qualified reference, `<projectpath>:<id>`. `None` is the current project.
pub project: Option<String>,
pub name: String,
pub target: Target,
pub loc: Location,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FormError {
pub loc: Location,
pub message: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Lint {
pub loc: Location,
pub message: String,
}
/// A paragraph `**§ <projectpath>:<id>[.<letter>]**` that takes another project's law, or one of
/// its letters, as a duty of the current project.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Adoption {
pub project: String,
pub id: String,
pub letter: Option<String>,
pub loc: Location,
}
#[derive(Debug, Clone, Default)]
pub struct Scan {
pub laws: Vec<Law>,
pub pointers: Vec<Pointer>,
/// `§ <id>[.<letter>]` named in the prose of a documentation file: a cite only `check` reads.
pub mentions: Vec<Pointer>,
pub adoptions: Vec<Adoption>,
pub form_errors: Vec<FormError>,
pub lints: Vec<Lint>,
/// The files the `docs` list matches, relative to the project root.
pub doc_files: Vec<PathBuf>,
}