forked from idea-fasoc/OpenFASOC
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |