From cd017ba6650a03be252fe5225a2388def5d4739f Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Sun, 23 Jun 2024 00:45:49 +0200 Subject: [PATCH] Fix Constraint Set Grammar. Add Or Constraint Test --- .../dhbwstuttgart/input/parser/ConstraintSet.g4 | 4 ++-- src/test/java/UnifyTest.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/antlr4/de/dhbwstuttgart/input/parser/ConstraintSet.g4 b/src/main/antlr4/de/dhbwstuttgart/input/parser/ConstraintSet.g4 index c80ffab..699378d 100644 --- a/src/main/antlr4/de/dhbwstuttgart/input/parser/ConstraintSet.g4 +++ b/src/main/antlr4/de/dhbwstuttgart/input/parser/ConstraintSet.g4 @@ -1,12 +1,12 @@ grammar ConstraintSet; -constraintSet : (constraints | orConstraint | extendsRelation)+; +constraintSet : (constraints | orConstraint | extendsRelation | ',')+; extendsRelation: IDENTIFIER typeParams? '<' type; typeParams : '<' IDENTIFIER (',' IDENTIFIER)* '>'; orConstraint : '{' constraints ('|' constraints)* '}'; -constraints : '{' constraint+ '}' | constraint+; +constraints : '{' constraint (','? constraint)* '}' | constraint (','? constraint)*; constraint: subtypeCons | equalsCons; subtypeCons : type '<.' type; diff --git a/src/test/java/UnifyTest.java b/src/test/java/UnifyTest.java index 824025b..32411cb 100644 --- a/src/test/java/UnifyTest.java +++ b/src/test/java/UnifyTest.java @@ -40,6 +40,22 @@ public class UnifyTest { //TODO: Finish Extends Relation parser } + @Test + public void alotOfOrConstraintsTest(){ + String input = + "Vector < List," + + "MyPair < Pair," + + "Pair < Object," + + "List < Object," + + "Integer < Object, String < Object, " + + "{List <. _a | List <. _a}{List<_c> <. _b | List<_c> <. _b} {List <. _b | List <. _b}"+ + "{List <. _aa | List <. _aa}{List<_c> <. _ba | List<_c> <. _ba} {List <. _ba | List <. _ba}"+ + "{List <. _a | List <. _aaa}{List<_c> <. _baa | List<_c> <. _baa} {List <. _baa | List <. _baa}"; + + System.out.println(ASPGenerator.generateASP(ConstraintParser.parse(input))); + System.out.println(ASPGenerator.generateExtendsRelations(ConstraintParser.parseExtendsRelations(input))); + } + @Test public void matrix(){ String input = "java.lang.Boolean < Object," +