diff --git a/concrete_syntax/common.py b/concrete_syntax/common.py index 3427b03..1ab0d3c 100644 --- a/concrete_syntax/common.py +++ b/concrete_syntax/common.py @@ -16,6 +16,8 @@ def display_value(val: any, type_name: str, indentation=0, newline_character='\n return '"'+val+'"'.replace('\n', newline_character) elif type_name == "Integer" or type_name == "Boolean": return str(val) + elif type_name == "Bytes": + return val else: raise Exception("don't know how to display value" + type_name) @@ -48,6 +50,9 @@ class TBase(Transformer): def CODE(self, token): return _Code(str(token[1:-1])) # strip the `` + def BYTES(self, token): + return (bytes(token[2:-1], "utf-8"), token.line) # Strip b"" or b'' + def INDENTED_CODE(self, token): skip = 4 # strip the ``` and the following newline character space_count = 0 diff --git a/state/base.py b/state/base.py index 614ae9e..78c4307 100644 --- a/state/base.py +++ b/state/base.py @@ -2,13 +2,14 @@ from abc import ABC, abstractmethod from typing import Any, List, Tuple, Optional, Union from uuid import UUID, uuid4 -primitive_types = (int, float, str, bool) +primitive_types = (int, float, str, bool, bytes) INTEGER = ("Integer",) FLOAT = ("Float",) STRING = ("String",) BOOLEAN = ("Boolean",) TYPE = ("Type",) -type_values = (INTEGER, FLOAT, STRING, BOOLEAN, TYPE) +BYTES = ("Bytes",) +type_values = (INTEGER, FLOAT, STRING, BOOLEAN, TYPE, BYTES) Node = UUID diff --git a/transformation/merger.py b/transformation/merger.py index 6caecb1..fcf6f81 100644 --- a/transformation/merger.py +++ b/transformation/merger.py @@ -4,7 +4,7 @@ from concrete_syntax.textual_od import parser, renderer from services.scd import SCD from util.timer import Timer -PRIMITIVE_TYPES = set(["Integer", "String", "Boolean", "ActionCode"]) +PRIMITIVE_TYPES = set(["Integer", "String", "Boolean", "ActionCode", "Bytes"]) # Merges N models. The models must have the same meta-model. # Care should be taken to avoid naming collisions before calling this function. @@ -12,7 +12,7 @@ def merge_models(state, mm, models: list[UUID]): with Timer("merge_models"): primitive_types = { type_name : UUID(state.read_value(state.read_dict(state.read_root(), type_name))) - for type_name in ["Integer", "String", "Boolean", "ActionCode"] + for type_name in ["Integer", "String", "Boolean", "ActionCode", "Bytes"] } merged = state.create_node()