Adding bytes as a type

This commit is contained in:
Inte Vleminckx 2025-02-05 15:20:25 +01:00
parent 6c41c83f4f
commit 86cd7027f3
7 changed files with 57 additions and 4 deletions

View file

@ -21,6 +21,7 @@ literal: INT
| STR
| BOOL
| CODE
| BYTES
| INDENTED_CODE
INT: /[0-9]+/
@ -28,6 +29,8 @@ STR: /"[^"]*"/
| /'[^']*'/
BOOL: "True" | "False"
CODE: /`[^`]*`/
BYTES: /b"[^"]*"/
| /b'[^']*'/
INDENTED_CODE: /```[^`]*```/
type_name: IDENTIFIER
@ -67,7 +70,7 @@ def parse_od(state,
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"]
}
class T(Transformer):
@ -89,6 +92,10 @@ def parse_od(state,
def CODE(self, token):
return (_Code(str(token[1:-1])), token.line) # strip the ``
def BYTES(self, token):
# return (bytes(token[2:-1], "utf-8"), token.line) # Strip b"" or b''
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

View file

@ -9,7 +9,7 @@ def render_od(state, m_id, mm_id, hide_names=True):
m_od = od.OD(mm_id, m_id, state)
serialized = set(["Integer", "String", "Boolean", "ActionCode"]) # assume these types always already exist
serialized = set(["Integer", "String", "Boolean", "ActionCode", "Bytes"]) # assume these types always already exist
def display_name(name: str):
# object names that start with "__" are hidden