initial commit

This commit is contained in:
Bacruru Sakaguchi
2025-09-12 17:10:13 +07:00
commit 9e5e214944
57 changed files with 1538 additions and 0 deletions

42
shell/Parser.py Normal file
View File

@@ -0,0 +1,42 @@
class Parser:
def __init__(self):
self.in_quotes = False
def parse(self, command: str) -> list[str]:
tokens = []
current_token = []
for char in command:
if char == '"':
if self.in_quotes:
# Завершаем токен внутри кавычек
tokens.append(''.join(current_token))
current_token = []
self.in_quotes = False
else:
# Начинаем новый токен в кавычках
if current_token:
# Если до кавычек были символы, добавляем их как отдельный токен
tokens.append(''.join(current_token))
current_token = []
self.in_quotes = True
elif char == ' ':
if self.in_quotes:
# Внутри кавычек пробелы добавляем к текущему токену
current_token.append(char)
else:
if current_token:
# Завершаем текущий токен, если он есть
tokens.append(''.join(current_token))
current_token = []
else:
# Любой символ, кроме кавычек и пробела
current_token.append(char)
if current_token:
tokens.append(''.join(current_token))
return tokens