def colon_annotation(prs): #was opt_colon_type, opt_colon_sort """Parser for ': A', discarding the colon. A is parsed by prs. Parser returns an empty list if there is no annotation.""" #def trt1(toks): # if len(toks)==0: # return toks # return prs.process(toks) prs1 = (next_value(':') + post_colon_balanced()).treat( lib.snd).possibly().treat(lib.fflatten) return prs1.reparse(prs)
def top_level(): def f(acc): (((a,b),c),p) = acc return {'finished':bool(p),'nonterminal':a,'production':b,'annotated':c} return (Inner.nontermprod() + Inner.annotated().plus() + next_value('$').possibly()).treat(f)
def opt(): def f(acc): ((_,a),_) = acc return ('OPT',a) return (next_type('(') + Inner.annotated().plus(next_value('|')) + next_type(')')).treat(f).name('opt')
def assign_expr(): """parser for := followed by an expression The output is the expression """ return (next_value(':=') + expr()).treat(lib.snd)
def identifier_pattern(): ##XX return (lit('a') + identifier().if_test(p)) | next_value('_')
def function_copula(): return (Macro.copula() | opt_colon_type() + next_value(':='))
def copula(): """Parser for copula in macro declarations. """ return ((lit('is') + lit('defined-as').possibly()) | (next_value(':=')) | (lit('denote')))
def var_multisubsect_pattern(): return ((Pattern._var() + next_value(',') + Pattern._var()) | c.paren(Pattern._var() + next_value(',') + Pattern._var() + opt_colon_type_meta()))
def var_or_atomic_or_blank(): """parser for var or atomic or _. The parser output is a single token that is one of those types.""" return var_or_atomic() | next_value('_')
return (Parse.word('we').possibly() + first_word('record register') + Parse.word('identification').possibly() + Parse.word('that').possibly()) if s == 'doc': return lit['document'] | lit['end-document'] if s == 'location': return Parse.first( [lit_dict['document'], lit_dict['theorem'], lit_dict['axiom']]) return lit_dict[s] #others: #label = atomic period = next_value('.').clear_history() comma = next_value(',') semicolon = next_value(';') colon = next_value(':') #renamed map -> call # instructions do nothing except store for now instruct = {} class Instruction: def _param_value(ls): if ls == []: return ''