Source code for gam.ast.ops
from typing import Literal
from pydantic import Field
from gam.ast.base_ast import ASTNode
[docs]
class Operator(ASTNode):
"""Base class for all operators"""
name: Literal['Operator'] = Field(default='Operator')
id: str
[docs]
class BinaryOperator(Operator):
"""Represents a binary operator"""
name: Literal['BinaryOperator'] = Field(default='BinaryOperator')
[docs]
class UnaryOperator(Operator):
"""Represents a unary operator"""
name: Literal['UnaryOperator'] = Field(default='UnaryOperator')
[docs]
class ComparisonOperator(Operator):
"""Represents a comparison operator"""
name: Literal['ComparisonOperator'] = Field(default='ComparisonOperator')
# Implement the operators
[docs]
class AddOps(BinaryOperator):
"""Represents an addition operator"""
name: Literal['AddOps'] = Field(default='AddOps')
id: Literal['add'] = 'add'
[docs]
class SubtractOps(BinaryOperator):
"""Represents a subtraction operator"""
name: Literal['SubtractOps'] = Field(default='SubtractOps')
id: Literal['subtract'] = 'subtract'
[docs]
class MultiplyOps(BinaryOperator):
"""Represents a multiplication operator"""
name: Literal['MultiplyOps'] = Field(default='MultiplyOps')
id: Literal['multiply'] = 'multiply'
[docs]
class DivideOps(BinaryOperator):
"""Represents a division operator"""
name: Literal['DivideOps'] = Field(default='DivideOps')
id: Literal['divide'] = 'divide'
[docs]
class EqualOps(BinaryOperator):
"""Represents an equal operator"""
name: Literal['EqualOps'] = Field(default='EqualOps')
id: Literal['equal'] = 'equal'
[docs]
class NotEqualOps(BinaryOperator):
"""Represents a not equal operator"""
name: Literal['NotEqualOps'] = Field(default='NotEqualOps')
id: Literal['not_equal'] = 'not_equal'
[docs]
class LessThanOps(BinaryOperator):
"""Represents a less than operator"""
name: Literal['LessThanOps'] = Field(default='LessThanOps')
id: Literal['less_than'] = 'less_than'
[docs]
class LessThanEqualOps(BinaryOperator):
"""Represents a less than or equal operator"""
name: Literal['LessThanEqualOps'] = Field(default='LessThanEqualOps')
id: Literal['less_than_equal'] = 'less_than_equal'
[docs]
class GreaterThanOps(BinaryOperator):
"""Represents a greater than operator"""
name: Literal['GreaterThanOps'] = Field(default='GreaterThanOps')
id: Literal['greater_than'] = 'greater_than'
[docs]
class GreaterThanEqualOps(BinaryOperator):
"""Represents a greater than or equal operator"""
name: Literal['GreaterThanEqualOps'] = Field(default='GreaterThanEqualOps')
id: Literal['greater_than_equal'] = 'greater_than_equal'
[docs]
class AndOps(BinaryOperator):
"""Represents a and operator"""
name: Literal['AndOps'] = Field(default='AndOps')
id: Literal['and'] = 'and'
[docs]
class OrOps(BinaryOperator):
"""Represents a or operator"""
name: Literal['OrOps'] = Field(default='OrOps')
id: Literal['or'] = 'or'
[docs]
class NotOps(UnaryOperator):
name: Literal['NotOps'] = Field(default='NotOps')
id: Literal['not'] = 'not'