Skip to content

Commit

Permalink
modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
xor2003 committed Mar 7, 2023
1 parent 7f39562 commit c4df187
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion masm2c/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse_args(args):
"-v",
"--version",
action="version",
version="{ver}".format(ver=__version__),
version=f"{__version__}",
)
aparser.add_argument(
"-d",
Expand Down
13 changes: 6 additions & 7 deletions masm2c/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import logging
import os
import re
from builtins import hex, range, str
from collections import OrderedDict

from lark import lark
Expand Down Expand Up @@ -822,8 +821,8 @@ def save_cpp_files(self, fname):

logging.info(f' *** Generating output files in C++ {cpp_fname} {header_fname}')

cpp_file = open(cpp_fname, "wt", encoding=self.__codeset)
hpp_file = open(header_fname, "wt", encoding=self.__codeset)
cpp_file = open(cpp_fname, "w", encoding=self.__codeset)
hpp_file = open(header_fname, "w", encoding=self.__codeset)

cpp_file.write(f"""{banner}
#include \"{header_fname}\"
Expand Down Expand Up @@ -897,7 +896,7 @@ def write_procedures(self, banner, header_fname):

cpp_segment_fname = f"{self._namespace.lower()}_{segment}.cpp"
logging.info(f' *** Generating output file in C++ {cpp_segment_fname}')
cpp_segment_file = open(cpp_segment_fname, "wt", encoding=self.__codeset)
cpp_segment_file = open(cpp_segment_fname, "w", encoding=self.__codeset)
cpp_segment_file.write(f'''{banner}
#include "{header_fname}"
Expand Down Expand Up @@ -954,7 +953,7 @@ def write_data_segments_cpp(self, segments, structures):
_, data_h, data_cpp_reference, _ = self.render_data_c(segments)
fname = "_data.cpp"
header = "_data.h"
with open(fname, "wt", encoding=self.__codeset) as fd:
with open(fname, "w", encoding=self.__codeset) as fd:
fd.write(f'''#include "_data.h"
namespace m2c{{
Expand All @@ -969,7 +968,7 @@ def write_data_segments_cpp(self, segments, structures):
''')

with open(header, "wt", encoding=self.__codeset) as hd:
with open(header, "w", encoding=self.__codeset) as hd:
hd.write('''
#ifndef ___DATA_H__
#define ___DATA_H__
Expand Down Expand Up @@ -1285,7 +1284,7 @@ def convert_str(self, c):
elif c == 0:
vvv = r"\0"
elif c < 32:
vvv = "\\x{:02x}".format(c)
vvv = f"\\x{c:02x}"
else:
vvv = chr(c)
elif isinstance(c, str):
Expand Down
1 change: 0 additions & 1 deletion masm2c/op.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
from builtins import str
from collections import OrderedDict
from copy import deepcopy
from enum import Enum
Expand Down
3 changes: 1 addition & 2 deletions masm2c/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import os
import re
import sys
from builtins import str
from collections import OrderedDict
from copy import deepcopy

Expand Down Expand Up @@ -140,7 +139,7 @@ def read_whole_file(file_name):
:return: The content of the file.
"""
logging.info(" Reading file %s...", file_name)
with open(file_name, 'rt', encoding="cp437") as file:
with open(file_name, encoding="cp437") as file:
content = file.read()
return content

Expand Down
4 changes: 2 additions & 2 deletions masm2c/pgparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from collections import OrderedDict
from copy import deepcopy, copy
from typing import Iterator
from collections.abc import Iterator

from lark import Transformer, Lark, v_args, Discard, Tree, lark

Expand Down Expand Up @@ -648,7 +648,7 @@ def __new__(cls, *args, **kwargs):

file_name = os.path.dirname(os.path.realpath(__file__)) + "/_masm61.lark"
debug = True
with open(file_name, 'rt') as gr:
with open(file_name) as gr:
cls._inst.or_parser = Lark(gr, parser='lalr', propagate_positions=True, cache=True, debug=debug,
postlex=MatchTag(context=kwargs['context']), start=['start', 'insegdirlist',
'instruction', 'expr',
Expand Down
3 changes: 1 addition & 2 deletions masm2c/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#
import logging
import re
from builtins import range, str

from lark import lark

Expand Down Expand Up @@ -157,7 +156,7 @@ def create_assignment_op(self, label, value, line_number=0):
return o

def __str__(self):
return "\n".join((i.__str__() for i in self.stmts))
return "\n".join(i.__str__() for i in self.stmts)

def set_instruction_compare_subclass(self, stmt, full_command, itislst):
"""Sets libdosbox's emulator the instruction subclass
Expand Down

0 comments on commit c4df187

Please sign in to comment.