Author: fperrad
Date: Tue Feb 20 06:54:33 2007
New Revision: 17080

Modified:
   trunk/languages/lua/src/ASTGrammar.tg
   trunk/languages/lua/src/lua.pg
   trunk/languages/lua/src/lua51_testlex.pg
   trunk/languages/lua/test_lex.pir

Log:
[Lua]
- small fix for lexico part of the grammar
- use quoted_literal instead of PGE::Text::bracketed (implement Lua rules)
- text_lex uses Lua::Grammar rules

Modified: trunk/languages/lua/src/ASTGrammar.tg
==============================================================================
--- trunk/languages/lua/src/ASTGrammar.tg       (original)
+++ trunk/languages/lua/src/ASTGrammar.tg       Tue Feb 20 06:54:33 2007
@@ -449,50 +449,23 @@
 
 
 transform past (Lua::Grammar::string) :language('PIR') {
-  stringsingle:
-    $P0 = node['stringsingle']
-    if null $P0 goto stringdouble
-    .return tree.'get'('past', $P0, 'Lua::Grammar::stringsingle')
-   stringdouble:
-     $P0 = node['stringsingle']
-    .return tree.'get'('past', $P0, 'Lua::Grammar::stringsingle')
-}
-
-transform past (Lua::Grammar::stringdouble) :language('PIR') {
     .local pmc result
     result = new 'PAST::Val'
 
     .local string value
-    # Check if this is a string match
-    $I0 = defined node["PGE::Text::bracketed"]
-    if $I0 goto bracketed_value
-    value = node
-    goto no_bracketed_value
-  bracketed_value:
-    value = node["PGE::Text::bracketed"]
-  no_bracketed_value:
-
-    # NOTE: Will have to come back and handle interpolation properly.
-    # Currently have no way to distinguish between single quoted and
-    # double quoted strings.
+  quoted_literal:
+    $P0 = node['quoted_literal']
+    if null $P0 goto long_string
+    value = $P0
     result.'init'('node'=>node, 'vtype'=>'.String', 'name'=>value)
     .return (result)
-}
-
-transform past (Lua::Grammar::stringsingle) :language('PIR') {
-    .local pmc result
-    result = new 'PAST::Val'
-
-    .local string value
-    # Check if this is a string match
-    $I0 = defined node["PGE::Text::bracketed"]
-    if $I0 goto bracketed_value
-    value = node
-    goto no_bracketed_value
-  bracketed_value:
-    value = node["PGE::Text::bracketed"]
-  no_bracketed_value:
-
+  long_string:
+    $P0 = node['long_string']
+    if null $P0 goto error
+    value = $P0
     result.'init'('node'=>node, 'vtype'=>'.String', 'name'=>value)
     .return (result)
+  error:
+    printerr "Unknown string\n"
 }
+

Modified: trunk/languages/lua/src/lua.pg
==============================================================================
--- trunk/languages/lua/src/lua.pg      (original)
+++ trunk/languages/lua/src/lua.pg      Tue Feb 20 06:54:33 2007
@@ -292,27 +292,24 @@
 
 =cut
 
-rule string {
-  <stringdouble> | <stringsingle> | <long_string>
+token string {
+  | \" <quoted_literal: "> \"
+  | \' <quoted_literal: '> \'
+  | <long_string>
 }
 
-regex stringdouble { <PGE::Text::bracketed: "> }
-regex stringsingle { <PGE::Text::bracketed: '> }
 
 token number {
-  [ <digit>+
-    [ <'.'> <digit>+ ]?
-    [ <[eE]> <[+\-]>? <digit>+ ]?
-  ]
-  | [ <'.'> <digit>+  ] [ <[eE]> <[+\-]>? <digit>+ ]?
-  | [ 0 <[xX]> <xdigit>+ ]
+  | 0 <[Xx]> <xdigit>+
+  | [ <digit>+ [ \. <digit>* ]? | \. <digit>+ ]
+    [ <[Ee]> <[+\-]>? <digit>+ ]?
 }
 
 
 token ws {
     [ \s+
-    | <'--'> \N*
     | <'--'> <long_comment>
+    | <'--'> \N*
     ]*
 }
 

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 06:54:33 2007
@@ -44,59 +44,3 @@
         | \]
 }
 
-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: '> \'
-        | <long_string>
-}
-
-token Number {
-        | 0 <[Xx]> <xdigit>+
-        | [ <digit>+ [ \. <digit>* ]? | \. <digit>+ ]
-          [ <[Ee]> <[+\-]>? <digit>+ ]?
-}
-
-token ws {
-        [ \s+
-        | \-\- <long_comment>
-        | \-\- \N*
-        ]*
-}
-

Modified: trunk/languages/lua/test_lex.pir
==============================================================================
--- trunk/languages/lua/test_lex.pir    (original)
+++ trunk/languages/lua/test_lex.pir    Tue Feb 20 06:54:33 2007
@@ -28,8 +28,17 @@
     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'], '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'
+    set_hll_global ['Lua::TestLex'], 'Number', $P0
+    $P0 = get_hll_global ['Lua::Grammar'], 'ws'
+    set_hll_global ['Lua::TestLex'], 'ws', $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'

Reply via email to