typecoders/
lib.rs

1// MIT License
2//
3// Copyright (c) 2021 Ferhat Geçdoğan All Rights Reserved.
4// Distributed under the terms of the MIT License.
5//
6// typecoders - An interpreter that introduces you.
7//
8// An example code:
9//  $%#/*++;%##*++;#/++++;#/*++;#/*+++;-%##*;$@/*+;+++;#/;@
10//
11// Output:
12//  Languages:
13//      FlaScript
14//      Gretea
15//      C
16//      C++
17//      C++/CLI
18//      Python
19//
20//  Branches:
21//      Computer Science
22//      Programming languages
23//      Programming languages and compilers
24//
25// github.com/ferhatgec/typecoders
26// github.com/ferhatgec/typecode
27// github.com/ferhatgec/typecode.py
28
29pub enum Tokens {
30    Lang,
31    Branch,
32    OS,
33
34    Push,
35    Push5,
36    Push10,
37    Push50,
38    Push100,
39    Print,
40    Undef
41}
42
43pub struct TypeCode {
44    // taken from https://dzone.com/articles/big-list-256-programming
45    languages: Vec<String>,
46
47    // taken from https://www.quora.com/What-are-the-branches-of-computer-science
48    branches : Vec<String>,
49
50    osystems : Vec<String>,
51    is_lang  : bool,
52    is_branch: bool,
53    is_os    : bool,
54
55    stack    : u64,
56
57    pub info_languages  : Vec<String>,
58    pub info_branches   : Vec<String>,
59    pub info_osystems   : Vec<String>
60}
61
62impl Tokens {
63    fn val(ch: char) -> Self {
64        use self::Tokens::{*};
65
66        match ch {
67            '$' => { Lang },
68            '@' => { Branch },
69            '?' => { OS },
70
71            '+' => { Push },
72            '*' => { Push5 },
73            '/' => { Push10 },
74            '%' => { Push50 },
75            '-' => { Push100 },
76
77            ';' => { Print },
78            _   => { unreachable!("Undefined character: '{}'", ch) }
79        }
80    }
81}
82
83impl Default for TypeCode {
84    fn default() -> Self {
85        TypeCode {
86            languages     : vec![
87                "4th Dimension/4D",
88                "ABAP",
89                "ABC",
90                "ActionScript",
91                "Ada",
92                "Agilent VEE",
93                "Algol",
94                "Alice",
95                "Angelscript",
96                "Apex",
97                "APL",
98                "AppleScript",
99                "Arc",
100                "Arduino",
101                "ASP",
102                "AspectJ",
103                "Assembly",
104                "ATLAS",
105                "Augeas",
106                "AutoHotkey",
107                "AutoIt",
108                "AutoLISP",
109                "Automator",
110                "Avenue",
111                "Awk",
112                "Bash",
113                "(Visual) Basic",
114                "bc",
115                "BCPL",
116                "BETA",
117                "BlitzMax",
118                "Boo",
119                "Bourne Shell",
120                "Bro",
121                "C",
122                "C Shell",
123                "C#",
124                "C++",
125                "C++/CLI",
126                "C-Omega",
127                "Caml",
128                "Ceylon",
129                "CFML",
130                "cg",
131                "Ch",
132                "CHILL",
133                "CIL",
134                "CL (OS/400)",
135                "Clarion",
136                "Clean",
137                "Clipper",
138                "Clojure",
139                "CLU",
140                "COBOL",
141                "Cobra",
142                "CoffeeScript",
143                "ColdFusion",
144                "COMAL",
145                "Common Lisp",
146                "Coq",
147                "cT",
148                "Curl",
149                "D",
150                "Dart",
151                "DCL",
152                "DCPU-16 ASM",
153                "Delphi/Object Pascal",
154                "DiBOL",
155                "Dylan",
156                "E",
157                "eC",
158                "Ecl",
159                "ECMAScript",
160                "EGL",
161                "Eiffel",
162                "Elixir",
163                "Emacs Lisp",
164                "Erlang",
165                "Etoys",
166                "Euphoria",
167                "EXEC",
168                "F#",
169                "Factor",
170                "Falcon",
171                "Fancy",
172                "Fantom",
173                "Felix",
174                "FlaScript",
175                "Forth",
176                "Fortran",
177                "Fortress",
178                "(Visual) FoxPro",
179                "Gambas",
180                "GNU Octave",
181                "Go",
182                "Google AppsScript",
183                "Gosu",
184                "Gretea",
185                "Groovy",
186                "Haskell",
187                "haXe",
188                "Heron",
189                "HPL",
190                "HyperTalk",
191                "Icon",
192                "IDL",
193                "Inform",
194                "Informix-4GL",
195                "INTERCAL",
196                "Io",
197                "Ioke",
198                "J",
199                "J#",
200                "JADE",
201                "Java",
202                "Java FX Script",
203                "JavaScript",
204                "JScript",
205                "JScript.NET",
206                "Julia",
207                "Korn Shell",
208                "Kotlin",
209                "LabVIEW",
210                "Ladder Logic",
211                "Lasso",
212                "Limbo",
213                "Lingo",
214                "Lisp",
215                "Logo",
216                "Logtalk",
217                "LotusScript",
218                "LPC",
219                "Lua",
220                "Lustre",
221                "M4",
222                "MAD",
223                "Magic",
224                "Magik",
225                "Malbolge",
226                "MANTIS",
227                "Maple",
228                "Mathematica",
229                "MATLAB",
230                "Max/MSP",
231                "MAXScript",
232                "MEL",
233                "Mercury",
234                "Mirah",
235                "Miva",
236                "ML",
237                "Monkey",
238                "Modula-2",
239                "Modula-3",
240                "MOO",
241                "Moto",
242                "MS-DOS Batch",
243                "MUMPS",
244                "NATURAL",
245                "Nemerle",
246                "Nim",
247                "NQC",
248                "NSIS",
249                "Nu",
250                "NXT-G",
251                "Oberon",
252                "Object Rexx",
253                "Objective-C",
254                "Objective-J",
255                "OCaml",
256                "Occam",
257                "ooc",
258                "Opa",
259                "OpenCL",
260                "OpenEdge ABL",
261                "OPL",
262                "Oz",
263                "Paradox",
264                "Parrot",
265                "Pascal",
266                "Perl",
267                "PHP",
268                "Pike",
269                "PILOT",
270                "PL/I",
271                "PL/SQL",
272                "Pliant",
273                "PostScript",
274                "POV-Ray",
275                "PowerBasic",
276                "PowerScript",
277                "PowerShell",
278                "Processing",
279                "Prolog",
280                "Puppet",
281                "Pure Data",
282                "Python",
283                "Q",
284                "R",
285                "Racket",
286                "REALBasic",
287                "REBOL",
288                "Revolution",
289                "REXX",
290                "RPG (OS/400)",
291                "Ruby",
292                "Rust",
293                "S",
294                "S-PLUS",
295                "SAS",
296                "Sather",
297                "Scala",
298                "Scheme",
299                "Scilab",
300                "Scratch",
301                "sed",
302                "Seed7",
303                "Self",
304                "Shell",
305                "SIGNAL",
306                "Simula",
307                "Simulink",
308                "Slate",
309                "Smalltalk",
310                "Smarty",
311                "SPARK",
312                "SPSS",
313                "SQR",
314                "Squeak",
315                "Squirrel",
316                "Standard ML",
317                "Suneido",
318                "SuperCollider",
319                "TACL",
320                "Tcl",
321                "Tex",
322                "thinBasic",
323                "TOM",
324                "Transact-SQL",
325                "Turing",
326                "TypeScript",
327                "Vala/Genie",
328                "VBScript",
329                "Verilog",
330                "VHDL",
331                "VimL",
332                "Visual Basic .NET",
333                "WebDNA",
334                "Whitespace",
335                "X10",
336                "xBase",
337                "XBase++",
338                "Xen",
339                "XPL",
340                "XSLT",
341                "XQuery",
342                "yacc",
343                "Yorick",
344                "Z shell"
345            ].iter().map(|&s| s.into()).collect(),
346            branches      : vec![
347                "Human-computer interaction",
348                "Data science",
349                "Natural language processing",
350                "Programming languages",
351                "Software engineering",
352                "Architecture and organization",
353                "Cyber security",
354                "Information management",
355                "Networking and communication",
356                "Computer graphics",
357                "Platform-based development",
358                "Graphics and visual computing",
359                "Algorithms and complexity",
360                "Parallel and distributed computing",
361                "Intelligent systems",
362                "Security and information assurance",
363                "Computer Science",
364                "Computer Engineering",
365                "Information Systems",
366                "New Media",
367                "Information Technology (IT)",
368                "Information Science",
369                "Mathematical foundations.",
370                "Algorithms and data structures.",
371                "Artificial intelligence.",
372                "Communication and security.",
373                "Computer architecture.",
374                "Computer graphics.",
375                "Concurrent, parallel, and distributed systems.",
376                "Databases.",
377                "Programming languages and compilers",
378                "Scientific computing",
379                "Software engineering",
380                "Theory of computing"
381            ].iter().map(|&s| s.into()).collect(),
382            osystems      : vec![
383                "Arthur",
384                "RISC OS",
385                "Fire OS",
386                "Amiga OS",
387                "AMSDOS",
388                "macOS",
389                "iOS",
390                "iPadOS",
391                "tvOS",
392                "bridgeOS",
393                "Atari DOS",
394                "BeOS",
395                "Unix",
396                "BESYS",
397                "Plan 9",
398                "Inferno",
399                "Android",
400                "Harmony OS",
401                "LiteOS",
402                "iRMX",
403                "PC DOS",
404                "OS/2",
405                "Remix OS",
406                "KaiOS",
407                "LynxOS",
408                "Xenix",
409                "MS-DOS",
410                "DOS/V",
411                "Windows",
412                    "Windows 1.0",
413                    "Windows 2.0",
414                    "Windows 3.0",
415                    "Windows 3.1x",
416                    "Windows 3.2",
417                    "Windows 95",
418                    "Windows 98",
419                    "Windows ME",
420
421                    "Windows NT",
422                        "Windows NT 3.1",
423                        "Windows NT 4.0",
424                        "Windows 2000",
425                        "Windows XP",
426                        "Windows Server 2003",
427                        "Windows Vista",
428                        "Windows Phone 7",
429                        "Windows 8",
430                        "Windows RT",
431                        "Windows Phone 8",
432                        "Windows 8.1",
433                        "Windows Phone 8.1",
434                        "Windows 10",
435                        "Windows 10 Mobile",
436                        "Windows 11",
437                "ES",
438                "NeXTSTEP",
439                "NetWare",
440                "UnixWare",
441                "Bada",
442                "Tizen",
443                "One UI",
444                "Sun OS",
445                "BSD",
446                    "FreeBSD",
447                        "DragonFlyBSD",
448                        "MidnightBSD",
449                        "GhostBSD",
450                        "TrueOS",
451                        "prismBSD",
452                    "NetBSD",
453                        "OpenBSD",
454                            "Bitrig",
455                    "Darwin",
456
457                "GNU Hurd",
458                "Linux",
459                    "RHEL",
460                        "Rocky Linux",
461                        "Red Hat Linux",
462                        "CentOS",
463                        "Fedora",
464                        "openSUSE",
465                            "SUSE Linux Enterprise Desktop",
466                            "SUSE Linux Enterprise Server",
467                            "SUSE Studio",
468                            "GeckoLinux",
469                        "Mandrake Linux",
470                    "Debian",
471                        "MX Linux",
472                        "Deepin",
473                        "Devuan",
474                        "Kali Linux",
475                        "Pure OS",
476                        "Ubuntu",
477                            "Kubuntu",
478                            "Lubuntu",
479                            "Ubuntu Budgie",
480                            "Ubuntu Kylin",
481                            "Ubuntu Mate",
482                            "Xubuntu",
483
484                            "Bodhi Linux",
485                            "elementary OS",
486                            "Linux Mint",
487                            "Zorin OS",
488                            "Pop!_OS",
489
490                    "Arch Linux",
491                        "Manjaro",
492                        "Artix Linux",
493                        "EndeavourOS",
494                        "SteamOS",
495                    "Gentoo",
496                        "Chrome OS",
497                        "Chromium OS",
498                    "NixOS",
499                    "Void Linux",
500                    "GuixSD",
501                    "Solus",
502                "Redox",
503                "illumos",
504                    "OpenIndiana",
505
506                "FreeDOS",
507                "Genode",
508                "FFusionOS",
509                "Ghost OS",
510                "Haiku",
511                "ReactOS",
512                "TempleOS",
513                "Serenity",
514                "Visopsys"
515            ].iter().map(|&s| s.into()).collect(),
516            is_lang       : false,
517            is_branch     : false,
518            is_os         : false,
519            stack         : 0,
520            info_languages: vec![],
521            info_branches : vec![],
522            info_osystems : vec![]
523        }
524    }
525}
526
527impl TypeCode {
528    pub fn init(&mut self, file_data: String) {
529        use Tokens::{*};
530
531        for ch in file_data.chars() {
532            match Tokens::val(ch) {
533                Lang => {
534                    self.is_lang = !self.is_lang;
535                },
536                Branch => {
537                    self.is_branch = !self.is_branch;
538                },
539                OS => {
540                    self.is_os = !self.is_os;
541                },
542
543                Push => {
544                    self.stack += 1;
545                },
546                Push5 => {
547                    self.stack += 5;
548                },
549                Push10 => {
550                    self.stack += 10;
551                },
552                Push50 => {
553                    self.stack += 50;
554                },
555                Push100 => {
556                    self.stack += 100;
557                },
558
559                Print => {
560                    if self.is_branch && self.stack < self.branches.len() as u64 {
561                        self.info_branches.push(self.branches[self.stack as usize].clone());
562                    } else if self.is_lang && self.stack < self.languages.len() as u64 {
563                       self.info_languages.push(self.languages[self.stack as usize].clone());
564                    } else if self.is_os && self.stack < self.osystems.len() as u64 {
565                        self.info_osystems.push(self.osystems[self.stack as usize].clone());
566                    }
567
568                    self.stack = 0;
569                },
570                _ => {}
571            }
572        }
573    }
574}
575
576#[cfg(test)]
577mod tests {
578    use crate::TypeCode;
579    #[test]
580    fn hmm() {
581        let mut init = TypeCode::default();
582        let val = String::from("$%///*++;%////*++;///++++;///*++;///*+++;-%////*;$@/*+;+++;///;@?-++;%/*++;?");
583        init.init(val);
584
585
586        println!("\x1b[0;93mLanguages\x1b[0m:");
587
588        for lang in init.info_languages {
589            println!("  {}", lang);
590        } println!("\n\x1b[0;92mBranches\x1b[0m:");
591
592        for branch in init.info_branches {
593            println!("  {}", branch);
594        } println!("\n\x1b[0;92mOperating Systems\x1b[0m:");
595
596        for os in init.info_osystems {
597            println!("  {}", os);
598        }
599    }
600}