Skip to content

Commit

Permalink
syntaxer2
Browse files Browse the repository at this point in the history
  • Loading branch information
srpathen committed Aug 2, 2024
1 parent 2811bbc commit cb9f1db
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 5 deletions.
40 changes: 35 additions & 5 deletions openfasoc/generators/glayout/glayout/syntaxer2/Command.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions openfasoc/generators/glayout/glayout/syntaxer2/Commands/help.py
Original file line number Diff line number Diff line change
@@ -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





41 changes: 41 additions & 0 deletions openfasoc/generators/glayout/glayout/syntaxer2/Commands/move.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit cb9f1db

Please sign in to comment.