Skip to content

Fix cics converse rewrite #2535

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

Merged

Conversation

mm-broadcom
Copy link
Contributor

Added ability to parse subrules rather than just a single layer down. Added new tests to account for these changes.

How Has This Been Tested?

Ran and tested existing tests, changed error message(s) to reflect changes,

Checklist:

  • Each of my commits contains one meaningful change
  • I have performed rebase of my branch on top of the development
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Add check for FROMLENGTH and FROMFLENGTH as they are mutually exclusive.
Add subrule parsing and checks, fix tests.
@mm-broadcom
Copy link
Contributor Author

@slavek-kucera @chacebot Could you review this when you get the chance?

Fix checkstyle error.
Comment on lines 115 to 129
protected <E extends ParserRuleContext> void checkIfSelfCalledMultipleTimes(String options, E ctx) {
if (ctx.getParent().getRuleContexts(ctx.getClass()).size() > 1) {
throwException(ErrorSeverity.ERROR, getLocality(ctx), "Options \"" + options + "\" cannot be used more than once in a given command.", "");
}
}

protected <E extends ParserRuleContext> void checkSubrules(E ctx, Map<Integer, Consumer<ParserRuleContext>> subruleOptions) {
ArrayList<ParserRuleContext> childRules = new ArrayList<>(ctx.getRuleContexts(ParserRuleContext.class));
for (ParserRuleContext child : childRules) {
if (subruleOptions.containsKey(child.getRuleIndex())) {
subruleOptions.get(child.getRuleIndex()).accept(child);
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could be much simplified (and eventually integrated with the token duplicate checking).
Something like

  protected void checkSubrules(ParserRuleContext ctx, Map<Integer, String> subruleOptions) {
    Set<Integer> seenRules = new HashSet<>();
    for (ParserRuleContext child : ctx.getRuleContexts(ParserRuleContext.class)) {
      int ruleId = child.getRuleIndex();
      String name = subruleOptions.get(ruleId);
      if (name == null) continue;
      if (seenRules.add(ruleId)) continue;
      throwException(ErrorSeverity.ERROR, getLocality(child), "Options \"" + name + "\" cannot be used more than once in a given command.", "");
    }
  }

with the subruleOptions being

    private final static Map<Integer, String> subruleOptions = new HashMap<Integer, String>() {
        {
            put(CICSParser.RULE_cics_into, "INTO or SET");
            put(CICSParser.RULE_cics_converse_from, "FROMLENGTH or FROMFLENGTH");
            put(CICSParser.RULE_cics_converse_to, "TOLENGTH or TOFLENGTH");
            put(CICSParser.RULE_cics_maxlength, "MAXLENGTH or MAXFLENGTH");
        }
    };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That won't work. The intent of the current Map and checkSubrules function is tying the rule index to a pointer to a given function using a Consumer type.

It resolves needing to write out the Switch statement, lessening overhead. You could even have a base set which is then added to on a per main rule basis.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understand the intent. I am proposing to replace all that with the mechanism described above. All those functions (checkInto, checkFrom, ...) call throwException when they detect duplicates, the only variability is in the name used in the error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure for this so far, thing is there will be times we want more flexibility in the functions being called. (ie. Mutually exclusive rules/tokens, change what is checked if a given token is found and so on.)

Switching to this would remove a lot of that flexibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd wait for that time to come and then tailor the solution to whatever the problem will actually look like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just renamed it for clarity. Its purpose wasn't to check anything, but to call the corresponding subrule function(s).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented the rule duplication check into the existing checkDuplicates function in the latest commit.

@ap891843 ap891843 merged commit a99a55a into eclipse-che4z:development Oct 15, 2024
18 checks passed
ap891843 pushed a commit that referenced this pull request Mar 14, 2025
* Add check for FROMLENGTH and FROMFLENGTH

Add check for FROMLENGTH and FROMFLENGTH as they are mutually exclusive.

* Add subrule parsing and checks

Add subrule parsing and checks, fix tests.

* Fix checkstyle error.

Fix checkstyle error.

* Removed unused function

* Renamed cics_converse_from/to to fromlength/tolength

* Renamed checkSubrules to callSubruleFunctions

Renamed checkSubrules to callSubruleFunctions for clarity of purpose.

* Add duplicate checks for rules

Add duplicate checks for rules

* Removed erroneous comment.

* Removed unused functions

Removed unused functions

* Fix checkstyle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants