Skip to content

Commit

Permalink
Fix comments in include lines breaking the assembler
Browse files Browse the repository at this point in the history
  • Loading branch information
theandrew168 committed Feb 9, 2024
1 parent cb3835f commit 47a5fce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions bronzebeard/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,12 @@ def lookup(path, dirs):
# handle include in the reader
if raw_line.lower().startswith('include '):
try:
_, rel_path = raw_line.split()
# strip any comments from the include line
raw_include = re.sub(r'#.*$', r'', raw_line)
# isolate the path
_, rel_path = raw_include.split()
# strip any leading / trailing quotes
rel_path = rel_path.strip('"\'')
except ValueError:
raise AssemblerError('include must specify a file', line)

Expand Down Expand Up @@ -2155,7 +2160,7 @@ def lex_tokens(line):
return LineTokens(line, tokens)

# strip comments
contents = re.sub(r'#.*$', r'', line.contents, flags=re.MULTILINE)
contents = re.sub(r'#.*$', r'', line.contents)

# pad parens before split
contents = contents.replace('(', ' ( ').replace(')', ' ) ')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def test_read_assembly():


def test_lex_assembly():
line = r'addi t0 zero 1'
line = r'addi t0 zero 1# comment'
tokens = asm.lex_tokens(line)
assert len(tokens) == 4
assert tokens.tokens == ['addi', 't0', 'zero', '1']


def test_parse_assembly():
line = r'addi t0 zero 1'
line = r'addi t0 zero 1 # comment'
tokens = asm.lex_tokens(line)
item = asm.parse_item(tokens)
assert isinstance(item, asm.ITypeInstruction)
Expand Down

0 comments on commit 47a5fce

Please sign in to comment.