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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//! # Parser Module
//!
//! This module provides FFI functions for parsing KoiLang text and managing parser state.
//! It allows C and other foreign languages to parse KoiLang documents and extract commands.
//!
//! ## Main Components
//!
//! - [`KoiParser`]: Main parser structure for parsing KoiLang text
//! - [`KoiParserConfig`]: Configuration options for parser behavior
//! - [`KoiParserError`]: Error handling for parsing operations
//! - [`KoiInputSource`]: Input source abstraction for different data sources
//!
//! ## Usage Pattern
//!
//! 1. Create an input source from a string, file, or custom callback
//! 2. Configure parser options using `KoiParserConfig`
//! 3. Create a parser with `KoiParser_New`
//! 4. Iteratively retrieve commands with `KoiParser_NextCommand`
//! 5. Check for errors with `KoiParser_Error` if needed
//! 6. Clean up resources with the appropriate `_Del` functions
//!
//! ## Thread Safety
//!
//! Each `KoiParser` instance is not thread-safe and should only be used from a single thread.
//! Multiple parser instances can be used concurrently from different threads.
use ptr;
use ;
use Parser;
use crateKoiCommand;
pub use KoiParserConfig;
pub use KoiParserError;
pub use ;
/// Opaque handle for KoiLang parser
///
/// This structure represents a parser instance that can parse KoiLang text from various sources.
/// The parser maintains internal state including the current position, error information,
/// and end-of-file status.
/// Create a new KoiLang parser
///
/// Creates a new parser instance with the provided input source and configuration.
/// This function takes ownership of the input source, which means the caller should
/// not use or free the input source after this call. The parser will manage the input
/// source's lifecycle.
///
/// # Arguments
/// * `input` - Input source pointer (ownership is transferred to the parser)
/// * `config` - Parser configuration pointer
///
/// # Returns
/// Pointer to the new parser instance, or null on error:
/// - null if config is null
/// - null if input is null
///
/// # Safety
///
/// The input pointer must be a valid KoiInputSource created with one of the
/// KoiInputSource_From* functions. After calling this function, the input pointer
/// becomes invalid and must not be used or freed.
/// The config pointer must be a valid KoiParserConfig created with KoiParserConfig_New.
pub unsafe extern "C"
/// Delete a KoiLang parser and free its resources
///
/// This function destroys a parser instance and releases all associated memory,
/// including the input source that was transferred to it during creation.
/// After calling this function, the parser pointer becomes invalid and must not
/// be used.
///
/// # Arguments
/// * `parser` - Parser pointer to delete
///
/// # Safety
/// The parser pointer must be a valid KoiParser created with KoiParser_New.
/// After this call, the parser pointer becomes invalid and must not be used.
pub unsafe extern "C"
/// Get the next command from the parser
///
/// Retrieves the next command from the input source. Returns null when the end of
/// the input is reached or when an error occurs. If an error occurs, the error
/// can be retrieved using KoiParser_Error.
///
/// # Arguments
/// * `parser` - Parser pointer
///
/// # Returns
/// Pointer to the next command, or null in these cases:
/// - null if parser is null
/// - null if end of input is reached
/// - null if a parsing error occurred
///
/// # Safety
/// The parser pointer must be a valid KoiParser created with KoiParser_New.
/// The returned command pointer is owned by the caller and must be freed with
/// KoiCommand_Del when no longer needed.
pub unsafe extern "C"
/// Get the last parsing error from the parser
///
/// Retrieves the last error that occurred during parsing, if any. This function
/// transfers ownership of the error to the caller, so subsequent calls will
/// return null until another error occurs.
///
/// # Arguments
/// * `parser` - Parser pointer
///
/// # Returns
/// Pointer to the last error, or null in these cases:
/// - null if parser is null
/// - null if no error has occurred
/// - null if the error has already been retrieved
///
/// # Safety
/// The parser pointer must be a valid KoiParser created with KoiParser_New.
/// The returned error pointer is owned by the caller and must be freed with
/// KoiParserError_Del when no longer needed.
pub unsafe extern "C"