-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppParser.py.vfc
More file actions
782 lines (760 loc) · 28.1 KB
/
cppParser.py.vfc
File metadata and controls
782 lines (760 loc) · 28.1 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
; IRL FlowCode Version: Version 10.0
; c1995-2015: Visual Flow Coder by 2LResearch
;
; File Name : cppParser.py.vfc
; File Date : 03:08:50 PM - 22:Dec:2025
set( );//Complete Arduino Structure Comment Parser
set( );//A two-phase parser that:
set( );//1) Formats Arduino code using clang-format (plus indents else-if blocks)
set( );//2) Adds structure comments with focus on functions and control structures, correctly handling if-else chains
set( );//Usage: ./arduino_parser.py input.ino -o output.ino
set();//"""
event(import subprocess);//
event(import sys);//
event(import os);//
event(import argparse);//
event(import tempfile);//
event(import re);//
event(import string);//
event(from typing import List, Tuple, Optional, Set);//
set(PRINTCODE = True;);//PRINTCODE = False;
branch();//
path(STRUCTURE_TAGS = {"if": ("beginif", "endif"),);//// //
set("for": ("beginfor", "endfor"),);//
set("while": ("beginwhile", "endwhile"),);//
set("switch": ("beginswitch","endswitch"),);//
set("function":("beginfunc", "endfunc"),);//
set("class":("beginclass", "endclass")});//
path(config = """);//// //
set(Language: Cpp);//
set(BasedOnStyle: Google);//
set(IndentWidth: 4);//
set(AccessModifierOffset: -4);//
set(AllowShortIfStatementsOnASingleLine: false);//
set(AllowShortLoopsOnASingleLine: false);//
set(AllowShortFunctionsOnASingleLine: None);//
set(BreakBeforeBraces: Allman);//
set(ColumnLimit: 100);//
set(PointerAlignment: Left);//
set(SortIncludes: false);//
set(ReflowComments: false);//
set(UseTab: Never);//
set(SpacesBeforeTrailingComments: 1);//
set(""");//
bend();//
end();//
input(def filter_ascii(text):);//
generic();//"""Keep only printable ASCII characters""
end(return ''.join(char for char in text if ord(char) < 128));//
input(def create_clang_config():);// beginfunc
set("""Create a temporary clang-format configuration file for Arduino code.""");//
set(fd, path = tempfile.mkstemp(prefix='.clang-format-', text=True));//
branch(with os.fdopen(fd, 'w') as f:);// beginwith
path();//
set(f.write(config));//
bend();// endwith
set(return path);//
end();// endfunc
input(def indent_else_blocks(code: str) -> str:);// beginfunc
set(""");//
set(After formatting, indent 'else'/'else if' lines one level deeper);//
set(under the preceding block's closing brace.);//
set(""");//
set(lines = code.split('\n'));//
set(new_lines = []);//
loop(for line in lines:);// beginfor
set(stripped = line.lstrip());//
branch(if stripped.startswith('else') and new_lines:);// beginif
path();//
set(prev = new_lines[-1]);//
set(prev_indent = len(prev) - len(prev.lstrip()));//
set(new_indent = prev_indent + 4);//
set(new_lines.append(' ' * new_indent + stripped));//
path(else:);//
set(new_lines.append(line));//
bend();// endif
lend();// endfor
set(return '\n'.join(new_lines));//
end();// endfunc
input(def format_code(code: str) -> str:);// beginfunc
set(""");//
set(Format Arduino code using clang-format, then indent else-if blocks.);//
set(Args:);//
set(code: The original code);//
set(Returns:);//
set(Formatted code with else-if indented);//
set(""");//
branch(try:);// begintry
path();//
set( );//config_path = create_clang_config()
set( );//formatted = proc.stdout.decode('utf-8')
set( );//os.unlink(config_path)
generic(script_dir = os.path.dirname(os.path.abspath(__file__)));// ////
output(print(f"Script is running from: {script_dir} - make sure clang-format is also installed on path"));//// //////
generic(clang_format_path = r"clang-format");//clang_format_path = r"C:\\Users\\lopezl10\\AppData\\Roaming\\Python\\Python312\\Scripts\\clang-format"
generic(clang_yaml_path =os.path.join( script_dir , "vfc.yaml" ));//clang_yaml_path = r"C:\\Users\\lopezl10\\AppData\\Local\\RedHorseVR\\C2VFC_parser\\vfc.yaml"
generic(stream = os.popen(f'"{clang_format_path}" -style=file:"{clang_yaml_path}" "{code_file}"'));//stream = os.popen(f'"{clang_format_path}" "{code_file}"')
set();//
generic(formatted = stream.read());// ////
output();//print( "--->" + code_file )
output();//if PRINTCODE : print( "Formatted Code: \n\n" , formatted + "\n\n")
process(return formatted);//return indent_else_blocks(formatted)
path(except Exception as e:);//
set(print(f"Error during formatting: {e}", file=sys.stderr));//
set(sys.exit(1));//
bend();// endtry
end();// endfunc
input(def add_structure_comments(code: str) -> str:);// beginfunc
set(""");//
set(Add structure comments focusing only on selected block types, handling if-else chains.);//
set(Args:);//
set(code: The formatted code);//
set(Returns:);//
set(Code with added structure comments);//
set(""");//
set(lines = code.split('\n'));//
set(result = lines.copy());//
set(function_regex = re.compile(r'^\s*(?!(?:if|for|while|else|switch)\b)[\w\s\*\&\:\<\>\~]+\w+\s*\([^;{]*\)\s*$'));//
set(blocks: List[Tuple[str, int, Optional[int], Optional[int]]] = []);//
set(brace_stack: List[Tuple[int, int, Optional[int]]] = []);//
set(tagged_lines: Set[int] = set());//
set();// First pass - detect blocks and track braces
loop(for i, line in enumerate(lines):);// beginfor
set(stripped = line.strip());//
branch(if not stripped or stripped.startswith('//'):);// beginif
path();//
end(continue);//// //
bend();// endif
set(indent = len(line) - len(line.lstrip()));//
set();// More precise detection of control structures
branch(if re.search(r'^\s*if\s*\(', line):);// beginif
path();//
set(blocks.append(('if', i, None, None)));//
path(elif re.search(r'^\s*for\s*\(', line):);// beginelif
set(blocks.append(('for', i, None, None)));//
path(elif re.search(r'^\s*while\s*\(', line):);// beginelif
set(blocks.append(('while', i, None, None)));//
path(elif re.search(r'^\s*switch\s*\(', line):);// beginelif
set(blocks.append(('switch', i, None, None)));//
path(elif re.search(r'^\s*class\s*\(', line):);// beginelif
set(blocks.append(('class', i, None, None)));//
path(elif function_regex.match(line):);// beginelif
set(blocks.append(('function', i, None, None)));//
set();// endlif
set();// endlif
set();// endlif
set();// endlif
bend();// endif
set();// Track opening braces
branch(if '{' in stripped:);// beginif
path();//
set();// Check if this opening brace belongs to a control structure
set();// Look at recent blocks that don't have an opening brace assigned yet
set(potential_owners = [(idx, block) for idx, block in enumerate(blocks));//
set(if block[2] is None and block[1] <= i and i - block[1] <= 2]);//
branch(if potential_owners:);// beginif
path();//
set();// Associate this brace with the most recent matching block
set(bidx = potential_owners[-1][0]);//
set(btype, sline, _, eline = blocks[bidx]);//
set(blocks[bidx] = (btype, sline, i, eline));//
path(else:);//
set(bidx = None);//
bend();// endif
set(brace_stack.append((i, indent, bidx)));//
bend();// endif
set();// Track closing braces
branch(if '}' in stripped:);// beginif
path();//
branch(if brace_stack:);// beginif
path();//
set(_, _, bidx = brace_stack.pop());//
branch(if bidx is not None:);// beginif
path();//
set(btype, sline, ob, _ = blocks[bidx]);//
set(blocks[bidx] = (btype, sline, ob, i));//
bend();// endif
bend();// endif
bend();// endif
lend();// endfor
set();// Process if-else chains
set(updated = []);//
loop(for btype, sline, ob, eline in blocks:);// beginfor
branch(if btype == 'if' and eline is not None:);// beginif
path();//
set(chain_end = eline);//
set(j = eline + 1);//
loop(while j < len(lines):);// beginwhile
set(st = lines[j].strip());//
branch(if not st or st.startswith('//'):);// beginif
path();//
set(j += 1);//
set(continue);//
bend();// endif
branch(if st.startswith('else'):);// beginif
path();//
set(# locate '{');// locate 0
branch(if '{' in st:);// beginif
path();//
set(open_j = j);//
path(else:);//
set(k = j + 1);//
loop(while k < len(lines) and '{' not in lines[k]:);// beginwhile
set(k += 1);//
lend();// endwhile
set(open_j = k);//
bend();// endif
set(count = 0);//
loop(for ch in lines[open_j]:);// beginfor
branch(if ch == '{':);// beginif
path();//
set(count += 1);//
bend();// endif
branch(if ch == '}':);// beginif
path();//
set(count -= 1);//
bend();// endif
lend();// endfor
set(m = open_j + 1);//
loop(while m < len(lines) and count > 0:);// beginwhile
loop(for ch in lines[m]:);// beginfor
branch(if ch == '{':);// beginif
path();//
set(count += 1);//
bend();// endif
branch(if ch == '}':);// beginif
path();//
set(count -= 1);//
bend();// endif
lend();// endfor
set(m += 1);//
lend();// endwhile
set(chain_end = m - 1);//
set(j = chain_end + 1);//
set(continue);//
bend();// endif
set(break);//
lend();// endwhile
set(updated.append((btype, sline, ob, chain_end)));//
path(else:);//
set(updated.append((btype, sline, ob, eline)));//
bend();// endif
lend();// endfor
set(blocks = updated);//
set();// Apply structure comments
loop(for btype, sline, ob, eline in blocks:);// beginfor
branch(if btype in STRUCTURE_TAGS and sline is not None and eline is not None:);// beginif
path();//
set(start_tag, end_tag = STRUCTURE_TAGS[btype]);//
branch(if sline not in tagged_lines and '//' not in result[sline]:);// beginif
path();//
set(result[sline] = f"{result[sline]} //{start_tag}");//
set(tagged_lines.add(sline));//
bend();// endif
branch(if eline not in tagged_lines and '//' not in result[eline]:);// beginif
path();//
set(result[eline] = f"{result[eline]} //{end_tag}");//
set(tagged_lines.add(eline));//
bend();// endif
bend();// endif
lend();// endfor
set(return '\n'.join(result));//
end();// endfunc
input(def process_file(input_file: str, output_file: str = None, skip_format: bool = False) -> None:);// beginfunc
set();//
process();//
generic(global code_file);// ////
generic(code_file = input_file);// ////
branch(try:);// begintry
path();//
set(code = open(input_file).read());//
process(code = filter_ascii( code ));//
set(formatted = code if skip_format else format_code(code));//
set(final = add_structure_comments(formatted));//
branch(if output_file:);// beginif
path();//
set(open(output_file, 'w').write(final));//
set(print(f"Output written to {output_file}"));//
path(else:);//
output(pass);//print(final)
bend();// endif
path(except Exception as e:);//
set(print(f"Error: {e}", file=sys.stderr));//
set(sys.exit(1));//
bend();// endtry
set(return final);//
end();// endfunc
set(############################################ HUMAN ONLY CAN MODIFY BELOW);// ########################################### HUMAN ONLY CAN MODIFY BELOW
set(VFCSEPERATOR = ';//');//
branch();//
path(Begins = [);//// //
set("beginfunc",);//
set("beginmethod",);//
set("beginclass",);//
set("beginif",);//
set("begintry",);//
set("beginswitch",);//
set("beginwith",);//
set("beginwhile",);//
set("beginfor",);//
set(]);//
path(Ends = [);//// //
set("endfunc",);//
set("endmethod",);//
set("endclass",);//
set("endif",);//
set("endtry",);//
set("endswitch",);//
set("endwith",);//
set("endfor",);//
set("endwhile",);//
set(]);//
path(begin_type = {);//// //
set("beginfunc": "input",);//
set("beginmethod": "input",);//
set("beginclass": "input",);//
set("beginif": "branch",);//
set("begintry": "branch",);//
set("beginswitch": "branch",);//
set("beginwith": "branch",);//
set("beginwhile": "loop",);//
set("beginfor": "loop",);//
set(});//
path(end_type = {);//// //
set("endfunc": "end",);//
set("endmethod": "end",);//
set("endclass": "end",);//
set("endif": "bend",);//
set("endtry": "bend",);//
set("endswitch": "bend",);//
set("endwith": "bend",);//
set("endfor": "lend",);//
set("endwhile": "lend",);//
set(});//
path(paths = [);//// //
set("else if",);//
set("else",);//
set("case",);//
set("except",);//
set("finally",);//
set(]);//
path(ends = [);//// //
set("return",);//
set("continue",);//
set("break",);//
set(]);//
path(events = [);//// //
set("#include",);//
set("#define",);//
set("using",);//
set("delay",);//
set(]);//
path(outputs = [);//// //
set("Serial",);//
set("write",);//
set("cout",);//
set(]);//
bend();//
end();//
input(def is_path(line: str) -> bool:);// beginfunc
set(""");//
set(""");//
set(parts = line.strip().split(None, 1));//
branch(if not parts:);// beginif
path();//
set(return False);//
bend();// endif
branch(if parts[0].strip(" :") in paths:);// beginif
path();//
set(return True);//
bend();// endif
end();// endfunc
input(def replace_string_literals(input_string):);// beginfunc
set(result = re.sub(r'(["\'])(.*?)(\1)', '0', input_string));//
set(return result);//
end();// endfunc
input(def split_on_comment(input_string):);// beginfunc
set(match = re.search(r'(?<!")#.*$', temp_str));//
branch(if match:);// beginif
path();//
set(s1 = input_string.strip());//
set(s2 = match.strip());//
path(else:);//
set(s1, s2 = input_string.strip(), "");//
bend();// endif
set(return (s1, s2));//
end();// endfunc
set(INLINECOMMENT = '//');//
input(def split_string(input_string):);// beginfunc
set(temp_str = replace_string_literals(input_string));//
set(parts = temp_str.split( INLINECOMMENT , 1));//
set(s1 = input_string.strip());//
branch(if len(parts) > 1 :);// beginif
path();//
set(s2 = parts[1]);//
set(s1 = s1.replace( INLINECOMMENT + s2, ""));//
path(else:);//
set(s2 = "");//
bend();// endif
set(return (s1, s2));//
end();// endfunc
input(def get_marker( comment ):);// beginfunc
set(parts = comment.strip().split(None, 1));//
branch(if not parts:);// beginif
path();//
set(return "none");//
bend();// endif
set(marker = parts[0]);//
set(return marker);//
end();// endfunc
input(def first_token(code):);// beginfunc
set(tokens = re.split(r'[.;(]+', code.strip()));//
set(return tokens[0] if tokens else "none");//
end();// endfunc
input(def get_VFC_type(code : str, line: str) -> Optional[str]:);// beginfunc
set();//"""
set( );//If the first word of `line` (without any leading INLINECOMMENT ) is in Begins or Ends,
set( );//returns its mapped type; otherwise returns None.
set();//"""
set(token = code.strip().split(None, 1)[0] if len(code) > 1 else "none");//
branch(if first_token(code) in outputs:);//
path();//// beginif//
end(return "output");//// //
path(elif first_token(code) in ends:);// beginif
end(return "end");//// //
path(elif token in events:);//// beginif//
end(return "event");//// //
path(elif is_path(code):);//// beginif//
end(return 'path');//// //
bend();// endif
set(parts = line.strip().split(None, 1));//
branch(if not parts:);// beginif
path();//
set(return "set");//
bend();// endif
set(marker = parts[0]);//
branch(if marker in Begins:);// beginif
path();//
set(return begin_type[marker]);//
bend();// endif
branch(if marker in Ends:);// beginif
path();//
set(return end_type[marker]);//
bend();// endif
set(return "set");//
end();// endfunc
input(def generate_VFC(input_string):);// beginfunc
output(DEBUG = False);//DEBUG = True
set(strings = input_string.split("\n"));//
set(VFC = '');//
set(fix_stack = []);//
generic(types="(void|bool|char|wchar_t|char8_t|char16_t|char32_t|short|int|long|longlong|float|double|longdouble)");// ////
generic(integers="(unsigned +char|unsigned +short|unsigned +int|unsigned +long|unsigned +long)");// ////
set(CLASS_TYPE = r'^\s*(?:enum\s+|struct\s+|interface\s+|abstract\s+)?class\s+\w+\b(?!.*;\s*$)');//CLASS_TYPE = r'^\s*(\w\s)*class\b'
generic(STRUCT_ENUM_TYPE = r'^\s*(typedef\s+)?(struct|enum(?!\s+class))\s+\w+\b(?!.*;\s*$)');//
set(function_type = r'(?:void|int|float|double|char|long|short|bool|inline|static|extern|APIENTRY|\w|\*|&)*\s+\w+\s*\(');//
set(OUTPUT_types = [ "cout" , "read" , "write", "print", "send" , "echo" ]);//
set(method_type = r'\b[\w\s&\*]+::');//method_type = r'\b[\w\s&\*]+::\w+\s*\([^)]*\)\s*\{'
set(prev_type = 'set');//
set(prev_code = '');//
loop(for string in strings:);// beginfor
branch(if not string.strip():);// beginif
path();//
set( );//VFC += f"set(){VFCSEPERATOR}\n"
set(VFC += f"set(){VFCSEPERATOR}\n");//
set(continue);// pass
bend();// endif
set(code, comment = split_string(string));//
set(code = code.strip());//
set(type = get_VFC_type(code, comment));//
set(#--------------------------------------------------------------------------------------------------------- FIX);//#--------------------------------------------------------------------------------------------------------- FIX
set(#--------------------------------------------------------------------------------------------------------- FIX);//#--------------------------------------------------------------------------------------------------------- FIX
set(#--------------------------------------------------------------------------------------------------------- FIX);//#--------------------------------------------------------------------------------------------------------- FIX
branch(if ( re.match( r'^if\b', code ) or re.match( STRUCT_ENUM_TYPE , code ) ) and type != 'branch' :);//
path();//
set(type = "branch");//
branch(if not re.match( r'^if\b.*;$', code ) :);//
path();//
set(fix_stack.append( 'bend' ));//
bend();// endif
set(if DEBUG : comment = ' + br ' + comment);//
path(elif code == '{' and (prev_type == 'path' or 'case' in prev_code ) :);//elif code == '{' :
set(fix_stack.append( 'end' ));//
set(if DEBUG : comment= ' + p{ ' + comment);//
path(elif '#pragma' in code :);//
set(type = 'event');//
set(if DEBUG : comment= ' +ev ' + comment);//
path(elif type == 'path' and 'case' in prev_code :);//collapse paths
set(type = 'set');//collapse paths
set(if DEBUG : comment= ' +cp ' + comment);//
path(elif re.match( r'^try\b', code ) and type == 'set' :);//
set(type = 'branch');//
set(fix_stack.append( 'bend' ));//
set(if DEBUG : comment= ' + try ' + comment);//
path(elif re.match( r".*\bcase\b" , code ) :);//elif re.match( r'} catch (const exception& e) {', code ) and type == 'set' :
set(type = 'path');//
set(if DEBUG : comment= ' + case ' + comment);//
path(elif re.match( r".*\belse\b *if\b" , code ) :);//elif re.match( r'} catch (const exception& e) {', code ) and type == 'set' :
set(type = 'path');//
set(if DEBUG : comment= ' + case ' + comment);//
path(elif re.match( r".*\bcatch\b" , code ) :);//elif re.match( r'} catch (const exception& e) {', code ) and type == 'set' :
set(type = 'path');//
set(if DEBUG : comment= ' + cat ' + comment);//
path(elif re.match( r'^#if', code ) and type == 'set' :);//
set(type = 'branch');//
set(if DEBUG : comment= ' + #if ' + comment);//
path(elif re.match( r'(typedef +)*(enum|struct|union|namespace) *{$', code ) and type == 'set' :);//
set(type = 'branch');//
set(if DEBUG : comment= ' + #enum' + comment);//
set(fix_stack.append( 'bend' ));//
set();//
set();//
set();//
set();//''' --------------------------------------------
path(elif re.match( r'^(namespace)', code ) and type == 'set' :);//////////
set(type = 'branch');//
set(if DEBUG : comment= ' + namespace ' + comment);//
set(fix_stack.append( 'bend' ));//
set();//-------------------------------------------- '''
path(elif re.match( r'^#end', code ) and type == 'set' :);//
set(type = 'bend');//
set(if DEBUG : comment= ' + #eif ' + comment);//
path(elif re.match( r'^return\b', code ) and type == 'set' :);//
set(type = 'end');//
set(if DEBUG : comment= ' + end ' + comment);//
path(elif re.match( r'} while\b', code ) and type == 'set' :);//
set(type = "lend");//
set(if DEBUG : comment= ' + dw ' + comment);//
path(elif re.match( r'^default\b', code ) or re.match( r'^#else', code ) or re.match( r'^#elif', code ) :);//elif re.match( r'^case\b.*\{$', code ) :
set(type = "path");//
set( );//fix_stack.append( 'end' )
set(if DEBUG : comment= ' + def ' + comment);//
path(elif re.match( r'\} else\b', code ) and type != 'path' :);//
set(type = "path");//
set(if DEBUG : comment= ' + pa ' + comment);//
path(elif ( re.match( r'^while\b', code ) or re.match( r'^for\b', code ) or re.match( r'^do\b', code ) ) and type != 'loop' :);//
set(type = "loop");//
set(fix_stack.append( 'lend' ));//
set(if DEBUG : comment= ' + lo ' + comment);//
path(elif re.match( r"^inline\b.+\(.*\) *\{.*\}$", code ) :);//
output(if DEBUG : comment= ' + inline function ' + comment);//comment= ' + template function ' + comment
output(type = 'input');//
set( );//fix_stack.append( 'end' )
path(elif re.match( r"^inline\b.+\(.*\) *\{$", code ) :);//
output(if DEBUG : comment= ' + inline function ' + comment);//comment= ' + template function ' + comment
output(type = 'input');//
set(fix_stack.append( 'end' ));//
path(elif re.match( fr"^\w.+<.*>.*::.+\(.*\)", code ) :);//
output(if DEBUG : comment= ' + template function ' + comment);//comment= ' + template function ' + comment
output(type = 'input');//
set(fix_stack.append( 'end' ));//
path(elif re.match( r"^(template|typedef)\b" , code ) :);//
set(if DEBUG : comment= ' + template ' + comment);//comment= ' + template ' + comment
output(type = 'event');//
set( );//fix_stack.append( 'end' )
path(elif re.match(function_type, code ) or re.match(method_type, code ) or re.match( r'\w*\s+APIENTRY' , code ) or re.match( CLASS_TYPE, code ):);//
set(type = 'input');//
branch(if not '}' in code :);//
path();//
branch(if not r';' in code :);//
path();//
set(fix_stack.append( 'end' ));//
output(if DEBUG : comment= ' + in ' + comment);// comment= ' + in ' + comment
path(else:);//
set(type = 'process');//
set(if DEBUG : comment= ' + pr in ' + comment);//
bend( );//
path(else:);//
branch(if re.match( r'.*;$', code ) :);//
path( );//
set(type = 'process');//
path(else:);//
output(pass);//
bend( );//
set(if DEBUG : comment= ' + sl in ' + comment);//
bend( );//
path(elif type == 'set' and any(word in code for word in OUTPUT_types):);//// //
output( type = 'output');// pass
path(elif re.match( r'^}', code ) and type == 'set' :);//elif re.match( r'^}$', code ) and type == 'set' :
branch(#try-catch-exception);//
path(try:);//
set(type = fix_stack.pop());//
set(if DEBUG : comment= ' + pop ' + comment);//
path(except :);//
set(type = 'set');// type = 'bend'
set(if DEBUG : comment= ' + def pop ' + comment);//
bend( );//
bend( );//
set(prev_type = type);//
set(prev_code = code);//
set(#--------------------------------------------------------------------------------------------------- FIX);//#--------------------------------------------------------------------------------------------------- FIX
set(#--------------------------------------------------------------------------------------------------- FIX);//#--------------------------------------------------------------------------------------------------- FIX
set(#--------------------------------------------------------------------------------------------------- FIX);//#--------------------------------------------------------------------------------------------------- FIX
set(marker = get_marker( comment ));//
branch(if marker == "endclass" :);// beginif
path();//
set(VFC += f"bend(){VFCSEPERATOR}\n");//
bend();// endif
branch(if type == "input" :);//
path();//
output( pass);////VFC += f"end(){VFCSEPERATOR}\n"//
bend();// endif
branch(if re.match( CLASS_TYPE , code ):);//// if re.match( r'\s*class\b' , code ):////
path();//
set(VFC += f"end(){VFCSEPERATOR}\n");//
bend();// endif
branch(if re.match( r'\};' , code ):);//
path();//
set(VFC += f"bend(){VFCSEPERATOR}\n");// VFC += f"bend(){VFCSEPERATOR}<--- end class\n"
set(type = 'end');//
bend();// endif
branch(if re.match( r'^(public|protected|private):' , code ) and type=='set':);//
path();//
set(type = 'path');//
bend();// endif
branch(if DEBUG :);//
path( );//
output(pass);//VFC += f'{type}({code}){VFCSEPERATOR} {comment}\n'
path(else:);//
branch(token_list = [);//
path();//
generic("beginfor", "endfor",);// ////
generic("beginwhile", "endwhile",);// ////
generic("beginswitch", "endswitch",);// ////
generic("beginfunc", "endfunc",);// ////
generic("beginclass", "endclass",);// ////
generic("beginmethod", "endmethod" ,);// ////
path();//
generic("begininput", "endinput",);// ////
generic("beginif", "endif",);// ////
generic("begintry", "endtry",);// ////
generic("beginwith", "endwith",);// ////
generic("beginbranch", "endbranch",);// ////
generic("beginloop" , "endloop");// ////
bend(]);//// //////
set(pattern = r'^(' + '|'.join(re.escape(token) for token in token_list) + r')\s*');// ////
generic(comment = re.sub(pattern, '', comment.strip() ));// ////
bend( );//
branch(if INLINECOMMENT in code :);//if INLINECOMMENT in code and comment in code :
path();//
output(VFC += f'{type}({code}){VFCSEPERATOR}\n');//// //
path(else:);//
output(VFC += f'{type}({code}){VFCSEPERATOR} {comment}\n');//// //
bend( );//
branch(if re.match( CLASS_TYPE , code ):);//// if re.match( r'\s*class\b' , code ):////
path();//
set( VFC += f"branch(){VFCSEPERATOR}\n");//VFC += f"branch(){VFCSEPERATOR}<---class\n"
set(VFC += f"path(){VFCSEPERATOR}\n");//
set( );//VFC += f"path(){VFCSEPERATOR} --- \n"
bend();// endif
branch(if type == "branch":);// beginif
path();//
set(VFC += f"path(){VFCSEPERATOR}\n");//
bend();// endif
branch(if type == "branch" and re.match( r'^if\b.*;$', code ) :);//
path();//
set(VFC += f"bend(){VFCSEPERATOR}\n");//
bend();// endif
branch(if marker == "beginclass" :);// beginif
path();//
set(VFC += f"branch(){VFCSEPERATOR}\n");//
set(VFC += f"path(){VFCSEPERATOR}\n");//
set(VFC += f"path(){VFCSEPERATOR}\n");//
bend();// endif
lend();// endfor
set(VFC += f"set(){VFCSEPERATOR}\n");//
set(VFC += f"set(){VFCSEPERATOR}\n");//
set(VFC += f"set(){VFCSEPERATOR}\n");//
set(return VFC);//
end();// endfunc
input(def footer( exportname ):);// beginfunc
set(ENVTOK = 'INSECTA');//
set(foot = f';{ENVTOK} EMBEDDED SESSION INFORMATION\n');//
set(foot+='; 255 16777215 65280 16777088 16711680 32896 8421504 0 255 255 16777215 4227327 2960640\n');//
set(foot+= f'; { os.path.basename(exportname) } // \n');//
set(foot+='; notepad.exe\n');//
set(foot+=f';{ENVTOK} EMBEDDED ALTSESSION INFORMATION\n');//
set(foot+='; 880 168 766 1516 0 110 392 31 C++.key 0\n');//
set(return foot);//
end();// endfunc
input(def __fix_VFC_paths( input_string ):);// beginfunc
set(strings = input_string.split("\n"));//
set(VFC = '');//
set(skip_next = 0);//
loop(for i in range( len(strings) ) :);// beginfor
set(code = strings[i]);//
branch(if code.startswith( "branch") :);// beginif
path();//
set(code2 = strings[i+1].strip());//
set(code3 = strings[i+2].strip());//
branch(if code2.startswith("path()") and code3.startswith("set({)"):);// beginif
path();//
set(VFC +=code + "\n");//
set(VFC += "path({)" + VFCSEPERATOR + '\n');//
set(skip_next = 3);//
bend();// endif
bend();// endif
branch(if skip_next > 0:);// beginif
path();//
set(skip_next -= 1);//
set(continue);//
bend();// endif
set(VFC +=code + "\n");//
lend();// endfor
set(return VFC);//
end();// endfunc
input(def fix_VFC_paths( input_string ):);// beginfunc
set(strings = input_string.split("\n"));//
set(VFC = '');//
set(skip_next = 0);//
loop(for i in range( len(strings) ) :);// beginfor
set(code = strings[i]);//
branch(if code.startswith( "branch") :);// beginif
path();//
set(code2 = strings[i+1].strip());//
set(code3 = strings[i+2].strip());//
branch(if code2.startswith("path()") and code3.startswith("set({)"):);// beginif
path();//
set(VFC +=code + "\n");//
set(VFC += "path({)" + VFCSEPERATOR + '\n');//
set(skip_next = 3);//
bend();// endif
bend();// endif
branch(if skip_next > 0:);// beginif
path();//
set(skip_next -= 1);//
set(continue);//
bend();// endif
set(VFC +=code + "\n");//
lend();// endfor
set(return VFC);//
end();// endfunc
input(def main():);// beginfunc
set(global modified_code);//
set(p = argparse.ArgumentParser());//
set(p.add_argument('input_file'));//
set(p.add_argument('-o', '--output'));//
set(p.add_argument('--skip-format', action='store_true'));//
set(args = p.parse_args());//
output(print( "INPUT: ", args.input_file ));//// //
set(modified_code = process_file(args.input_file, args.output, args.skip_format));//
set(VFC = generate_VFC(modified_code));//
set(VFC = fix_VFC_paths( VFC ));//
output();//print( modified_code )
branch(with open(args.input_file+'.vfc', 'w') as VFC_output:);// beginwith
path();//
set(VFC_output.write(VFC));//
set(VFC_output.write( footer( args.input_file ) ));//
bend();// endwith
end();// endfunc
branch(if __name__ == '__main__':);// beginif
path();//
set(main());//
bend();// endif
set();// Export Date: 12:09:11 PM - 23:Apr:2025.
;INSECTA EMBEDDED SESSION INFORMATION
; 255 16777215 65280 16777088 16711680 13158600 13158600 0 255 255 9895835 6946660 6172416
; cppParser.py # .
; notepad.exe
;INSECTA EMBEDDED ALTSESSION INFORMATION
; 327 395 3251 1399 458 118 1054 4294954240 python.key 0