packages feed

hsmt-0.1.0.0: src/HSMT/SMTLib/Syntax.hs

-- | Abstract syntax of the SMT-LIB 2 commands understood by hsmt.
--
-- Terms are represented directly as core expressions ('HSMT.Core.Expr'):
-- the parser elaborates and sort-checks them, and the printer renders them
-- back. Parameters of @define-fun@ are represented as nullary uninterpreted
-- symbols.
module HSMT.SMTLib.Syntax
  ( Command (..)
  , Answer (..)
  , renderAnswer
  ) where

import Data.Text (Text)

import HSMT.Core.Expr
import HSMT.Core.Op
import HSMT.Core.Sort

-- | An SMT-LIB command.
data Command
  = SetLogic Text
    -- ^ @set-logic@ with the logic name.
  | SetOption Text Text
    -- ^ Option name (without the leading colon) and its value, verbatim.
  | SetInfo Text Text
    -- ^ @set-info@: keyword (without the leading colon) and its value,
    -- verbatim.
  | DeclareSort Text
    -- ^ An uninterpreted sort of arity 0.
  | DeclareRecord [(Text, Sort)]
    -- ^ A record sort, rendered as a single-constructor datatype.
  | DeclareFun Symbol
    -- ^ @declare-fun@ (or @declare-const@) of an uninterpreted symbol.
  | DefineFun Symbol [Symbol] Expr
    -- ^ A macro: the defined symbol, its parameters and its body.
  | Assert Expr
    -- ^ @assert@ of a Boolean expression.
  | AssertNamed Text Expr
    -- ^ @(assert (! e :named n))@: the name identifies the assertion in
    -- unsatisfiable cores.
  | Push Int
    -- ^ @push@ the given number of assertion levels.
  | Pop Int
    -- ^ @pop@ the given number of assertion levels.
  | CheckSat
    -- ^ @check-sat@.
  | CheckSatAssuming [Expr]
    -- ^ @check-sat-assuming@ with Boolean assumptions.
  | GetModel
    -- ^ @get-model@.
  | GetValue [Expr]
    -- ^ @get-value@ of the given terms.
  | GetAssertions
    -- ^ @get-assertions@.
  | GetUnsatCore
    -- ^ @get-unsat-core@.
  | GetInfo Text
    -- ^ The keyword, without the leading colon.
  | GetOption Text
    -- ^ The option name, without the leading colon.
  | Echo Text
    -- ^ @echo@ of a string literal (its contents, without the quotes).
  | Reset
    -- ^ @reset@: back to the initial state.
  | ResetAssertions
    -- ^ @reset-assertions@: drop all assertions and declarations, keeping
    -- options.
  | Exit
    -- ^ @exit@.
  deriving (Eq, Show)

-- | Answer to a @check-sat@ command.
data Answer = AnsSat | AnsUnsat | AnsUnknown
  deriving (Eq, Ord, Show)

-- | The SMT-LIB spelling of an answer (@sat@, @unsat@ or @unknown@).
renderAnswer :: Answer -> Text
renderAnswer = \case
  AnsSat -> "sat"
  AnsUnsat -> "unsat"
  AnsUnknown -> "unknown"