Gbury / dolmen

Dolmen provides a library and a binary to parse, typecheck, and evaluate languages used in automated deduction
BSD 2-Clause "Simplified" License
80 stars 17 forks source link

Term printers #8

Open Gbury opened 6 years ago

Gbury commented 6 years ago

Implement printers for terms in each language.

This brings some questions that need answers:

cc @anmaped cc @c-cube for the unicode-related escaping question

c-cube commented 6 years ago

I'd say printing unicode in languages not designed for it is going to be tough. You can try "u1234" instead of the corresponding codepoint, though.

Gbury commented 6 years ago

To be clear, the point of escaping was precisely to not print unicode in languages that don't support it.

Basically, the idea of escaping would be to map every unicode character to a list of unicode character (kind of like a flat_map : (char -> string) -> string -> string function but unicode-aware) so that all printed identifiers exactly respect the lexical conventions of the target language. For instance, as shown in https://github.com/Gbury/archsat/blob/master/src/output/tptp.ml#L51 , for tptp, all non ASCII alphanumeric characters would be substituted with an arbitrary allowed character, e.g. '_'.

I asked about that because, as I recall you objected to adding dependencies such as uutf and uucp, which means the printer would have to be part of a sub-package with additional dependencies.

anmaped commented 6 years ago

Regarding the question "should statements also be printable ?" I would say, Yes.

what to do when the term uses features not available in the output languages (higher-order terms printed in smtlib, first-order terms printed in dimacs/iCNF, ...)

To be safe, I think we should't do this translations yet unless we know that it is safe to do. If you try to prety print features in one language that are not supported you should tell to the user exactly that.

particularly, dimacs and iCNF are not easy to print, since they have quite a loose relation with the terms: propositional atoms expressed as integers in dimacs and iCNF are encoded using constants named #1, #2, etc... So should we just not give printer for them, or have the printer maintain a map of terms to numbered propositional atoms ?

For now, we may skip the print of the terms for iCNF and dimacs. Later on we may use a map as you sugested.

anmaped commented 6 years ago

@Gbury I will start with the pretty-printers. Do you want to provide some skeleton?

Gbury commented 6 years ago

I already started some work on branch printer, where there is some skeleton you can start from.

Gbury commented 4 years ago

This will be greatly benefit from the typed terms now that there is a type-checker. I'll upstream some code from archsat soon to cover this feature.

Gbury commented 6 months ago

See #211 for an implementation of printers for smtlib v2.6.