From cb9f1db85abbf9d5ae303b4a9d62f8c8b47de94c Mon Sep 17 00:00:00 2001 From: srpathen Date: Thu, 1 Aug 2024 20:05:40 -0400 Subject: [PATCH] syntaxer2 --- .../glayout/glayout/syntaxer2/Command.py | 40 +++++++++++++++--- .../glayout/syntaxer2/Commands/help.py | 30 ++++++++++++++ .../glayout/syntaxer2/Commands/move.py | 41 +++++++++++++++++++ 3 files changed, 106 insertions(+), 5 deletions(-) diff --git a/openfasoc/generators/glayout/glayout/syntaxer2/Command.py b/openfasoc/generators/glayout/glayout/syntaxer2/Command.py index 3a578660f..bee517848 100644 --- a/openfasoc/generators/glayout/glayout/syntaxer2/Command.py +++ b/openfasoc/generators/glayout/glayout/syntaxer2/Command.py @@ -1,6 +1,36 @@ -# This is the template for the Command class, each command for the StrictSyntax will follow the template described in this file +from glayout.syntaxer.process_input import Session +from abc import ABC, abstractmethod + +class Command(ABC): + def __init__(self, session: Session): + self.session = session + pass + + @abstractmethod + def manipulate_code(self): + """This function is here to manipulate the Code object of a session + It doesn't return anything, it just manipulates the code class + """ + pass + + @abstractmethod + def action(self): + """this function is here to complete actions that don't affect the code class + Doesn't return anything either + """ + pass + + @abstractmethod + def pattern_matcher(self) -> bool: + """this function here is to return is the command matches a certain pattern + """ + pass + + @property + @abstractmethod + def name(self): + """this is just a variable describing the name of the class + """ + pass + -class Command: - def __init__(self): - self.name = "" - def \ No newline at end of file diff --git a/openfasoc/generators/glayout/glayout/syntaxer2/Commands/help.py b/openfasoc/generators/glayout/glayout/syntaxer2/Commands/help.py index e69de29bb..76b17b3f1 100644 --- a/openfasoc/generators/glayout/glayout/syntaxer2/Commands/help.py +++ b/openfasoc/generators/glayout/glayout/syntaxer2/Commands/help.py @@ -0,0 +1,30 @@ +from glayout.syntaxer2.Command import Command + +class help(Command): + name = "help" + summary = "gives general/specific help" + help = """help - gives general help about StrictSyntax\nhelp {command} - gives help about {command}""" + + def action(self): + """prints out the supported commands, and summaries for them + """ + words = self.line.split(" ") + # if the command is just help, then it just wants general help + gen_help = "StrictSyntax currently has support for these commands:\n" + + if len(words) == 1: + for command in self.session.commands: + gen_help += f"{command.name} - {command.summary}\n" + + gen_help += "To view specific help for a command, type \"help {command name}\"" + print(gen_help) + + def manipulate_code(): + """does nothing to manipulate the code, this is a command language specific command + """ + pass + + + + + diff --git a/openfasoc/generators/glayout/glayout/syntaxer2/Commands/move.py b/openfasoc/generators/glayout/glayout/syntaxer2/Commands/move.py index e69de29bb..e7c36e561 100644 --- a/openfasoc/generators/glayout/glayout/syntaxer2/Commands/move.py +++ b/openfasoc/generators/glayout/glayout/syntaxer2/Commands/move.py @@ -0,0 +1,41 @@ +from glayout.syntaxer2.Command import Command + +class move(Command): + name = "move" + summary = "moves components" + help = "move {component 1} {direction} {component 2}" + + def action(self): + """doesn't have any actions on the front end, this just manipulate code + """ + pass + + def manipulate_code(self): + """adds to the movement table + """ + + words = self.line.split(" ") + irrelevant_words = ["to", "of", "the"] + + words = [for word in words if word not in irrelevant_words] + + direction_dict = { + "left": 0, "west": 0, + "right": 1, "east": 1, + "above": 2, "north": 2, + "below": 3, "south": 3 + } + + component1 = words[1] + direction = direction_dict[words[2]] + component2 = direction_dict[words[3]] + seperation = None + + # if there is a seperation argument + if len(words) > 4: + seperation = words[6:] + + seperation = "".join(seperation) + seperation = seperation.split("=")[-1] + + self.session.code.add_movement_code(component1, component2, direction, seperation)