Skip to content

Commit 83213de

Browse files
authored
Rename to cvldoc (#20)
* rename to cvldoc, add raw field * bump version * renamed remaining references
1 parent eb440b1 commit 83213de

File tree

8 files changed

+56
-48
lines changed

8 files changed

+56
-48
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cvldoc_parser"
2+
name = "cvldoc_parser_core"
33
version = "0.4.0"
44
edition = "2021"
55

src/diagnostics.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{AssociatedElement, CvlDoc, Tag, DocData};
1+
use crate::{AssociatedElement, CvlDoc, DocData, Tag};
22
use lsp_types::{Diagnostic, DiagnosticSeverity, Range};
33

44
impl AssociatedElement {
@@ -42,15 +42,16 @@ impl CvlDoc {
4242
const WARNING: DiagnosticSeverity = DiagnosticSeverity::WARNING;
4343
const ERROR: DiagnosticSeverity = DiagnosticSeverity::ERROR;
4444

45-
let mut add = |message: String, diag_range: Option<Range>, severity: DiagnosticSeverity| {
46-
let diag = Diagnostic {
47-
range: diag_range.unwrap_or(self.range),
48-
severity: Some(severity),
49-
message,
50-
..Default::default()
45+
let mut add =
46+
|message: String, diag_range: Option<Range>, severity: DiagnosticSeverity| {
47+
let diag = Diagnostic {
48+
range: diag_range.unwrap_or(self.range),
49+
severity: Some(severity),
50+
message,
51+
..Default::default()
52+
};
53+
warnings.push(diag);
5154
};
52-
warnings.push(diag);
53-
};
5455

5556
if let Some(associated) = associated {
5657
if tags.iter().all(|tag| tag.kind != Tag::Notice) {
@@ -80,7 +81,7 @@ impl CvlDoc {
8081
}
8182
}
8283
} else {
83-
let error_desc = "no associated element for NatSpec documentation block".into();
84+
let error_desc = "no associated element for CVLDoc documentation block".into();
8485
add(error_desc, None, ERROR);
8586
}
8687

src/parse/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn commented_out_line<'src>() -> BoxedParser<'src, char, CvlDocBuilder, Simple<c
9191
.boxed()
9292
}
9393

94-
fn natspec_doc<'src>() -> BoxedParser<'src, char, CvlDocBuilder, Simple<char>> {
94+
fn cvldoc_documentation<'src>() -> BoxedParser<'src, char, CvlDocBuilder, Simple<char>> {
9595
let spanned_slashed_line = just("///")
9696
.ignore_then(none_of('/').rewind())
9797
.ignore_then(horizontal_ws())
@@ -109,10 +109,11 @@ fn natspec_doc<'src>() -> BoxedParser<'src, char, CvlDocBuilder, Simple<char>> {
109109
.ignore_then(take_to_starred_terminator().map_with_span(builder::split_starred_doc_lines))
110110
.boxed();
111111

112-
let doc = choice([slashed_documentation, starred_documentation])
112+
let documentation = choice([slashed_documentation, starred_documentation])
113113
.map_with_span(|spanned_body, span| (spanned_body, span));
114114

115-
doc.then(associated_element().or_not())
115+
documentation
116+
.then(associated_element().or_not())
116117
.map(
117118
|((spanned_body, span), element_under_doc)| CvlDocBuilder::Documentation {
118119
span,
@@ -124,10 +125,10 @@ fn natspec_doc<'src>() -> BoxedParser<'src, char, CvlDocBuilder, Simple<char>> {
124125
}
125126

126127
pub(super) fn parser() -> impl Parser<char, Vec<CvlDocBuilder>, Error = Simple<char>> {
127-
let valid_natspec = choice([free_form_comment(), natspec_doc()]);
128-
let natspec = choice((commented_out_block(), commented_out_line(), valid_natspec));
128+
let valid_cvldoc = choice([free_form_comment(), cvldoc_documentation()]);
129+
let cvldoc = choice((commented_out_block(), commented_out_line(), valid_cvldoc));
129130

130-
natspec
131+
cvldoc
131132
.recover_with(skip_until(['\n', ' '], |_| CvlDocBuilder::ParseError).consume_end())
132133
.repeated()
133134
.boxed()

src/python_wrapper/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ crate-type = ["cdylib"]
1010

1111
[dependencies]
1212
pyo3 = { version = "0.17.1", features = ["extension-module", "abi3-py37"] }
13-
cvldoc_parser = { path = "../.." }
13+
cvldoc_parser_core = { path = "../.." }
1414
color-eyre = "0.6.2"
1515
indoc = "1.0.7"
1616
itertools = "0.10.4"

src/python_wrapper/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# NatSpec Parser: Python module
2-
Exposes a Python API for the NatSpec module. WIP.
1+
# CVLDoc Parser: Python module
2+
Exposes a Python API for the CVLDoc module. WIP.
33

44
## Usage
55
First, make sure **Rust 1.62** or newer is installed.
6-
Clone [the entire repo](https://github.com/Certora/natspec_parser), then from the project base:
6+
Clone [the entire repo](https://github.com/Certora/cvldoc_parser), then from the project base:
77
```bash
88
$ cd src/python_wrapper
99
$ python -m venv .env
@@ -20,9 +20,9 @@ in order to build the module, which can then be used in the `virtualenv` or inst
2020
It is now possible to import the module:
2121
```bash
2222
$ python
23-
>>> import natspec_parser
23+
>>> import cvldoc_parser
2424
```
2525

2626
## API
27-
Currently exposes a single function, `natspec_parser.parse(paths)`. It takes a list of file paths as strings, and returns a list of parsed NatSpec objects for each path.
28-
A parsed NatSpec object is either a `Documentation` or a `FreeForm`. They both support a `diagnostics()` method, that returns a list of warnings or errors associated with that object.
27+
Currently exposes a single function, `cvldoc_parser.parse(paths)`. It takes a list of file paths as strings, and returns a list of parsed CVLDoc objects for each path.
28+
A parsed CVLDoc object is either a `Documentation` or a `FreeForm`. They both support a `diagnostics()` method, that returns a list of warnings or errors associated with that object.

src/python_wrapper/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
mod wrapper_structs;
22

3-
use ::cvldoc_parser::CvlDoc;
43
use color_eyre::eyre::WrapErr;
54
use color_eyre::Result;
5+
use cvldoc_parser_core::CvlDoc;
66
use itertools::Itertools;
77
use pyo3::{prelude::*, types::PyList};
88
use ropey::Rope;
@@ -20,13 +20,13 @@ fn cvldocs_from_path(path: &str) -> Result<Vec<CvlDoc>> {
2020
Rope::from_str(&data)
2121
};
2222

23-
let natspecs = CvlDoc::from_rope(rope);
23+
let cvldocs = CvlDoc::from_rope(rope);
2424

25-
Ok(natspecs)
25+
Ok(cvldocs)
2626
}
2727

2828
/// takes a list of file paths as strings, returns a list of parsed cvldocs for each path,
29-
/// if any natspecs were parsed for the path, otherwise returns an empty list for that path.
29+
/// if any cvldocs were parsed for the path, otherwise returns an empty list for that path.
3030
/// currently panics if a file fails to open, or fails to read.
3131
#[pyfunction]
3232
fn parse(paths: Vec<&str>) -> Vec<Py<PyAny>> {
@@ -39,10 +39,10 @@ fn parse(paths: Vec<&str>) -> Vec<Py<PyAny>> {
3939
Python::with_gil(|py| {
4040
cvldocs_per_file
4141
.into_iter()
42-
.map(|file_natspecs| {
43-
let elements = file_natspecs
42+
.map(|file_cvldocs| {
43+
let elements = file_cvldocs
4444
.into_iter()
45-
.map(|natspec| cvldoc_to_py_object(natspec, py));
45+
.map(|cvldoc| cvldoc_to_py_object(cvldoc, py));
4646

4747
PyList::new(py, elements).into_py(py)
4848
})

src/python_wrapper/src/wrapper_structs/conversions.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use super::{
22
AssociatedElement, Diagnostic, Documentation, DocumentationTag, FreeForm, Position, Range,
33
Severity,
44
};
5+
use cvldoc_parser_core::{
6+
AssociatedElement as AssociatedElementR, CvlDoc as CvlDocR, DocData as DocDataR,
7+
DocumentationTag as DocumentationTagR,
8+
};
59
use lsp_types::{
610
Diagnostic as DiagnosticR, DiagnosticSeverity as DiagnosticSeverityR, Position as PositionR,
711
Range as RangeR,
812
};
9-
use cvldoc_parser::{
10-
AssociatedElement as AssociatedElementR, CvlDoc as CvlDocR, DocData as DocDataR,
11-
DocumentationTag as DocumentationTagR,
12-
};
1313
use pyo3::{IntoPy, Py, PyAny, Python};
1414

1515
impl From<DocumentationTagR> for DocumentationTag {
@@ -86,7 +86,7 @@ impl From<FreeForm> for CvlDocR {
8686
CvlDocR {
8787
raw,
8888
range: range.into(),
89-
data: DocDataR::FreeForm(text)
89+
data: DocDataR::FreeForm(text),
9090
}
9191
}
9292
}
@@ -95,10 +95,16 @@ pub fn cvldoc_to_py_object(doc: CvlDocR, py: Python<'_>) -> Py<PyAny> {
9595
match doc.data {
9696
DocDataR::FreeForm(text) => {
9797
let range = doc.range.into();
98-
FreeForm { raw: doc.raw, range, text }.into_py(py)
98+
FreeForm {
99+
raw: doc.raw,
100+
range,
101+
text,
102+
}
103+
.into_py(py)
99104
}
100105
DocDataR::Documentation { tags, associated } => {
101-
Documentation::from_rust_repr_components(doc.raw, tags, associated, doc.range).into_py(py)
106+
Documentation::from_rust_repr_components(doc.raw, tags, associated, doc.range)
107+
.into_py(py)
102108
}
103109
}
104110
}

src/python_wrapper/src/wrapper_structs/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
pub mod conversions;
22

3+
use cvldoc_parser_core::{Param, Ty};
34
use derivative::Derivative;
4-
use cvldoc_parser::{Param, Ty};
55
use pyo3::prelude::*;
66

77
#[derive(Derivative, Clone)]
88
#[derivative(Debug)]
99
#[pyclass(module = "cvldoc_parser")]
1010
pub struct Documentation {
1111
#[pyo3(get)]
12-
#[derivative(Debug="ignore")]
12+
#[derivative(Debug = "ignore")]
1313
pub raw: String,
1414
#[pyo3(get)]
15-
#[derivative(Debug="ignore")]
15+
#[derivative(Debug = "ignore")]
1616
pub range: Range,
1717
#[pyo3(get)]
1818
pub tags: Vec<DocumentationTag>,
@@ -56,7 +56,7 @@ impl Position {
5656
#[derivative(Debug)]
5757
#[pyclass(module = "cvldoc_parser")]
5858
pub struct Diagnostic {
59-
#[derivative(Debug="ignore")]
59+
#[derivative(Debug = "ignore")]
6060
#[pyo3(get)]
6161
pub range: Range,
6262
#[pyo3(get)]
@@ -83,10 +83,10 @@ pub enum Severity {
8383
#[derivative(Debug)]
8484
#[pyclass(module = "cvldoc_parser")]
8585
pub struct FreeForm {
86-
#[derivative(Debug="ignore")]
86+
#[derivative(Debug = "ignore")]
8787
#[pyo3(get)]
8888
pub raw: String,
89-
#[derivative(Debug="ignore")]
89+
#[derivative(Debug = "ignore")]
9090
#[pyo3(get)]
9191
pub range: Range,
9292
#[pyo3(get)]
@@ -100,7 +100,7 @@ impl Documentation {
100100
}
101101

102102
fn diagnostics(&self) -> Vec<Diagnostic> {
103-
let c: cvldoc_parser::CvlDoc = self.clone().into();
103+
let c: cvldoc_parser_core::CvlDoc = self.clone().into();
104104
c.enumerate_diagnostics()
105105
.into_iter()
106106
.map(Into::into)
@@ -115,7 +115,7 @@ impl FreeForm {
115115
}
116116

117117
fn diagnostics(&self) -> Vec<Diagnostic> {
118-
let c: cvldoc_parser::CvlDoc = self.clone().into();
118+
let c: cvldoc_parser_core::CvlDoc = self.clone().into();
119119
c.enumerate_diagnostics()
120120
.into_iter()
121121
.map(Into::into)
@@ -125,7 +125,7 @@ impl FreeForm {
125125

126126
#[derive(Debug, Clone)]
127127
#[pyclass(module = "cvldoc_parser")]
128-
pub struct AssociatedElement(cvldoc_parser::AssociatedElement);
128+
pub struct AssociatedElement(cvldoc_parser_core::AssociatedElement);
129129

130130
#[pymethods]
131131
impl AssociatedElement {
@@ -192,7 +192,7 @@ pub struct DocumentationTag {
192192
pub kind: String,
193193
#[pyo3(get)]
194194
pub description: String,
195-
#[derivative(Debug="ignore")]
195+
#[derivative(Debug = "ignore")]
196196
#[pyo3(get)]
197197
pub range: Option<Range>,
198198
}

0 commit comments

Comments
 (0)