Commit 506cc52d authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Support value notation for empty sequences

parent 1c77933f
......@@ -142,6 +142,9 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
1.3.17 (04/2016)
- Add support for value notation of empty SEQUENCEs ("{}")
1.3.16 (03/2016)
- Bugfix in testing aggregation states in the GUI
......
......@@ -683,13 +683,19 @@ def check_type_compatibility(primary, type_ref, context):
elif isinstance(primary, ogAST.PrimBoolean) and is_boolean(type_ref):
return
elif (isinstance(primary, ogAST.PrimEmptyString) and
basic_type.kind == 'SequenceOfType'):
if int(basic_type.Min) == 0:
return
elif isinstance(primary, ogAST.PrimEmptyString):
# Empty strings ("{ }") can be used for arrays and empty records
if basic_type.kind == 'SequenceOfType':
if int(basic_type.Min) == 0:
return
else:
raise TypeError('SEQUENCE OF has a minimum size of '
+ basic_type.Min + ')')
elif basic_type.kind == 'SequenceType':
if len(basic_type.Children.keys()) > 0:
raise TypeError('SEQUENCE is not empty, wrong "{}" syntax')
else:
raise TypeError('SEQUENCE OF has a minimum size of '
+ basic_type.Min + ')')
raise TypeError('Not a type compatible with empty string syntax')
elif isinstance(primary, ogAST.PrimSequenceOf) \
and basic_type.kind == 'SequenceOfType':
if type_ref.__name__ != 'Apnd' and \
......@@ -1714,7 +1720,8 @@ def primary(root, context):
'Max': str(value)
})
elif root.type == lexer.EMPTYSTR:
# Empty SEQUENCE OF (i.e. "{}")
# Primary "{ }" used in empty SEQUENCE OF (i.e. "{}")
# and also in value notation of SEQUENCEs that have no fields
prim = ogAST.PrimEmptyString()
prim.exprType = type('PrES', (object,), {
'kind': 'SequenceOfType',
......
......@@ -117,7 +117,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '1.3.16'
__version__ = '1.3.17'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......
......@@ -18,10 +18,10 @@ signal we;
CONNECT c AND r;
/* CIF PROCESS (225, 49), (150, 75) */
PROCESS og;
/* CIF TEXT (57, 58), (442, 158) */
/* CIF TEXT (57, 58), (474, 158) */
-- Test support for empty sequences and NULL type
-- The parser does not support the value notation for these types
-- this demo shows a workaround: define constants in the ASN.1 file
-- The parser does not support the value notation for NULL types yet
-- this demo proposes a workaround: define constants in the ASN.1 file
-- and use them when needed to define a variable of one of these types
dcl empty1 EmptySeq := c1;
......@@ -33,20 +33,28 @@ dcl choice1 ChoiceWithEmptySeq := a: n1;
/* CIF START (160, 226), (70, 35) */
START;
/* CIF TASK (137, 276), (115, 35) */
TASK empty1 := c1;
/* CIF TASK (130, 326), (130, 35) */
TASK empty1 := c1
/* CIF COMMENT (272, 276), (138, 35) */
COMMENT 'Using a constant';
/* CIF TASK (140, 326), (110, 35) */
TASK empty1 := {}
/* CIF COMMENT (270, 326), (135, 35) */
COMMENT 'Classic notation';
/* CIF TASK (130, 376), (130, 35) */
TASK choice1 := b: c1;
/* CIF TASK (146, 376), (97, 35) */
/* CIF TASK (132, 426), (125, 35) */
TASK choice1 := b: {};
/* CIF TASK (146, 476), (97, 35) */
TASK null1 := n1;
/* CIF NEXTSTATE (160, 426), (70, 35) */
/* CIF NEXTSTATE (160, 526), (70, 35) */
NEXTSTATE wait;
/* CIF STATE (296, 231), (70, 35) */
/* CIF STATE (424, 231), (70, 35) */
STATE wait;
/* CIF INPUT (289, 286), (84, 35) */
/* CIF INPUT (417, 286), (84, 35) */
INPUT dd;
/* CIF OUTPUT (286, 336), (89, 35) */
/* CIF OUTPUT (415, 336), (89, 35) */
OUTPUT we;
/* CIF NEXTSTATE (296, 386), (70, 35) */
/* CIF NEXTSTATE (424, 386), (70, 35) */
NEXTSTATE wait;
ENDSTATE;
ENDPROCESS og;
......
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