Skip to content

Commit 13f36c1

Browse files
committed
implement value conversions for simple types
1 parent 6b26410 commit 13f36c1

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/exp2python/python/SCL/Part21.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,29 @@ def t_newline(self, t):
177177
t.lexer.lineno += len(t.value)
178178

179179
# Simple Data Types
180-
t_REAL = r'[+-]*[0-9][0-9]*\.[0-9]*(?:E[+-]*[0-9][0-9]*)?'
181-
t_INTEGER = r'[+-]*[0-9][0-9]*'
182-
t_STRING = r"'(?:[][!\"*$%&.#+,\-()?/:;<=>@{}|^`~0-9a-zA-Z_\\ ]|'')*'"
183-
t_BINARY = r'"[0-3][0-9A-F]*"'
180+
def t_REAL(self, t):
181+
r'[+-]*[0-9][0-9]*\.[0-9]*(?:E[+-]*[0-9][0-9]*)?'
182+
t.value = float(t.value)
183+
return t
184+
185+
def t_INTEGER(self, t):
186+
r'[+-]*[0-9][0-9]*'
187+
t.value = int(t.value)
188+
return t
189+
190+
def t_STRING(self, t):
191+
r"'(?:[][!\"*$%&.#+,\-()?/:;<=>@{}|^`~0-9a-zA-Z_\\ ]|'')*'"
192+
t.value = t.value.strip("'")
193+
return t
194+
195+
def t_BINARY(self, t):
196+
r'"[0-3][0-9A-F]*"'
197+
try:
198+
t.value = int(t.value.strip('"')[1:], base=16)
199+
except ValueError:
200+
t.value = None
201+
return t
202+
184203
t_ENTITY_INSTANCE_NAME = r'\#[0-9]+'
185204
t_ENUMERATION = r'\.[A-Z_][A-Z0-9_]*\.'
186205

0 commit comments

Comments
 (0)