diff --git a/CHANGELOG.md b/CHANGELOG.md index 10b014cb..1e9b85fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ LogicNG uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.4.1] - 2022-12-01 + +### Changed + +- Allowing symbol `#` in variable names for the `PropositionalParser` and the `PseudoBooleanParser`. +- Set the Java Jigsaw automatic module name to `logicng` in the manifest. + ## [2.4.0] - 2022-11-24 ### Added diff --git a/README.md b/README.md index 80344698..25518bed 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ An extensive white paper with a lot of interesting use cases of LogicNG for conf ## Philosophy -The most important philosophy of the library is to avoid unnecessary object creation. Therefore formulas can only be generated via formula factories. A formula +The most important philosophy of the library is to avoid unnecessary object creation. Therefore, formulas can only be generated via formula factories. A formula factory assures that a formula is only created once in memory. If another instance of the same formula is created by the user, the already existing one is returned by the factory. This leads to a small memory footprint and fast execution of algorithms. Formulas can cache the results of algorithms executed on them and since every formula is hold only once in memory it is assured that the same algorithm on the same formula is also executed only once. @@ -34,7 +34,7 @@ LogicNG is released in the Maven Central Repository. To include it just add org.logicng logicng - 2.4.0 + 2.4.1 ``` diff --git a/pom.xml b/pom.xml index dc9068f5..46a1fb80 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 org.logicng logicng - 2.4.0 + 2.4.1 bundle LogicNG @@ -124,7 +124,7 @@ - + org.apache.maven.plugins maven-jar-plugin @@ -138,6 +138,7 @@ BooleWorks GmbH + logicng diff --git a/src/main/antlr/LogicNGPropositional.g4 b/src/main/antlr/LogicNGPropositional.g4 index 4b016890..967ddb2d 100644 --- a/src/main/antlr/LogicNGPropositional.g4 +++ b/src/main/antlr/LogicNGPropositional.g4 @@ -84,7 +84,7 @@ equiv returns [Formula f] @init{Formula[] operands = new Formula[2];} : a = impl {operands[0] =$a.f;} (EQUIV b = equiv {operands[1] = $b.f;})? {$f = operands[1] == null ? operands[0] : f.equivalence(operands[0], operands[1]);}; -VARIABLE : [A-Za-z0-9_@][A-Za-z0-9_]*; +VARIABLE : [A-Za-z0-9_@#][A-Za-z0-9_#]*; TRUE : '$true'; FALSE : '$false'; LBR : '('; diff --git a/src/main/antlr/LogicNGPseudoBoolean.g4 b/src/main/antlr/LogicNGPseudoBoolean.g4 index a9e7c5b6..f907fd8e 100644 --- a/src/main/antlr/LogicNGPseudoBoolean.g4 +++ b/src/main/antlr/LogicNGPseudoBoolean.g4 @@ -105,7 +105,7 @@ add returns [List literals, List coeffs] NUMBER : [\-]?[0-9]+; -LITERAL : [~]?[A-Za-z0-9_@][A-Za-z0-9_]*; +LITERAL : [~]?[A-Za-z0-9_@#][A-Za-z0-9_#]*; TRUE : '$true'; FALSE : '$false'; LBR : '('; diff --git a/src/main/java/org/logicng/io/parsers/PropositionalParser.java b/src/main/java/org/logicng/io/parsers/PropositionalParser.java index d58bfb94..146754d5 100644 --- a/src/main/java/org/logicng/io/parsers/PropositionalParser.java +++ b/src/main/java/org/logicng/io/parsers/PropositionalParser.java @@ -46,11 +46,11 @@ * * Brackets are {@code (} and {@code )}. For variable names, there are the following rules: *
    - *
  • must begin with a alphabetic character, {@code _} or {@code @}
  • - *
  • can only contain alphanumerical character, or {@code _}
  • + *
  • must begin with a alphabetic character, {@code _}, {@code @}, or {@code #}
  • + *
  • can only contain alphanumerical character, {@code _}, or {@code #}
  • *
  • {@code @} is only allowed at the beginning of the variable name and is reserved for special internal variables
  • *
- * @version 1.2 + * @version 2.4.1 * @since 1.0 */ public final class PropositionalParser extends FormulaParser { diff --git a/src/main/java/org/logicng/io/parsers/PseudoBooleanParser.java b/src/main/java/org/logicng/io/parsers/PseudoBooleanParser.java index a6e06e8d..0725ca06 100644 --- a/src/main/java/org/logicng/io/parsers/PseudoBooleanParser.java +++ b/src/main/java/org/logicng/io/parsers/PseudoBooleanParser.java @@ -53,14 +53,14 @@ * * Brackets are {@code (} and {@code )}. For variable names, there are the following rules: *
    - *
  • must begin with a alphabetic character, {@code _} or {@code @}
  • - *
  • can only contain alphanumerical character, or {@code _}
  • + *
  • must begin with a alphabetic character, {@code _}, {@code @}, or {@code #}
  • + *
  • can only contain alphanumerical character, {@code _}, or {@code #}
  • *
  • {@code @} is only allowed at the beginning of the variable name and is reserved for special internal variables
  • *
*

* A valid pseudo Boolean expression is of the form {@code c_1 * l_1 + ... + c_n * l_n R k} where the {@code c_i} are coefficients, * {@code l_i} are literals, and {@code R} is one of {@code =, >, >=, <, <=}. - * @version 1.2 + * @version 2.4.1 * @since 1.0 */ public final class PseudoBooleanParser extends FormulaParser { diff --git a/src/test/java/org/logicng/io/parsers/PropositionalParserTest.java b/src/test/java/org/logicng/io/parsers/PropositionalParserTest.java index 5861444f..331f5f1b 100644 --- a/src/test/java/org/logicng/io/parsers/PropositionalParserTest.java +++ b/src/test/java/org/logicng/io/parsers/PropositionalParserTest.java @@ -40,7 +40,7 @@ /** * Unit Tests for the class {@link PropositionalParser}. - * @version 2.0.0 + * @version 2.4.1 * @since 1.0 */ public class PropositionalParserTest extends TestWithExampleFormulas { @@ -72,6 +72,13 @@ public void testParseLiterals() throws ParserException { assertThat(parser.parse("~a1")).isEqualTo(this.f.literal("a1", false)); assertThat(parser.parse("~aA_Bb_Cc_12_3")).isEqualTo(this.f.literal("aA_Bb_Cc_12_3", false)); assertThat(parser.parse("~@aA_Bb_Cc_12_3")).isEqualTo(this.f.literal("@aA_Bb_Cc_12_3", false)); + assertThat(parser.parse("#")).isEqualTo(this.f.literal("#", true)); + assertThat(parser.parse("~#")).isEqualTo(this.f.literal("#", false)); + assertThat(parser.parse("~A#B")).isEqualTo(this.f.literal("A#B", false)); + assertThat(parser.parse("A#B")).isEqualTo(this.f.literal("A#B", true)); + assertThat(parser.parse("~A#B")).isEqualTo(this.f.literal("A#B", false)); + assertThat(parser.parse("#A#B_")).isEqualTo(this.f.literal("#A#B_", true)); + assertThat(parser.parse("~#A#B_")).isEqualTo(this.f.literal("#A#B_", false)); } @Test @@ -250,7 +257,7 @@ public void testIllegalFormula8() { @Test public void testIllegalFormula9() { - final String string = "#"; + final String string = "@A@B"; final InputStream stream = new ByteArrayInputStream(string.getBytes(StandardCharsets.UTF_8)); assertThatThrownBy(() -> new PropositionalParser(this.f).parse(stream)).isInstanceOf(ParserException.class); } diff --git a/src/test/java/org/logicng/io/parsers/PseudoBooleanParserTest.java b/src/test/java/org/logicng/io/parsers/PseudoBooleanParserTest.java index 57748952..c98547e8 100644 --- a/src/test/java/org/logicng/io/parsers/PseudoBooleanParserTest.java +++ b/src/test/java/org/logicng/io/parsers/PseudoBooleanParserTest.java @@ -40,7 +40,7 @@ /** * Unit Tests for the class {@link PseudoBooleanParser}. - * @version 2.0.0 + * @version 4.4.1 * @since 1.0 */ public class PseudoBooleanParserTest extends TestWithExampleFormulas { @@ -69,6 +69,13 @@ public void testParseLiterals() throws ParserException { assertThat(parser.parse("~A")).isEqualTo(this.f.literal("A", false)); assertThat(parser.parse("~a")).isEqualTo(this.f.literal("a", false)); assertThat(parser.parse("~aA_Bb_Cc_12_3")).isEqualTo(this.f.literal("aA_Bb_Cc_12_3", false)); + assertThat(parser.parse("#")).isEqualTo(this.f.literal("#", true)); + assertThat(parser.parse("~#")).isEqualTo(this.f.literal("#", false)); + assertThat(parser.parse("~A#B")).isEqualTo(this.f.literal("A#B", false)); + assertThat(parser.parse("A#B")).isEqualTo(this.f.literal("A#B", true)); + assertThat(parser.parse("~A#B")).isEqualTo(this.f.literal("A#B", false)); + assertThat(parser.parse("#A#B_")).isEqualTo(this.f.literal("#A#B_", true)); + assertThat(parser.parse("~#A#B_")).isEqualTo(this.f.literal("#A#B_", false)); } @Test