Author: fperrad
Date: Tue May  1 22:51:30 2007
New Revision: 18391

Added:
   trunk/languages/lua/t/Parrot/Test/Lua_lex.pm
   trunk/languages/lua/t/test_lex.t
Modified:
   trunk/languages/lua/src/dumplex.tg
   trunk/languages/lua/src/lua51.pg
   trunk/languages/lua/src/lua51.pir
   trunk/languages/lua/src/lua51_testlex.pg
   trunk/languages/lua/t/Parrot/Test/Lua.pm
   trunk/languages/lua/t/harness
   trunk/languages/lua/test_lex.pir

Log:
[Lua]
- lexico : 'name' becomes a routine 
- add infrastructure for test lexico

Modified: trunk/languages/lua/src/dumplex.tg
==============================================================================
--- trunk/languages/lua/src/dumplex.tg  (original)
+++ trunk/languages/lua/src/dumplex.tg  Tue May  1 22:51:30 2007
@@ -56,12 +56,6 @@
     tree.get('past', $P1, 'Lua::TestLex::keyword')
 
 L7:
-    $I0 = defined $P0['ws']
-    unless $I0 goto L8
-    $P1 = $P0['ws']
-    tree.get('past', $P1, 'Lua::TestLex::ws')
-
-L8:
     goto L1
 L2:
     .return (node)
@@ -109,10 +103,6 @@
     print "\n"
 }
 
-transform past (Lua::TestLex::ws) :language('PIR') {
-    print "ws\n"
-}
-
 =head1 AUTHOR
 
 Francois Perrad

Modified: trunk/languages/lua/src/lua51.pg
==============================================================================
--- trunk/languages/lua/src/lua51.pg    (original)
+++ trunk/languages/lua/src/lua51.pg    Tue May  1 22:51:30 2007
@@ -271,20 +271,6 @@
 }
 
 
-=head2 TOKENS
-
-=head3 Name
-
-an identifier MUST start on a word boundary. If the \b is removed,
-this is allowed: a=1b=2, which of course should be an error.
-
-=cut
-
-token name {
-  <!keyword> \b <ident>
-}
-
-
 =head3 Strings
 
 A string can be either a single-quoted, double-quoted or a long string.
@@ -313,24 +299,6 @@
     ]*
 }
 
-=head3 Keywords
-
-Lua keywords may B<not> be used as identifiers. To make sure the longest
-identifier is matched, so that identifiers that B<start> with a keyword
-is still an identifier, a keyword should end at a word boundary.
-This way, for instance, the identifier C<format> is not read as C<for>.
-
-=cut
-
-token keyword {
-  [  <'and'>     | <'break'>  | <'do'>    | <'elseif'>
-  | <'else'>     | <'end'>    | <'false'> | <'for'>
-  | <'function'> | <'if'>     | <'in'>    | <'local'>
-  | <'nil'>      | <'not'>    | <'or'>    | <'repeat'>
-  | <'return'>   | <'then'>   | <'true'>  | <'until'>
-  | <'while'>    ] \b
-}
-
 =head1 AUTHORS
 
 Klaas-Jan Stol <[EMAIL PROTECTED]>

Modified: trunk/languages/lua/src/lua51.pir
==============================================================================
--- trunk/languages/lua/src/lua51.pir   (original)
+++ trunk/languages/lua/src/lua51.pir   Tue May  1 22:51:30 2007
@@ -121,6 +121,62 @@
 .end
 
 
+=item C<name>
+
+ident but not keywords
+
+=cut
+
+.sub 'name'
+    .param pmc mob
+    .param pmc params :slurpy
+
+    $P0 = get_hll_global ['PGE::Match'], 'ident'
+    mob = $P0(mob)
+
+    unless mob goto L1
+    .local pmc kw
+    kw = get_hll_global 'keyword'
+    unless null kw goto L2
+    kw = _const_keyword()
+    set_hll_global 'keyword', kw
+L2:
+    $S0 = mob.'text'()
+    $I0 = exists kw[$S0]
+    unless $I0 goto L1
+    mob.'next'()
+L1:
+    .return (mob)
+.end
+
+.sub _const_keyword :anon
+    .local pmc kw
+    new kw, .Hash
+    kw['and'] = 1
+    kw['break'] = 1
+    kw['do'] = 1
+    kw['else'] = 1
+    kw['elseif'] = 1
+    kw['end'] = 1
+    kw['false'] = 1
+    kw['for'] = 1
+    kw['function'] = 1
+    kw['if'] = 1
+    kw['in'] = 1
+    kw['local'] = 1
+    kw['nil'] = 1
+    kw['not'] = 1
+    kw['or'] = 1
+    kw['repeat'] = 1
+    kw['return'] = 1
+    kw['then'] = 1
+    kw['true'] = 1
+    kw['until'] = 1
+    kw['while'] = 1
+    .return (kw)
+.end
+
+
 =item C<quoted_literal>
 
 =cut

Modified: trunk/languages/lua/src/lua51_testlex.pg
==============================================================================
--- trunk/languages/lua/src/lua51_testlex.pg    (original)
+++ trunk/languages/lua/src/lua51_testlex.pg    Tue May  1 22:51:30 2007
@@ -30,6 +30,30 @@
         | <punctuator>
 }
 
+token keyword {
+        | and
+        | break
+        | do
+        | elseif
+        | else
+        | end
+        | false
+        | for
+        | function
+        | if
+        | in
+        | local
+        | nil
+        | not
+        | or
+        | repeat
+        | return
+        | then
+        | true
+        | until
+        | while
+}
+
 token punctuator {
         | \+
         | \-

Modified: trunk/languages/lua/t/Parrot/Test/Lua.pm
==============================================================================
--- trunk/languages/lua/t/Parrot/Test/Lua.pm    (original)
+++ trunk/languages/lua/t/Parrot/Test/Lua.pm    Tue May  1 22:51:30 2007
@@ -1,4 +1,4 @@
-# Copyright (C) 2005-2006, The Perl Foundation.
+# Copyright (C) 2005-2007, The Perl Foundation.
 # $Id$
 
 package Parrot::Test::Lua;
@@ -74,11 +74,6 @@
                 "$self->{parrot} languages/${pir_fn}",
             );
         }
-        elsif ( $lua_test eq 'test_lex' ) {
-            @test_prog = (
-                "$self->{parrot} languages/lua/test_lex.pir 
languages/${lang_fn}",
-            );
-        }
         else {
             @test_prog = (
                 "perl -Ilanguages/lua languages/lua/luac.pl 
languages/${lang_fn}",

Added: trunk/languages/lua/t/Parrot/Test/Lua_lex.pm
==============================================================================
--- (empty file)
+++ trunk/languages/lua/t/Parrot/Test/Lua_lex.pm        Tue May  1 22:51:30 2007
@@ -0,0 +1,110 @@
+# Copyright (C) 2007, The Perl Foundation.

+# $Id: Lua_lex.pm $

+

+package Parrot::Test::Lua_lex;

+

+use strict;

+

+use Data::Dumper;

+use File::Basename;

+

+require Parrot::Test;

+

+=head1 NAME

+

+Test/Lua_lex.pm - Testing routines specific to 'lua' lexicography.

+

+=head1 DESCRIPTION

+

+Call F<languages/lua/test_lex.pir>.

+

+=head1 METHODS

+

+=head2 new

+

+Yet another constructor.

+

+=cut

+

+use strict;

+use warnings;

+

+sub new {

+    return bless {};

+}

+

+my %language_test_map = (

+    output_is   => 'is_eq',

+    output_like => 'like',

+    output_isnt => 'isnt_eq',

+);

+

+foreach my $func ( keys %language_test_map ) {

+    no strict 'refs';

+

+    *{"Parrot::Test::Lua_lex::$func"} = sub {

+        my $self = shift;

+        my ( $code, $output, $desc, %options ) = @_;

+

+        my $count = $self->{builder}->current_test + 1;

+

+        my $params = $options{params} || q{};

+

+        # flatten filenames (don't use directories)

+        my $lang_fn = Parrot::Test::per_test( '.lua', $count );

+        my $lua_out_fn = Parrot::Test::per_test( '.parrot_out', $count );

+        my @test_prog = (

+            "$self->{parrot} languages/lua/test_lex.pir languages/${lang_fn}",

+        );

+

+        # This does not create byte code, but lua code

+        Parrot::Test::write_code_to_file( $code, $lang_fn );

+

+        # STDERR is written into same output file

+        my $exit_code = Parrot::Test::run_command(

+            [EMAIL PROTECTED],

+            CD     => $self->{relpath},

+            STDOUT => $lua_out_fn,

+            STDERR => $lua_out_fn,

+        );

+

+        my $builder_func = $language_test_map{$func};

+

+        # That's the reason for:   no strict 'refs';

+        my $pass =

+            $self->{builder}

+            ->$builder_func( Parrot::Test::slurp_file($lua_out_fn), $output, 
$desc );

+        unless ($pass) {

+            my $diag = q{};

+            my $test_prog = join ' && ', @test_prog;

+            $diag .= "'$test_prog' failed with exit code $exit_code."

+                if $exit_code;

+            $self->{builder}->diag($diag) if $diag;

+        }

+

+        # The generated files are left in the t/* directories.

+        # Let 'make clean' and 'svn:ignore' take care of them.

+

+        return $pass;

+        }

+}

+

+=head1 SEE ALSO

+

+F<languages/lua/lib/Parrot/Test/Lua.pm>

+

+=head1 AUTHOR

+

+Francois Perrad

+

+=cut

+

+1;

+

+# Local Variables:

+#   mode: cperl

+#   cperl-indent-level: 4

+#   fill-column: 100

+# End:

+# vim: expandtab shiftwidth=4:

+


Modified: trunk/languages/lua/t/harness
==============================================================================
--- trunk/languages/lua/t/harness       (original)
+++ trunk/languages/lua/t/harness       Tue May  1 22:51:30 2007
@@ -1,4 +1,4 @@
-# Copyright (C) 2005-2006, The Perl Foundation.
+# Copyright (C) 2005-2007, The Perl Foundation.
 # $Id$
 
 =head1 NAME
@@ -48,13 +48,12 @@
 my $language = 'lua';
 
 my $opt_files;
-my ($use_orig_lua, $use_monkey, $use_lua2pir, $use_testlex);
+my ($use_orig_lua, $use_monkey, $use_lua2pir);
 GetOptions(
     'files' => \$opt_files,
     'use-lua' => \$use_orig_lua,
     'use-monkey' => \$use_monkey,
     'use-lua2pir' => \$use_lua2pir,
-    'use-testlex' => \$use_testlex,
 );
 
 if ( $opt_files ) {
@@ -103,9 +102,6 @@
     elsif ($use_lua2pir) {
         $ENV{PARROT_LUA_TEST_PROG} = 'lua2pir';
     }
-    elsif ($use_testlex) {
-        $ENV{PARROT_LUA_TEST_PROG} = 'test_lex';
-    }
     else {
         $ENV{PARROT_LUA_TEST_PROG} = q{};
     }

Added: trunk/languages/lua/t/test_lex.t
==============================================================================
--- (empty file)
+++ trunk/languages/lua/t/test_lex.t    Tue May  1 22:51:30 2007
@@ -0,0 +1,175 @@
+#! perl

+# Copyright (C) 2007, The Perl Foundation.

+# $Id: test_lex.t $

+

+=head1 NAME

+

+t/test_lex.t - Lua lexicography test

+

+=head1 SYNOPSIS

+

+    % perl -I../lib -Ilua/t lua/t/test_lex.t

+

+=head1 DESCRIPTION

+

+Tests Lua lexicograaphy

+(implemented in F<languages/lua/test_lex.pir>).

+

+See "Lua 5.1 Reference Manual", section 2.1 "Lexical Conventions",

+L<http://www.lua.org/manual/5.1/manual.html#2.1>.

+

+=cut

+

+use strict;

+use warnings;

+use FindBin;

+use lib "$FindBin::Bin";

+

+use Parrot::Test tests => 8;

+use Test::More;

+

+language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'hello' );

+print("hello")

+CODE

+Name:  print

+punct: (

+String:        hello

+punct: )

+"past" => PMC 'Lua::TestLex' { ... }

+OUT

+

+language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'keyword' );

+and

+break

+do

+else

+elseif

+end

+false

+for

+function

+if

+in

+local

+nil

+not

+or

+repeat

+return

+then

+true

+until

+while

+CODE

+keyword:       and

+keyword:       break

+keyword:       do

+keyword:       else

+keyword:       elseif

+keyword:       end

+keyword:       false

+keyword:       for

+keyword:       function

+keyword:       if

+keyword:       in

+keyword:       local

+keyword:       nil

+keyword:       not

+keyword:       or

+keyword:       repeat

+keyword:       return

+keyword:       then

+keyword:       true

+keyword:       until

+keyword:       while

+"past" => PMC 'Lua::TestLex' { ... }

+OUT

+

+language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'not keyword' );

+format      -- not for

+doit        -- not do

+CODE

+Name:  format

+Name:  doit

+"past" => PMC 'Lua::TestLex' { ... }

+OUT

+

+language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'string' );

+'alo\n123"'

+"alo\n123\""

+'\97lo\10\04923"'

+CODE

+String:        alo

+123"

+String:        alo

+123"

+String:        alo

+123"

+"past" => PMC 'Lua::TestLex' { ... }

+OUT

+

+language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'long string' );

+[[alo

+123"]]

+[==[

+alo

+123"]==]

+CODE

+LongString:    alo

+123"

+LongString:    alo

+123"

+"past" => PMC 'Lua::TestLex' { ... }

+OUT

+

+language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'number' );

+3

+3.0

+3.1416

+314.16e-2

+0.31416E1

+.31416E+1

+0xff

+0x56

+CODE

+Number:        3

+Number:        3.0

+Number:        3.1416

+Number:        314.16e-2

+Number:        0.31416E1

+Number:        .31416E+1

+Number:        0xff

+Number:        0x56

+"past" => PMC 'Lua::TestLex' { ... }

+OUT

+

+language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'comment' );

+-- comment

+1   -- comment

+2

+CODE

+Number:        1

+Number:        2

+"past" => PMC 'Lua::TestLex' { ... }

+OUT

+

+language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'long comment' );

+--[[

+long comment

+]]

+1

+--[===[

+long comment

+]===]

+CODE

+Number:        1

+"past" => PMC 'Lua::TestLex' { ... }

+OUT

+

+# Local Variables:

+#   mode: cperl

+#   cperl-indent-level: 4

+#   fill-column: 100

+# End:

+# vim: expandtab shiftwidth=4:

+


Modified: trunk/languages/lua/test_lex.pir
==============================================================================
--- trunk/languages/lua/test_lex.pir    (original)
+++ trunk/languages/lua/test_lex.pir    Tue May  1 22:51:30 2007
@@ -34,8 +34,6 @@
     # import Lua::Grammar::* into Lua::TestLex
     $P0 = get_hll_global ['Lua::Grammar'], 'name'
     set_hll_global ['Lua::TestLex'], 'Name', $P0
-    $P0 = get_hll_global ['Lua::Grammar'], 'keyword'
-    set_hll_global ['Lua::TestLex'], 'keyword', $P0
     $P0 = get_hll_global ['Lua::Grammar'], 'string'
     set_hll_global ['Lua::TestLex'], 'String', $P0
     $P0 = get_hll_global ['Lua::Grammar'], 'number'

Reply via email to