# New Ticket Created by Klaas-Jan Stol # Please include the string: [perl #41670] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41670 >
hi, attached a patch for lang/pynie. fixing: * added transform for is [not] and [not] in. Note that the instruction used is a hack, but it only needs replacement with something real. The framework is ok. * change "is_not_test" and "not_in_test" into "is_test" and "in_test" resp. regards, kjs
Index: languages/pynie/src/parser/Grammar.pg =================================================================== --- languages/pynie/src/parser/Grammar.pg (revision 17282) +++ languages/pynie/src/parser/Grammar.pg (working copy) @@ -482,15 +482,15 @@ rule not_test { | <'not'> <not_test> - | <not_in_test> + | <in_test> } -rule not_in_test { - <is_not_test> [ <'not'>? <'in'> <is_not_test> ]* +rule in_test { + <is_test> [ (<'not'>)? <'in'> <is_test> ]* } -rule is_not_test { - <comparison> [ <'is'> <'not'>? <comparison> ]* +rule is_test { + <comparison> [ <'is'> (<'not'>)? <comparison> ]* } token 'comparison' is optable { ... } Index: languages/pynie/src/PAST/Grammar.tg =================================================================== --- languages/pynie/src/PAST/Grammar.tg (revision 17282) +++ languages/pynie/src/PAST/Grammar.tg (working copy) @@ -203,10 +203,15 @@ transform past (Pynie::Grammar::expression) :language('PIR') { + $S0 = node.'find_key'() $P0 = node['or_test'] + if null $P0 goto lambda $P0 = $P0[0] # this is a hack, 'rule expression' has 1 or more <or_test>s, so it stores them in an array. Handle $P0[1] later. #printerr "pynie::grammar::expression\n" .return tree.'get'('past', $P0, 'Pynie::Grammar::or_test') + lambda: + $P0 = node['lambda'] + .return tree.'get'('past', $P0, 'Pynie::Grammar::lambda_form') } transform past (Pynie::Grammar::or_test) :language('PIR') { @@ -226,30 +231,94 @@ } transform past (Pynie::Grammar::and_test) :language('PIR') { - $P0 = node['not_test'] - $P0 = $P0[0] # this is a hack, 'rule expression' has 1 or more <or_test>s, so it stores them in an array. Handle $P0[1] later. - #printerr "pynie::grammar::and_test\n" - .return tree.'get'('past', $P0, 'Pynie::Grammar::not_test') + .local pmc past, iter, clist, cnode + clist = node['not_test'] + clist = clone clist + cnode = pop clist + past = tree.'get'('past', cnode, 'Pynie::Grammar::not_test') + unless clist goto end + clist_loop: + cnode = pop clist + $P0 = tree.'get'('past', cnode, 'Pynie::Grammar::not_test') + past = past.'new'('PAST::Op', $P0, past, 'node'=>node, 'pasttype'=>'if') + if clist goto clist_loop + end: + .return (past) } transform past (Pynie::Grammar::not_test) :language('PIR') { - $P0 = node['not_in_test'] - #printerr "pynie::grammar::not_test\n" - .return tree.'get'('past', $P0, 'Pynie::Grammar::not_in_test') + .local string key, fullkey + .local pmc cnode, past, notpast + + cnode = node['not_test'] + if null cnode goto do_in_test + notpast = tree.'get'('past', cnode, 'Pynie::Grammar::not_test') + + past = new 'PAST::Op' + past.'init'('node'=>cnode, 'pasttype'=>'pirop', 'pirop'=>'not') + past.'push'(notpast) + + .return (past) + + do_in_test: + cnode = node['in_test'] + past = tree.'get'('past', cnode, 'Pynie::Grammar::in_test') + .return (past) } -transform past (Pynie::Grammar::not_in_test) :language('PIR') { - $P0 = node['is_not_test'] - $P0 = $P0[0] # this is a hack, 'rule expression' has 1 or more <or_test>s, so it stores them in an array. Handle $P0[1] later. - #printerr "pynie::grammar::not_in_test\n" - .return tree.'get'('past', $P0, 'Pynie::Grammar::is_not_test') +transform past (Pynie::Grammar::in_test) :language('PIR') { + .local pmc past, iter, clist, cnode + clist = node['is_test'] + clist = clone clist + cnode = pop clist + past = tree.'get'('past', cnode, 'Pynie::Grammar::is_test') + unless clist goto end + clist_loop: + cnode = pop clist + $P0 = tree.'get'('past', cnode, 'Pynie::Grammar::is_test') + # + # FIX THIS; also check for "not" + # + past = past.'new'('PAST::Op', $P0, past, 'node'=>node, 'pasttype'=>'pirop', 'pirop'=>'IN (FIX)') + if clist goto clist_loop + end: + .return (past) } -transform past (Pynie::Grammar::is_not_test) :language('PIR') { - $P0 = node['comparison'] - $P0 = $P0[0] - $P0 = $P0['expr'] - #printerr "pynie::grammar::is_not_test\n" +transform past (Pynie::Grammar::is_test) :language('PIR') { + .local pmc past, iter, clist, cnode + .local int hasnot + + hasnot = 1 + # HACK: + # TODO: figure out how presence of "not" can be checked. + # then set flag for each iteration. + + clist = node['comparison'] + clist = clone clist + + cnode = pop clist + past = tree.'get'('past', cnode, 'Pynie::Grammar::comparison') + unless clist goto end + + clist_loop: + cnode = pop clist + $P0 = tree.'get'('past', cnode, 'Pynie::Grammar::comparison') + if hasnot == 0 goto do_issame + $S0 = "isntsame" + goto done + do_issame: + $S0 = "issame" + done: + past = past.'new'('PAST::Op', $P0, past, 'node'=>node, 'pasttype'=>'pirop', 'pirop'=>$S0) + if clist goto clist_loop + end: + .return (past) +} + + +transform past (Pynie::Grammar::comparison) :language('PIR') { + $P0 = node['expr'] .return tree.'get'('past', $P0, 'Pynie::Grammar::expr') }