Skip to content
Open
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
32 changes: 32 additions & 0 deletions src/evAssembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,44 @@ def process(self, macro, commands, strTbl, tags):
evCmdType = textMacroMap[macro.cmdType]
return self.processTextMacro(evCmdType, macro, commands, strTbl, tags)

if macro.cmdType == EvMacroType._MACRO_MSG:
return self.processUnifiedMacro(macro, commands, strTbl, tags)

raise RuntimeError(
"Invalid EvMacro: {} at {}:{}:{}".format(
macro, self.fileName, macro.line, macro.column
)
)

def processUnifiedMacro(self, macro, commands, strTbl, tags):
"""Handle _MACRO_MSG('TYPE', 'bundle', 'label', 'text', ...) by dispatching to processTextMacro."""
if not macro.args:
raise RuntimeError("_MACRO_MSG is missing message type argument at {}:{}:{}".format(
self.fileName, macro.line, macro.column))

msgTypeArg = macro.args[0]
if msgTypeArg.argType != EvArgType.MacroString:
raise RuntimeError("_MACRO_MSG first argument must be a string type name at {}:{}:{}".format(
self.fileName, msgTypeArg.line, msgTypeArg.column))

unifiedTypeMap = {
'TALKMSG': EvCmdType._TALKMSG,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change all of the keys for this to be the actual command name like "_TALKMSG".

'TALK_KEYWAIT': EvCmdType._TALK_KEYWAIT,
'EASY_OBJ_MSG': EvCmdType._EASY_OBJ_MSG,
'EASY_BOARD_MSG': EvCmdType._EASY_BOARD_MSG,
'ADD_CUSTUM_WIN_LABEL': EvCmdType._ADD_CUSTUM_WIN_LABEL,
}

evCmdType = unifiedTypeMap.get(msgTypeArg.data)
if evCmdType is None:
raise RuntimeError("Unknown message type '{}' in _MACRO_MSG at {}:{}:{}. Valid types: {}".format(
msgTypeArg.data, self.fileName, msgTypeArg.line, msgTypeArg.column,
', '.join(unifiedTypeMap.keys())))

# Create a new macro with args shifted (skip the type arg)
shifted = EvMacro(macro.cmdType, macro.args[1:], macro.line, macro.column)
return self.processTextMacro(evCmdType, shifted, commands, strTbl, tags)

class evAssembler(evListener):
def __init__(self, fileName, commands=None, flags=None, works=None, sysflags=None):
self.fileName = fileName
Expand Down
1 change: 1 addition & 0 deletions src/ev_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class EvMacroType(IntEnum):
_MACRO_TALK_KEYWAIT = auto()
_MACRO_EASY_OBJ_MSG = auto()
_MACRO_ADD_CUSTUM_WIN_LABEL = auto()
_MACRO_MSG = auto()

def isValid(self):
return self != EvMacroType.Invalid