Commit 5ba1bf19 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Parse, generate code and print the result

parent 1fe01443
......@@ -29,22 +29,18 @@ import argparse
from ColorFormatter import ColorFormatter
import opengeode
# Set up the logging facilities
log = logging.getLogger(__name__)
terminal_formatter = logging.Formatter(
fmt="%(levelname)s - %(name)s: %(message)s")
handler_console = logging.StreamHandler()
handler_console.setLevel(logging.DEBUG)
handler_console.setFormatter(terminal_formatter)
log.addHandler(handler_console)
# Make sure the gui can import modules in the current directory
sys.path.insert(0, '.')
console = logging.StreamHandler(sys.__stdout__)
console.setFormatter(ColorFormatter())
log.addHandler(console)
def parse_input_files(pr_files, ppty_file):
''' Invoke opengeode to parse the SDL models and use the expression
parser to analyse the properties (stop conditions) '''
# Parse the SDL model
try:
ast = opengeode.parse(pr_files)
process = ast[0].processes[0]
......@@ -52,18 +48,37 @@ def parse_input_files(pr_files, ppty_file):
raise IOError('SDL Parser failed - {}'.format(err))
log.info('SDL parser OK')
# Parse the stop conditions (property file)
stop_conditions = []
with open(ppty_file, 'r') as ppties:
for line in ppties.readlines():
if not line.strip():
continue
expr, syntax, semantic, warnings, term = \
opengeode.ogParser.parseSingleElement('stop_if', line, process)
if syntax or semantic or warnings:
log.error('Error in expression: {}'.format(line))
else:
stop_conditions.append(expr)
# Set the context in the Ada generator
if stop_conditions:
opengeode.AdaGenerator.TYPES = process.dataview
opengeode.AdaGenerator.VARIABLES = process.variables
opengeode.AdaGenerator.PROCEDURES = process.procedures
opengeode.AdaGenerator.OUT_SIGNALS = process.output_signals
# Generate Ada code for each stop condition
for each in stop_conditions:
stmts, string, local_decl = opengeode.AdaGenerator.expression(each)
log.info(string)
def cli():
''' Application entry point, when used from the command line '''
version = 'Taste Properties version {}'.format(__version__)
# Set up the logging facilities
log = logging.getLogger("properties")
console = logging.StreamHandler(sys.__stdout__)
console.setFormatter(ColorFormatter())
log.addHandler(console)
# Parse the command line
parser = argparse.ArgumentParser(version=version)
parser.add_argument('-g', '--verbose', action='store_true', default=False,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment