Skip to content

Commit

Permalink
Remove useless whitespaces at the end of some lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-develop committed Sep 6, 2024
1 parent 2842fe8 commit 7e11a65
Show file tree
Hide file tree
Showing 28 changed files with 166 additions and 166 deletions.
6 changes: 3 additions & 3 deletions examples/calculator.noug
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ while:main_loop True then
print_in_red(error_msg)
continue
end

# tokenize
var tokens = []
var floating_point = 0
Expand Down Expand Up @@ -280,7 +280,7 @@ while:main_loop True then

if debug.is_debug_enabled then \
print(tokens)

# parse
var i = -1
var last_token = ""
Expand Down Expand Up @@ -415,7 +415,7 @@ while:main_loop True then
end
var last_token = token
end

if len(stack) >= 1 then
if verbose then print(stack(-1))
var answer = stack(-1)
Expand Down
16 changes: 8 additions & 8 deletions lib_/_conffiles_.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def copy(self):
"""Return a copy of self"""
copy = Conffiles(self.name)
return self.set_context_and_pos_to_a_copy(copy)

def is_eq(self, other: Value):
return isinstance(other, Conffiles) and self.name == other.name

# functions
def execute__conffiles_access_data(self, context: Context):
"""Returns the asked data. RTFileNotFoundError if file not found, or None if not_found_ok=True"""
Expand All @@ -56,7 +56,7 @@ def execute__conffiles_access_data(self, context: Context):
file_name.pos_start, file_name.pos_end, "first", "_conffiles.access_data", "str", file_name,
context, origin_file="lib_._conffiles_.Conffiles.execute__conffiles_access_data"
))

if file_name.value == "please give me a syntax warning":
eval("1 is 1") # easter egg lol

Expand All @@ -67,7 +67,7 @@ def execute__conffiles_access_data(self, context: Context):
not_found_ok.pos_start, not_found_ok.pos_end, "second", "_conffiles.access_data", "int", not_found_ok,
context, origin_file="lib_._conffiles_.Conffiles.execute__conffiles_access_data"
))

data = src.conffiles.access_data(file_name.value)
if data is None:
if not_found_ok.is_true():
Expand All @@ -76,7 +76,7 @@ def execute__conffiles_access_data(self, context: Context):
file_name.pos_start, file_name.pos_end, f"config file not found: {file_name}.", context,
origin_file="lib_._conffiles_.Conffiles.execute__conffiles_access_data", custom=True
))

return RTResult().success(String(data, self.pos_start, self.pos_end).set_context(context))

functions["access_data"] = {
Expand All @@ -101,7 +101,7 @@ def execute__conffiles_write_data(self, context: Context):
file_name.pos_start, file_name.pos_end, "first", "_conffiles.write_data", "str", file_name,
context, origin_file="lib_._conffiles_.Conffiles.execute__conffiles_write_data"
))

data_to_write = nice_str_from_idk(data).value

if name_reserved_ok is None:
Expand All @@ -113,7 +113,7 @@ def execute__conffiles_write_data(self, context: Context):
name_reserved_ok.pos_start, name_reserved_ok.pos_end, "second", "_conffiles.write_data", "int", name_reserved_ok,
context, origin_file="lib_._conffiles_.Conffiles.execute__conffiles_write_data"
))

errmsg = src.conffiles.write_data(file_name.value, data_to_write, silent=True, return_error_messages=True)

if errmsg is not None:
Expand All @@ -132,7 +132,7 @@ def execute__conffiles_write_data(self, context: Context):
errmsg, context,
origin_file="lib_._conffiles_.Conffiles.execute__conffiles_write_data"
))

return RTResult().success(NoneValue(self.pos_start, self.pos_end, False).set_context(context))

functions["write_data"] = {
Expand Down
12 changes: 6 additions & 6 deletions lib_/lorem.noug
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def ipsum(paragraphs)
var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
var last_paragraph_first_sentence = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
var last_sentence = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."

for i = 0 to paragraphs then
var paragraph = ""
var sentence = ""

var sentences = random.randint(5, 10)
for j = 0 to sentences then
if j == 0 and i != 0 then
Expand All @@ -40,17 +40,17 @@ def ipsum(paragraphs)
do var sentence = random.choice(lorem_sentences)\
then loop while sentence == last_sentence
end

var last_sentence = sentence
if i != 0 and j == 0 then var last_paragraph_first_sentence = sentence

var paragraph += sentence + if j != sentences-1 then ' ' else ''
end

var text += paragraph
if i != paragraphs-1 then var text += "\n\n"
end

return text
end

Expand Down
2 changes: 1 addition & 1 deletion lib_/math_.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def execute_math_factorial(self, exec_context: Context):
value.pos_start, value.pos_end, "first", "math.factorial", "non-negative integer (int)", value,
exec_context, "lib_.math_.Math.execute_math_factorial"
))

if value.value < 0:
return RTResult().failure(RunTimeError(
value.pos_start, value.pos_end,
Expand Down
10 changes: 5 additions & 5 deletions lib_/random_.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def copy(self):
"""Return a copy of self"""
copy = Random(self.name)
return self.set_context_and_pos_to_a_copy(copy)

def is_eq(self, other: Value):
return isinstance(other, Random) and self.name == other.name

Expand Down Expand Up @@ -138,13 +138,13 @@ def execute_random_shuffle(self, exec_ctx: Context):
list_.pos_start, list_.pos_end, "first", "random.shuffle", "list", list_,
exec_ctx, "lib_.random_.Random.execute_random_shuffle"
))

py_list = list_.elements.copy()
random.shuffle(py_list)
list_.elements = py_list

return RTResult().success(list_)

functions["shuffle"] = {
"function": execute_random_shuffle,
"param_names": ["list_"],
Expand All @@ -153,7 +153,7 @@ def execute_random_shuffle(self, exec_ctx: Context):
"run_noug_dir": False,
"noug_dir": False
}

def execute_random_seed(self, exec_ctx: Context):
"""Set the seed to generate pseudo-random numbers."""
# Params:
Expand All @@ -168,7 +168,7 @@ def execute_random_seed(self, exec_ctx: Context):
))
random.seed(seed.value)
return RTResult().success(NoneValue(self.pos_start, self.pos_end, False))

functions["seed"] = {
"function": execute_random_seed,
"param_names": ["seed"],
Expand Down
4 changes: 2 additions & 2 deletions lib_/statistics_.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def copy(self):
"""Return a copy of self"""
copy = Statistics(self.name)
return self.set_context_and_pos_to_a_copy(copy)

def is_eq(self, other: Value):
return isinstance(other, Statistics) and self.name == other.name

Expand Down Expand Up @@ -460,7 +460,7 @@ def execute_statistics_quantiles(self, exec_ctx: Context):
"run_noug_dir": False,
"noug_dir": False
}

def execute_statistics_scope(self, exec_ctx: Context):
"""Returns the scope of a list, i.e. the difference between the max and the min value."""
# Params:
Expand Down
2 changes: 1 addition & 1 deletion lib_/time_.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def copy(self):
"""Return a copy of self"""
copy = Time(self.name)
return self.set_context_and_pos_to_a_copy(copy)

def is_eq(self, other: Value):
return isinstance(other, Time) and self.name == other.name

Expand Down
4 changes: 2 additions & 2 deletions lib_/unicodedata_.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def copy(self):
"""Return a copy of self"""
copy = UnicodeData(self.name)
return self.set_context_and_pos_to_a_copy(copy)

def is_eq(self, other: Value):
return isinstance(other, UnicodeData) and self.name == other.name

Expand Down Expand Up @@ -311,7 +311,7 @@ def execute_unicodedata_normalize(self, exec_ctx: Context):
form.value, uni_str.value # type: ignore
), self.pos_start, self.pos_end
)
)
)

functions["normalize"] = {
"function": execute_unicodedata_normalize,
Expand Down
10 changes: 5 additions & 5 deletions lib_/webbrowser_.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def copy(self):
"""Return a copy of self"""
copy = WebBrowser(self.name)
return self.set_context_and_pos_to_a_copy(copy)

def is_eq(self, other: Value):
return isinstance(other, WebBrowser) and self.name == other.name

# functions
def open(self, context: Context):
"""
Expand All @@ -70,7 +70,7 @@ def open(self, context: Context):
url.pos_start, url.pos_end, "first", "webbrowser.open", "str", url,
context, "lib_.webbrowser_.WebBrowser.open"
))

if new is None:
new = Number(0, url.pos_end, self.pos_end).set_context(context)
if not (isinstance(new, Number) and isinstance(new.value, int)):
Expand All @@ -83,10 +83,10 @@ def open(self, context: Context):
new.pos_start, new.pos_end, "the 'new' argument should either be 0 (same window), 1 (new window), or 2 (new tab)",
context, origin_file="lib_.webbrowser_.WebBrowser.open"
))

if autoraise is None:
autoraise = Number(True, self.pos_start, self.pos_end).set_context(context)

try:
webbrowser.open(url.value, new.value, autoraise.is_true())
except webbrowser.Error as e:
Expand Down
12 changes: 6 additions & 6 deletions src/conffiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def _write_readme(readme_file: str, version_guide_file: str, version: str, versi
with open(readme_file, "w+", encoding="UTF-8") as readme:
if readme.readlines() != README_TEXT:
readme.writelines(README_TEXT)


if os.path.isfile(version_guide_file):
with open(version_guide_file, "r+", encoding="UTF-8") as versions_f:
versions = versions_f.readlines()
else:
versions = []

if f"Version {version} has an id of {version_id}.\n" not in versions:
with open(version_guide_file, "a+", encoding="UTF-8") as versions_f_ap:
versions_f_ap.write(f"Version {version} has an id of {version_id}.\n")
Expand Down Expand Up @@ -89,7 +89,7 @@ def _determine_config_directory():
version, version_id = src.noug_version.VERSION, src.noug_version.VERSION_ID

_write_readme(root_config_directory + "/" + "README.md", root_config_directory + "/" + "version_guide.txt", version, str(version_id))

version_directory = os.path.abspath(root_config_directory + "/" + str(version_id) + "/")
if not os.path.isdir(version_directory):
os.mkdir(version_directory)
Expand Down Expand Up @@ -150,7 +150,7 @@ def _find_files_in_legacy_directories():
print_context = print_context_f.read()
else:
print_context = "0"

if debug.endswith("\n"):
debug = debug[:-1]
if print_context.endswith("\n"):
Expand Down Expand Up @@ -185,7 +185,7 @@ def create_config_files():
# checks if the config path is empty (create or copy config files)
if len(os.listdir(CONFIG_DIRECTORY)) == 0:
_create_or_copy_files()

define_expected_type("debug", "int")
define_expected_type("print_context", "int")
define_expected_type("print_time", "int")
Expand Down
6 changes: 3 additions & 3 deletions src/errors/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def as_string(self):
result += '\t' + line + '\n '
result += f'{self.error_name}: {self.details}' if self.details != '' else f'{self.error_name}'
return result

def set_pos(self, pos_start: Position, pos_end: Position):
self.pos_start = pos_start
self.pos_end = pos_end
Expand Down Expand Up @@ -168,7 +168,7 @@ def generate_traceback(self):
lines_to_append.append((line_to_append, 1))
pos = ctx.entry_pos
ctx = ctx.parent

for line, count in lines_to_append:
if count <= 5:
for _ in range(count):
Expand All @@ -180,7 +180,7 @@ def generate_traceback(self):
return f"(from {self.origin_file})\nTraceback (most recent call last):\n" + result
else:
return "Traceback (most recent call last):\n" + result


class RTIndexError(RunTimeError):
"""Index error (like '[1, 2](2)')"""
Expand Down
8 changes: 4 additions & 4 deletions src/lexer/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def next_char(self, n_next_chars: int = 1):
chars_to_return = next_char
else:
chars_to_return = ""

for _ in range(n_next_chars-1):
new_pos.advance(self.get_char(new_pos))
next_char = self.get_char(new_pos)
Expand All @@ -75,7 +75,7 @@ def next_char(self, n_next_chars: int = 1):
# get the next char in the code (or None if this is EOF (end of file))
next_char = self.get_char(new_pos)
return next_char

def is_empty_file(self, tokens: list[Token]):
"""Returns if the given list of tokens corresponds to an empty file or not."""
if len(tokens) == 0:
Expand Down Expand Up @@ -337,7 +337,7 @@ def make_meta(self, is_empty_file: bool, dont_panic_on_errors: bool = False) ->
"src.lexer.lexer.Lexer.make_tokens"
)
current_char = self.advance()

meta_name = ""
while current_char is not None and current_char in LETTERS:
meta_name += current_char
Expand All @@ -349,7 +349,7 @@ def make_meta(self, is_empty_file: bool, dont_panic_on_errors: bool = False) ->
while current_char is not None and current_char in LETTERS:
meta_argument += current_char
current_char = self.advance()

if current_char is not None and current_char in " \N{NBSP}\N{NNBSP}\t":
current_char = self.advance()

Expand Down
2 changes: 1 addition & 1 deletion src/lexer/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def advance(self, current_char: str | None = None):
self.colon = 0

return self

def set_file_name(self, new_file_name: str):
self.file_name = new_file_name
return self
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __repr__(self) -> str:

def __str__(self):
return repr(self)

def __eq__(self, other: object):
if not isinstance(other, Token):
return False
Expand Down
Loading

0 comments on commit 7e11a65

Please sign in to comment.