Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Makefile #52

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions grammars/f1_c_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,13 @@ def to_bytes(self):
# subnode_count
subnode_count = len(self)
ret += subnode_count.to_bytes(4, byteorder='little', signed=False)
# val_len
val_len = len(self.val)

# Encode the value as UTF-8
val_bytes = self.val.encode('utf-8')
# val_len (now stores the byte length of the UTF-8 encoded string)
val_len = len(val_bytes)
ret += val_len.to_bytes(4, byteorder='little', signed=False)
# val
# Latin-1 is an 8-bit character set. The first 128 characters of its
# set are identical to the US ASCII standard. By encoding the string as
# Latin-1, we can handle all hex characters from \u0000 to \u00ff
# Refs:
# - https://stackoverflow.com/questions/66601743/python3-str-to-bytes-convertation-problem
# - https://kb.iu.edu/d/aepu
val_bytes = bytes(self.val, 'latin-1')
if val_len != len(val_bytes):
print(f'The length of `val` should be {val_len}, but found {len(val_bytes)}.')
print(f'`val` bytes in UTF-8 encoding: {val_bytes}')
print('Please check your grammar file!')
sys.exit(1)
ret += val_bytes

# subnodes
Expand All @@ -103,6 +94,7 @@ def to_bytes(self):
return ret

@staticmethod

def from_bytes(data: bytes):
node = TreeNode()
consumed = 0
Expand Down Expand Up @@ -133,6 +125,7 @@ def from_bytes(data: bytes):

return node, consumed


def __str__(self):
ret = ''
if len(self) == 0:
Expand Down
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ BENCHMARK_OBJS = $(BENCHMARK_SRC_FILES:.c=.o)
OBJS = $(LIB_OBJS) $(GEN_OBJS) $(BENCHMARK_OBJS)

C_FLAGS = $(C_FLAGS_OPT)
C_FLAGS += -Wno-error=bidi-chars
C_DEFINES =
C_INCLUDES = -I../include -I../third_party/rxi_map -I../third_party/Cyan4973_xxHash

Expand Down
Loading