diff --git a/src/CommandLib/command.go b/src/CommandLib/command.go index 7f6aa19..c241953 100644 --- a/src/CommandLib/command.go +++ b/src/CommandLib/command.go @@ -55,7 +55,7 @@ func (cmd *command) Name() string { return cmd.name } -func (cmd *command) DoWork(argValues []ArgumentValue) (err error) { +func (cmd *command) Execute(argValues []ArgumentValue) (err error) { for i, v := range cmd.args { if i > len(argValues)-1 { diff --git a/src/CommandLib/command_context.go b/src/CommandLib/command_context.go new file mode 100644 index 0000000..5987254 --- /dev/null +++ b/src/CommandLib/command_context.go @@ -0,0 +1,30 @@ +package commandlib + +type commandContext struct { + commandString string + tokens []Token + + command Command +} + +func CreateCommandContext(commandString string) (ctx *commandContext, err error) { + tokenizer := CreateTokenizer() + + tokens, tokenizerError := tokenizer.Tokenize(commandString) + + if tokenizerError != nil { + err = tokenizerError + return + } + + ctx = &commandContext{ + commandString: commandString, + tokens: tokens, + } + + return +} + +func (ctx *commandContext) Execute() (err error) { + ctx.command.Execute() +} diff --git a/src/CommandLib/command_definition.go b/src/CommandLib/command_definition.go new file mode 100644 index 0000000..fa0307a --- /dev/null +++ b/src/CommandLib/command_definition.go @@ -0,0 +1,4 @@ +package commandlib + +type CommandDefinition struct { +} diff --git a/src/CommandLib/interface.go b/src/CommandLib/interface.go new file mode 100644 index 0000000..f8ad6fe --- /dev/null +++ b/src/CommandLib/interface.go @@ -0,0 +1,10 @@ +package commandlib + +type Parameter interface { + Value() any +} + +type Command interface { + Name() string + Parameters() []Parameter +} diff --git a/src/CommandLib/tokenizer.go b/src/CommandLib/tokenizer.go index 7a1ef2f..9beaa50 100644 --- a/src/CommandLib/tokenizer.go +++ b/src/CommandLib/tokenizer.go @@ -126,6 +126,7 @@ func (t *tokenizer) Tokenize(commandMsg string) (tokens []Token, err error) { // All patterns are case-insensitive and must match the beginning of the input (^) re, regexError := regexp.Compile(`(?i)^` + pattern.pattern) + // If we encounter a regex error, stop tokenization ( wrongly defined pattern? ) if regexError != nil { tokens = nil err = regexError diff --git a/src/Server/main.go b/src/Server/main.go index 285a602..25aea94 100644 --- a/src/Server/main.go +++ b/src/Server/main.go @@ -14,10 +14,6 @@ type Command interface { Name() string } -type argValue struct { - value string -} - func main() { // testcmd, err := commandlib.CreateCommand( // "test",