diff --git a/src/arch/micro_asm.py b/src/arch/micro_asm.py index 60d7216fd2..1eb82b53dc 100644 --- a/src/arch/micro_asm.py +++ b/src/arch/micro_asm.py @@ -197,6 +197,7 @@ tokens = reserved + ( states = ( ('asm', 'exclusive'), ('params', 'exclusive'), + ('header', 'exclusive'), ) reserved_map = { } @@ -244,17 +245,27 @@ def t_asm_ID(t): t.lexer.push_state('params') return t +def t_header_ID(t): + r'[A-Za-z_]\w*' + return t + # If there is a label and you're -not- in the assembler (which would be caught # above), don't start looking for parameters. def t_ANY_ID(t): r'[A-Za-z_]\w*' t.type = reserved_map.get(t.value, 'ID') + if t.type == 'MACROOP': + t.lexer.push_state('asm') + t.lexer.push_state('header') + elif t.type == 'ROM': + t.lexer.push_state('asm') + t.lexer.push_state('header') return t # Braces enter and exit micro assembly -def t_INITIAL_LBRACE(t): +def t_header_LBRACE(t): r'\{' - t.lexer.push_state('asm') + t.lexer.pop_state() return t def t_asm_RBRACE(t): @@ -262,11 +273,6 @@ def t_asm_RBRACE(t): t.lexer.pop_state() return t -# At the top level, keep track of newlines only for line counting. -def t_INITIAL_NEWLINE(t): - r'\n+' - t.lineno += t.value.count('\n') - # In the micro assembler, do line counting but also return a token. The # token is needed by the parser to detect the end of a statement. def t_asm_NEWLINE(t): @@ -287,6 +293,11 @@ def t_params_SEMI(t): t.lexer.pop_state() return t +# Unless handled specially above, track newlines only for line counting. +def t_ANY_NEWLINE(t): + r'\n+' + t.lineno += t.value.count('\n') + # Basic regular expressions to pick out simple tokens t_ANY_LPAREN = r'\(' t_ANY_RPAREN = r'\)'