MCPcopy Create free account
hub / github.com/cherryramatisdev/regexer / parse

Function parse

regexer/src/lexer/ast.rs:121–215  ·  view source on GitHub ↗

TODO: define a `consume` function to not keep repeating the peeks_tokens.next() all the time

(tokens: Vec<tokens::Token>)

Source from the content-addressed store, hash-verified

119
120// TODO: define a `consume` function to not keep repeating the peeks_tokens.next() all the time
121pub fn parse(tokens: Vec<tokens::Token>) -> Vec<Function> {
122 let mut peeks_tokens = tokens.clone().into_iter().enumerate().peekable();
123 let mut functions: Vec<Function> = vec![];
124
125 while let Some((index, token)) = peeks_tokens.peek() {
126 if let tokens::Token::Identifier(identifier) = token {
127 match identifier.as_str() {
128 "letter" | "letters" => {
129 let (func_tokens, right_pos_idx) = slice_until_end_func(&tokens, &index);
130
131 let casing = find_casing_parameter(func_tokens, "upcase".to_string());
132 let select = find_int_parameter(func_tokens, "select".to_string());
133
134 if identifier == "letter" {
135 functions.push(Function::Letter {
136 casing: casing.clone(),
137 select: select.clone(),
138 });
139 }
140
141 if identifier == "letters" {
142 functions.push(Function::Letters {
143 casing: casing.clone(),
144 });
145 }
146
147 peeks_tokens.nth(right_pos_idx + 1);
148 }
149 "number" => {
150 let (func_tokens, right_pos_idx) = slice_until_end_func(&tokens, &index);
151
152 let select = find_int_parameter(func_tokens, "select".to_string());
153
154 functions.push(Function::Number {
155 select: select.clone(),
156 });
157
158 peeks_tokens.nth(right_pos_idx + 1);
159 }
160 "numbers" => {
161 peeks_tokens.next();
162 functions.push(Function::Numbers)
163 }
164 "glob" => {
165 let (func_tokens, right_pos_idx) = slice_until_end_func(&tokens, &index);
166 if func_tokens
167 == [
168 tokens::Token::LeftParen,
169 tokens::Token::Parameter("rest".to_string()),
170 tokens::Token::Equal,
171 tokens::Token::True,
172 tokens::Token::RightParen,
173 ]
174 {
175 functions.push(Function::Glob { rest: true });
176 }
177
178 if func_tokens

Callers

nothing calls this directly

Calls 4

slice_until_end_funcFunction · 0.85
find_casing_parameterFunction · 0.85
find_int_parameterFunction · 0.85
slice_until_end_groupFunction · 0.85

Tested by

no test coverage detected