Skip to content

Commit

Permalink
fix(more_command_nodes): 🐛 fix parse of FloatsArgument
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jul 8, 2022
1 parent 57c8081 commit dc65f2c
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions more_command_nodes/more_command_nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@


class IllegalFloat(CommandSyntaxError):
def __init__(self, char_read: int):
super().__init__('Invalid Point', char_read)
def __init__(self, char_read: str):
super().__init__('Invalid Float', char_read)


class IncompleteFloat(CommandSyntaxError):
def __init__(self, char_read: int):
super().__init__('Incomplete Point', char_read)
def __init__(self, char_read: str):
super().__init__('Incomplete Float', char_read)


class FloatsArgument(ArgumentNode):
Expand All @@ -32,17 +32,15 @@ def __init__(self, name: str, number: int):
self.__number = number

def parse(self, text: str) -> ParseResult:
total_read = 0
coords = []
for i in range(self.__number):
value, read = command_builder_util.get_float(text[total_read:])
if read == 0:
raise IncompleteFloat(total_read)
total_read += read
if value is None:
raise IllegalFloat(total_read)
coords.append(value)
return ParseResult(coords, total_read)
try:
texts = text.split()[:self.__number]
coords = list(map(float, texts))
if len(coords) < self.__number:
raise IncompleteFloat(text)
except ValueError:
raise IllegalFloat(text)
else:
return ParseResult(coords, len(' '.join(texts)))


class Position(FloatsArgument):
Expand Down

0 comments on commit dc65f2c

Please sign in to comment.