Commit d0816dba authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fix with unicode

parent 3745cd22
......@@ -647,8 +647,6 @@ def _task_forloop(task):
stop_stmt, stop_str, stop_local = expression(loop['range']['stop'])
local_decl.extend(stop_local)
stmt.extend(stop_stmt)
#if isinstance(loop['range']['stop'], ogAST.PrimInteger):
# stop_str = 'Integer({})'.format(stop_str)
if loop['range']['step'] == 1:
if unicode.isnumeric(stop_str):
stop_str = unicode(int(stop_str) - 1)
......@@ -896,7 +894,7 @@ def _prim_path(primary_id):
ada_string += ', '.join(list_of_params)
ada_string += ')'
sep = '.'
return stmts, ada_string, local_decl
return stmts, unicode(ada_string), local_decl
@expression.register(ogAST.ExprPlus)
......@@ -923,7 +921,7 @@ def _basic_operators(expr):
code.extend(right_stmts)
local_decl.extend(left_local)
local_decl.extend(right_local)
return code, ada_string, local_decl
return code, unicode(ada_string), local_decl
@expression.register(ogAST.ExprOr)
......@@ -939,7 +937,7 @@ def _bitwise_operators(expr):
# Sequence of boolean or bit string
if expr.right.is_raw:
# Declare a temporary variable to store the raw value
tmp_string = 'tmp{}'.format(expr.right.tmpVar)
tmp_string = u'tmp{}'.format(expr.right.tmpVar)
local_decl.append(u'{tmp} : aliased asn1Scc{eType};'.format(
tmp=tmp_string,
eType=expr.right.exprType.ReferencedTypeName
......@@ -962,7 +960,7 @@ def _bitwise_operators(expr):
code.extend(right_stmts)
local_decl.extend(left_local)
local_decl.extend(right_local)
return code, ada_string, local_decl
return code, unicode(ada_string), local_decl
@expression.register(ogAST.ExprNot)
......@@ -974,7 +972,7 @@ def _unary_operator(expr):
ada_string = u'({op} {expr})'.format(op=expr.operand, expr=expr_str)
code.extend(expr_stmts)
local_decl.extend(expr_local)
return code, ada_string, local_decl
return code, unicode(ada_string), local_decl
@expression.register(ogAST.ExprAppend)
......@@ -1043,7 +1041,7 @@ def _append(expr):
rid=expr.right.sid, l2=expr.right.slen))
stmts.append('{res}.Length := {l1} + {l2};'.format(
res=ada_string, l1=expr.left.slen, l2=expr.right.slen))
return stmts, ada_string, local_decl
return stmts, unicode(ada_string), local_decl
......@@ -1075,7 +1073,7 @@ def _expr_in(expr):
stmts.append("exit in_loop_{tmp} when {tmp} = True;"
.format(tmp=ada_string))
stmts.append("end loop in_loop_{};".format(ada_string))
return stmts, ada_string, local_decl
return stmts, unicode(ada_string), local_decl
@expression.register(ogAST.PrimEnumeratedValue)
......@@ -1083,8 +1081,8 @@ def _enumerated_value(primary):
''' Generate code for an enumerated value '''
enumerant = primary.value[0].replace('_', '-')
basic = find_basic_type(primary.exprType)
ada_string = ('asn1Scc' + basic.EnumValues[enumerant].EnumID)
return [], ada_string, []
ada_string = (u'asn1Scc' + basic.EnumValues[enumerant].EnumID)
return [], unicode(ada_string), []
@expression.register(ogAST.PrimChoiceDeterminant)
......@@ -1092,7 +1090,7 @@ def _choice_determinant(primary):
''' Generate code for a choice determinant (enumerated) '''
enumerant = primary.value[0].replace('_', '-')
ada_string = primary.exprType.EnumValues[enumerant].EnumID
return [], ada_string, []
return [], unicode(ada_string), []
@expression.register(ogAST.PrimInteger)
......@@ -1100,26 +1098,27 @@ def _choice_determinant(primary):
def _integer(primary):
''' Generate code for a raw numerical value '''
if float(primary.value[0]) < 0:
# Parentesize negative integers for maintaining the precedence in the generated code
ada_string = '({})'.format(primary.value[0])
# Parentesize negative integers for maintaining
# the precedence in the generated code
ada_string = u'({})'.format(primary.value[0])
else:
ada_string = primary.value[0]
return [], ada_string, []
return [], unicode(ada_string), []
@expression.register(ogAST.PrimBoolean)
def _integer(primary):
''' Generate code for a raw boolean value '''
ada_string = primary.value[0]
return [], ada_string, []
return [], unicode(ada_string), []
@expression.register(ogAST.PrimEmptyString)
def _empty_string(primary):
''' Generate code for an empty SEQUENCE OF: {} '''
ada_string = 'asn1Scc{typeRef}_Init'.format(
ada_string = u'asn1Scc{typeRef}_Init'.format(
typeRef=primary.exprType.ReferencedTypeName.replace('-', '_'))
return [], ada_string, []
return [], unicode(ada_string), []
@expression.register(ogAST.PrimStringLiteral)
......@@ -1130,20 +1129,20 @@ def _string_literal(primary):
# then convert the string to an array of unsigned_8 integers
# as expected by the Ada type corresponding to Octet String
unsigned_8 = [str(ord(val)) for val in primary.value[1:-1]]
ada_string = '(Data => (' + ', '.join(
ada_string = u'(Data => (' + ', '.join(
unsigned_8) + ', others => 0)'
if basic_type.Min != basic_type.Max:
# Non-fixed string size -> add Length field
ada_string += ', Length => {}'.format(
ada_string += u', Length => {}'.format(
str(len(primary.value[1:-1])))
ada_string += ')'
return [], ada_string, []
return [], unicode(ada_string), []
@expression.register(ogAST.PrimConstant)
def _constant(primary):
''' Generate code for a reference to an ASN.1 constant '''
return [], primary.value[0], []
return [], unicode(primary.value[0]), []
@expression.register(ogAST.PrimMantissaBaseExp)
......@@ -1151,7 +1150,7 @@ def _mantissa_base_exp(primary):
''' Generate code for a Real with Mantissa-base-Exponent representation '''
# TODO
_ = primary
return [], '', []
return [], u'', []
@expression.register(ogAST.PrimIfThenElse)
......@@ -1196,7 +1195,7 @@ def _if_then_else(ifThenElse):
else_str=else_str))
stmts.append('end if;')
ada_string = u'tmp{idx}'.format(idx=ifThenElse.value['tmpVar'])
return stmts, ada_string, local_decl
return stmts, unicode(ada_string), local_decl
@expression.register(ogAST.PrimSequence)
......@@ -1220,7 +1219,7 @@ def _sequence(seq):
stmts.extend(value_stmts)
local_decl.extend(local_var)
ada_string += ')'
return stmts, ada_string, local_decl
return stmts, unicode(ada_string), local_decl
@expression.register(ogAST.PrimSequenceOf)
......@@ -1253,7 +1252,7 @@ def _sequence_of(seqof):
local_decl.extend(local_var)
ada_string += '{i} => {value}, '.format(i=i + 1, value=item_str)
ada_string += 'others => {anyVal}))'.format(anyVal=item_str)
return stmts, ada_string, local_decl
return stmts, unicode(ada_string), local_decl
@expression.register(ogAST.PrimChoiceItem)
......@@ -1268,7 +1267,7 @@ def _choiceitem(choice):
cType=actual_type,
opt=choice.value['choice'],
expr=choice_str)
return stmts, ada_string, local_decl
return stmts, unicode(ada_string), local_decl
@generate.register(ogAST.Decision)
......
......@@ -20,7 +20,7 @@ compile-all:
install: compile-all
mkdir -p opengeode
for f in AdaGenerator.py __init__.py genericSymbols.py icons.py ogAST.py ogParser.py opengeode.py Renderer.py samnmax.py sdl92Lexer.py sdl92Parser.py sdlSymbols.py undoCommands.py Clipboard.py Statechart.py LlvmGenerator.py Lander.py Helper.py Connectors.py; do echo Installing $$f && cp $$f opengeode; done
for f in AdaGenerator.py __init__.py genericSymbols.py icons.py ogAST.py ogParser.py opengeode.py Renderer.py samnmax.py sdl92Lexer.py sdl92Parser.py sdlSymbols.py undoCommands.py Clipboard.py Statechart.py LlvmGenerator.py Lander.py Helper.py Connectors.py Asn1scc.py; do echo Installing $$f && cp $$f opengeode; done
python setup.py install
publish: install
......
......@@ -106,8 +106,9 @@ def recursive_aligned(symbol):
def generate(symbol, *args, **kwargs):
''' Generate text for a symbol, recursively or not - return a list of
strings '''
_, _ = symbol, recursive
raise NotImplementedError('[PR Generator] Unsupported AST construct')
_ = symbol
raise NotImplementedError('Unsupported AST construct: {}'
.format(type(symbol)))
return Indent()
......
......@@ -145,6 +145,15 @@ The fonts are the fonts from Ubuntu, check licence in file FONT-LICENSE.TXT
Changelog
=========
0.993 (07/2014)
- Parser bugfixes
- Better support for nested states
- Ada generator improvements
- Support for unicode
- Indentation of PR code
- Copy-paste of procedures and nested states
- Improved regression testing
0.99 (04/2014)
- Refactoring of the backend engine, now using singledispatch
- Support of hierachical states
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module is a free SDL editor.
It allows to graphically design state machines, using a formal, well-
defined language, and generate Ada code from the models.
"""
__version__ = "0.992"
from opengeode import opengeode
from opengeode import opengeode, __version__
......@@ -306,6 +306,25 @@ class EditableText(QGraphicsTextItem, object):
text_cursor = self.textCursor()
text_cursor.select(QTextCursor.WordUnderCursor)
self.completion_prefix = text_cursor.selectedText()
# Work in progress - to support advanced autocompletion
tmp = self.textCursor()
pos = tmp.positionInBlock()
tmp.select(QTextCursor.BlockUnderCursor)
try:
import string
line = tmp.selectedText()
if line[pos] in string.ascii_letters + '!' + '.' + '_':
last_word = line[slice(0, pos + 1)].split()[-1]
else:
last_word = ''
except IndexError:
pass
else:
pass
# print last_word.encode('utf-8')
# -- END
completion_count = self.completer.set_completion_prefix(
self.completion_prefix)
if event.key() in (Qt.Key_Period, Qt.Key_Exclam):
......
......@@ -2,7 +2,7 @@
# Resource object code
#
# Created: Wed Jul 2 08:06:50 2014
# Created: Sun Jul 13 22:01:20 2014
# by: The Resource Compiler for PySide (Qt v4.8.6)
#
# WARNING! All changes made in this file will be lost!
......@@ -98,7 +98,7 @@ except ImportError:
pass
__all__ = ['opengeode']
__version__ = '0.992'
__version__ = '0.993'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-07-10 16:56:08
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-07-13 22:01:22
import sys
from antlr3 import *
......
This diff is collapsed.
......@@ -25,4 +25,4 @@ SYSTEM og;
ENDBLOCK;
ENDSYSTEM;
\ No newline at end of file
ENDSYSTEM;
/* CIF PROCESS (150, 150), (150, 75) */
/* CIF PROCESS (288, 143), (150, 75) */
PROCESS trafficlight;
STATE Maintenance;
SUBSTRUCTURE
STATE YellowOff;
SUBSTRUCTURE
/* CIF PROCEDURE (239, 367), (73, 35) */
PROCEDURE entry;
/* CIF START (180, 35), (70, 35) */
START;
/* CIF PROCEDURECALL (122, 85), (186, 35) */
CALL set_timer(500, timeout);
/* CIF OUTPUT (109, 135), (211, 35) */
OUTPUT SetTrafficLightColor(all_off);
/* CIF RETURN (197, 185), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF START (348, 437), (70, 35) */
START;
/* CIF NEXTSTATE (348, 487), (70, 35) */
NEXTSTATE idle;
/* CIF STATE (558, 458), (70, 35) */
STATE idle;
ENDSTATE;
ENDSUBSTRUCTURE;
STATE YellowOn;
SUBSTRUCTURE
/* CIF PROCEDURE (291, 312), (73, 35) */
PROCEDURE entry;
/* CIF START (292, 124), (70, 35) */
START;
/* CIF PROCEDURECALL (234, 174), (186, 35) */
CALL set_timer(500, timeout);
/* CIF OUTPUT (221, 224), (211, 35) */
OUTPUT SetTrafficLightColor(yellow);
/* CIF RETURN (309, 274), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF START (495, 331), (70, 35) */
START;
/* CIF NEXTSTATE (489, 381), (81, 35) */
NEXTSTATE idle;
/* CIF STATE (696, 342), (67, 35) */
STATE idle;
ENDSTATE;
ENDSUBSTRUCTURE;
/* CIF START (752, 254), (70, 35) */
START;
/* CIF PROCEDURECALL (671, 304), (231, 35) */
CALL writeln('Entering Maintenance');
/* CIF NEXTSTATE (740, 354), (94, 35) */
NEXTSTATE YellowOn;
/* CIF STATE (738, 459), (97, 35) */
STATE YellowOff;
/* CIF INPUT (743, 514), (87, 35) */
INPUT timeout;
/* CIF NEXTSTATE (736, 564), (102, 35) */
NEXTSTATE YellowOn;
ENDSTATE;
/* CIF STATE (740, 354), (94, 35) */
STATE YellowOn;
/* CIF INPUT (743, 409), (87, 35) */
INPUT timeout;
/* CIF NEXTSTATE (738, 459), (97, 35) */
NEXTSTATE YellowOff;
ENDSTATE;
ENDSUBSTRUCTURE;
STATE on;
SUBSTRUCTURE
STATE PedWaiting;
SUBSTRUCTURE
out (counter_expired);
out (counter_expired);
STATE waitOn;
SUBSTRUCTURE
/* CIF PROCEDURE (560, 288), (70, 35) */
PROCEDURE exit;
/* CIF START (280, 159), (70, 35) */
START;
/* CIF TASK (198, 209), (233, 35) */
TASK counter := (counter + 1) mod 255;
/* CIF RETURN (297, 259), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF PROCEDURE (548, 222), (73, 35) */
PROCEDURE entry;
/* CIF START (185, 47), (70, 35) */
START;
/* CIF PROCEDURECALL (125, 97), (189, 35) */
CALL set_timer(500, timeout);
/* CIF RETURN (202, 147), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF START (371, 56), (70, 35) */
START;
/* CIF NEXTSTATE (347, 106), (117, 35) */
NEXTSTATE wait_counter;
/* CIF STATE (510, 120), (117, 35) */
STATE wait_counter;
ENDSTATE;
ENDSUBSTRUCTURE;
/* CIF TEXT (93, 69), (184, 53) */
-- 7 sec counter
/* CIF PROCEDURE (548, 222), (73, 35) */
PROCEDURE entry;
/* CIF START (185, 47), (70, 35) */
START;
/* CIF PROCEDURECALL (125, 97), (189, 35) */
CALL set_timer(500, timeout);
/* CIF RETURN (202, 147), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF PROCEDURE (560, 288), (70, 35) */
PROCEDURE exit;
/* CIF START (280, 159), (70, 35) */
START;
/* CIF TASK (198, 209), (233, 35) */
TASK counter := (counter + 1) mod 255;
/* CIF RETURN (297, 259), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF START (371, 56), (70, 35) */
START;
/* CIF NEXTSTATE (347, 106), (117, 35) */
NEXTSTATE wait_counter;
/* CIF STATE (510, 120), (117, 35) */
STATE wait_counter;
ENDSTATE;
ENDSUBSTRUCTURE;
/* CIF TEXT (93, 69), (184, 53) */
-- 7 sec counter
dcl counter t_uint8 := 0;
dcl color Light;
/* CIF ENDTEXT */
/* CIF PROCEDURE (129, 166), (73, 35) */
PROCEDURE entry;
/* CIF START (383, 113), (70, 35) */
START;
/* CIF PROCEDURECALL (310, 163), (216, 35) */
CALL writeln('Pedestrian request');
/* CIF TASK (359, 213), (117, 35) */
TASK counter := 0;
/* CIF RETURN (400, 263), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF START (348, 130), (81, 35) */
START;
/* CIF NEXTSTATE (348, 180), (80, 35) */
NEXTSTATE waitOn;
/* CIF STATE (348, 180), (80, 35) */
STATE waitOn;
/* CIF INPUT (345, 235), (87, 35) */
INPUT timeout;
/* CIF DECISION (345, 285), (86, 50) */
DECISION counter;
/* CIF ANSWER (161, 355), (70, 23) */
(14):
/* CIF PROCEDURECALL (87, 393), (218, 35) */
CALL writeln('Leaving PedWaiting');
/* CIF RETURN (178, 443), (35, 35) */
RETURN counter_expired;
/* CIF ANSWER (465, 355), (70, 23) */
ELSE:
/* CIF TASK (315, 393), (370, 35) */
TASK color := if counter mod 2 = 0 then red else all_off fi;
/* CIF OUTPUT (400, 443), (199, 35) */
OUTPUT SetPedestrianColor(color);
/* CIF NEXTSTATE (465, 493), (70, 35) */
NEXTSTATE -;
ENDDECISION;
ENDSTATE;
ENDSUBSTRUCTURE;
/* CIF START (721, 150), (70, 35) */
START;
/* CIF NEXTSTATE (698, 200), (115, 35) */
NEXTSTATE StreetGreen;
/* CIF STATE (1013, 592), (141, 35) */
STATE StreetPrepare;
/* CIF INPUT (1040, 647), (87, 35) */
INPUT timeout;
/* CIF OUTPUT (978, 697), (211, 35) */
OUTPUT SetTrafficLightColor(green);
/* CIF NEXTSTATE (1013, 747), (141, 35) */
NEXTSTATE StreetGreen;
ENDSTATE;
/* CIF STATE (1013, 387), (141, 35) */
STATE PedestrianRed;
/* CIF INPUT (1040, 442), (87, 35) */
INPUT timeout;
/* CIF PROCEDURECALL (987, 492), (193, 35) */
CALL set_timer(2000, timeout);
/* CIF OUTPUT (978, 542), (211, 35) */
OUTPUT SetTrafficLightColor(yellow);
/* CIF NEXTSTATE (1013, 592), (141, 35) */
NEXTSTATE StreetPrepare;
ENDSTATE;
/* CIF STATE (1013, 182), (141, 35) */
STATE PedestrianGreen;
/* CIF INPUT (1040, 237), (87, 35) */
INPUT timeout;
/* CIF PROCEDURECALL (987, 287), (193, 35) */
CALL set_timer(5000, timeout);
/* CIF OUTPUT (982, 337), (203, 35) */
OUTPUT SetPedestrianColor(red);
/* CIF NEXTSTATE (1013, 387), (141, 35) */
NEXTSTATE PedestrianRed;
ENDSTATE;
/* CIF STATE (704, 773), (102, 35) */
STATE StreetRed;
/* CIF INPUT (712, 828), (87, 35) */
INPUT timeout;
/* CIF PROCEDURECALL (659, 878), (193, 35) */
CALL set_timer(7000, timeout);
/* CIF OUTPUT (654, 928), (203, 35) */
OUTPUT SetPedestrianColor(green);
/* CIF NEXTSTATE (685, 978), (141, 35) */
NEXTSTATE PedestrianGreen;
ENDSTATE;
/* CIF STATE (679, 568), (151, 35) */
STATE StreetAttention;
/* CIF INPUT (711, 623), (87, 35) */
INPUT timeout;
/* CIF PROCEDURECALL (647, 673), (214, 35) */
CALL set_timer(2000, timeout);
/* CIF OUTPUT (649, 723), (211, 35) */
OUTPUT SetTrafficLightColor(red);
/* CIF NEXTSTATE (704, 773), (102, 35) */
NEXTSTATE StreetRed;
ENDSTATE;
/* CIF STATE (702, 313), (107, 35) */
STATE PedWaiting;
/* CIF CONNECT (755, 368), (0, 35) */
CONNECT counter_expired;
/* CIF PROCEDURECALL (652, 418), (205, 35) */
CALL writeln('counter_expired');
/* CIF PROCEDURECALL (658, 468), (193, 35) */
CALL set_timer(2000, timeout);
/* CIF OUTPUT (649, 518), (211, 35) */
OUTPUT SetTrafficLightColor(yellow);
/* CIF NEXTSTATE (679, 568), (151, 35) */
NEXTSTATE StreetAttention;
ENDSTATE;
/* CIF STATE (698, 200), (115, 35) */
STATE StreetGreen;
/* CIF INPUT (678, 255), (155, 38) */
INPUT PedestrianRequest
/* CIF ENDTEXT */
/* CIF PROCEDURE (129, 166), (73, 35) */
PROCEDURE entry;
/* CIF START (383, 113), (70, 35) */
START;
/* CIF PROCEDURECALL (310, 163), (216, 35) */
CALL writeln('Pedestrian request');
/* CIF TASK (359, 213), (117, 35) */
TASK counter := 0;
/* CIF RETURN (400, 263), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF START (348, 130), (81, 35) */
START;
/* CIF NEXTSTATE (348, 180), (80, 35) */
NEXTSTATE waitOn;
/* CIF STATE (348, 180), (80, 35) */
STATE waitOn;
/* CIF INPUT (345, 235), (87, 35) */
INPUT timeout;
/* CIF DECISION (345, 285), (86, 50) */
DECISION counter;
/* CIF ANSWER (161, 355), (70, 23) */
(14):
/* CIF PROCEDURECALL (87, 393), (218, 35) */
CALL writeln('Leaving PedWaiting');
/* CIF RETURN (178, 443), (35, 35) */
RETURN counter_expired;
/* CIF ANSWER (465, 355), (70, 23) */
ELSE:
/* CIF TASK (315, 393), (370, 35) */
TASK color := if counter mod 2 = 0 then red else all_off fi;
/* CIF OUTPUT (400, 443), (199, 35) */
OUTPUT SetPedestrianColor(color);
/* CIF NEXTSTATE (465, 493), (70, 35) */
NEXTSTATE -;
ENDDECISION;
ENDSTATE;
ENDSUBSTRUCTURE;
/* CIF START (721, 150), (70, 35) */
START;
/* CIF NEXTSTATE (698, 200), (115, 35) */
NEXTSTATE StreetGreen;
/* CIF STATE (1013, 592), (141, 35) */
STATE StreetPrepare;
/* CIF INPUT (1040, 647), (87, 35) */
INPUT timeout;
/* CIF OUTPUT (978, 697), (211, 35) */
OUTPUT SetTrafficLightColor(green);
/* CIF NEXTSTATE (1013, 747), (141, 35) */
NEXTSTATE StreetGreen;
ENDSTATE;
/* CIF STATE (1013, 387), (141, 35) */
STATE PedestrianRed;
/* CIF INPUT (1040, 442), (87, 35) */
INPUT timeout;
/* CIF PROCEDURECALL (987, 492), (193, 35) */
CALL set_timer(2000, timeout);
/* CIF OUTPUT (978, 542), (211, 35) */
OUTPUT SetTrafficLightColor(yellow);
/* CIF NEXTSTATE (1013, 592), (141, 35) */
NEXTSTATE StreetPrepare;
ENDSTATE;
/* CIF STATE (1013, 182), (141, 35) */
STATE PedestrianGreen;
/* CIF INPUT (1040, 237), (87, 35) */
INPUT timeout;
/* CIF PROCEDURECALL (987, 287), (193, 35) */
CALL set_timer(5000, timeout);
/* CIF OUTPUT (982, 337), (203, 35) */
OUTPUT SetPedestrianColor(red);
/* CIF NEXTSTATE (1013, 387), (141, 35) */