Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New unreachable token value warning #2066

Merged
merged 10 commits into from
Dec 6, 2017
Merged

Conversation

KvanTTT
Copy link
Member

@KvanTTT KvanTTT commented Oct 22, 2017

Partial fix for #1072 (see unit tests).

I tested my version on grammars-v4 repository and found a couple of such warnings:

  • warning(184): LessLexer.g4:224:0: One of the token FORMAT values unreachable. % is always overlapped by token PERC
  • warning(184): ZLexer.g4:478:0: One of the token ID0 values unreachable. _ is always overlapped by token ARGUMENT

Also I discovered and fixed such warnings in ANTLR unit tests itself (testInvalidLexerCommand, testLexerCommandArgumentValidation).

@@ -96,8 +89,7 @@ public void checkActionRedefinitions(List<GrammarAST> actions) {
nameNode = (GrammarAST) ampersandAST.getChild(0);
if (ampersandAST.getChildCount() == 2) {
name = nameNode.getText();
}
else {
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi. please use same style. } on line by themselves

* for repeated defs.
*/
public void checkForLabelConflicts(Collection<Rule> rules) {
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you changing whitespace by mistake?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сonversely I replaced all whitespaces on tabs (respect to general project style).

@@ -341,42 +318,130 @@ public void checkForModeConflicts(Grammar g) {
}
}

public void checkForUnreachableTokens(Grammar g) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain in a comment your strategy for finding unreachable tokens? I also need to review that strategy to know if it is correct. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@KvanTTT
Copy link
Member Author

KvanTTT commented Oct 28, 2017

Please wait, do not merge. I want to implement yet another check.

@KvanTTT
Copy link
Member Author

KvanTTT commented Nov 1, 2017

Probably the complexity can be reduced down to linear. I'll take a look until the end of the week.

Copy link
Member

@sharwell sharwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove the unrelated formatting changes from this.

@@ -223,11 +207,11 @@ private void checkForTypeMismatch(Rule r, LabelElementPair prevLabelPair, LabelE
labelPair.type + "!=" + prevLabelPair.type);
}
if (!prevLabelPair.element.getText().equals(labelPair.element.getText()) &&
(prevLabelPair.type.equals(LabelType.RULE_LABEL) || prevLabelPair.type.equals(LabelType.RULE_LIST_LABEL)) &&
(labelPair.type.equals(LabelType.RULE_LABEL) || labelPair.type.equals(LabelType.RULE_LIST_LABEL))) {
(prevLabelPair.type.equals(LabelType.RULE_LABEL) || prevLabelPair.type.equals(LabelType.RULE_LIST_LABEL)) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Previous indentation was correct here:

<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width>4</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width>

}
}

protected void checkReservedNames(Collection<Rule> rules) {
for (Rule rule : rules) {
if (reservedNames.contains(rule.name)) {
errMgr.grammarError(ErrorType.RESERVED_RULE_NAME, g.fileName, ((GrammarAST)rule.ast.getChild(0)).getToken(), rule.name);
errMgr.grammarError(ErrorType.RESERVED_RULE_NAME, g.fileName, ((GrammarAST) rule.ast.getChild(0)).getToken(), rule.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Previous spacing was correct here:

<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceAfterTypeCast>false</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceAfterTypeCast>

GrammarAST arg = (GrammarAST)ref.getFirstChildWithType(ANTLRParser.ARG_ACTION);
if ( arg!=null && (r==null || r.args==null) ) {
GrammarAST arg = (GrammarAST) ref.getFirstChildWithType(ANTLRParser.ARG_ACTION);
if (arg != null && (r == null || r.args == null)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Spacing here was generally unspecified (@parrt uses the previous spacing, while I use the updated spacing). Generally accepted practice became not changing it unless you were rewriting the line.

@@ -522,15 +522,15 @@
*/
USE_OF_BAD_WORD(134, "symbol <arg> conflicts with generated code in target language or runtime", ErrorSeverity.ERROR),
/**
* Compiler Error 134.
* Compiler Error 183.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 Wasn't this part of another pull request?

Copy link
Member Author

@KvanTTT KvanTTT Nov 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is, but already merged.

"TOKEN7: 'qwer'+;\n" +
"TOKEN8: 'a' 'b' | 'b' | 'a' 'b';\n" +
"fragment\n" +
"TOKEN9: 'asdf' | 'qwer' | 'qwer';\n" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Should include tokens with characters that need escapes, to make sure the values are properly escaped in the error messages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@parrt
Copy link
Member

parrt commented Nov 29, 2017

Ok, are we ready to go with this merge?

@parrt parrt added this to the 4.7.1 milestone Nov 29, 2017
@KvanTTT
Copy link
Member Author

KvanTTT commented Nov 29, 2017

@sharwell please check last fixes.

@parrt
Copy link
Member

parrt commented Dec 6, 2017

@KvanTTT How many grammars have you run this on?

@KvanTTT
Copy link
Member Author

KvanTTT commented Dec 6, 2017

All grammars from an official grammars-v4 repository, see my first comment: #2066 (comment)

@parrt parrt merged commit 489a11b into antlr:master Dec 6, 2017
@KvanTTT KvanTTT deleted the unreachable-tokens branch November 8, 2021 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants