Mentions légales du service

Skip to content
Snippets Groups Projects
Commit c05baab5 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib] PEP Format gt_visitors.py

parent a142eaf4
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
""" """
Utilities for compiling conditions, event and constraints Utilities for compiling conditions, event and constraints
""" """
#import sys
from antlr3 import ANTLRStringStream, CommonTokenStream, RecognitionException from antlr3 import ANTLRStringStream, CommonTokenStream, RecognitionException
from cadbiom.models.biosignal.translators.sigexpr_lexer import sigexpr_lexer from cadbiom.models.biosignal.translators.sigexpr_lexer import sigexpr_lexer
...@@ -57,17 +56,17 @@ INACT = "_inac" ...@@ -57,17 +56,17 @@ INACT = "_inac"
UPDAT = "_update" 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 text: string to be compiled
@param symb_table: symbol table of the compiler @param symb_table: symbol table of the compiler
@param error_reporter: use a CompilReporter for full information!! @param error_reporter: use a CompilReporter for full information!!
@param deep: optional - if >0 the compiler doesn't accept states @param deep: optional - if >0 the compiler doesn't accept states
declared inside macro declared inside macro
@return: a tree representing the expression
""" """
text_c = text+" $" text_c = text + " $"
reader = ANTLRStringStream(text_c) reader = ANTLRStringStream(text_c)
lexer = sigexpr_lexer(reader) lexer = sigexpr_lexer(reader)
parser = sigexpr_compiler(CommonTokenStream(lexer)) parser = sigexpr_compiler(CommonTokenStream(lexer))
...@@ -80,48 +79,51 @@ def compile_cond(text, symb_table, error_reporter, deep = -1, message = ""): ...@@ -80,48 +79,51 @@ def compile_cond(text, symb_table, error_reporter, deep = -1, message = ""):
parser.state_only = True parser.state_only = True
try: try:
tree = parser.sig_bool(symb_table) tree = parser.sig_bool(symb_table)
except RecognitionException , exc: except RecognitionException as exc:
if error_reporter: if error_reporter:
error_reporter.display( 'Error in condition: %s'%exc) error_reporter.display("Error in condition: %s" % exc)
parser.displayExceptionMessage(exc) parser.displayExceptionMessage(exc)
return None return None
else: else:
raise exc raise exc
return tree.exp return tree.exp
def compile_constraint(const_txt, symb_table, error_reporter): 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 const_txt: string to be compiled
@param symb_table: symbol table of the compiler @param symb_table: symbol table of the compiler
@param error_reporter: output error messages @param error_reporter: output error messages
@return: a tree representing the expression @return: a tree representing the expression
""" """
text_c = const_txt+" $" text_c = const_txt + " $"
reader = ANTLRStringStream(text_c) reader = ANTLRStringStream(text_c)
lexer = sigexpr_lexer(reader) lexer = sigexpr_lexer(reader)
parser = sigexpr_compiler(CommonTokenStream(lexer)) parser = sigexpr_compiler(CommonTokenStream(lexer))
parser.set_error_reporter(error_reporter) parser.set_error_reporter(error_reporter)
try: try:
tree = parser.sig_expression(symb_table) tree = parser.sig_expression(symb_table)
except RecognitionException , exc: except RecognitionException as exc:
error_reporter.display('Error in constraints: %s'%exc) error_reporter.display("Error in constraints: %s" % exc)
parser.displayExceptionMessage(exc) parser.displayExceptionMessage(exc)
return None return None
return tree.exp return tree.exp
def compile_event(text, symb_table, free_clocks, error_reporter): 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 text: string to be compiled
@param symb_table: symbol table of the compiler @param symb_table: symbol table of the compiler
@param free_clocks: boolean if true free clocks are collected @param free_clocks: boolean if true free clocks are collected
@param error_reporter: output error messages @param error_reporter: output error messages
@return: a triple exp, se, fc where exp is the event expression, @return: a triple exp, se, fc
se the state events (s#> ..) used and where exp is the event expression,
fc is the free clocks used in 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) reader = ANTLRStringStream(text_c)
lexer = sigexpr_lexer(reader) lexer = sigexpr_lexer(reader)
# default options on compiler (state_only = False) # default options on compiler (state_only = False)
...@@ -132,9 +134,8 @@ def compile_event(text, symb_table, free_clocks, error_reporter): ...@@ -132,9 +134,8 @@ def compile_event(text, symb_table, free_clocks, error_reporter):
parser.state_only_in_bool = True parser.state_only_in_bool = True
try: try:
tree = parser.sig_expression(symb_table) tree = parser.sig_expression(symb_table)
except RecognitionException , exc: except RecognitionException as exc:
error_reporter.display('Error in event: %s'%exc) error_reporter.display("Error in event: %s" % exc)
parser.displayExceptionMessage(exc) parser.displayExceptionMessage(exc)
return None return None
return tree.exp, parser.state_events, parser.free_clocks return tree.exp, parser.state_events, parser.free_clocks
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment