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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! [Xschem] schematic and symbol parser.
//!
//! This library supports up to Xschem file version 1.2.
//! See Xschem [developer info] for more information on the file format.
//!
//! # Usage
//!
//! Use [`from_str`] or [`from_slice`] to parse a [`token::Schematic`] from a
//! string or byte slice. The parser is zero-copy so the resulting data
//! structure contains references to the input.
//!
//! The parse error result [`Error`] implements [`std::fmt::Display`] to convert
//! the error to a nice human readable format.
//!
//! # Examples
//!
//! ## Parse from string
//!
//! ```
//! use nom::Input;
//! use xschem_parser::Span;
//! use xschem_parser::token::{Flip, Objects, Property, Rotation, Schematic, Text, Version};
//!
//! let input = "\
//! v {xschem version=3.4.5 file_version=1.2}
//! K {type=regulator}
//! T {@name} -17.5 -15 0 0 0.2 0.2 {}
//! ";
//!
//! // Get a span so we can reference to locations in the input string.
//! // The parsed schematic contains references with column and line in
//! // the input string.
//! let span = Span::new(input);
//!
//! let expected = Schematic {
//! version: Version(Property {
//! prop: span.take_from(3).take(37),
//! attrs: [
//! (span.take_from(10).take(7), span.take_from(18).take(5)),
//! (span.take_from(24).take(12), span.take_from(37).take(3)),
//! ].into(),
//! }),
//! spice_property: None,
//! verilog_property: None,
//! vhdl_property: None,
//! tedax_property: None,
//! symbol_property: Some(Property {
//! prop: span.take_from(45).take(14).into(),
//! attrs: [
//! (span.take_from(45).take(4), span.take_from(50).take(9)),
//! ].into(),
//! }.into()),
//! texts: vec![Text {
//! text: span.take_from(64).take(5),
//! position: (-17.5, -15.0).try_into().unwrap(),
//! rotation: Rotation::Zero,
//! flip: Flip::Unflipped,
//! size: (0.2, 0.2).try_into().unwrap(),
//! property: Property {
//! prop: span.take_from(94).take(0),
//! attrs: [].into(),
//! },
//! }].into(),
//! lines: Objects::default(),
//! rectangles: Objects::default(),
//! polygons: Objects::default(),
//! arcs: Objects::default(),
//! wires: Objects::default(),
//! components: Objects::default(),
//! };
//!
//! let result = xschem_parser::from_str(input);
//!
//! assert_eq!(result, Ok(expected));
//! ```
//!
//! ## Parse from invalid string
//!
//! ```
//! // invalid input, wrong brackets
//! let input = "v []";
//!
//! let expected = "\
//! error: expected '{'
//! --> :1:3
//! |
//! 1 | v []
//! | ^
//! |
//! in version
//! --> :1:1
//! |
//! 1 | v []
//! | ^
//! |";
//!
//! let result = xschem_parser::from_str(input);
//!
//! assert!(result.is_err());
//! assert_eq!(result.unwrap_err().to_string(), expected);
//! ```
//!
//! ## Parse from file
//!
//! Since a parsed schematic contains references to the input, this library
//! cannot provide an implementation of parsing from file, since that would
//! require copying the contents of the file contents to make the lifetimes work
//! out.
//!
//! ```no_run
//! use std::path::Path;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let path = Path::new("test.sch");
//! let contents = std::fs::read_to_string(path)?;
//! match xschem_parser::from_str_file(&contents, path) {
//! Ok(schematic) => println!("{schematic}"),
//! Err(e) => eprintln!("{e}"),
//! }
//! # Ok(())
//! # }
//! ```
//!
//! [Xschem]: https://xschem.sourceforge.io/stefan/index.html
//! [developer info]: https://xschem.sourceforge.io/stefan/xschem_man/developer_info.html
use Path;
use LocatedSpan;
use crateError;
use crateSchematic;
/// String reference with location.
pub type Span<'a, X = > = ;
/// String reference with location in file.
pub type FileSpan<'a, 'b> = ;
/// Bytes reference with location.
pub type ByteSpan<'a, X = > = ;
/// Bytes reference with location in file.
pub type ByteFileSpan<'a, 'b> = ;
/// Parse a [`Schematic`] from a [`str`].
/// Parse a [`Schematic`] from a byte slice.
/// Parse a [`Schematic`] from a [`str`] with [`Path`] info.
/// Parse a [`Schematic`] from a byte slice with [`Path`] info.