clingo.ast API documentation
clingo.ast module
The clingo.ast-5.4.0 module.
The grammar below defines valid ASTs. For each upper case identifier there is a
matching function in the module. Arguments follow in parenthesis: 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
)
| Defined
( location : Location
, name : str
, arity : int
, sign : 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*
, type : term
)
| 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
)
Overview
Functions
def Aggregate()def AggregateGuard()def BinaryOperation()def BodyAggregate()def BodyAggregateElement()def BooleanConstant()def CSPGuard()def CSPLiteral()def CSPProduct()def CSPSum()def Comparison()def ConditionalLiteral()def Defined()def Definition()def Disjoint()def DisjointElement()def Disjunction()def Edge()def External()def Function()def HeadAggregate()def HeadAggregateElement()def Heuristic()def Id()def Interval()def Literal()def Minimize()def Pool()def Program()def ProjectAtom()def ProjectSignature()def Rule()def Script()def ShowSignature()def ShowTerm()def Symbol()def SymbolicAtom()def TheoryAtom()def TheoryAtomDefinition()def TheoryAtomElement()def TheoryDefinition()def TheoryFunction()def TheoryGuard()def TheoryGuardDefinition()def TheoryOperatorDefinition()def TheorySequence()def TheoryTermDefinition()def TheoryUnparsedTerm()def TheoryUnparsedTermElement()def UnaryOperation()def Variable()
Classes
class AST(type:ASTType, **arguments:Mapping[str,Any])-
Represents a node in the abstract syntax tree.
AST nodes implement Python's rich comparison operators and are ordered structurally ignoring the location. They can also be used as dictionary keys. Their string representation corresponds to their gringo representation.
Parameters
type:ASTType- The type of the onde.
arguments:Mapping[str,Any]- 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.
Notes
It is also possible to create AST nodes using one of the functions provided in this module. The parameters of the functions correspond to the nonterminals as given in the grammar above.
Instance variables
var child_keys :List[str]-
List of names of all AST child nodes.
var type :ASTType-
The type of the node.
Methods
class ASTType-
Enumeration of ast node types.
Class variables
var Aggregatevar AggregateGuardvar BinaryOperationvar BodyAggregatevar BodyAggregateElementvar BooleanConstantvar CSPGuardvar CSPLiteralvar CSPProductvar CSPSumvar Comparisonvar ConditionalLiteralvar Definedvar Definitionvar Disjointvar DisjointElementvar Disjunctionvar Edgevar Externalvar Functionvar HeadAggregatevar HeadAggregateElementvar Heuristicvar Idvar Intervalvar Literalvar Minimizevar Poolvar Programvar ProjectAtomvar ProjectSignaturevar Rulevar Scriptvar ShowSignaturevar ShowTermvar Symbolvar SymbolicAtomvar TheoryAtomvar TheoryAtomDefinitionvar TheoryAtomElementvar TheoryDefinitionvar TheoryFunctionvar TheoryGuardvar TheoryGuardDefinitionvar TheoryOperatorDefinitionvar TheorySequencevar TheoryTermDefinitionvar TheoryUnparsedTermvar TheoryUnparsedTermElementvar UnaryOperationvar Variable
class AggregateFunction-
Enumeration of aggegate functions.
AggregateFunctionobjects have a readable string representation, implement Python's rich comparison operators, and can be used as dictionary keys.Furthermore, they cannot be constructed from Python. Instead the following preconstructed class attributes are available:
Attributes
Count:AggregateFunction- The
#countfunction. Sum:AggregateFunction- The
#sumfunction. SumPlus:AggregateFunction- The
#sum+function. Min:AggregateFunction- The
#minfunction. Max:AggregateFunction- The
#maxfunction.
Class variables
var Countvar Maxvar Minvar Sumvar SumPlus
class BinaryOperator-
Enumeration of binary operators.
BinaryOperatorobjects have a readable string representation, implement Python's rich comparison operators, and can be used as dictionary keys.Furthermore, they cannot be constructed from Python. Instead the following preconstructed class attributes are available:
Attributes
XOr:BinaryOperator- For bitwise exclusive or.
Or:BinaryOperator- For bitwise or.
And:BinaryOperator- For bitwise and.
Plus:BinaryOperator- For arithmetic addition.
Minus:BinaryOperator- For arithmetic subtraction.
Multiplication:BinaryOperator- For arithmetic multipilcation.
Division:BinaryOperator- For arithmetic division.
Modulo:BinaryOperator- For arithmetic modulo.
Power:BinaryOperator- For arithmetic exponentiation.
Class variables
var Andvar Divisionvar Minusvar Modulovar Multiplicationvar Orvar Plusvar Powervar XOr
class ComparisonOperator-
Enumeration of comparison operators.
ComparisonOperatorobjects have a readable string representation, implement Python's rich comparison operators, and can be used as dictionary keys.Furthermore, they cannot be constructed from Python. Instead the following preconstructed class attributes are available:
Attributes
GreaterThan:ComparisonOperator- The
>operator. LessThan:ComparisonOperator- The
<operator. LessEqual:ComparisonOperator- The
<=operator. GreaterEqual:ComparisonOperator- The
>=operator. NotEqual:ComparisonOperator- The
!=operator. Equal:ComparisonOperator- The
=operator
Class variables
var Equalvar GreaterEqualvar GreaterThanvar LessEqualvar LessThanvar NotEqual
class ScriptType-
Enumeration of theory atom types.
ScriptTypeobjects have a readable string representation, implement Python's rich comparison operators, and can be used as dictionary keys.Furthermore, they cannot be constructed from Python. Instead the following preconstructed class attributes are available:
Attributes
Python:ScriptType- For Python code.
Lua:ScriptType- For Lua code.
Class variables
var Luavar Python
class Sign-
Enumeration of signs for literals.
Signobjects have a readable string representation, implement Python's rich comparison operators, and can be used as dictionary keys.Furthermore, they cannot be constructed from Python. Instead the following preconstructed class attributes are available:
Attributes
Class variables
var DoubleNegationvar Negationvar NoSign
class TheoryAtomType-
Enumeration of theory atom types.
TheoryAtomTypeobjects have a readable string representation, implement Python's rich comparison operators, and can be used as dictionary keys.Furthermore, they cannot be constructed from Python. Instead the following preconstructed class attributes are available:
Attributes
Any:TheoryAtomType- For atoms that can occur anywhere.
Body:TheoryAtomType- For atoms that can only occur in rule bodies.
Head:TheoryAtomType- For atoms that can only occur in rule heads.
Directive:TheoryAtomType- For atoms that can only occur in facts.
Class variables
var Anyvar Bodyvar Directivevar Head
class TheoryOperatorType-
Enumeration of operator types.
TheoryOperatorTypeobjects have a readable string representation, implement Python's rich comparison operators, and can be used as dictionary keys.Furthermore, they cannot be constructed from Python. Instead the following preconstructed class attributes are available:
Attributes
Unary:TheoryOperatorType- For unary operators.
BinaryLeft:TheoryOperatorType- For binary left associative operators.
BinaryRight:TheoryOperatorType- For binary right associative operator.
Class variables
var BinaryLeftvar BinaryRightvar Unary
class TheorySequenceType-
Enumeration of theory term sequence types.
TheorySequenceTypeobjects have a readable string representation, implement Python's rich comparison operators, and can be used as dictionary keys.Furthermore, they cannot be constructed from Python. Instead the following preconstructed class attributes are available:
Attributes
Tuple:TheorySequenceType- For sequences enclosed in parenthesis.
List:TheorySequenceType- For sequences enclosed in brackets.
Set:TheorySequenceType- For sequences enclosed in braces.
Class variables
var Listvar Setvar Tuple
Instance variables
var left_hand_side :str-
Left-hand side representation of the sequence.
var right_hand_side :str-
Right-hand side representation of the sequence.
class UnaryOperator-
Enumeration of signs for literals.
UnaryOperatorobjects have a readable string representation, implement Python's rich comparison operators, and can be used as dictionary keys.Furthermore, they cannot be constructed from Python. Instead the following preconstructed class attributes are available:
Attributes
Negation:UnaryOperator- For bitwise negation.
Minus:UnaryOperator- For unary minus and classical negation.
Absolute:UnaryOperator- For taking the absolute value.
Class variables
var Absolutevar Minusvar Negation
Instance variables
var left_hand_side :str-
Left-hand side representation of the operator.
var right_hand_side :str-
Right-hand side representation of the operator.
