-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleScript.py
More file actions
100 lines (83 loc) · 2.38 KB
/
BubbleScript.py
File metadata and controls
100 lines (83 loc) · 2.38 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
import re
import time
import random
variables = {"autobubble": "on"}
custom_functions = {} # <-- Prevents the language from crashing
def auto_bubble(text):
print(f"[{'='*10} Bubble {'='*10}]")
print(f" > {text}")
print(f"[{'='*28}]")
def cmd_print(arg):
val = variables.get(arg, arg)
if variables.get("autobubble") == "on":
auto_bubble(val)
else:
print(val)
def cmd_bubble(arg):
clean_text= arg.strip('"')
auto_bubble(clean_text)
def cmd_wait(arg):
try:
time.sleep(float(arg))
except ValueError:
print(f"Error: '{arg}' is not a valid number for wait")
def cmd_define(arg):
try:
name, action = arg.split(" ", 1)
custom_functions[name.lower()] = [action]
print(f"Function '{name}' defined.")
except ValueError:
print("Error: 'Define' command requires a name and an action. (e.g., def hi bubble \"Hello\")")
COMMANDS = {
"print": cmd_print,
"write": cmd_print,
"bubble": cmd_bubble,
"wait": cmd_wait,
"define": cmd_define,
"def": cmd_define
}
def run_line(line):
"""Parses and executes a single line of BubbleScript."""
line = line.strip()
if not line or line.startswith("#"):
return
if "=" in line and "input" not in line:
name, val = line.split("=", 1)
variables[name.strip()] = val.strip().strip('"')
return
parts = line.split(" ", 1)
command_name = parts[0].lower()
arg = parts[1].strip() if len(parts) > 1 else ""
if command_name in custom_functions:
for sub_line in custom_functions[command_name]:
run_line(sub_line)
return
if command_name in COMMANDS:
COMMANDS[command_name](arg)
else:
print(f"Unknown command: {command_name}")
def run_language(code):
for line in code.split('\n'):
run_line(line)
bubble_script = """
# Configuration
app_name = BubbleScript_Core
version = v1.0
# Execution
bubble "Initializing BubbleScript..."
wait 0.5
print app_name
print version
bubble "System Ready."
"""
def start_bubblescript():
run_language(bubble_script)
print("\n[ BubbleScript Shell - Type 'exit' to quit ]")
while True:
user_input = input("BubbleScript> ")
if user_input.lower() == "exit":
print("Shutting down...")
break
run_line(user_input)
if __name__ == "__main__":
start_bubblescript()