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
//! A parser for the Valve map format.
//! Also a provided convience [macro](crate::traverse) for iterating over subblocks using the [traversal](https://crates.io/crates/traversal) crate.
//!
//! # Vmf Format
//!
//! See [`parse()`] for the implementation.
//! Read more about the vmf format on [Valve Developer Community](https://developer.valvesoftware.com/wiki/Valve_Map_Format)
//!
//! ```vmf
//! ```
//!
//! # Example
//!
//! ```rust
//! use vmf_parser_nom::ast::{Block};
//! use vmf_parser_nom::parse;
//! use vmf_parser_nom::error::{VerboseError, SimpleError, ErrorKind};
//!
//! let input = "ClassName_1
//! {
//! \t\"Property_1\" \"Value_1\"
//! \t\"Property_2\" \"Value_2\"
//! \tClassName_2
//! \t{
//! \t\t\"Property_1\" \"Value_1\"
//! \t}
//! \tClassName_3
//! \t{
//! \t}
//! }";
//!
//! // parse the input to a vmf, borrowing from input
//! let vmf = parse::<&str, ()>(input).unwrap();
//! println!("vmf:\n{vmf}");
//! assert_eq!(input, vmf.to_string());
//!
//! // handy method to generate new ids so you don't have to deal with them
//! // same as display with alternate flag
//! assert_eq!(vmf.to_string_new_ids(), format!("{vmf:#}"));
//!
//! // parse to owned strings instead
//! let vmf_owned = parse::<String, ()>(input).unwrap();
//!
//! // All valid error types
//! let invalid_input = "block{\"property_with_no_value\"}";
//! let err_verbose = parse::<&str, VerboseError<_>>(invalid_input).unwrap_err();
//! let err_simple = parse::<&str, SimpleError<_>>(invalid_input).unwrap_err();
//! let err_tuple = parse::<&str, (_, ErrorKind)>(invalid_input).unwrap_err();
//! let err_unit = parse::<&str, ()>(invalid_input).unwrap_err();
//!
//! println!("verbose: {err_verbose:?}");
//! println!("simple: {err_simple:?}");
//! println!("tuple: {err_tuple:?}");
//! println!("unit: {err_unit:?}");
//!
//! // implements Deref
//! let block: &Block<String> = &vmf_owned;
//! assert_eq!(vmf_owned.inner, *block);
//!
//! // inner value is simply a block with no properties
//! assert_eq!(vmf_owned.inner.name, "root");
//! assert_eq!(vmf_owned.inner.props, vec![]);
//! assert!(!vmf_owned.inner.blocks.is_empty());
//! ```
use *;
use *;
use vmf;
pub use *;
// pub(crate) type VerboseError<I> = VerboseError<I>;
/// Macro for making an iterator over all the children of a block using
/// the [traversal](https://docs.rs/traversal/latest/traversal/index.html) crate.
/// Calls `.as_ref()` on input so works for [`Vmf`]s and [`Block`]s.
/// Usage is `traverse!(<traverse struct>, block)`.
///
/// Valid traverse structs are:
/// [`traversal::Bft`](https://docs.rs/traversal/latest/traversal/struct.Bft.html), [`traversal::DftPre`](https://docs.rs/traversal/latest/traversal/struct.DftPre.html), [`traversal::DftPost`](https://docs.rs/traversal/latest/traversal/struct.DftPost.html), [`traversal::DftPreRev`](https://docs.rs/traversal/latest/traversal/struct.DftPreRev.html), [`traversal::DftPostRev`](https://docs.rs/traversal/latest/traversal/struct.DftPostRev.html).
///
/// These also work but return paths:
/// [`traversal::DftPaths`](https://docs.rs/traversal/latest/traversal/struct.DftPaths.html), [`traversal::DftLongestPaths`](https://docs.rs/traversal/latest/traversal/struct.DftLongestPaths.html), [`traversal::DftCycles`](https://docs.rs/traversal/latest/traversal/struct.DftCycles.html).
///
/// # Examples
///
/// ```rust
/// use traversal::Bft;
/// use vmf_parser_nom::traverse;
/// use vmf_parser_nom::parse;
///
/// let input = "block1{}block2{}block3{}";
/// let vmf = parse::<&str, ()>(input).unwrap();
///
/// // returns an iterator
/// let bft = traverse!(Bft, vmf);
/// for (level, block) in bft {
/// // prints:
/// // root @ level 0
/// // block1 @ level 1
/// // block2 @ level 1
/// // block3 @ level 1
/// println!("{} @ level {}", block.name, level);
/// }
/// ```
// FromStr unable to be implemented because dumb lifetime stuff
/// Parse a `&str` into a [`Vmf`], completely ignoring whitespace.
/// You can specify the output string type to be
/// any type that implements `From<&str>`.
///
/// Valid error types are
/// `()`, [`(I, nom::error::ErrorKind)`](nom::error::ErrorKind), [`nom::error::Error<&str>`], [`nom::error::VerboseError<&str>`].
/// Or other types that impl [`ParseError`] and [`ContextError`]
///
/// See [Vmf Format](./index.html#vmf-format).