1#![allow(
7 unused,
8 unreachable_patterns,
9 non_snake_case,
10 non_camel_case_types,
11 invalid_nan_comparisons,
12 clippy::float_cmp,
13 clippy::suboptimal_flops,
14 clippy::cast_precision_loss,
15 clippy::cast_possible_truncation,
16 clippy::cast_sign_loss
17)]
18
19pub mod ml_array {
21 #[must_use]
22 pub fn optional_at<T: Clone>(values: &[T], index: Option<usize>) -> Option<T> {
23 index.and_then(|index| values.get(index)).cloned()
24 }
25 #[must_use]
28 pub fn at<T: Clone>(values: &[T], index: Option<usize>) -> T {
29 index
30 .and_then(|index| values.get(index))
31 .map_or_else(|| panic!("array index out of range"), Clone::clone)
32 }
33
34 #[must_use]
36 pub fn number_index(index: f64) -> Option<usize> {
37 if index >= 0.0 && index.fract() == 0.0 && index < 9_007_199_254_740_992.0 {
38 Some(index as usize)
39 } else {
40 None
41 }
42 }
43
44 #[must_use]
45 pub fn append<T>(mut left: Vec<T>, right: Vec<T>) -> Vec<T> {
46 left.extend(right);
47 left
48 }
49 const fn integer(value: f64) -> f64 {
50 if value.is_nan() { 0.0 } else { value.trunc() }
51 }
52 fn relative(value: f64, length: usize) -> usize {
53 let value = integer(value);
54 if value < 0.0 {
55 (length as f64 + value).max(0.0) as usize
56 } else {
57 value.min(length as f64) as usize
58 }
59 }
60 #[must_use]
61 pub fn slice<T: Clone>(values: &[T], start: f64, end: f64) -> Vec<T> {
62 let start = relative(start, values.len());
63 let end = relative(end, values.len());
64 values[start..end.max(start)].to_vec()
65 }
66 #[must_use]
67 pub fn index_of<T, F: Fn(&T, &T) -> bool>(
68 values: &[T],
69 search: &T,
70 from: f64,
71 reverse: bool,
72 equal: F,
73 ) -> f64 {
74 if values.is_empty() {
75 return -1.0;
76 }
77 let from = integer(from);
78 if reverse {
79 if from < -(values.len() as f64) {
80 return -1.0;
81 }
82 let start = if from < 0.0 {
83 (values.len() as f64 + from) as usize
84 } else {
85 from.min((values.len() - 1) as f64) as usize
86 };
87 (0..=start)
88 .rev()
89 .find(|&index| equal(&values[index], search))
90 .map_or(-1.0, |index| index as f64)
91 } else {
92 let start = if from < 0.0 {
93 (values.len() as f64 + from).max(0.0) as usize
94 } else {
95 from.min(values.len() as f64) as usize
96 };
97 (start..values.len())
98 .find(|&index| equal(&values[index], search))
99 .map_or(-1.0, |index| index as f64)
100 }
101 }
102 #[must_use]
103 pub fn includes<T, F: Fn(&T, &T) -> bool>(
104 values: &[T],
105 search: &T,
106 from: f64,
107 reverse: bool,
108 equal: F,
109 ) -> bool {
110 index_of(values, search, from, reverse, equal) >= 0.0
111 }
112 #[must_use]
113 pub fn set<T, F: Fn(&T, &T) -> bool>(values: Vec<T>, equal: F) -> Vec<T> {
114 let mut out = Vec::new();
115 for value in values {
116 if !out.iter().any(|previous| equal(previous, &value)) {
117 out.push(value);
118 }
119 }
120 out
121 }
122 #[must_use]
123 pub fn map<K, V, F: Fn(&K, &K) -> bool>(values: Vec<(K, V)>, equal: F) -> Vec<(K, V)> {
124 let mut out: Vec<(K, V)> = Vec::new();
125 for (key, value) in values {
126 if let Some(index) = out.iter().position(|(previous, _)| equal(previous, &key)) {
127 out[index].1 = value;
128 } else {
129 out.push((key, value));
130 }
131 }
132 out
133 }
134}
135
136#[derive(Clone, Debug, PartialEq)]
137pub enum UnicodeEscape {
138 Scalar(f64, f64),
139 Malformed,
140 Unsupported(f64, f64),
141}
142
143pub fn decode_unicode_escape(
144 units: Vec<f64>,
145 allow_fixed: bool,
146) -> crate::translation::frontend_rules::UnicodeEscape {
147 if ((((units.len() as f64) < (2f64))
148 || !(match (
149 crate::translation::frontend_rules::ml_array::optional_at(
150 &units,
151 crate::translation::frontend_rules::ml_array::number_index(0f64),
152 ),
153 92f64,
154 ) {
155 (Some(ml_left), ml_right) => ml_left == ml_right,
156 _ => false,
157 }))
158 || (!(match (
159 crate::translation::frontend_rules::ml_array::optional_at(
160 &units,
161 crate::translation::frontend_rules::ml_array::number_index(1f64),
162 ),
163 117f64,
164 ) {
165 (Some(ml_left), ml_right) => ml_left == ml_right,
166 _ => false,
167 }) && !(match (
168 crate::translation::frontend_rules::ml_array::optional_at(
169 &units,
170 crate::translation::frontend_rules::ml_array::number_index(1f64),
171 ),
172 120f64,
173 ) {
174 (Some(ml_left), ml_right) => ml_left == ml_right,
175 _ => false,
176 })))
177 {
178 crate::translation::frontend_rules::UnicodeEscape::Malformed
179 } else {
180 {
181 let fixed = 4f64;
182 {
183 let ml_s1 = if match (
184 crate::translation::frontend_rules::ml_array::optional_at(
185 &units,
186 crate::translation::frontend_rules::ml_array::number_index(1f64),
187 ),
188 120f64,
189 ) {
190 (Some(ml_left), ml_right) => ml_left == ml_right,
191 _ => false,
192 } {
193 if allow_fixed {
194 {
195 let fixed_2 = 2f64;
196 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin1::MlDecodeUnicodeEscapeJoin1Next(fixed_2)
197 }
198 } else {
199 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin1::MlDecodeUnicodeEscapeJoin1Return(Box::new(crate::translation::frontend_rules::UnicodeEscape::Malformed))
200 }
201 } else {
202 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin1::MlDecodeUnicodeEscapeJoin1Next(fixed)
203 };
204 match ml_s1 {
205 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin1::MlDecodeUnicodeEscapeJoin1Next(fixed_3) => {
206 {
207 let index = 2f64;
208 {
209 let code = 0f64;
210 {
211 let digits = 0f64;
212 {
213 let braced = false;
214 {
215 let ml_s2 = if (((fixed_3 == (4f64)) && ((units.len() as f64) > (2f64))) && match (crate::translation::frontend_rules::ml_array::optional_at(&units, crate::translation::frontend_rules::ml_array::number_index(2f64)), 123f64) { (Some(ml_left), ml_right) => ml_left == ml_right, _ => false }) {
216 {
217 let braced_2 = true;
218 {
219 let index_2 = 3f64;
220 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin2::MlDecodeUnicodeEscapeJoin2Next(index_2, braced_2)
221 }
222 }
223 } else if allow_fixed {
224 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin2::MlDecodeUnicodeEscapeJoin2Next(index, braced)
225 } else {
226 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin2::MlDecodeUnicodeEscapeJoin2Return(Box::new(crate::translation::frontend_rules::UnicodeEscape::Malformed))
227 };
228 match ml_s2 {
229 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin2::MlDecodeUnicodeEscapeJoin2Next(index_3, braced_3) => {
230 {
231 let ml_s3 = crate::translation::frontend_rules::ml_decode_unicode_escape_loop3(units.clone(), fixed_3, index_3, code, digits, braced_3);
232 match ml_s3 {
233 crate::translation::frontend_rules::MlDecodeUnicodeEscapeLoop3Result::MlDecodeUnicodeEscapeLoop3Done(index_4, code_2, digits_2) => {
234 {
235 let ml_s4 = if braced_3 {
236 if (((digits_2 == (0f64)) || (index_4 >= (units.len() as f64))) || !(match (crate::translation::frontend_rules::ml_array::optional_at(&units, crate::translation::frontend_rules::ml_array::number_index(index_4)), 125f64) { (Some(ml_left), ml_right) => ml_left == ml_right, _ => false })) {
237 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin4::MlDecodeUnicodeEscapeJoin4Return(Box::new(crate::translation::frontend_rules::UnicodeEscape::Malformed))
238 } else {
239 {
240 let index_5 = (index_4 + 1f64);
241 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin4::MlDecodeUnicodeEscapeJoin4Next(index_5)
242 }
243 }
244 } else {
245 if digits_2 == fixed_3 {
246 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin4::MlDecodeUnicodeEscapeJoin4Next(index_4)
247 } else {
248 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin4::MlDecodeUnicodeEscapeJoin4Return(Box::new(crate::translation::frontend_rules::UnicodeEscape::Malformed))
249 }
250 };
251 match ml_s4 {
252 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin4::MlDecodeUnicodeEscapeJoin4Next(index_6) => {
253 {
254 let escape_length = index_6;
255 {
256 let ml_s6 = if (((((!braced_3 && (code_2 >= (55296f64))) && (code_2 <= (56319f64))) && ((units.len() as f64) >= (index_6 + 6f64))) && match (crate::translation::frontend_rules::ml_array::optional_at(&units, crate::translation::frontend_rules::ml_array::number_index(index_6)), 92f64) { (Some(ml_left), ml_right) => ml_left == ml_right, _ => false }) && match (crate::translation::frontend_rules::ml_array::optional_at(&units, crate::translation::frontend_rules::ml_array::number_index(index_6 + 1f64)), 117f64) { (Some(ml_left), ml_right) => ml_left == ml_right, _ => false }) {
257 {
258 let low = 0f64;
259 {
260 let offset = 2f64;
261 {
262 let ml_s7 = crate::translation::frontend_rules::ml_decode_unicode_escape_loop6(units, index_6, low, offset);
263 match ml_s7 {
264 crate::translation::frontend_rules::MlDecodeUnicodeEscapeLoop6Result::MlDecodeUnicodeEscapeLoop6Done(low_2, offset_2) => {
265 if (((offset_2 == (6f64)) && (low_2 >= (56320f64))) && (low_2 <= (57343f64))) {
266 {
267 let code_3 = (((65536f64 + ((code_2 - 55296f64) * 1024f64)) + low_2) - 56320f64);
268 {
269 let index_7 = (index_6 + 6f64);
270 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin5::MlDecodeUnicodeEscapeJoin5Next(index_7, code_3)
271 }
272 }
273 } else {
274 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin5::MlDecodeUnicodeEscapeJoin5Next(index_6, code_2)
275 }
276 }
277 }
278 }
279 }
280 }
281 } else {
282 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin5::MlDecodeUnicodeEscapeJoin5Next(index_6, code_2)
283 };
284 match ml_s6 {
285 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin5::MlDecodeUnicodeEscapeJoin5Next(index_8, code_4) => {
286 if ((code_4 > (1_114_111_f64)) || (55296f64..=57343f64).contains(&code_4)) {
287 crate::translation::frontend_rules::UnicodeEscape::Unsupported(index_8, escape_length)
288 } else {
289 crate::translation::frontend_rules::UnicodeEscape::Scalar(code_4, index_8)
290 }
291 }
292 }
293 }
294 }
295 }
296 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin4::MlDecodeUnicodeEscapeJoin4Return(ml_result6) => {
297
298 *ml_result6
299 }
300 }
301 }
302 }
303 }
304 }
305 }
306 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin2::MlDecodeUnicodeEscapeJoin2Return(ml_result6_2) => {
307
308 *ml_result6_2
309 }
310 }
311 }
312 }
313 }
314 }
315 }
316 }
317 crate::translation::frontend_rules::MlDecodeUnicodeEscapeJoin1::MlDecodeUnicodeEscapeJoin1Return(ml_result6_3) => {
318
319 *ml_result6_3
320 }
321 }
322 }
323 }
324 }
325}
326
327pub fn accept_argument_count(defaults: Vec<bool>, count: f64) -> bool {
328 if (count > (defaults.len() as f64)) {
329 false
330 } else {
331 {
332 let index = count;
333 {
334 let ml_s8 = crate::translation::frontend_rules::ml_accept_argument_count_loop7(
335 defaults, index,
336 );
337 match ml_s8 {
338 crate::translation::frontend_rules::MlAcceptArgumentCountLoop7Result::MlAcceptArgumentCountLoop7Done => {
339 true
340 }
341 crate::translation::frontend_rules::MlAcceptArgumentCountLoop7Result::MlAcceptArgumentCountLoop7Return(ml_result7) => {
342 ml_result7
343 }
344 }
345 }
346 }
347 }
348}
349
350pub fn find_default_parameter_reference(
351 kinds: Vec<String>,
352 values: Vec<String>,
353 parameters: Vec<String>,
354) -> f64 {
355 {
356 let at = 0f64;
357 {
358 let depth = 0f64;
359 {
360 let ml_s9 =
361 crate::translation::frontend_rules::ml_find_default_parameter_reference_loop8(
362 kinds, values, parameters, at, depth,
363 );
364 match ml_s9 {
365 crate::translation::frontend_rules::MlFindDefaultParameterReferenceLoop8Result::MlFindDefaultParameterReferenceLoop8Done => {
366 (-1f64)
367 }
368 crate::translation::frontend_rules::MlFindDefaultParameterReferenceLoop8Result::MlFindDefaultParameterReferenceLoop8Return(ml_result8) => {
369 ml_result8
370 }
371 }
372 }
373 }
374 }
375}
376
377pub fn start_regular_expression(kind: &str, value: &str) -> bool {
378 if (kind.is_empty()) {
379 true
380 } else if (kind == "identifier") {
381 ((((((((((((value == "return") || (value == "throw")) || (value == "case"))
382 || (value == "delete"))
383 || (value == "void"))
384 || (value == "typeof"))
385 || (value == "yield"))
386 || (value == "await"))
387 || (value == "in"))
388 || (value == "of"))
389 || (value == "else"))
390 || (value == "do"))
391 } else if kind == "punct" {
392 (((((((value != ")") && (value != "]")) && (value != "}")) && (value != "."))
393 && (value != "?."))
394 && (value != "++"))
395 && (value != "--"))
396 } else {
397 false
398 }
399}
400
401pub fn accept_statement_brace(
402 kind: &str,
403 value: &str,
404 control_closed: bool,
405 declaration_body: bool,
406) -> bool {
407 declaration_body
408 || control_closed
409 || kind.is_empty()
410 || (kind == "identifier" && matches!(value, "else" | "do" | "try" | "finally"))
411 || (kind == "punct" && matches!(value, ";" | "{" | "}"))
412}
413
414pub fn accept_control_parenthesis(kind: &str, value: &str, qualified: bool) -> bool {
415 if (qualified || (kind != "identifier")) {
416 false
417 } else {
418 ((((((value == "if") || (value == "while")) || (value == "for")) || (value == "with"))
419 || (value == "switch"))
420 || (value == "catch"))
421 }
422}
423
424pub fn regular_expression_end(units: &[f64], start: f64) -> f64 {
425 {
426 let index = (start + 1f64);
427 {
428 let escaped = false;
429 {
430 let character_class = false;
431 {
432 let ml_s10 =
433 crate::translation::frontend_rules::ml_regular_expression_end_loop11(
434 units.to_vec(),
435 index,
436 escaped,
437 character_class,
438 );
439 match ml_s10 {
440 crate::translation::frontend_rules::MlRegularExpressionEndLoop11Result::MlRegularExpressionEndLoop11Done => {
441 (-1f64)
442 }
443 crate::translation::frontend_rules::MlRegularExpressionEndLoop11Result::MlRegularExpressionEndLoop11Return(ml_result11) => {
444 ml_result11
445 }
446 }
447 }
448 }
449 }
450 }
451}
452
453pub fn find_binding_run_end(terms: &[String], start: f64) -> f64 {
454 {
455 let end = start;
456 {
457 let end_2 = crate::translation::frontend_rules::ml_find_binding_run_end_loop14(
458 terms.to_vec(),
459 end,
460 );
461 if (end_2 == start) {
462 (start + 1f64)
463 } else {
464 end_2
465 }
466 }
467 }
468}
469
470pub fn accept_binding_scope(statuses: &[String], reasons: &[String]) -> bool {
471 if ((statuses.len() as f64) < (2f64)) {
472 false
473 } else {
474 {
475 let index = 0f64;
476 {
477 let ml_s11 = crate::translation::frontend_rules::ml_accept_binding_scope_loop15(
478 statuses.to_vec(),
479 reasons.to_vec(),
480 index,
481 );
482 match ml_s11 {
483 crate::translation::frontend_rules::MlAcceptBindingScopeLoop15Result::MlAcceptBindingScopeLoop15Done => {
484 false
485 }
486 crate::translation::frontend_rules::MlAcceptBindingScopeLoop15Result::MlAcceptBindingScopeLoop15Return(ml_result15) => {
487 ml_result15
488 }
489 }
490 }
491 }
492 }
493}
494
495pub fn accept_literal_binding(
496 value_kind: &str,
497 constant: bool,
498 effect_count: f64,
499 declaration_count: f64,
500) -> bool {
501 (((constant && (effect_count == (1f64))) && (declaration_count == (0f64)))
502 && (((value_kind == "num") || (value_kind == "bool")) || (value_kind == "str")))
503}
504
505pub fn constant_binding_form(value_kind: &str, type_kind: &str) -> String {
506 if ((value_kind == "lit")
507 && (((type_kind == "float") || (type_kind == "bool")) || (type_kind == "fixed")))
508 {
509 String::from("scalar")
510 } else if ((value_kind == "lit") && (type_kind == "string")) {
511 String::from("string")
512 } else {
513 String::from("lazy")
514 }
515}
516
517pub fn accept_constant_emission(
518 constant: bool,
519 effects: f64,
520 declarations: f64,
521 legal_name: bool,
522) -> bool {
523 (((constant && (effects == (1f64))) && (declarations == (0f64))) && legal_name)
524}
525
526pub fn render_constant_binding(form: &str, name: &str, type_: &str, value: &str) -> String {
527 if (form == "lazy") {
528 format!(
529 "{}{}",
530 (format!(
531 "{}{}",
532 (format!(
533 "{}{}",
534 (format!(
535 "{}{}",
536 (format!(
537 "{}{}",
538 (format!("{}{}", (String::from("pub static ")), name)),
539 (String::from(": std::sync::LazyLock<"))
540 )),
541 type_
542 )),
543 (String::from("> = std::sync::LazyLock::new(|| "))
544 )),
545 value
546 )),
547 (String::from(");"))
548 )
549 } else {
550 format!(
551 "{}{}",
552 (format!(
553 "{}{}",
554 (format!(
555 "{}{}",
556 (format!(
557 "{}{}",
558 (format!(
559 "{}{}",
560 (format!("{}{}", (String::from("pub const ")), name)),
561 (String::from(": "))
562 )),
563 type_
564 )),
565 (String::from(" = "))
566 )),
567 value
568 )),
569 (String::from(";"))
570 )
571 }
572}
573
574pub fn accept_module_binding_scope(terms: &[String], carried: bool) -> bool {
575 if carried {
576 {
577 let declarations = 0f64;
578 {
579 let index = 0f64;
580 {
581 let ml_s12 =
582 crate::translation::frontend_rules::ml_accept_module_binding_scope_loop16(
583 terms.to_vec(),
584 declarations,
585 index,
586 );
587 match ml_s12 {
588 crate::translation::frontend_rules::MlAcceptModuleBindingScopeLoop16Result::MlAcceptModuleBindingScopeLoop16Done(declarations_2) => {
589 (declarations_2 > (0f64))
590 }
591 crate::translation::frontend_rules::MlAcceptModuleBindingScopeLoop16Result::MlAcceptModuleBindingScopeLoop16Return(ml_result16) => {
592 ml_result16
593 }
594 }
595 }
596 }
597 }
598 } else {
599 false
600 }
601}
602
603pub fn find_documentation_parameter_range(units: &[f64]) -> Vec<f64> {
604 {
605 let start = 0f64;
606 {
607 let start_2 =
608 crate::translation::frontend_rules::ml_find_documentation_parameter_range_loop17(
609 units.to_vec(),
610 start,
611 );
612 {
613 let optional = false;
614 {
615 let ml_s13 = if ((start_2 < (units.len() as f64))
616 && match (
617 crate::translation::frontend_rules::ml_array::optional_at(
618 units,
619 crate::translation::frontend_rules::ml_array::number_index(start_2),
620 ),
621 91f64,
622 ) {
623 (Some(ml_left), ml_right) => ml_left == ml_right,
624 _ => false,
625 }) {
626 {
627 let optional_2 = true;
628 {
629 let start_3 = (start_2 + 1f64);
630 crate::translation::frontend_rules::MlFindDocumentationParameterRangeJoin18::MlFindDocumentationParameterRangeJoin18Next(start_3, optional_2)
631 }
632 }
633 } else {
634 crate::translation::frontend_rules::MlFindDocumentationParameterRangeJoin18::MlFindDocumentationParameterRangeJoin18Next(start_2, optional)
635 };
636 match ml_s13 {
637 crate::translation::frontend_rules::MlFindDocumentationParameterRangeJoin18::MlFindDocumentationParameterRangeJoin18Next(start_4, optional_3) => {
638 {
639 let end = start_4;
640 {
641 let end_2 = crate::translation::frontend_rules::ml_find_documentation_parameter_range_loop19(units.to_vec(), start_4, end);
642 if (end_2 == start_4) {
643 Vec::<f64>::new()
644 } else {
645 {
646 let ml_s14 = if optional_3 {
647 {
648 let after = end_2;
649 {
650 let after_2 = crate::translation::frontend_rules::ml_find_documentation_parameter_range_loop21(units.to_vec(), after);
651 if ((after_2 >= (units.len() as f64)) || (!(match (crate::translation::frontend_rules::ml_array::optional_at(units, crate::translation::frontend_rules::ml_array::number_index(after_2)), 93f64) { (Some(ml_left), ml_right) => ml_left == ml_right, _ => false }) && !(match (crate::translation::frontend_rules::ml_array::optional_at(units, crate::translation::frontend_rules::ml_array::number_index(after_2)), 61f64) { (Some(ml_left), ml_right) => ml_left == ml_right, _ => false }))) {
652 crate::translation::frontend_rules::MlFindDocumentationParameterRangeJoin20::MlFindDocumentationParameterRangeJoin20Return(Vec::<f64>::new())
653 } else {
654 crate::translation::frontend_rules::MlFindDocumentationParameterRangeJoin20::MlFindDocumentationParameterRangeJoin20Next
655 }
656 }
657 }
658 } else {
659 crate::translation::frontend_rules::MlFindDocumentationParameterRangeJoin20::MlFindDocumentationParameterRangeJoin20Next
660 };
661 match ml_s14 {
662 crate::translation::frontend_rules::MlFindDocumentationParameterRangeJoin20::MlFindDocumentationParameterRangeJoin20Next => {
663 vec![start_4, end_2]
664 }
665 crate::translation::frontend_rules::MlFindDocumentationParameterRangeJoin20::MlFindDocumentationParameterRangeJoin20Return(ml_result20) => {
666 ml_result20
667 }
668 }
669 }
670 }
671 }
672 }
673 }
674 }
675 }
676 }
677 }
678 }
679}
680
681pub fn accept_type_query_operand(kind: &str) -> bool {
682 matches!(
683 kind,
684 "var" | "lit" | "name" | "num" | "bool" | "str" | "functionValue" | "functionRef"
685 )
686}
687
688pub fn read_type_query_result(kind: &str) -> String {
689 if kind == "float" {
690 String::from("number")
691 } else if (kind == "nat") || (kind == "int") {
692 String::from("bigint")
693 } else if kind == "bool" {
694 String::from("boolean")
695 } else if kind == "string" {
696 String::from("string")
697 } else if kind == "function" {
698 String::from("function")
699 } else if (((((kind == "array") || (kind == "data")) || (kind == "record"))
700 || (kind == "tuple"))
701 || (kind == "map"))
702 || (kind == "set")
703 {
704 String::from("object")
705 } else {
706 String::new()
707 }
708}
709
710pub fn accept_java_script_optional_tuple_context(
711 language: &str,
712 source_kind: &str,
713 expected_kind: &str,
714 present_kind: &str,
715) -> bool {
716 (((language == "JavaScript") && ((source_kind == "array") || (source_kind == "tuple")))
717 && (expected_kind == "option"))
718 && (present_kind == "tuple")
719}
720
721pub fn read_array_method_form(method: &str) -> String {
722 if method == "concat" {
723 String::from("concatenate")
724 } else if method == "slice" {
725 String::from("copy")
726 } else if method == "Array.from" {
727 String::from("copy-from")
728 } else if method == "Array.of" {
729 String::from("construct")
730 } else {
731 String::new()
732 }
733}
734
735pub fn accept_root_syntax_item(term: &str, has_children: bool, has_content: bool) -> bool {
736 term == "ERROR" && !has_children && has_content
737}
738
739pub const fn accept_source_prefix_restoration(
740 source_matches: bool,
741 body_matches: bool,
742 layout_only: bool,
743) -> bool {
744 source_matches && body_matches && layout_only
745}
746
747pub const fn accept_declaration_signature(constant: bool, literal: bool) -> bool {
748 (!constant || literal)
749}
750
751pub fn read_string_test_operation(language: &str, method: &str) -> String {
752 if (language == "JavaScript") {
753 if (((method == "startsWith") || (method == "endsWith")) || (method == "includes")) {
754 method.to_owned()
755 } else {
756 String::new()
757 }
758 } else {
759 if (language == "Rust") {
760 if (method == "starts_with") {
761 String::from("startsWith")
762 } else if (method == "ends_with") {
763 String::from("endsWith")
764 } else if (method == "contains") {
765 String::from("includes")
766 } else {
767 String::new()
768 }
769 } else {
770 String::new()
771 }
772 }
773}
774
775pub fn render_string_test_expression(
776 target: &str,
777 operation: &str,
778 object: &str,
779 search: &str,
780) -> String {
781 if (target == "JavaScript") {
782 format!(
783 "{}{}",
784 (format!(
785 "{}{}",
786 (format!(
787 "{}{}",
788 (format!(
789 "{}{}",
790 (format!("{}{}", object, (String::from(".")))),
791 operation
792 )),
793 (String::from("("))
794 )),
795 search
796 )),
797 (String::from(")"))
798 )
799 } else if (target == "Rust") {
800 {
801 let method = String::new();
802 {
803 let method_3 = if (operation == "startsWith") {
804 { String::from("starts_with") }
805 } else {
806 method
807 };
808 {
809 let method_5 = if (operation == "endsWith") {
810 { String::from("ends_with") }
811 } else {
812 method_3
813 };
814 {
815 let method_7 = if (operation == "includes") {
816 { String::from("contains") }
817 } else {
818 method_5
819 };
820 format!(
821 "{}{}",
822 (format!(
823 "{}{}",
824 (format!(
825 "{}{}",
826 (format!(
827 "{}{}",
828 (format!("{}{}", object, (String::from(".")))),
829 method_7
830 )),
831 (String::from("("))
832 )),
833 search
834 )),
835 (String::from(")"))
836 )
837 }
838 }
839 }
840 }
841 } else if (target == "Lean") {
842 if (operation == "includes") {
843 format!(
844 "{}{}",
845 (format!(
846 "{}{}",
847 (format!(
848 "{}{}",
849 (format!("{}{}", (String::from("(ml_string_includes ")), object)),
850 (String::from(" "))
851 )),
852 search
853 )),
854 (String::from(")"))
855 )
856 } else {
857 format!(
858 "{}{}",
859 (format!(
860 "{}{}",
861 (format!(
862 "{}{}",
863 (format!(
864 "{}{}",
865 (format!(
866 "{}{}",
867 (format!("{}{}", (String::from("(String.")), operation)),
868 (String::from(" "))
869 )),
870 object
871 )),
872 (String::from(" "))
873 )),
874 search
875 )),
876 (String::from(")"))
877 )
878 }
879 } else {
880 {
881 let helper = String::new();
882 {
883 let helper_3 = if (operation == "startsWith") {
884 { String::from("ml_string_starts_with") }
885 } else {
886 helper
887 };
888 {
889 let helper_5 = if (operation == "endsWith") {
890 { String::from("ml_string_ends_with") }
891 } else {
892 helper_3
893 };
894 {
895 let helper_7 = if (operation == "includes") {
896 { String::from("ml_string_includes") }
897 } else {
898 helper_5
899 };
900 format!(
901 "{}{}",
902 (format!(
903 "{}{}",
904 (format!(
905 "{}{}",
906 (format!(
907 "{}{}",
908 (format!(
909 "{}{}",
910 (format!("{}{}", (String::from("(")), helper_7)),
911 (String::from(" "))
912 )),
913 object
914 )),
915 (String::from(" "))
916 )),
917 search
918 )),
919 (String::from(")"))
920 )
921 }
922 }
923 }
924 }
925 }
926}
927
928pub fn read_string_test_helper(target: &str, operation: &str) -> String {
929 if (target == "Lean") {
930 if (operation == "includes") {
931 String::from("stringIncludes")
932 } else {
933 String::new()
934 }
935 } else {
936 if (target == "Rocq") {
937 if (operation == "startsWith") {
938 String::from("stringStartsWith")
939 } else if (operation == "endsWith") {
940 String::from("stringEndsWith")
941 } else if (operation == "includes") {
942 String::from("stringIncludes")
943 } else {
944 String::new()
945 }
946 } else {
947 String::new()
948 }
949 }
950}
951
952pub fn read_string_test_support(target: &str, operation: &str) -> String {
953 if ((target == "Lean") && (operation == "includes")) {
954 String::from(
955 "/-- String.prototype.includes: the search occurs at some position of the string. -/\ndef ml_string_includes (string search : String) : Bool :=\n (List.range (string.length + 1)).any fun index => (string.drop index).startsWith search",
956 )
957 } else if ((target == "Rocq") && (operation == "startsWith")) {
958 String::from(
959 "(* String.prototype.startsWith: the string begins with the search. *)\nDefinition ml_string_starts_with (string search : string) : bool := String.prefix search string.",
960 )
961 } else if ((target == "Rocq") && (operation == "endsWith")) {
962 String::from(
963 "(* String.prototype.endsWith: the string ends with the search. *)\nDefinition ml_string_ends_with (string search : string) : bool :=\n Nat.leb (String.length search) (String.length string) &&\n String.eqb (String.substring (String.length string - String.length search) (String.length search) string) search.",
964 )
965 } else if ((target == "Rocq") && (operation == "includes")) {
966 String::from(
967 "(* String.prototype.includes: the search occurs at some position of the string. *)\nDefinition ml_string_includes (string search : string) : bool :=\n match String.index 0 search string with Some _ => true | None => false end.",
968 )
969 } else {
970 String::new()
971 }
972}
973
974#[path = "frontend_rules/strings.rs"]
975mod strings;
976pub use strings::*;
977#[path = "frontend_rules/rust_strings.rs"]
978mod rust_strings;
979pub use rust_strings::*;
980#[path = "frontend_rules/continuations.rs"]
981mod continuations;
982pub use continuations::*;
983#[path = "frontend_rules/continuations_2.rs"]
984mod continuations_2;
985pub use continuations_2::*;