I am writing a tool to generation sequence diagram from some text. I need to support this two syntax:
anInstance:AClass.DoSomething()
andparticipant A -> participant B: Any character except for \r\n (<>{}?)etc.
.
Let's call the fist one strict
syntax and the second one free
syntax. In anInstance:AClass.DoSomething()
, I need it to be matched by to
( ID ':' ID
) as in the strict
syntax. However, :AClass.DoSomething()
will be first matched by CONTENT
. I am thinking some kind of lookahead, checking if ->
is there but not able to figure it out.
Strict
syntax
message
: to '.' signature
;
signature
: methodName '()'
;
to
: ID ':' ID
;
methodName
: ID
;
ID
: [a-zA-Z_] [a-zA-Z_0-9]*
;
Free
syntax
asyncMessage
: source '->' target content
;
source
: ID+
;
target
: ID+
;
content
: CONTENT
;
ID
: [a-zA-Z_] [a-zA-Z_0-9]*
;
CONTENT
: ':' ~[\r\n]+
;
SPACE
: [ \t\r\n] -> channel(HIDDEN)
;