How do I implement a Antlr4 parser that resolve ambiguity when both rules use “==”?

I know the title is not clear enough. Here is the details. I need to parse something like below:

Client->iFrame.Initialise() {
  res = Server.loadStaticResource()
  if (res.status == 404 || res.status == 503) {  <1>
     throw Error()
  }
}
== Initialisation done! ==                       <2>
Client->iFrame.load(data) {
   moreStatements()
}

It is a Java-like syntax, except that we support a Divider (shown as == Initialisation done! == in the example). Note that:

  1. both <1> and <2> uses ==.
  2. It is treated as a Divider only if it appears at the beginning of the line (after spaces removed).
  3. Any character can be used between the starting == and ending == except for changelines.
  4. There could be more = in the Divider component, such as === 3 equals ===.

How should I implement that?

What I have tried?

I was looking for a way to use lookahead in the Lexer, but could not find any good examples. I am currently limiting the content between starting == and ending == to ONE word only.

My implementation is here:

  1. The parser: https://github.com/ZenUml/core/blob/b84c9ca0a6d023c5e520bf83a225e4931db134fc/src/g4/sequenceParser.g4#L88-L89
  2. The lexer: https://github.com/ZenUml/core/blob/main/src/g4/sequenceLexer.g4