<s> '''<STR_LIT>''' <EOL> from zen . exceptions import * <EOL> from zen . graph import Graph <EOL> from zen . digraph import DiGraph <EOL> from zen . bipartite import BipartiteGraph <EOL> import pdb <EOL> class GMLInterpreter ( object ) : <EOL> def __init__ ( self , gml_codec , tokenizer ) : <EOL> self . codec = gml_codec <EOL> try : <EOL> self . VAL_TOK = tokenizer . VAL_TOK <EOL> self . KEY_TOK = tokenizer . KEY_TOK <EOL> self . SLIST_TOK = tokenizer . SLIST_TOK <EOL> self . ELIST_TOK = tokenizer . ELIST_TOK <EOL> except AttributeError as e : <EOL> raise ZenException ( '<STR_LIT>' '<STR_LIT>' ) <EOL> def restart ( self ) : <EOL> self . ptr = <NUM_LIT:0> <EOL> def evaluate_list ( self , tokens , depth ) : <EOL> interpretation = { } <EOL> while self . ptr < len ( tokens ) : <EOL> token_type = tokens [ self . ptr ] [ <NUM_LIT:1> ] <EOL> if token_type == self . KEY_TOK : <EOL> pass <EOL> elif token_type == self . ELIST_TOK : <EOL> if depth > <NUM_LIT:0> : <EOL> pass <EOL> else : <EOL> raise ZenException ( '<STR_LIT>' '<STR_LIT>' % tokens [ self . ptr ] [ <NUM_LIT:2> ] ) <EOL> elif token_type == self . SLIST_TOK or token_type == self . VAL_TOK : <EOL> raise ZenException ( '<STR_LIT>' <EOL> % ( repr ( tokens [ self . ptr ] [ <NUM_LIT:0> ] ) , tokens [ self . ptr ] [ <NUM_LIT:2> ] ) ) <EOL> else : <EOL> raise ZenException ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' % repr ( tokens [ self . ptr ] ) ) <EOL> next_key = tokens [ self . ptr ] <EOL> if token_type == self . ELIST_TOK : <EOL> self . ptr += <NUM_LIT:1> <EOL> return interpretation <EOL> else : <EOL> new_key = tokens [ self . ptr ] [ <NUM_LIT:0> ] <EOL> if self . ptr + <NUM_LIT:1> >= len ( tokens ) : <EOL> raise ZenException ( '<STR_LIT>' '<STR_LIT>' % repr ( tokens [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) ) <EOL> if tokens [ self . ptr + <NUM_LIT:1> ] [ <NUM_LIT:1> ] == self . SLIST_TOK : <EOL> self . ptr += <NUM_LIT:2> <EOL> new_val = self . evaluate_list ( tokens , depth + <NUM_LIT:1> ) <EOL> else : <EOL> if tokens [ self . ptr + <NUM_LIT:1> ] [ <NUM_LIT:1> ] != self . VAL_TOK : <EOL> raise ZenException ( '<STR_LIT>' '<STR_LIT>' % ( tokens [ self . ptr + <NUM_LIT:1> ] [ <NUM_LIT:0> ] , <EOL> tokens [ self . ptr + <NUM_LIT:1> ] [ <NUM_LIT:2> ] ) ) <EOL> new_val = self . codec . decode ( tokens [ self . ptr + <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> self . ptr += <NUM_LIT:2> <EOL> if new_key in interpretation : <EOL> if isinstance ( interpretation [ new_key ] , list ) : <EOL> interpretation [ new_key ] . append ( new_val ) <EOL> else : <EOL> old_val = interpretation [ new_key ] <EOL> interpretation [ new_key ] = [ old_val , new_val ] <EOL> else : <EOL> interpretation [ new_key ] = new_val <EOL> if depth > <NUM_LIT:0> : <EOL> raise ZenException ( '<STR_LIT>' '<STR_LIT>' ) <EOL> if self . ptr < len ( tokens ) : <EOL> raise ZenException ( '<STR_LIT>' '<STR_LIT:%s>' % repr ( tokens [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) ) <EOL> return interpretation <EOL> def interpret ( self , tokens ) : <EOL> self . restart ( ) <EOL> return self . evaluate_list ( tokens , <NUM_LIT:0> ) </s>
