Skip to content

Commit

Permalink
Merge pull request #4 from almosr/const_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
intoinside authored Apr 9, 2024
2 parents 11cbe45 + e54dbb7 commit ce1151d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions KickAssemblerToDoxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def remove_inital_dot_from_keywords(content):
content = content.replace('.macro ', 'macro ')
content = content.replace('.function ', 'function ')
content = content.replace('.label ', 'label ')
content = content.replace('.const ', 'const ')
content = content.replace('.pseudocommand ', 'pseudocommand ')
content = content.replace('.struct ', 'struct ')

Expand All @@ -92,6 +93,13 @@ def add_semicolon_to_label_declaration(content):

return content

def add_semicolon_to_const_declaration(content):
"""Function printing python version."""
# add semicolon at the end of const declaration
content = re.sub(r'(const[^\n\,]+)', r'\1;', content)

return content

def remove_some_newline(content):
"""Function printing python version."""
content = re.sub(r"[\n]{2,}\/\*\*", r"\n\n/**", content)
Expand Down Expand Up @@ -130,6 +138,8 @@ def convert_file(content):
content = remove_inital_dot_from_keywords(content)

content = add_semicolon_to_label_declaration(content)

content = add_semicolon_to_const_declaration(content)

content = remove_some_newline(content)
return content
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ This script removes:

After removing all these stuff, it fixes struct declaration.

Next step is to remove initial dot from keywords and then add a semicolon at the end of every label declaration.
Next step is to remove initial dot from keywords and then add a semicolon at the end of every label and const declaration.

This sequence is repeated for every file specificated as argument and edited file are saved in output folder.
10 changes: 10 additions & 0 deletions test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def testremoveInitalDotFromKeywordsLabel(self):
expected = "label "
self.assertEqual(remove_inital_dot_from_keywords(sourceCode), expected, "Should not have initial dot")

def testremoveInitalDotFromKeywordsConst(self):
sourceCode = ".const "
expected = "const "
self.assertEqual(remove_inital_dot_from_keywords(sourceCode), expected, "Should not have initial dot")

def testremoveInitalDotFromKeywordsPseudocommand(self):
sourceCode = ".pseudocommand "
expected = "pseudocommand "
Expand All @@ -88,6 +93,11 @@ def testAddSemicolonToLabel(self):
expected = "label xyz = $beef;"
self.assertEqual(add_semicolon_to_label_declaration(sourceCode), expected, "Should have semicolon at end")

def testAddSemicolonToConst(self):
sourceCode = "const xyz = $beef"
expected = "const xyz = $beef;"
self.assertEqual(add_semicolon_to_const_declaration(sourceCode), expected, "Should have semicolon at end")

def testRemoveSomeNewLine(self):
sourceCode = "\n\n\n/**"
expected = "\n\n/**"
Expand Down

0 comments on commit ce1151d

Please sign in to comment.