MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / parse_route

Method parse_route

aiscript-runtime/src/parser.rs:47–78  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

45 }
46
47 pub fn parse_route(&mut self) -> Result<Route, String> {
48 let annotation = self.parse_route_annotation();
49 let mut docs = String::new();
50 let mut path = (String::from("/"), Vec::new());
51
52 // Check if this is a top-level route declaration
53 let is_top_route = self.check_identifier("route");
54 if is_top_route {
55 self.advance(); // consume 'route'
56 path = self.parse_path()?;
57 self.consume(TokenType::OpenBrace, "Expect '{' after route path")?;
58
59 docs = self.parse_docs();
60 }
61
62 let mut endpoints = Vec::new();
63 while !self.is_at_end() && !self.check(TokenType::CloseBrace) {
64 endpoints.push(self.parse_endpoint()?);
65 }
66
67 if is_top_route {
68 self.consume(TokenType::CloseBrace, "Expect '}' after route body")?;
69 }
70
71 Ok(Route {
72 annotation,
73 prefix: path.0,
74 params: path.1,
75 endpoints,
76 docs,
77 })
78 }
79
80 fn parse_endpoint(&mut self) -> Result<Endpoint, String> {
81 let annotation = self.parse_route_annotation();

Callers 10

parse_routeFunction · 0.80
test_basic_routeFunction · 0.80
test_no_top_routeFunction · 0.80
test_multiple_methodsFunction · 0.80
test_validatorsFunction · 0.80
test_empty_pathsFunction · 0.80
test_path_with_dashFunction · 0.80

Calls 10

check_identifierMethod · 0.80
advanceMethod · 0.80
parse_pathMethod · 0.80
parse_docsMethod · 0.80
is_at_endMethod · 0.80
checkMethod · 0.80
pushMethod · 0.80
parse_endpointMethod · 0.80
consumeMethod · 0.45

Tested by 9

test_basic_routeFunction · 0.64
test_no_top_routeFunction · 0.64
test_multiple_methodsFunction · 0.64
test_validatorsFunction · 0.64
test_empty_pathsFunction · 0.64
test_path_with_dashFunction · 0.64