clingo.ast
«Potassco

The clingo.ast-5.0.0 module.
 
 
The grammar below defines valid ASTs. For each upper case identifier there is a
matching function in the module. Arguments follow in paranthesis: each having a
type given on the right-hand side of the colon. The symbols ?, *, and + are
used to denote optional arguments (None encodes abscence), list arguments, and
non-empty list arguments.
 
-- Terms
 
term = Symbol
        ( location : Location
        , symbol   : clingo.Symbol
        )
     | Variable
        ( location : Location
        , name     : str
        )
     | UnaryOperation
        ( location : Location
        , operator : UnaryOperator
        , argument : term
        )
     | BinaryOperation
        ( location : Location
        , operator : BinaryOperator
        , left     : term
        , right    : term
        )
     | Interval
        ( location : Location
        , left     : term
        , right    : term
        )
     | Function
        ( location  : Location
        , name      : str
        , arguments : term*
        , external  : bool
        )
     | Pool
        ( location  : Location
        , arguments : term*
        )
 
csp_term = CSPSum
            ( location : Location
            , terms    : CSPProduct
                          ( location    : Location
                          , coefficient : term
                          , variable    : term?
                          )*
 
theory_term = Symbol
               ( location : Location
               , symbol   : clingo.Symbol
               )
            | Variable
               ( location : Location
               , name     : str
               )
            | TheoryTermSequence
               ( location : Location
               , sequence_type : TheorySequenceType
               , terms         : theory_term*
               )
            | TheoryFunction
               ( location  : Location
               , name      : str
               , arguments : theory_term*
               )
            | TheoryUnparsedTerm
               ( location : Location
               , elements : TheoryUnparsedTermElement
                             ( operators : str*
                             , term      : theory_term
                             )+
               )
 
-- Literals
 
symbolic_atom = SymbolicAtom
                 ( term : term
                 )
 
literal = Literal
           ( location : Location
           , sign     : Sign
           , atom     : Comparison
                         ( comparison : ComparisonOperator
                         , left       : term
                         , right      : term
                         )
                      | BooleanConstant
                         ( value : bool
                         )
                      | symbolic_atom
           )
 
        | CSPLiteral
           ( location : Location
           , term     : csp_term
           , guards   : CSPGuard
                         ( comparison : ComparisonOperator
                         , term       : csp_term
                         )+
 
-- Head and Body Literals
 
aggregate_guard = AggregateGuard
                   ( comparison : ComparisonOperator
                   , term       : term
                   )
 
conditional_literal = ConditionalLiteral
                       ( location  : Location
                       , literal   : Literal
                       , condition : Literal*
                       )
 
aggregate = Aggregate
             ( location    : Location
             , left_guard  : aggregate_guard?
             , elements    : conditional_literal*
             , right_guard : aggregate_guard?
             )
 
theory_atom = TheoryAtom
               ( location : Location
               , term     : term
               , elements : TheoryAtomElement
                             ( tuple     : theory_term*
                             , condition : literal*
                             )*
               , guard    : TheoryGuard
                             ( operator_name : str
                             , term          : theory_term
                             )?
 
body_atom = Aggregate
          | BodyAggregate
             ( location    : Location
             , left_guard  : aggregate_guard?
             , function    : AggregateFunction
             , elements    : BodyAggregateElement
                              ( tuple     : term*
                              , condition : literal*
                              )*
             , right_guard : aggregate_guard?
             )
          | Disjoint
             ( location : Location
             , elements : DisjointElement
                           ( location  : Location
                           , tuple     : term*
                           , term      : csp_term
                           , condition : literal*
                           )*
             )
          | theory_atom
 
body_literal = literal
             | conditional_literal
             | Literal
                ( location : Location
                , sign     : Sign
                , atom     : body_atom
                )
 
head = literal
     | Aggregate
     | HeadAggregate
        ( location    : Location
        , left_guard  : aggregate_guard?
        , function    : AggregateFunction
        , elements    : HeadAggregateElement
                         ( tuple     : term*
                         , condition : conditional_literal
                         )*
        , right_guard : aggregate_guard?
        )
     | Disjunction
        ( location : Location
        , elements : conditional_literal*
        )
     | theory_atom
 
-- Theory Definitions
 
theory = TheoryDefinition
          ( location : Location
          , name     : str
          , terms    : TheoryTermDefinition
                        ( location  : Location
                        , name      : str
                        , operators : TheoryOperatorDefinition
                                       ( location      : Location
                                       , name          : str
                                       , priority      : int
                                       , operator_type : TheoryOperatorType
                                       )*
                        )
          , atoms    : TheoryAtomDefinition
                        ( location  : Location
                        , atom_type : TheoryAtomType
                        , name      : str
                        , arity     : int
                        , elements  : str*
                        , guard     : TheoryGuardDefinition
                                       ( operators : str*
                                       , term      : str
                                       )?
                        )
          )
 
-- Statements
 
statement = Rule
             ( location : Location
             , head     : head
             , body     : body_literal*
             )
          | Definition
             ( location   : Location
             , name       : str
             , value      : term
             , is_default : bool
          | ShowSignature
             ( location   : Location
             , name       : str
             , arity      : int
             , sign       : bool
             , csp        : bool
             )
          | ShowTerm
             ( location : Location
             , term     : term
             , body     : body_literal*
             , csp      : bool
             )
          | Minimize
             ( location : Location
             , weight   : term
             , priority : term
             , tuple    : term*
             , body     : body_literal*
             )
          | Script
             ( location    : Location
             , script_type : ScriptType
             , code        : str
             )
          | Program
             ( location   : Location
             , name       : str
             , parameters : Id
                             ( location : Location
                             , id       : str
                             )*
             )
          | External
             ( location : Location
             , atom     : symbolic_atom
             , body     : body_literal*
             )
          | Edge
             ( location : Location
             , u        : term
             , v        : term
             , body     : body_literal*
             )
          | Heuristic
             ( location : Location
             , atom     : symbolic_atom
             , body     : body_literal*
             , bias     : term
             , priority : term
             , modifier : term
             )
          | ProjectAtom
             ( location : Location
             , atom     : symbolic_atom
             , body     : body_literal*
             )
          | ProjectSignature
             ( location   : Location
             , name       : str
             , arity      : int
             , positive   : bool
             )

 
Classes
       
object
AST
ASTType
AggregateFunction
BinaryOperator
ComparisonOperator
ScriptType
Sign
TheoryAtomType
TheoryOperatorType
TheorySequenceType
UnaryOperator

 
class AST(object)
    AST(type, **arguments) -> AST
 
Node in the abstract syntax tree.
 
Arguments:
type -- value in the enumeration ASTType
 
Additionally, the functions takes an arbitrary number of keyword arguments.
These should contain the required fields of the node but can also be set
later.
 
AST nodes can be structually compared ignoring the location.
 
Note that it is also possible to create AST nodes using one of the functions
provided in this module.
 
  Methods defined here:
__contains__(...)
x.__contains__(y) <==> y in x
__delattr__(...)
x.__delattr__('name') <==> del x.name
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__gt__(...)
x.__gt__(y) <==> x>y
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setitem__(...)
x.__setitem__(i, y) <==> x[i]=y
__str__(...)
x.__str__() <==> str(x)
items(...)
items(self) -> list
 
The list of items of the AST node.
keys(...)
keys(self) -> list
 
The list of keys of the AST node.
values(...)
values(self) -> list
 
The list of values of the AST node.

Data descriptors defined here:
child_keys
List of names of all AST child nodes.
type
The type of the node.

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class ASTType(object)
    Enumeration of ast node types.
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)

Data and other attributes defined here:
Aggregate = Aggregate
AggregateGuard = AggregateGuard
BinaryOperation = BinaryOperation
BodyAggregate = BodyAggregate
BodyAggregateElement = BodyAggregateElement
BooleanConstant = BooleanConstant
CSPGuard = CSPGuard
CSPLiteral = CSPLiteral
CSPProduct = CSPProduct
CSPSum = CSPSum
Comparison = Comparison
ConditionalLiteral = ConditionalLiteral
Definition = Definition
Disjoint = Disjoint
DisjointElement = DisjointElement
Disjunction = Disjunction
Edge = Edge
External = External
Function = Function
HeadAggregate = HeadAggregate
HeadAggregateElement = HeadAggregateElement
Heuristic = Heuristic
Id = Id
Interval = Interval
Literal = Literal
Minimize = Minimize
Pool = Pool
Program = Program
ProjectAtom = ProjectAtom
ProjectSignature = ProjectSignature
Rule = Rule
Script = Script
ShowSignature = ShowSignature
ShowTerm = ShowTerm
Symbol = Symbol
SymbolicAtom = SymbolicAtom
TheoryAtom = TheoryAtom
TheoryAtomDefinition = TheoryAtomDefinition
TheoryAtomElement = TheoryAtomElement
TheoryDefinition = TheoryDefinition
TheoryFunction = TheoryFunction
TheoryGuard = TheoryGuard
TheoryGuardDefinition = TheoryGuardDefinition
TheoryOperatorDefinition = TheoryOperatorDefinition
TheorySequence = TheorySequence
TheoryTermDefinition = TheoryTermDefinition
TheoryUnparsedTerm = TheoryUnparsedTerm
TheoryUnparsedTermElement = TheoryUnparsedTermElement
UnaryOperation = UnaryOperation
Variable = Variable

 
class AggregateFunction(object)
    Enumeration of aggegate functions.
 
AggregateFunction.Count   -- the #count function
AggregateFunction.Sum     -- the #sum function
AggregateFunction.SumPlus -- the #sum+ function
AggregateFunction.Min     -- the #min function
AggregateFunction.Max     -- the #max function
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)

Data and other attributes defined here:
Count = #count
Max = #max
Min = #min
Sum = #sum
SumPlus = #sum+

 
class BinaryOperator(object)
    Enumeration of binary operators.
 
BinaryOperator.XOr            -- bitwise exclusive or
BinaryOperator.Or             -- bitwise or
BinaryOperator.And            -- bitwise and
BinaryOperator.Plus           -- arithmetic addition
BinaryOperator.Minus          -- arithmetic substraction and classical negation
BinaryOperator.Multiplication -- arithmetic multipilcation
BinaryOperator.Division       -- arithmetic division
BinaryOperator.Modulo         -- arithmetic modulo
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)

Data and other attributes defined here:
And = &
Division = /
Minus = -
Modulo = \
Multiplication = *
Or = ?
Plus = +
XOr = ^

 
class ComparisonOperator(object)
    Enumeration of comparison operators.
 
ComparisonOperator.GreaterThan  -- the > operator
ComparisonOperator.LessThan     -- the < operator
ComparisonOperator.LessEqual    -- the <= operator
ComparisonOperator.GreaterEqual -- the >= operator
ComparisonOperator.NotEqual     -- the != operator
ComparisonOperator.Equal        -- the = operator
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)

Data and other attributes defined here:
Equal = =
GreaterEqual = >=
GreaterThan = >
LessEqual = <=
LessThan = <
NotEqual = !=

 
class ScriptType(object)
    Enumeration of theory atom types.
 
ScriptType.Python -- python code
ScriptType.Lua    -- lua code
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)

Data and other attributes defined here:
Lua = lua
Python = python

 
class Sign(object)
    The available signs for literals.
 
Sign.None           --
Sign.Negation       -- not
Sign.DoubleNegation -- not not
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)

Data and other attributes defined here:
DoubleNegation = not not
Negation = not
None =

 
class TheoryAtomType(object)
    Enumeration of theory atom types.
 
TheoryAtomType.Any       -- atom can occur anywhere
TheoryAtomType.Body      -- atom can only occur in rule bodies
TheoryAtomType.Head      -- atom can only occur in rule heads
TheoryAtomType.Directive -- atom can only occrur in facts
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)

Data and other attributes defined here:
Any = any
Body = body
Directive = directive
Head = head

 
class TheoryOperatorType(object)
    Enumeration of operator types.
 
TheoryOperatorType.Unary       -- unary operator
TheoryOperatorType.BinaryLeft  -- binary left associative operator
TheoryOperatorType.BinaryRight -- binary right associative operator
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)

Data and other attributes defined here:
BinaryLeft = binary, left
BinaryRight = binary, right
Unary = unary

 
class TheorySequenceType(object)
    Enumeration of theory term sequence types.
 
TheorySequenceType.Tuple -- sequence enclosed in parenthesis
TheorySequenceType.List  -- sequence enclosed in brackets
TheorySequenceType.Set   -- sequence enclosed in braces
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)
left_hand_side(...)
left_hand_side(self) -> str
 
Left-hand side representation of the sequence.
right_hand_side(...)
right_hand_side(self) -> str
 
Right-hand side representation of the sequence.

Data and other attributes defined here:
List = List
Set = Set
Tuple = Tuple

 
class UnaryOperator(object)
    Enumeration of unary operators.
 
UnaryOperator.Negation -- bitwise negation
UnaryOperator.Minus    -- unary minus
UnaryOperator.Absolute -- absolute value
 
  Methods defined here:
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__le__(...)
x.__le__(y) <==> x<=y
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__str__(...)
x.__str__() <==> str(x)
left_hand_side(...)
left_hand_side(self) -> str
 
Left-hand side representation of the operator.
right_hand_side(...)
right_hand_side(self) -> str
 
Right-hand side representation of the operator.

Data and other attributes defined here:
Absolute = Absolute
Minus = Minus
Negation = Negation

 
Functions
       
Aggregate(...)
AggregateGuard(...)
BinaryOperation(...)
BodyAggregate(...)
BodyAggregateElement(...)
BooleanConstant(...)
CSPGuard(...)
CSPLiteral(...)
CSPProduct(...)
CSPSum(...)
Comparison(...)
ConditionalLiteral(...)
Definition(...)
Disjoint(...)
DisjointElement(...)
Disjunction(...)
Edge(...)
External(...)
Function(...)
HeadAggregate(...)
HeadAggregateElement(...)
Heuristic(...)
Id(...)
Interval(...)
Literal(...)
Minimize(...)
Pool(...)
Program(...)
ProjectAtom(...)
ProjectSignature(...)
Rule(...)
Script(...)
ShowSignature(...)
ShowTerm(...)
Symbol(...)
SymbolicAtom(...)
TheoryAtom(...)
TheoryAtomDefinition(...)
TheoryAtomElement(...)
TheoryDefinition(...)
TheoryFunction(...)
TheoryGuard(...)
TheoryGuardDefinition(...)
TheoryOperatorDefinition(...)
TheorySequence(...)
TheoryTermDefinition(...)
TheoryUnparsedTerm(...)
TheoryUnparsedTermElement(...)
UnaryOperation(...)
Variable(...)