From cf01cbd3133d30e0c5402b77f9531f0c3afcfbea Mon Sep 17 00:00:00 2001
From: Jonas Zohren <jonas.zohren@adesso.de>
Date: Fri, 26 Feb 2021 00:12:27 +0100
Subject: [PATCH] Allow easily typable not, and, or

---
 src/knf-parser.pegjs |  6 +++---
 src/knf-parser.ts    | 32 ++++++++++++++++----------------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/knf-parser.pegjs b/src/knf-parser.pegjs
index 367121f..ba514a7 100644
--- a/src/knf-parser.pegjs
+++ b/src/knf-parser.pegjs
@@ -1,15 +1,15 @@
 ConjunctiveClause
-  = '{' head:DisunctiveClause tail:( '∧' _ DisunctiveClause)* '}' {
+  = '{' head:DisunctiveClause tail:( [∧&] _ DisunctiveClause)* '}' {
   	return [head, ...tail.map(e => e[2])];
   }
   
 DisunctiveClause
-  = '{' head:VariableOccurence tail:( '∨' _ VariableOccurence)* '}' {
+  = '{' head:VariableOccurence tail:( [∨|] _ VariableOccurence)* '}' {
   	return [head, ...tail.map(e => e[2])];
   }
 
 VariableOccurence
-  = a:('¬')? b:[A-Z]c:[0-9] {
+  = a:([¬!])? b:[A-Z]c:[0-9] {
   	return {name:b+c, polarity: a === null};
   }
 
diff --git a/src/knf-parser.ts b/src/knf-parser.ts
index b4e3c39..6c41c15 100644
--- a/src/knf-parser.ts
+++ b/src/knf-parser.ts
@@ -172,17 +172,17 @@ function peg$parse(input: string, options?: IParseOptions) {
 
   const peg$c0 = "{";
   const peg$c1 = peg$literalExpectation("{", false);
-  const peg$c2 = "\u2227";
-  const peg$c3 = peg$literalExpectation("\u2227", false);
+  const peg$c2 = /^[\u2227&]/;
+  const peg$c3 = peg$classExpectation(["\u2227", "&"], false, false);
   const peg$c4 = "}";
   const peg$c5 = peg$literalExpectation("}", false);
   const peg$c6 = function(head: any, tail: any): any {
     	return [head, ...tail.map(e => e[2])];
     };
-  const peg$c7 = "\u2228";
-  const peg$c8 = peg$literalExpectation("\u2228", false);
-  const peg$c9 = "\xAC";
-  const peg$c10 = peg$literalExpectation("\xAC", false);
+  const peg$c7 = /^[\u2228|]/;
+  const peg$c8 = peg$classExpectation(["\u2228", "|"], false, false);
+  const peg$c9 = /^[\xAC!]/;
+  const peg$c10 = peg$classExpectation(["\xAC", "!"], false, false);
   const peg$c11 = /^[A-Z]/;
   const peg$c12 = peg$classExpectation([["A", "Z"]], false, false);
   const peg$c13 = /^[0-9]/;
@@ -363,8 +363,8 @@ function peg$parse(input: string, options?: IParseOptions) {
       if (s2 !== peg$FAILED) {
         s3 = [];
         s4 = peg$currPos;
-        if (input.charCodeAt(peg$currPos) === 8743) {
-          s5 = peg$c2;
+        if (peg$c2.test(input.charAt(peg$currPos))) {
+          s5 = input.charAt(peg$currPos);
           peg$currPos++;
         } else {
           s5 = peg$FAILED;
@@ -392,8 +392,8 @@ function peg$parse(input: string, options?: IParseOptions) {
         while (s4 !== peg$FAILED) {
           s3.push(s4);
           s4 = peg$currPos;
-          if (input.charCodeAt(peg$currPos) === 8743) {
-            s5 = peg$c2;
+          if (peg$c2.test(input.charAt(peg$currPos))) {
+            s5 = input.charAt(peg$currPos);
             peg$currPos++;
           } else {
             s5 = peg$FAILED;
@@ -478,8 +478,8 @@ function peg$parse(input: string, options?: IParseOptions) {
       if (s2 !== peg$FAILED) {
         s3 = [];
         s4 = peg$currPos;
-        if (input.charCodeAt(peg$currPos) === 8744) {
-          s5 = peg$c7;
+        if (peg$c7.test(input.charAt(peg$currPos))) {
+          s5 = input.charAt(peg$currPos);
           peg$currPos++;
         } else {
           s5 = peg$FAILED;
@@ -507,8 +507,8 @@ function peg$parse(input: string, options?: IParseOptions) {
         while (s4 !== peg$FAILED) {
           s3.push(s4);
           s4 = peg$currPos;
-          if (input.charCodeAt(peg$currPos) === 8744) {
-            s5 = peg$c7;
+          if (peg$c7.test(input.charAt(peg$currPos))) {
+            s5 = input.charAt(peg$currPos);
             peg$currPos++;
           } else {
             s5 = peg$FAILED;
@@ -581,8 +581,8 @@ function peg$parse(input: string, options?: IParseOptions) {
     }
 
     s0 = peg$currPos;
-    if (input.charCodeAt(peg$currPos) === 172) {
-      s1 = peg$c9;
+    if (peg$c9.test(input.charAt(peg$currPos))) {
+      s1 = input.charAt(peg$currPos);
       peg$currPos++;
     } else {
       s1 = peg$FAILED;
-- 
GitLab