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

Support octet string literals

parent f27d3e6a
......@@ -148,11 +148,12 @@ The fonts are the fonts from Ubuntu, check licence in file FONT-LICENSE.TXT
Changelog
=========
1.2.8 (10/2015)
1.2.9 (10/2015)
- Better support of renamePolicy
- Better handling of models without CIF coordinates
- Minor bug fixes
- Forloop syntax error handled correctly when using range
- support Hex and bit string literals when working with OCTET STRING
1.2.4 (07/2015)
- Use version 3.2.x of the ASN1SCC compiler with new -renamePolicy flag
......
......@@ -2,8 +2,8 @@
 
# Resource object code
#
# Created: Sat Jul 11 15:47:41 2015
# by: The Resource Compiler for PySide (Qt v4.8.4)
# Created: Thu Oct 8 21:18:37 2015
# by: The Resource Compiler for PySide (Qt v4.8.6)
#
# WARNING! All changes made in this file will be lost!
 
......@@ -31,6 +31,7 @@ import os
import math
import logging
import traceback
import binascii
from itertools import chain, permutations, combinations
from collections import defaultdict, Counter
import antlr3
......@@ -1670,7 +1671,23 @@ def primary(root, context):
})
elif root.type == lexer.STRING:
prim = ogAST.PrimStringLiteral()
prim.value = root.text
if root.text[-1] in ('B', 'b'):
try:
prim.value = "'{}'".format(
binascii.unhexlify('%x' % int(root.text[1:-2], 2)))
except (ValueError, TypeError) as err:
errors.append(error
(root, 'Bit string literal: {}'.format(err)))
prim.value = "''"
elif root.text[-1] in ('H', 'h'):
try:
prim.value = "'{}'".format(root.text[1:-2].decode('hex'))
except (ValueError, TypeError) as err:
errors.append(error
(root, 'Octet string literal: {}'.format(err)))
prim.value = "''"
else:
prim.value = root.text
prim.exprType = type('PrStr', (object,), {
'kind': 'StringType',
'Min': str(len(prim.value) - 2),
......@@ -1735,13 +1752,6 @@ def primary(root, context):
'Max': str(len(root.children)),
'type': prim_elem.exprType
})
elif root.type == lexer.BITSTR:
prim = ogAST.PrimBitStringLiteral()
warnings.append(warning(root, 'Bit string literal not supported yet'))
elif root.type == lexer.OCTSTR:
prim = ogAST.PrimOctetStringLiteral()
warnings.append(
warning(root, 'Octet string literal not supported yet'))
elif root.type == lexer.STATE:
prim = ogAST.PrimStateReference()
prim.exprType = ENUMERATED()
......
......@@ -116,7 +116,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '1.2.8'
__version__ = '1.2.9'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......
This diff is collapsed.
This diff is collapsed.
......@@ -870,9 +870,7 @@ primary_expression
primary
: BITSTR^
| OCTSTR^
| TRUE^
: TRUE^
| FALSE^
| STRING
| NULL^
......@@ -1310,25 +1308,19 @@ ENDNEWTYPE : E N D N E W T Y P E;
ARRAY : A R R A Y;
CONSTANTS : C O N S T A N T S;
STRUCT : S T R U C T;
SYNONYM : S Y N O N Y M;
SYNONYM : S Y N O N Y M;
IMPORT : I M P O R T;
VIEW : V I E W;
ACTIVE : A C T I V E;
fragment
STR
: '\'' ( options {greedy=false;} : .)* '\'';
STRING
: STR+ ;
BITSTR
: '"' ('0'|'1'|' ' | '\t' | '\r' | '\n')* '"B';
STRING
: STR+ (B|H)?;
OCTSTR
: '"' ('0'..'9'|'a'..'f'|'A'..'F'|' ' | '\t' | '\r' | '\n')*
'"H';
fragment
STR
: '\'' ( options {greedy=false;} : .)* '\'';
ID
: ALPHA (ALPHA | DIGITS | '_')*;
......
......@@ -15,7 +15,7 @@ signal run;
CONNECT c AND r;
/* CIF PROCESS (253, 105), (150, 75) */
PROCESS og;
/* CIF TEXT (0, 33), (356, 143) */
/* CIF TEXT (0, 33), (356, 203) */
-- Text area for declarations and comments
dcl a List := {'a', 'b', 'foo', 'bar
......@@ -25,29 +25,35 @@ dcl result OutStr := '';
dcl sep OutStr := ', ';
dcl nosep OutStr := '';
dcl strlit outStr := '68656c6c6f'H;
dcl bitstrlit outStr := '01010110'B;
/* CIF ENDTEXT */
/* CIF START (597, 63), (70, 35) */
/* CIF START (639, 63), (70, 35) */
START;
/* CIF TASK (539, 113), (185, 35) */
/* CIF TASK (581, 113), (185, 35) */
TASK result := result // 'Hello!';
/* CIF TASK (584, 163), (96, 35) */
/* CIF TASK (626, 163), (96, 35) */
TASK result := '';
/* CIF TASK (403, 213), (457, 78) */
/* CIF TASK (445, 213), (457, 78) */
TASK for each in a(2, length(a) - 1):
result := result // (if length(result) > 0 then sep else nosep fi) // each
endfor;;;;
/* CIF PROCEDURECALL (567, 306), (129, 35) */
endfor;
/* CIF PROCEDURECALL (609, 306), (129, 35) */
CALL writeln(result);
/* CIF TASK (554, 356), (155, 53) */
/* CIF TASK (596, 356), (155, 53) */
TASK for sep in a:
call writeln(sep);
endfor
/* CIF COMMENT (729, 365), (194, 38) */
/* CIF COMMENT (771, 365), (194, 38) */
COMMENT 'Test to check scope
(sep is also a dcl-variable)';
/* CIF NEXTSTATE (597, 424), (70, 35) */
/* CIF PROCEDURECALL (509, 424), (330, 35) */
CALL writeln('String literal (should be "hello"):', strlit);
/* CIF NEXTSTATE (639, 474), (70, 35) */
NEXTSTATE wait;
/* CIF STATE (286, 217), (70, 35) */
/* CIF STATE (366, 217), (70, 35) */
STATE 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