diff --git a/library/cadbiom/models/biosignal/translators/gt_visitors.py b/library/cadbiom/models/biosignal/translators/gt_visitors.py index cd9b4cf760056d5021fcf5d6160b3c7f4152731c..1841c2f07edc70e524ecd57ebccc45c19a139cd8 100644 --- a/library/cadbiom/models/biosignal/translators/gt_visitors.py +++ b/library/cadbiom/models/biosignal/translators/gt_visitors.py @@ -41,7 +41,6 @@ """ Utilities for compiling conditions, event and constraints """ -#import sys from antlr3 import ANTLRStringStream, CommonTokenStream, RecognitionException from cadbiom.models.biosignal.translators.sigexpr_lexer import sigexpr_lexer @@ -57,17 +56,17 @@ INACT = "_inac" UPDAT = "_update" +def compile_cond(text, symb_table, error_reporter, deep=-1, message=""): + """Compile a condition expression to a tree representation -def compile_cond(text, symb_table, error_reporter, deep = -1, message = ""): - """ - Compile a condition expression to a tree representation @param text: string to be compiled @param symb_table: symbol table of the compiler @param error_reporter: use a CompilReporter for full information!! @param deep: optional - if >0 the compiler doesn't accept states declared inside macro + @return: a tree representing the expression """ - text_c = text+" $" + text_c = text + " $" reader = ANTLRStringStream(text_c) lexer = sigexpr_lexer(reader) parser = sigexpr_compiler(CommonTokenStream(lexer)) @@ -80,48 +79,51 @@ def compile_cond(text, symb_table, error_reporter, deep = -1, message = ""): parser.state_only = True try: tree = parser.sig_bool(symb_table) - except RecognitionException , exc: + except RecognitionException as exc: if error_reporter: - error_reporter.display( 'Error in condition: %s'%exc) + error_reporter.display("Error in condition: %s" % exc) parser.displayExceptionMessage(exc) return None else: raise exc return tree.exp + def compile_constraint(const_txt, symb_table, error_reporter): - """ - Compile a constraint expression to a tree representation + """Compile a constraint expression to a tree representation + @param const_txt: string to be compiled @param symb_table: symbol table of the compiler @param error_reporter: output error messages @return: a tree representing the expression """ - text_c = const_txt+" $" + text_c = const_txt + " $" reader = ANTLRStringStream(text_c) lexer = sigexpr_lexer(reader) parser = sigexpr_compiler(CommonTokenStream(lexer)) parser.set_error_reporter(error_reporter) try: tree = parser.sig_expression(symb_table) - except RecognitionException , exc: - error_reporter.display('Error in constraints: %s'%exc) + except RecognitionException as exc: + error_reporter.display("Error in constraints: %s" % exc) parser.displayExceptionMessage(exc) return None return tree.exp + def compile_event(text, symb_table, free_clocks, error_reporter): - """ - Compile an event expression to a tree representation + """Compile an event expression to a tree representation + @param text: string to be compiled @param symb_table: symbol table of the compiler @param free_clocks: boolean if true free clocks are collected @param error_reporter: output error messages - @return: a triple exp, se, fc where exp is the event expression, - se the state events (s#> ..) used and - fc is the free clocks used in the event expression. + @return: a triple exp, se, fc + where exp is the event expression, + se the state events (s#> ..) used and + fc is the free clocks used in the event expression. """ - text_c = text+' $' + text_c = text + " $" reader = ANTLRStringStream(text_c) lexer = sigexpr_lexer(reader) # default options on compiler (state_only = False) @@ -132,9 +134,8 @@ def compile_event(text, symb_table, free_clocks, error_reporter): parser.state_only_in_bool = True try: tree = parser.sig_expression(symb_table) - except RecognitionException , exc: - error_reporter.display('Error in event: %s'%exc) + except RecognitionException as exc: + error_reporter.display("Error in event: %s" % exc) parser.displayExceptionMessage(exc) return None return tree.exp, parser.state_events, parser.free_clocks -