We've made an assumption that a command and task are interchangeable. This is incorrect. Instead, a task is composed of a sequence of block, some of which might be slash commands (otherwise they are just text blocks).
This allows us to break up the text into lines, determine if the line is a slash command (it starts with a "/") or more text.
The interface to this new parser will need to be ParseTask(text string) (Task, error).
Once we've parse the text into a task, then we can turn the task into a prompt. For text blocks that would just be the text. For slash commands we'd need to get the correct Markdown file. Then we would need to expand the parameters.
Use github.com/alecthomas/participle/v2 to write a new parser.
Lexical Grammar (Tokens)
CmdStart ::= "(?m)^/" /* Matches "/" only at the start of a line */
Slash ::= "/" /* Matches "/" elsewhere */
Assign ::= "="
String ::= '"' (Escape | [^"])* '"'
Term ::= [^ \t\n\r/"=]+ /* Any char except space, newline, /, ", = */
Whitespace ::= [ \t]+ /* Spaces and tabs (horizontal only) */
Newline ::= [\n\r]+
Syntactic Grammar
Input ::= Block*
Block ::= SlashCommand | Text
/* SlashCommand must start with CmdStart (^/).
Arguments must be separated by mandatory Whitespace.
*/
SlashCommand ::= CmdStart Name (Whitespace Argument)* Whitespace? Newline
Name ::= Term
/* Argument handles both named (key=value) and positional (value).
The "Key Assign" part is optional.
*/
Argument ::= (Key Assign)? Value
Key ::= Term
Value ::= String | Term
/* Text consumes any token EXCEPT CmdStart.
It creates a multi-line block by consuming Newlines.
*/
Text ::= (Term | String | Slash | Assign | Whitespace | Newline)+
IMPORTANT: White-space is meaningful in the text blocks. It must be retained.
We can delete existing slashcommand.go code.
We've made an assumption that a command and task are interchangeable. This is incorrect. Instead, a task is composed of a sequence of block, some of which might be slash commands (otherwise they are just text blocks).
This allows us to break up the text into lines, determine if the line is a slash command (it starts with a "/") or more text.
The interface to this new parser will need to be
ParseTask(text string) (Task, error).Once we've parse the text into a task, then we can turn the task into a prompt. For text blocks that would just be the text. For slash commands we'd need to get the correct Markdown file. Then we would need to expand the parameters.
Use github.com/alecthomas/participle/v2 to write a new parser.
Lexical Grammar (Tokens)
Syntactic Grammar
IMPORTANT: White-space is meaningful in the text blocks. It must be retained.
We can delete existing slashcommand.go code.