oowekyala / intellij-javacc

JavaCC and JJTree grammar support for the IntelliJ Platform
https://plugins.jetbrains.com/plugin/11431-javacc
MIT License
44 stars 6 forks source link

"partial" regexps (<#FOO>) cause false-positive warnings #17

Closed dweiss closed 3 years ago

dweiss commented 3 years ago

Thank you for the plugin. It is helpful. I just wanted to point out that currently "partial" regexp definitions cause warnings. Something like:

<DEFAULT> TOKEN : {
      <#_NUM_CHAR:   ["0"-"9"] >
    // Every character that follows a backslash is considered as an escaped character
    | <#_ESCAPED_CHAR: "\\" ~[] >
    | <#_TERM_START_CHAR: ( ~[ " ", "\t", "\n", "\r", "\u3000", "+", "-", "!", "(", ")", ":", "^", "@",
    | <PLUS:          "+" >
...

would bring a warning like this:

"+" cannot be matched as the string literal token <PLUS>, _TERM_CHAR matches its input instead 

This isn't true because pound-starting definitions don't generate tokens of their own - they're just expanded into final tokens, if used.

oowekyala commented 3 years ago

Thanks for the report, I'll try to find time for this shortly

dweiss commented 3 years ago

No worries. Thank you!

oowekyala commented 3 years ago

So I've been looking into this bug and am having trouble reproducing it... The example you provide has a syntax error, and even if corrected, I don't see an issue (even when adding tokens like your _TERM_CHAR). Could you provide a minimal working example?

dweiss commented 3 years ago

Hi Clement. I will, sure. I am away from my computer - will do it tomorrow.

On Sat, Sep 19, 2020, 13:36 Clément Fournier notifications@github.com wrote:

So I've been looking into this bug and am having trouble reproducing it... The example you provide has a syntax error, and even if corrected, I don't see an issue (even when adding tokens like your _TERM_CHAR). Could you provide a minimal working example?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/oowekyala/intellij-javacc/issues/17#issuecomment-695202498, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQWLQDSUXCJA6LJMIUJWTSGSJVDANCNFSM4RRX3IUQ .

dweiss commented 3 years ago

This is a smaller example that reproduces the problem.

PARSER_BEGIN(Example)
public class Example {
}
PARSER_END(Example)

<DEFAULT> TOKEN : {
      <#_FRAGMENT:   ["0"-"9"] >
    | <QUOTED:        "\"" ( <_FRAGMENT> )* "\"">
    | <ZERO: "0" >
}

public Void Rule() :
{
}
{
  <QUOTED> | <ZERO>
  {
   return null;
  }
}  

Note how QUOTED uses the fragment to define a regexp that contains it. The fragment will never match on its own but the plugin claims a conflict with token ZERO.

oowekyala commented 3 years ago

Misclick

Thanks, I'll look into this tomorrow

dweiss commented 3 years ago

This isn't urgent. Thanks!

On Sat, Sep 19, 2020, 21:51 Clément Fournier notifications@github.com wrote:

Misclick

Thanks, I'll look into this tomorrow

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/oowekyala/intellij-javacc/issues/17#issuecomment-695349550, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQWLVVYDH3WI7UHCZ3FTLSGUDTJANCNFSM4RRX3IUQ .

oowekyala commented 3 years ago

I was able to reproduce the bug, it should be fixed in version 1.7, which I'll release sometime this week. Thanks for your cooperation Dawid !