<s> from pynhost import ruleparser , dynamic <EOL> class GrammarBase : <EOL> def __init__ ( self ) : <EOL> self . mapping = { } <EOL> self . app_context = '<STR_LIT>' <EOL> self . settings = { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . context_filters = { } <EOL> self . _rules = [ ] <EOL> self . _recording_macros = { } <EOL> def __lt__ ( self , other ) : <EOL> return self . settings [ '<STR_LIT>' ] < other . settings [ '<STR_LIT>' ] <EOL> def _change_global_context ( self , context , value ) : <EOL> self . _handler . process_contexts [ context ] = value <EOL> self . _handler . set_active_grammars ( ) <EOL> def _begin_recording_macro ( self , rule_name ) : <EOL> self . _recording_macros [ rule_name ] = [ ] <EOL> def _finish_recording_macros ( self ) : <EOL> new_rules = [ ] <EOL> for rule_name , macro in self . _recording_macros . items ( ) : <EOL> rule_name = '<STR_LIT>' . format ( rule_name ) <EOL> new_rules . append ( ruleparser . Rule ( rule_name , macro [ : - <NUM_LIT:1> ] + [ dynamic . Num ( - <NUM_LIT:1> ) . add ( - <NUM_LIT:1> ) ] , self ) ) <EOL> for rule in self . _rules : <EOL> if rule . pattern_text not in [ r . pattern_text for r in new_rules ] : <EOL> new_rules . append ( rule ) <EOL> self . _rules = new_rules <EOL> self . _recording_macros = { } <EOL> def _set_rules ( self ) : <EOL> for rule_text , actions in self . mapping . items ( ) : <EOL> rule = ruleparser . Rule ( rule_text , actions , self ) <EOL> self . _rules . append ( rule ) </s>
