-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add language extensions in the parsing of smtlib2 #190
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable and fits the needs of the Alt-Ergo team, thanks @Gbury!
The only thing I am not sure about is the Plain
arg containing an s-expr of the arguments with the command name stashed away in an attribute. I would have expected the Plain
arg to be the full command, because that is a term that actually appears as-is in the source.
I guess the reason you do this is so that users can distinguish statements coming from SMT extensions from other statements, but this could be done by having an attribute for the SMT extension that parsed the statement originally — this could even be useful for dispatch e.g. during typing.
Okay so, I replaced the Note that originally/before this PR, the only producer of |
This PR adds a new concept to the smtlib2 parser: extensions. Basically, extensions are sets of new statements that are allowed. For instance the
maxsmt
extension allows statements such asminimize
andmaximize
. By default, no extension is active/allowed, and thedolmen
binary will (at least for now) discourage the use of extensions, however, users of the library will be able to accept any new statement they might want to try.Statements accepted as part of an extension basically take a list of s-expr as payload, and it is up to the users to decide what to do with them. There are two points of control of extensions for users:
Dolmen_std.Extensions.Smtlib2.create
. Once active, such an extension will make the parser accept the corresponding statements, and these statements will appear asplain
statements, annotated with a term that stores the name of the original statement, and with a single s-expr as payload (that single s-exprs wraps the list of s-exprs into a single term)Ext
module when instantiating the parser. This basically means writing a functionf : string -> (term list -> statement) option
. That functionf
is first called when the parser sees a statement(foo ...)
wherefoo
is not one of the official smtlib2 statement. Iff
returnsNone
, then everything proceeds as "normal", i.e. the statement is rejected with a syntax error. Iff
returnsSome g
then g is then called with the list of parsed s-exprs as arguments. This makes it so that the parser can still generate parsing errors as early as possible on non-allowed statements.Note: the payloads of
Plain
statements for extensions are s-expr, and not smtlib2 terms of sorts. The functionssexpr_as_term
andsexpr_as_sort
from theDolmen_type.Core.Smtlib2
module may be used to easily recover parsed expressions that can then easily be typechecked.cc @bclement-ocp