Commit 3963ff98 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Support NULL type including value notation

parent 506cc52d
......@@ -142,6 +142,9 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
1.3.18 (04/2016)
- Add support for value notation of NULL type
1.3.17 (04/2016)
- Add support for value notation of empty SEQUENCEs ("{}")
......
......@@ -1704,6 +1704,13 @@ def _boolean(primary):
return [], unicode(ada_string), []
@expression.register(ogAST.PrimNull)
def _boolean(primary):
''' Generate code for a raw null value '''
ada_string = '0'
return [], unicode(ada_string), []
@expression.register(ogAST.PrimEmptyString)
def _empty_string(primary):
''' Generate code for an empty SEQUENCE OF: {} '''
......
......@@ -221,6 +221,9 @@ class PrimBoolean(Primary):
pass
class PrimNull(Primary):
pass
class PrimConstant(Primary):
is_raw = False
......
......@@ -206,6 +206,11 @@ def is_boolean(ty):
return find_basic_type(ty).kind == 'BooleanType'
def is_null(ty):
''' Return true if a type is a NULL Type '''
return find_basic_type(ty).kind == 'NullType'
def is_string(ty):
''' Return true if a type is a String Type '''
return find_basic_type(ty).kind in (
......@@ -683,6 +688,9 @@ def check_type_compatibility(primary, type_ref, context):
elif isinstance(primary, ogAST.PrimBoolean) and is_boolean(type_ref):
return
elif isinstance(primary, ogAST.PrimNull) and is_null(type_ref):
return
elif isinstance(primary, ogAST.PrimEmptyString):
# Empty strings ("{ }") can be used for arrays and empty records
if basic_type.kind == 'SequenceOfType':
......@@ -1674,6 +1682,10 @@ def primary(root, context):
prim = ogAST.PrimBoolean()
prim.value = [root.text.lower()]
prim.exprType = type('PrBool', (object,), {'kind': 'BooleanType'})
elif root.type == lexer.NULL:
prim = ogAST.PrimNull()
prim.value = [root.text.lower()]
prim.exprType = type('PrNull', (object,), {'kind': 'NullType'})
elif root.type == lexer.FLOAT:
prim = ogAST.PrimReal()
prim.value = [root.text]
......
......@@ -117,7 +117,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '1.3.17'
__version__ = '1.3.18'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......
SYSTEM og;
/* CIF TEXT (159, 221), (287, 188) */
/* CIF TEXT (159, 221), (289, 188) */
-- Text area for declarations and comments
use dv comment 'dataview.asn';
......@@ -18,15 +18,12 @@ signal we;
CONNECT c AND r;
/* CIF PROCESS (225, 49), (150, 75) */
PROCESS og;
/* CIF TEXT (57, 58), (474, 158) */
/* CIF TEXT (57, 58), (337, 130) */
-- Test support for empty sequences and NULL type
-- 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;
dcl null1 NullType;
dcl null1 NullType := NULL;
dcl choice1 ChoiceWithEmptySeq := a: n1;
/* CIF ENDTEXT */
......@@ -34,25 +31,27 @@ dcl choice1 ChoiceWithEmptySeq := a: n1;
START;
/* CIF TASK (137, 276), (115, 35) */
TASK empty1 := c1
/* CIF COMMENT (272, 276), (138, 35) */
/* CIF COMMENT (272, 276), (139, 35) */
COMMENT 'Using a constant';
/* CIF TASK (140, 326), (110, 35) */
/* CIF TASK (138, 326), (112, 35) */
TASK empty1 := {}
/* CIF COMMENT (270, 326), (135, 35) */
COMMENT 'Classic notation';
/* CIF TASK (130, 376), (130, 35) */
TASK choice1 := b: c1;
/* CIF TASK (132, 426), (125, 35) */
/* CIF TASK (131, 426), (126, 35) */
TASK choice1 := b: {};
/* CIF TASK (146, 476), (97, 35) */
/* CIF TASK (144, 476), (100, 35) */
TASK null1 := n1;
/* CIF NEXTSTATE (160, 526), (70, 35) */
/* CIF TASK (134, 526), (121, 35) */
TASK null1 := null;
/* CIF NEXTSTATE (160, 576), (70, 35) */
NEXTSTATE wait;
/* CIF STATE (424, 231), (70, 35) */
STATE wait;
/* CIF INPUT (417, 286), (84, 35) */
INPUT dd;
/* CIF OUTPUT (415, 336), (89, 35) */
/* CIF OUTPUT (414, 336), (89, 35) */
OUTPUT we;
/* CIF NEXTSTATE (424, 386), (70, 35) */
NEXTSTATE wait;
......
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