Skip to content

Commit

Permalink
Merge pull request #160 from nickovic/155-exceptions
Browse files Browse the repository at this point in the history
155 exceptions
  • Loading branch information
nickovic authored Aug 8, 2022
2 parents 3ff5f97 + 65835ab commit bea96b6
Show file tree
Hide file tree
Showing 35 changed files with 155 additions and 205 deletions.
11 changes: 0 additions & 11 deletions rtamt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
from rtamt.exception.stl.exception import STLException
from rtamt.exception.stl.exception import STLParseException
from rtamt.exception.stl.exception import STLOfflineException
from rtamt.exception.stl.exception import STLSpecificationException
from rtamt.exception.stl.exception import STLNotImplementedException
from rtamt.exception.ltl.exception import LTLNotImplementedException
from rtamt.exception.ltl.exception import LTLPastifyException
from rtamt.exception.ltl.exception import LTLException
from rtamt.exception.ltl.exception import LTLOfflineException
from rtamt.exception.ltl.exception import LTLParseException
from rtamt.exception.ltl.exception import LTLSpecificationException
from rtamt.exception.exception import RTAMTException
from rtamt.semantics.enumerations.io_type import StlIOType
from rtamt.semantics.enumerations.options import Language, Semantics, TimeInterpretation
Expand Down
10 changes: 5 additions & 5 deletions rtamt/antlr/parser/ltl/error/parser_error_listener.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from antlr4.error.ErrorListener import ErrorListener
from rtamt.exception.ltl.exception import LTLParseException
from rtamt.exception.exception import RTAMTException

class LTLParserErrorListener( ErrorListener ):
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
raise LTLParseException (str(line) + ":" + str(column) + ": Syntax ERROR, " + str(msg))
raise RTAMTException (str(line) + ":" + str(column) + ": Syntax ERROR, " + str(msg))

def reportAmbiguity(self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs):
raise LTLParseException("Ambiguity ERROR, " + str(configs))
raise RTAMTException("Ambiguity ERROR, " + str(configs))

def reportAttemptingFullContext(self, recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs):
raise LTLParseException("Attempting full context ERROR, " + str(configs))
raise RTAMTException("Attempting full context ERROR, " + str(configs))

def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs):
raise LTLParseException("Context ERROR, " + str(configs))
raise RTAMTException("Context ERROR, " + str(configs))
10 changes: 5 additions & 5 deletions rtamt/antlr/parser/stl/error/parser_error_listener.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from antlr4.error.ErrorListener import ErrorListener
from rtamt.exception.stl.exception import STLParseException
from rtamt.exception.exception import RTAMTException

class STLParserErrorListener( ErrorListener ):
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
raise STLParseException (str(line) + ":" + str(column) + ": Syntax ERROR, " + str(msg))
raise RTAMTException (str(line) + ":" + str(column) + ": Syntax ERROR, " + str(msg))

def reportAmbiguity(self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs):
raise STLParseException("Ambiguity ERROR, " + str(configs))
raise RTAMTException("Ambiguity ERROR, " + str(configs))

def reportAttemptingFullContext(self, recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs):
raise STLParseException("Attempting full context ERROR, " + str(configs))
raise RTAMTException("Attempting full context ERROR, " + str(configs))

def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs):
raise STLParseException("Context ERROR, " + str(configs))
raise RTAMTException("Context ERROR, " + str(configs))
15 changes: 10 additions & 5 deletions rtamt/exception/exception.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
class RTAMTException(Exception):
pass
def __init__(self, *args):
if args:
self.message = args[0]
else:
self.message = None

class AstVisitorException(RTAMTException):
pass
def __str__(self):
if self.message:
return 'RTAMT Exception: {0} '.format(self.message)
else:
return 'RTAMT Exception has been raised'

class AstParseException(RTAMTException):
pass
Empty file removed rtamt/exception/ltl/__init__.py
Empty file.
21 changes: 0 additions & 21 deletions rtamt/exception/ltl/exception.py

This file was deleted.

Empty file removed rtamt/exception/stl/__init__.py
Empty file.
19 changes: 0 additions & 19 deletions rtamt/exception/stl/exception.py

This file was deleted.

10 changes: 5 additions & 5 deletions rtamt/pastifier/ltl/horizon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rtamt.syntax.ast.visitor.ltl.ast_visitor import LtlAstVisitor

from rtamt.exception.ltl.exception import LTLPastifyException
from rtamt.exception.exception import RTAMTException


class LtlHorizon(LtlAstVisitor):
Expand Down Expand Up @@ -111,13 +111,13 @@ def visitXor(self, node, *args, **kwargs):
return max(op1_horizon, op2_horizon)

def visitEventually(self, node, *args, **kwargs):
raise LTLPastifyException('Cannot pastify an unbounded eventually.')
raise RTAMTException('Cannot pastify an unbounded eventually.')

def visitAlways(self, node, *args, **kwargs):
raise LTLPastifyException('Cannot pastify an unbounded always.')
raise RTAMTException('Cannot pastify an unbounded always.')

def visitUntil(self, node, *args, **kwargs):
raise LTLPastifyException('Cannot pastify an unbounded until.')
raise RTAMTException('Cannot pastify an unbounded until.')

def visitOnce(self, node, *args, **kwargs):
op_horizon = self.visit(node.children[0], *args, **kwargs)
Expand Down Expand Up @@ -146,4 +146,4 @@ def visitSince(self, node, *args, **kwargs):
return max(op1_horizon, op2_horizon)

def visitDefault(self, node):
raise LTLPastifyException('LTL Pastifier: encountered unexpected type of object.')
raise RTAMTException('LTL Pastifier: encountered unexpected type of object.')
10 changes: 5 additions & 5 deletions rtamt/pastifier/ltl/pastifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from rtamt.syntax.node.ltl.constant import Constant
from rtamt.syntax.node.ltl.previous import Previous

from rtamt.exception.ltl.exception import LTLPastifyException
from rtamt.exception.exception import RTAMTException
from rtamt.pastifier.ltl.horizon import LtlHorizon


Expand Down Expand Up @@ -154,13 +154,13 @@ def visitXor(self, node, *args, **kwargs):
return node

def visitEventually(self, node, *args, **kwargs):
raise LTLPastifyException('Cannot pastify an unbounded eventually.')
raise RTAMTException('Cannot pastify an unbounded eventually.')

def visitAlways(self, node, *args, **kwargs):
raise LTLPastifyException('Cannot pastify an unbounded always.')
raise RTAMTException('Cannot pastify an unbounded always.')

def visitUntil(self, node, *args, **kwargs):
raise LTLPastifyException('Cannot pastify an unbounded until.')
raise RTAMTException('Cannot pastify an unbounded until.')

def visitOnce(self, node, *args, **kwargs):
child_node = self.visit(node.children[0], *args, **kwargs)
Expand Down Expand Up @@ -189,4 +189,4 @@ def visitSince(self, node, *args, **kwargs):
return node

def visitDefault(self, node):
raise LTLPastifyException('LTL Pastifier: encountered unexpected type of object.')
raise RTAMTException('LTL Pastifier: encountered unexpected type of object.')
5 changes: 3 additions & 2 deletions rtamt/pastifier/stl/horizon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from rtamt.syntax.ast.visitor.stl.ast_visitor import StlAstVisitor
from rtamt.pastifier.ltl.horizon import LtlHorizon

from rtamt.exception.stl.exception import STLException
from rtamt.exception.exception import RTAMTException


class StlHorizon(LtlHorizon, StlAstVisitor):

Expand Down Expand Up @@ -50,4 +51,4 @@ def visitTimedPrecedes(self, node, *args, **kwargs):
return max(op1_horizon, op2_horizon)

def visitDefault(self, node):
raise STLException('STL Pastifier: encountered unexpected type of node.')
raise RTAMTException('STL Pastifier: encountered unexpected type of node.')
4 changes: 2 additions & 2 deletions rtamt/pastifier/stl/pastifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rtamt.syntax.node.stl.timed_once import TimedOnce
from rtamt.syntax.node.stl.timed_since import TimedSince

from rtamt.exception.stl.exception import STLException
from rtamt.exception.exception import RTAMTException
from rtamt.pastifier.stl.horizon import StlHorizon


Expand Down Expand Up @@ -93,4 +93,4 @@ def visitTimedPrecedes(self, node, *args, **kwargs):
return node

def visitDefault(self, node):
raise STLException('STL Pastifier: encountered unexpected type of node.')
raise RTAMTException('STL Pastifier: encountered unexpected type of node.')
12 changes: 6 additions & 6 deletions rtamt/semantics/stl/dense_time/offline/ast_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rtamt.syntax.ast.visitor.stl.ast_visitor import StlAstVisitor
from rtamt.semantics.enumerations.comp_oper import StlComparisonOperator

from rtamt.exception.stl.exception import STLNotImplementedException
from rtamt.exception.exception import RTAMTException

def subtraction_operation(sample_left, sample_right):
sample_return = []
Expand Down Expand Up @@ -558,26 +558,26 @@ def visitSince(self, node, *args, **kwargs):


def visitRise(self, node, *args, **kwargs):
raise STLNotImplementedException('Rise operator not implemented in STL dense monitor.')
raise RTAMTException('Rise operator not implemented in STL dense monitor.')

def visitFall(self, node, *args, **kwargs):
raise STLNotImplementedException('Fall operator not implemented in STL dense monitor.')
raise RTAMTException('Fall operator not implemented in STL dense monitor.')

#TODO: this code may not work.
def visitConstant(self, node, *args, **kwargs):
sample_return = [[0, node.val], [float("inf"), node.val]]
return sample_return

def visitPrevious(self, node, *args, **kwargs):
raise STLNotImplementedException('Previous operator not implemented in STL dense-time monitor.')
raise RTAMTException('Previous operator not implemented in STL dense-time monitor.')


def visitNext(self, node, *args, **kwargs):
raise STLNotImplementedException('Next operator not implemented in STL dense-time monitor.')
raise RTAMTException('Next operator not implemented in STL dense-time monitor.')


def visitTimedPrecedes(self, node, *args, **kwargs):
raise STLNotImplementedException('Precedes operator not implemented in STL dense-time monitor.')
raise RTAMTException('Precedes operator not implemented in STL dense-time monitor.')


def visitTimedOnce(self, node, *args, **kwargs):
Expand Down
25 changes: 12 additions & 13 deletions rtamt/semantics/stl/dense_time/online/ast_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
from rtamt.semantics.stl.dense_time.online.historically_timed_operation import HistoricallyTimedOperation
from rtamt.semantics.stl.dense_time.online.since_timed_operation import SinceTimedOperation

from rtamt.exception.stl.exception import STLNotImplementedException
from rtamt.exception.ltl.exception import LTLNotImplementedException
from rtamt.exception.exception import RTAMTException

class StlDenseTimeOnlineAstVisitor(StlAstVisitor):
def visitPredicate(self, node, *args, **kwargs):
Expand Down Expand Up @@ -89,13 +88,13 @@ def visitXor(self, node, *args, **kwargs):
self.online_operator_dict[node.name] = XorOperation()

def visitEventually(self, node, *args, **kwargs):
raise LTLNotImplementedException('Eventually operator is not implemented in the STL online monitor.')
raise RTAMTException('Eventually operator is not implemented in the STL online monitor.')

def visitAlways(self, node, *args, **kwargs):
raise LTLNotImplementedException('Always operator is not implemented in the STL online monitor.')
raise RTAMTException('Always operator is not implemented in the STL online monitor.')

def visitUntil(self, node, *args, **kwargs):
raise LTLNotImplementedException('Until operator is not implemented in the STL online monitor.')
raise RTAMTException('Until operator is not implemented in the STL online monitor.')

def visitOnce(self, node, *args, **kwargs):
self.visitChildren(node, *args, **kwargs)
Expand All @@ -110,19 +109,19 @@ def visitSince(self, node, *args, **kwargs):
self.online_operator_dict[node.name] = SinceOperation()

def visitRise(self, node, *args, **kwargs):
raise LTLNotImplementedException('Rise operator not implemented in STL dense monitor.')
raise RTAMTException('Rise operator not implemented in STL dense monitor.')

def visitFall(self, node, *args, **kwargs):
raise LTLNotImplementedException('Fall operator not implemented in STL dense monitor.')
raise RTAMTException('Fall operator not implemented in STL dense monitor.')

def visitPrevious(self, node, *args, **kwargs):
raise LTLNotImplementedException('Previous operator not implemented in STL dense-time monitor.')
raise RTAMTException('Previous operator not implemented in STL dense-time monitor.')

def visitNext(self, node, *args, **kwargs):
raise LTLNotImplementedException('Next operator not implemented in STL dense-time monitor.')
raise RTAMTException('Next operator not implemented in STL dense-time monitor.')

def visitTimedPrecedes(self, node, *args, **kwargs):
raise STLNotImplementedException('Precedes operator not implemented in STL dense-time monitor.')
raise RTAMTException('Precedes operator not implemented in STL dense-time monitor.')

def visitTimedOnce(self, node, *args, **kwargs):
self.visitChildren(node, *args, **kwargs)
Expand All @@ -140,10 +139,10 @@ def visitTimedSince(self, node, *args, **kwargs):
self.online_operator_dict[node.name] = SinceTimedOperation(begin, end)

def visitTimedAlways(self, node, *args, **kwargs):
raise STLNotImplementedException('Bounded always operator not implemented in STL dense-time monitor.')
raise RTAMTException('Bounded always operator not implemented in STL dense-time monitor.')

def visitTimedEventually(self, node, *args, **kwargs):
raise STLNotImplementedException('Bounded eventually operator not implemented in STL dense-time monitor.')
raise RTAMTException('Bounded eventually operator not implemented in STL dense-time monitor.')

def visitTimedUntil(self, node, *args, **kwargs):
raise STLNotImplementedException('Bounded until operator not implemented in STL dense-time monitor.')
raise RTAMTException('Bounded until operator not implemented in STL dense-time monitor.')
6 changes: 3 additions & 3 deletions rtamt/semantics/stl/dense_time/online/predicate_operation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rtamt.semantics.abstract_dense_time_online_operation import AbstractDenseTimeOnlineOperation
from rtamt.semantics.enumerations.comp_oper import StlComparisonOperator
from rtamt.semantics.arithmetic.dense_time.online.subtraction_operation import SubtractionOperation
from rtamt.exception.ltl.exception import LTLException
from rtamt.exception.exception import RTAMTException


class PredicateOperation(AbstractDenseTimeOnlineOperation):
Expand Down Expand Up @@ -83,7 +83,7 @@ def sat(self, sample_left, sample_right, *args, **kargs):
out_val = True if in_sample[1] > 0 else False
rval = in_sample[1]
else:
raise LTLException('Unknown predicate operation')
raise RTAMTException('Unknown predicate operation')

if rval != prev or i == len(input_list) - 1:
sample_result.append([in_sample[0], out_val])
Expand Down Expand Up @@ -116,7 +116,7 @@ def sat_final(self, sample_left, sample_right, *args, **kargs):
out_val = True if in_sample[1] > 0 else False
rval = in_sample[1]
else:
raise LTLException('Unknown predicate operation')
raise RTAMTException('Unknown predicate operation')

if rval != prev or i == len(input_list) - 1:
sample_result.append([in_sample[0], out_val])
Expand Down
7 changes: 3 additions & 4 deletions rtamt/semantics/stl/discrete_time/offline/ast_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from rtamt.syntax.ast.visitor.stl.ast_visitor import StlAstVisitor
from rtamt.semantics.enumerations.comp_oper import StlComparisonOperator
from rtamt.exception.stl.exception import STLException
from rtamt.exception.exception import RTAMTException


class StlDiscreteTimeOfflineAstVisitor(StlAstVisitor):
Expand All @@ -24,7 +24,7 @@ def visitPredicate(self, node, *args, **kwargs):
elif node.operator.value == StlComparisonOperator.GEQ.value or node.operator.value == StlComparisonOperator.GREATER.value:
val = sample_left[i] - sample_right[i]
else:
raise STLException('Unknown predicate operation')
raise RTAMTException('Unknown predicate operation')
sample_return.append(val)
return sample_return

Expand Down Expand Up @@ -292,8 +292,7 @@ def visitNext(self, node, *args, **kwargs):


def visitTimedPrecedes(self, node, *args, **kwargs):
#TODO consider correct exception
raise STLException('Offline does not need visitTimedPrecedes')
raise RTAMTException('Offline does not need visitTimedPrecedes')


def visitTimedOnce(self, node, *args, **kwargs):
Expand Down
Loading

0 comments on commit bea96b6

Please sign in to comment.