MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / use_declaration

Method use_declaration

aiscript-vm/src/parser/mod.rs:178–209  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

176 }
177
178 fn use_declaration(&mut self) -> Option<Stmt<'gc>> {
179 // Create a vector to store all parts of the module path
180 let mut path_parts = Vec::new();
181
182 self.consume(TokenType::Identifier, "Expect module name after 'use'.");
183 path_parts.push(self.previous);
184
185 // Handle dotted module paths (e.g., "std.math")
186 while self.match_token(TokenType::Dot) {
187 self.consume(TokenType::Identifier, "Expect identifier after '.'.");
188 path_parts.push(self.previous);
189 }
190
191 self.consume(TokenType::Semicolon, "Expect ';' after module path.");
192
193 // Combine all parts into a single module path
194 let mut full_path = String::new();
195 for (i, part) in path_parts.iter().enumerate() {
196 if i > 0 {
197 full_path.push('.');
198 }
199 full_path.push_str(part.lexeme);
200 }
201
202 // Create a new token with the full path
203 let path = Token::new(TokenType::Identifier, full_path.leak(), path_parts[0].line);
204
205 Some(Stmt::Use {
206 path,
207 line: path.line,
208 })
209 }
210
211 fn statement(&mut self) -> Option<Stmt<'gc>> {
212 if self.match_token(TokenType::OpenBrace) {

Callers 1

declarationMethod · 0.80

Calls 3

pushMethod · 0.80
match_tokenMethod · 0.80
consumeMethod · 0.45

Tested by

no test coverage detected