Commit Graph

61 Commits

Author SHA1 Message Date
c7d79e7b07
Make inner types customizable 2020-05-19 15:39:20 +02:00
170cde6a82
Fix parsing right-to-left implication 2020-05-18 06:00:41 +02:00
0216f90929
Add support for comments 2020-05-12 05:55:23 +02:00
ae46634d67
Rename ClosedFormula to OpenFormula 2020-05-11 03:52:36 +02:00
75e97a5c07
Use log crate rather than println 2020-05-05 19:43:41 +02:00
dd208ffeeb
Expose number parser 2020-05-04 20:29:07 +02:00
bdd5d0e583
Expose identifier parser 2020-05-04 18:07:39 +02:00
82e98e5ec0
Look up functions 2020-05-04 16:56:03 +02:00
1b4c400bfb
Look up variables 2020-05-04 16:55:21 +02:00
f8918628fa
Pass declarations to term parser 2020-05-04 16:53:42 +02:00
555f983285
Look up predicates 2020-05-04 16:48:35 +02:00
56885dc290
Pass declarations to formula parser 2020-05-04 16:40:59 +02:00
30c28c2bc4
Fix unit tests 2020-05-03 18:05:45 +02:00
8d474fa489
Finish dirty first pass over parser 2020-04-28 05:21:58 +02:00
66ac57c5b8
Work in progress 2020-04-28 03:18:05 +02:00
0fb2be4897
Minor refactoring 2020-04-28 02:39:58 +02:00
80aafb2359
Implement right-to-left implication 2020-04-28 02:36:53 +02:00
a2268ab85b
Minor renaming 2020-04-28 02:36:47 +02:00
451b887019
Minor renaming 2020-04-28 02:36:38 +02:00
a12acae633
Refactoring 2020-04-28 02:36:02 +02:00
35937d7930
Clean-up 2020-04-28 02:35:46 +02:00
31805fa9d8
Clean-up 2020-04-28 02:16:15 +02:00
a6edd2e9cc
Clean-up 2020-04-28 02:14:27 +02:00
834194d40a
Work in progress 2020-04-28 02:02:20 +02:00
15d0d2b76c
Work in progress 2020-04-27 19:36:12 +02:00
ff17c60cd1
Start rewriting parser 2020-04-22 20:01:29 +02:00
b516396977
Fix parsing nested quantified formulas 2020-04-20 02:57:32 +02:00
987e02f478
Allow period character as word boundary 2020-04-20 02:51:46 +02:00
ba385868cb
Fix parsing precedence of left implication vs. less-than comparison 2020-04-20 02:40:13 +02:00
04e2d61583
Fix order of operators 2020-04-19 23:05:12 +02:00
395c029ca9
Expose function/predicate name parser 2020-04-18 02:32:12 +02:00
c927fe4628
Expose Declarations type 2020-04-18 01:07:12 +02:00
2b3add562f
Update nom to 6.0.0-alpha1 2020-04-17 18:22:50 +02:00
0d5971cad7
Retrieve declarations using traits and not objects 2020-04-17 04:06:22 +02:00
0e78e4ea57
Minor refactoring 2020-04-17 03:30:32 +02:00
63c1931e30
Expose functions to access free and manipulate variable declarations 2020-04-17 03:18:25 +02:00
8a9a7b9132
Remove unneeded indirection 2020-04-17 03:13:18 +02:00
abbc047dda
Replace variable declaration stack with recursive layer implementation 2020-04-17 02:53:23 +02:00
62b9e2da04
Make variable declaration stack safer with guards 2020-04-17 01:40:19 +02:00
fa6f27beb4
Start reimplementing parser
Implement name parsing

Start parsing terms

Implement word boundaries

Implement strings

Add pipe character to allowed word boundaries

Implement booleans

Require word boundaries around names

Implement variable parsing

Finish implementing term parsing

Add term parsing test

Test associativity of multiplication

Make parse feature the default

Fix term parsing and finish tests

Start parsing formulas

Continue parsing formulas

Finish implementing formula parsing

Move boolean parser to separate module

Move integer parser to separate module

Move special integer parser to separate module

Move string parser to separate module

Address warnings

Fix negation parser

Refactor term parser tests

Address clippy warning

Disallow reserved keywords as names

Add missing word boundary character

Check that names don’t start with special characters

Minor refactoring

Add note

Test conjunction parser

Test disjunction parser

Parentheses for stronger checks

Add note

Fix implication parser and output

Split formatting functionality into two files

Test term formatting

Add unit test for function declaration formatting

Work in progress

Fix implication formatting

Refactor precedence rules

Start testing formula formatter

Minor formatting

Test remaining formula types

Add unit tests for precedence-0 formulas and lower

Before larger refactoring

Refactor precedence rules for formulas

Remove ChildPosition enum

Fix

Address warnings

Remove unneeded precedence implementation

Test negation

Test quantified formulas

Clean up tests

Clean up tests

Test conjunction

Test disjunction

Start testing implications

Refactor parenthesis requirement check

Fix precedence of implication

Continue testing implication

Test biconditionals

Experimental method for testing all permutations

Rewrite tests for clarity

Rewrite tests for clarity

Add type annotations

Rewrite tests for clarity

Reorganize tests

Finish testing biconditionals

Support empty n-aries

Support quantified expressions with 0 parameters

Rewrite term formatting tests for clarity

Reorganize term formatter tests

Refactor parenthesis rules for terms

Remove unneeded parentheses enum

Refactoring

Refactoring

Minor clean-up

Minor clean-up

Simplify representation of quantified formulas

Remove redundant indirection

Remove redundant indirection
2020-04-17 01:40:16 +02:00
1e34d726e1
Export formatting implementation functionality 2020-04-14 01:15:02 +02:00
1e610a77fe
Make variable formatting customizable
This introduces a Format trait, which can be implemented to customize
the appearance of variable declarations right now. The Format trait will
be extended with further customization options in the future.
2020-04-14 01:15:02 +02:00
9216bbbe31
Rename formatter variables
These formatter objects were just named “format,” but there’s no need
to abbreviate that. This renames all occurrences to “formatter” for
clarity.
2020-04-13 23:07:54 +02:00
d67e530fec
Rewrite formula and term formatting
The rules for determining required parentheses as opposed to parentheses
that can be omitted are more complicated than just showing parentheses
whenever a child expression has lower precedence than its parent. This
necessitated a rewrite.

This new implementation determines whether an expression requires to be
parenthesized with individual rules for each type of expression, which
may or may not depend on the type of the parent expression and the
position of a child within its parent expression. For example,
implication is defined to be right-associative, which means that the
parentheses in the formula

    (F -> G) -> H

cannot be ommitted. When determining whether the subformula (F -> G)
needs to be parenthesized, the new algorithm notices that the subformula
is contained as the antecedent of another implication and concludes that
parentheses are required.

Furthermore, this adds extensive unit tests for both formula and term
formatting. The general idea is to test all types of expressions
individually and, in addition to that, all combinations of parent and
child expression types.

Unit testing made it clear that the formatting of empty and 1-ary
conjunctions, disjunctions, and biconditionals needs to be well-defined
even though these types of formulas may be unconventional. The same
applies to existentially and universally quantified formulas where the
list of parameters is empty. Now, empty conjunctions and biconditionals
are rendered like true Booleans, empty disjunctions like false Booleans,
and 1-ary conjunctions, disjunctions, biconditionals, as well as
quantified expressions with empty parameter lists as their singleton
argument.

The latter formulas can be considered neutral intermediates. That is,
they should not affect whether their singleton arguments are
parenthesized or not. To account for that, all unit tests covering
combinations of formulas are tested with any of those five neutral
intermediates additionally.
2020-04-13 23:07:54 +02:00
8e32b58c99
Remove unneeded indirection from vector types
The type aliases for vectors of formulas and terms were defined as
vectors of boxed formulas and terms, respectively. This is an
unnecessary indirection, so store the formulas and terms directly.
2020-04-13 22:16:01 +02:00
2fa592576b
Take reference-counted arguments by value
These reference-counted arguments were taken by reference, which made it
necessary to clone them. If a reference-counted object is created for the
sole purpose of being passed to one of these methods, it would be cloned
unnecessarily. This changes the signatures to take these arguments by
value, shifting the responsibility of cloning the reference-counted
objects to the users of these methods.
2020-04-13 22:09:43 +02:00
7d22e47ba1
Represent quantified formulas consistently
Existential and universal quantification used redundant data
representations, while they actually share the same structure. This
unifies both into a single QuantifiedFormula type.
2020-04-13 22:05:09 +02:00
7566fdaa29
Support n-ary biconditionals
For convenience, support biconditionals with more than one argument.
An n-ary “if and only if” statement

    F_1 <-> F_2 <-> ... <-> F_n

is to be interpreted as

    F_1 <-> F_2 and F2 <-> F3 and ... and F_(n - 1) <-> F_n
2020-04-13 21:59:25 +02:00
855fd9abcf
Support right-to-left implications
As right-to-left implications are common in answer set programming, this
adds support for using implications in both directions.
2020-04-13 21:44:02 +02:00
5bbb09eef8
Split formatting utils into separate files
For clarity, this moves the formatting functionality related to formulas
and terms into two separate files.
2020-04-09 22:09:15 +02:00