lmika / goseq

A command line tool to generate sequence diagrams
https://goseq.lmika.dev
MIT License
205 stars 26 forks source link

Add "-x" as an action type between two actors, to denote message rejection/not accepted #10

Open tbayne opened 4 years ago

tbayne commented 4 years ago

I am trying to add this feature myself, and I have tried to modify the parser to accept "x" the same way it accepts other actions but still getting a syntax error, which means, I think that I haven't modified the parser correctly. Any hints?

lmika commented 4 years ago

Hi @tbayne, it's been a while since I've looked at this but I'll do my best to give you a hand here:

Goseq uses the goyacc tool for generating the parser, with a hand rolled scanner which uses the "text/scanner" package. For this I'm going to assume that you're familiar with the tool and scanner package. If not, please let me know. I'm also unsure as to how much you managed to grok from the code itself (not the greatest bit of code I've written). So apologies if I make assumptions in how everything is put together.

It sounds like what needs doing for this is to define a new arrow head, so along with modifying the various parts of the code which define the arrow-head constants, you'll need to modify the scanner defined in "grammar.y". The grammar separates the concept of an arrow stem and arrow head (see "grammar.y" line 316) so you'll need to add support for using "x" as an arrow head.

The easiest way to do this would be to make x a keyword, but I don't think that would be wise as there might be a legitimate need to use it as an identifier. So, I'd say the best course of action would be to modify the scanner logic to interpret an identifier x that occurs after an arrow-stem token. This would allow us to support the following constructs:

x -> y: x is an identifier
a -x b: x is an arrow head
y --x x: x is both an arrow head and identifier

Maybe a look-behind of the previous token will help here. You can then probably add a special case in scanKeywordOrIdent to treat x as a keyword only if the previous token was either DASH or DOUBLEDASH. You should then be able to map that to a token and add that as a rule to the arrowHead grammar reduction.

If you've got some code, I'll be happy to take a look.

Hope that helps.

Thanks,

Leon