Skip to content

Commit

Permalink
xtext: XtextValidator: Allow fragments in unordered groups
Browse files Browse the repository at this point in the history
Fixes eclipse-xtext#3068

Signed-off-by: Tommaso Fonda <[email protected]>
  • Loading branch information
tfonda-fbk committed Aug 12, 2024
1 parent e8e6e6d commit 60f8236
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,23 @@ public boolean apply(Diagnostic input) {
messageAcceptor.validate();
}

@Test public void testCheckFragmentCallInUnorderedGroup() throws Exception {
XtextValidator validator = get(XtextValidator.class);
UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
typeRef.setClassifier(EcorePackage.Literals.EOBJECT);
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setType(typeRef);
parserRule.setFragment(true);
ruleCall.setRule(parserRule);
unorderedGroup.getElements().add(ruleCall);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkRuleCallInUnorderedGroup(ruleCall);
messageAcceptor.validate();
}

@Test public void testCheckRuleCallInUnorderedGroup_01() throws Exception {
XtextValidator validator = get(XtextValidator.class);
UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,8 @@ public void checkRuleCallInUnorderedGroup(final RuleCall call) {
return;
if (GrammarUtil.isAssigned(call))
return;
if (GrammarUtil.isEObjectFragmentRuleCall(call))
return;
if (EcoreUtil2.getContainerOfType(call, UnorderedGroup.class) != null)
error(
"Unassigned rule calls may not be used in unordered groups.",
Expand Down

0 comments on commit 60f8236

Please sign in to comment.