# Copyright (C) 2006-2008, The Perl Foundation.
# $Id: /mirror/trunk/languages/lua/src/dumplex.tg 34462 2008-12-27T17:23:27.572097Z fperrad  $

=head1 NAME

src/dumplex.tg - a grammar for testing lexico

=head1 DESCRIPTION

Just emits code that prints terminal nodes.

Used by F<languages/lua/test_lex.pir>.

=cut

grammar Lua::DumpLex is TGE::Grammar;


=head2 Functions

=over 4

=item C<transform past (ROOT)>

=cut

transform past (ROOT) :language('PIR') {
    .local pmc past
    $P0 = get_hll_global ['PAST'], 'Stmts'
    past = $P0.'new'('node'=>node)
    $P0 = node['token']
    if null $P0 goto L1
    .local pmc iter
    new iter, 'Iterator', $P0
  L2:
    unless iter goto L1
    $P0 = shift iter
    $P1 = tree.'get'('past', $P0, 'Lua::TestLex::token')
    past.'push'($P1)
    goto L2
  L1:
    $P0 = get_hll_global ['PAST'], 'Block'
    .tailcall $P0.'new'(past, 'node'=>node, 'name'=>'anon')
}


=item C<transform past (Lua::TestLex::token)>

=cut

transform past (Lua::TestLex::token) :language('PIR') {
    .local pmc past
    $S0 = node.'find_key'()
    $P0 = node[$S0]
    $S1 = concat 'Lua::TestLex::', $S0
    past = tree.'get'('past', $P0, $S1)
    $P0 = get_hll_global ['PAST'], 'Op'
    .tailcall $P0.'new'(past, 'node'=>node, 'name'=>'println', 'pasttype'=>'call')
}


=item C<transform past (Lua::TestLex::keyword)>

=cut

transform past (Lua::TestLex::keyword) :language('PIR') {
    $S0 = node.'result_object'()
    $S1 = concat "keyword:\t", $S0
    $P0 = get_hll_global ['PAST'], 'Val'
    .tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}


=item C<transform past (Lua::TestLex::punctuator)>

=cut

transform past (Lua::TestLex::punctuator) :language('PIR') {
    $S0 = node.'result_object'()
    $S1 = concat "punct:\t", $S0
    $P0 = get_hll_global ['PAST'], 'Val'
    .tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}


=item C<transform past (Lua::TestLex::Name)>

=cut

transform past (Lua::TestLex::Name) :language('PIR') {
    $S0 = node.'result_object'()
    $S1 = concat "Name:\t", $S0
    $P0 = get_hll_global ['PAST'], 'Val'
    .tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}


=item C<transform past (Lua::TestLex::String)>

=cut

transform past (Lua::TestLex::String) :language('PIR') {
    $I0 = defined node['quoted_literal']
    unless $I0 goto L1
    $P0 = node['quoted_literal']
    $S0 = $P0.'result_object'()
    $S1 = concat "String:\t", $S0
    goto L9
  L1:
    $I0 = defined node['long_string']
    unless $I0 goto L2
    $P0 = node['long_string']
    $S0 = $P0.'result_object'()
    $S1 = concat "LongString:\t", $S0
    goto L9
  L2:
    internal_error('unknown string')
  L9:
    $P0 = get_hll_global ['PAST'], 'Val'
    .tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}


=item C<transform past (Lua::TestLex::Number)>

=cut

transform past (Lua::TestLex::Number) :language('PIR') {
    $S0 = node.'result_object'()
    $S1 = concat "Number:\t", $S0
    $P0 = get_hll_global ['PAST'], 'Val'
    .tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}

=back

=cut

