Author: fperrad
Date: Tue Feb 20 04:18:27 2007
New Revision: 17079

Modified:
   trunk/languages/lua/config/makefiles/root.in
   trunk/languages/lua/src/dumplex.tg
   trunk/languages/lua/src/lua.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]
- test_lex reworks

Modified: trunk/languages/lua/config/makefiles/root.in
==============================================================================
--- trunk/languages/lua/config/makefiles/root.in        (original)
+++ trunk/languages/lua/config/makefiles/root.in        Tue Feb 20 04:18:27 2007
@@ -52,14 +52,12 @@
  $(LIBPATH)/luadebug.pbc
 
 GEN_PIR = \
- src/lua51_grammar_gen.pir \
  src/lua51_testlex_gen.pir \
  src/dumplex_gen.pir \
  src/lua_grammar_gen.pir \
  src/ASTGrammar.pir
 
 GEN_PBC = \
- src/Lua51.pbc \
  src/Lua51TestLex.pbc \
  src/LuaDumpLex.pbc \
  src/lua.pbc \
@@ -71,12 +69,6 @@
  $(GEN_PBC) \
  Lua/parser.pm
 
-src/lua51_grammar_gen.pir: src/lua51.pg
-       $(PGE) --output=src/lua51_grammar_gen.pir src/lua51.pg
-
-src/Lua51.pbc: src/Lua51.pir src/lua51_grammar_gen.pir src/parse.pir
-       $(PARROT) -o src/Lua51.pbc --output-pbc src/Lua51.pir
-
 
 src/lua51_testlex_gen.pir: src/lua51_testlex.pg
        $(PGE) --output=src/lua51_testlex_gen.pir src/lua51_testlex.pg
@@ -90,8 +82,6 @@
 src/LuaDumpLex.pbc: src/dumplex_gen.pir
        $(PARROT) -o src/LuaDumpLex.pbc --output-pbc src/dumplex_gen.pir
 
-### <
-
 src/lua_grammar_gen.pir: src/lua.pg
        $(PGE) --output=src/lua_grammar_gen.pir src/lua.pg
 
@@ -104,7 +94,6 @@
 luac.pbc: luac.pir
        $(PARROT) -o luac.pbc --output-pbc luac.pir
 
-### >
 
 pmc/lua_group$(LOAD_EXT) : $(PMC_FILES)
        @cd $(PMCDIR) && $(PMCBUILD) generate $(PMCS)

Modified: trunk/languages/lua/src/dumplex.tg
==============================================================================
--- trunk/languages/lua/src/dumplex.tg  (original)
+++ trunk/languages/lua/src/dumplex.tg  Tue Feb 20 04:18:27 2007
@@ -1,4 +1,4 @@
-# Copyright (C) 2006, The Perl Foundation.
+# Copyright (C) 2006-2007, The Perl Foundation.
 # $Id$
 
 grammar Lua::DumpLex is TGE::Grammar;
@@ -38,10 +38,10 @@
     tree.get('dump', $P1, 'Lua::TestLex::punctuator')
 
 L6:
-    $I0 = defined $P0['reserved_words']
+    $I0 = defined $P0['keyword']
     unless $I0 goto L7
-    $P1 = $P0['reserved_words']
-    tree.get('dump', $P1, 'Lua::TestLex::reserved_words')
+    $P1 = $P0['keyword']
+    tree.get('dump', $P1, 'Lua::TestLex::keyword')
 
 L7:
     $I0 = defined $P0['ws']
@@ -54,8 +54,8 @@
 L2:
 }
 
-transform dump (Lua::TestLex::reserved_words) :language('PIR') {
-    print "word:\t"
+transform dump (Lua::TestLex::keyword) :language('PIR') {
+    print "keyword:\t"
     print node
     print "\n"
 }

Modified: trunk/languages/lua/src/lua.pir
==============================================================================
--- trunk/languages/lua/src/lua.pir     (original)
+++ trunk/languages/lua/src/lua.pir     Tue Feb 20 04:18:27 2007
@@ -72,6 +72,78 @@
 .end
 
 
+.sub 'quoted_literal'
+    .param pmc mob
+    .param string delim
+    .param pmc adv :slurpy :named
+
+    .local string target
+    .local pmc mfrom, mpos
+    .local int pos, lastpos
+    (mob, target, mfrom, mpos) = mob.'newfrom'(mob)
+    pos = mfrom
+    lastpos = length target
+
+    .local string literal
+    literal = ''
+LOOP:
+    if pos < lastpos goto L1
+    error(mob, "unfinished string")
+L1:
+    $S0 = substr target, pos, 1
+    if $S0 != delim goto L2
+    mob.'result_object'(literal)
+    mpos = pos
+    .return (mob)
+L2:
+    $I0 = index "\n\r", $S0
+    if $I0 < 0 goto L3
+    error(mob, "unfinished string")
+L3:
+    if $S0 != "\\" goto CONCAT
+    inc pos
+    if pos == lastpos goto LOOP # error
+    $S0 = substr target, pos, 1
+    $I0 = index 'abfnrtv', $S0
+    if $I0 < 0 goto L4
+    $S0 = substr "\a\b\f\n\r\t\x0b", $I0, 1
+    goto CONCAT
+L4:
+    $I0 = index "\n\r", $S0
+    if $I0 < 0 goto L5
+    $S0 = "\n"
+    goto CONCAT
+L5:
+    $I0 = index '0123456789', $S0
+    if $I0 < 0 goto CONCAT
+    inc pos
+    $S0 = substr target, pos, 1
+    $I1 = index '0123456789', $S0
+    if $I1 < 0 goto L6
+    $I0 *= 10
+    $I0 += $I1
+    inc pos
+    $S0 = substr target, pos, 1
+    $I1 = index '0123456789', $S0
+    if $I1 < 0 goto L6
+    $I0 *= 10
+    $I0 += $I1
+    goto L7
+L6:
+    dec pos
+L7:
+    if $I0 < 256 goto L8
+    error(mob, "escape sequence too large")
+L8:
+    $S0 = chr $I0
+
+CONCAT:
+    concat literal, $S0
+    inc pos
+    goto LOOP
+.end
+
+
 .sub 'long_string'
     .param pmc mob
     .param pmc adv :slurpy :named

Modified: trunk/languages/lua/src/lua51_testlex.pg
==============================================================================
--- trunk/languages/lua/src/lua51_testlex.pg    (original)
+++ trunk/languages/lua/src/lua51_testlex.pg    Tue Feb 20 04:18:27 2007
@@ -1,22 +1,18 @@
-# Copyright (C) 2006, The Perl Foundation.
+# Copyright (C) 2006-2007, The Perl Foundation.
 # $Id$
 
 grammar Lua::TestLex
 
 rule start {
-        <token>* [ $ | <error>]
-#        |
-#        [ <token> | <error> ]*
-#        | <error>
+        <token>* [ $ | <die>]
 }
 
 rule token {
         | <Name>
-        | <reserved_words>
+        | <keyword>
         | <String>
         | <Number>
         | <punctuator>
-#        | <?error>
 }
 
 token punctuator {
@@ -48,30 +44,43 @@
         | \]
 }
 
-token reserved_words {
-        | and
-        | break
-        | do
-        | else
-        | elseif
-        | end
-        | false
-        | for
-        | function
-        | if
-        | in
-        | local
-        | nil
-        | not
-        | or
-        | repeat
-        | return
-        | then
-        | true
-        | until
-        | while
+token Name {
+  <!keyword> \b <ident>
 }
 
+token keyword {
+  [  <'and'>     | <'break'>  | <'do'>    | <'elseif'>
+  | <'else'>     | <'end'>    | <'false'> | <'for'>
+  | <'function'> | <'if'>     | <'in'>    | <'local'>
+  | <'nil'>      | <'not'>    | <'or'>    | <'repeat'>
+  | <'return'>   | <'then'>   | <'true'>  | <'until'>
+  | <'while'>    ] \b
+}
+
+#token keyword {
+#        | and
+#        | break
+#        | do
+#        | else
+#        | elseif
+#        | end
+#        | false
+#        | for
+#        | function
+#        | if
+#        | in
+#        | local
+#        | nil
+#        | not
+#        | or
+#        | repeat
+#        | return
+#        | then
+#        | true
+#        | until
+#        | while
+#}
+
 token String {
         | \" <quoted_literal: "> \"
         | \' <quoted_literal: '> \'

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 Feb 20 04:18:27 2007
@@ -74,12 +74,16 @@
                 "$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}",
                 "$self->{parrot} --no-gc languages/${pir_fn} $params",
 
-                # "$self->{parrot} languages/lua/test_lex.pir 
languages/${lang_fn}",
                 # "$self->{parrot} languages/lua/luac.pir 
languages/${lang_fn}",
             );
         }

Modified: trunk/languages/lua/t/harness
==============================================================================
--- trunk/languages/lua/t/harness       (original)
+++ trunk/languages/lua/t/harness       Tue Feb 20 04:18:27 2007
@@ -48,12 +48,13 @@
 my $language = 'lua';
 
 my $opt_files;
-my ($use_orig_lua, $use_monkey, $use_lua2pir);
+my ($use_orig_lua, $use_monkey, $use_lua2pir, $use_testlex);
 GetOptions(
     'files' => \$opt_files,
     'use-lua' => \$use_orig_lua,
     'use-monkey' => \$use_monkey,
     'use-lua2pir' => \$use_lua2pir,
+    'use-testlex' => \$use_testlex,
 );
 
 if ( $opt_files ) {
@@ -102,6 +103,9 @@
     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{};
     }

Modified: trunk/languages/lua/test_lex.pir
==============================================================================
--- trunk/languages/lua/test_lex.pir    (original)
+++ trunk/languages/lua/test_lex.pir    Tue Feb 20 04:18:27 2007
@@ -1,4 +1,4 @@
-# Copyright (C) 2006, The Perl Foundation.
+# Copyright (C) 2006-2007, The Perl Foundation.
 # $Id$
 
 =head1 NAME
@@ -21,6 +21,22 @@
     load_bytecode 'PGE/Util.pbc'
     load_bytecode 'languages/lua/src/Lua51TestLex.pbc'
     load_bytecode 'languages/lua/src/LuaDumpLex.pbc'
+    load_bytecode 'languages/lua/src/lua.pbc'
+
+    # import PGE::Util::die into Lua::TestLex
+    $P0 = get_hll_global ['PGE::Util'], 'die'
+    set_hll_global ['Lua::TestLex'], 'die', $P0
+
+    # 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'], 'quoted_literal'
+    set_hll_global ['Lua::TestLex'], 'quoted_literal', $P0
+    $P0 = get_hll_global ['Lua::Grammar'], 'long_string'
+    set_hll_global ['Lua::TestLex'], 'long_string', $P0
+    $P0 = get_hll_global ['Lua::Grammar'], 'long_comment'
+    set_hll_global ['Lua::TestLex'], 'long_comment', $P0
+
     .local int argc
     argc = elements argv
     if argc != 2 goto USAGE
@@ -75,9 +91,6 @@
     .return (content)
 .end
 
-.namespace [ 'Lua::TestLex' ]
-.include 'languages/lua/src/parse.pir'
-
 =head1 AUTHOR
 
 Francois Perrad

Reply via email to