# -*- coding: utf-8 -*- from dao.t.classic_utils import * from dao.t.builtins.globalenv import classic as classic_module # dummies from dao.term import dummies _, _x, _type, _exp, _exp1, _exp2, _stmt = dummies('_, _x, _type, _exp, _exp1, _exp2, _stmt') __, __type, __prior, __assoc = nullvars(4) block_comment = t_default_block_comment # ===================================================== # classic grammar for t language defines = in_module(classic_module, define(program, function( ([exp], phrases(exp, 0), eoi), # indent: 0 )), define(phrases, function( ([exp, indent], any(phrase(_exp, indent), _exp, exp, greedy), eoi), )), define(phrase, function( ([exp, indent], and_p(any(noncode_line(), None, None, greedy), any(statement_line(_exp, indent), _exp, exp, greedy), eoi),
# letr ([v1,v2]<<value).do[...] letr = element('letr', let_grammar(special.letr)) @builtin.function('make_iff') def make_iff(test, clause, clauses, els_clause): els_clause = preparse(els_clause) if not isinstance(els_clause, Var) else None test = preparse(test[0]) clause = preparse(clause) clauses1 = [(preparse(t), preparse(c)) for t, c in clauses] return special.iff([(test, clause)] + clauses1, els_clause) _then, _elsif, _els = words('then, elsif, els') _test, _test2, _body = dummies('_test, _test2, _body') # iff(1).then[2], iff(1).then[2] .elsif(3).then[4] .els[5] iff = element('iff', (call(vv.test) + _do + getitem(vv.clause) + any( _elsif + call(_test) + _do + getitem(_body) + is_(_test2, first(_test)), (_test2, _body), vv.clauses) + may(_els + getitem(vv.els_clause)) + eoi + make_iff(vv.test, vv.clause, vv.clauses, vv.els_clause))) class CASE_ELS: pass CASE_ELS = CASE_ELS()
# letr (var << value).do[...] # letr (v1 << v2 << value).do[...] # letr ([v1,v2]<<value).do[...] letr = element('letr',let_grammar(special.letr)) @builtin.function('make_iff') def make_iff(test, clause, clauses, els_clause): els_clause = preparse(els_clause) if not isinstance(els_clause, Var) else None test = preparse(test[0]) clause = preparse(clause) clauses1 = [(preparse(t), preparse(c)) for t, c in clauses] return special.iff([(test, clause)]+clauses1, els_clause) _then, _elsif, _els = words('then, elsif, els') _test, _test2, _body = dummies('_test, _test2, _body') # iff(1).then[2], iff(1).then[2] .elsif(3).then[4] .els[5] iff = element('iff', (call(vv.test)+_do+getitem(vv.clause) +any(_elsif+call(_test)+_do+getitem(_body)+is_(_test2, first(_test)), (_test2, _body), vv.clauses) +may(_els+getitem(vv.els_clause))+eoi +make_iff(vv.test, vv.clause, vv.clauses, vv.els_clause)) ) class CASE_ELS: pass CASE_ELS = CASE_ELS() @builtin.function('make_case')