def parse_series(s):
if isinstance(s, Element):<EOL><INDENT>s = s._format_element()<EOL><DEDENT>if not s or s == '<STR_LIT:*>':<EOL><INDENT>return (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>if isinstance(s, int):<EOL><INDENT>return (<NUM_LIT:0>, s)<EOL><DEDENT>if s == '<STR_LIT>':<EOL><INDENT>return (<NUM_LIT:2>, <NUM_LIT:1>)<EOL><DEDENT>elif s == '<STR_LIT>':<EOL><INDENT>return (<NUM_LIT:2>, <NUM_LIT:0>)<EOL><DEDENT>elif s == '<STR_LIT:n>':<EOL><INDENT>return (<NUM_LIT:1>, <NUM_LIT:0>)<EOL><DEDENT>if '<STR_LIT:n>' not in s:<EOL><INDENT>return (<NUM_LIT:0>, int(s))<EOL><DEDENT>a, b = s.split('<STR_LIT:n>', <NUM_LIT:1>)<EOL>if not a:<EOL><INDENT>a = <NUM_LIT:1><EOL><DEDENT>elif a == '<STR_LIT:->' or a == '<STR_LIT:+>':<EOL><INDENT>a = int(a+'<STR_LIT:1>')<EOL><DEDENT>else:<EOL><INDENT>a = int(a)<EOL><DEDENT>if not b:<EOL><INDENT>b = <NUM_LIT:0><EOL><DEDENT>elif b == '<STR_LIT:->' or b == '<STR_LIT:+>':<EOL><INDENT>b = int(b+'<STR_LIT:1>')<EOL><DEDENT>else:<EOL><INDENT>b = int(b)<EOL><DEDENT>return (a, b)<EOL>
Parses things like '1n+2', or 'an+b' generally, returning (a, b)