perl.cvs.parrot
[Top] [All Lists]

[svn:parrot] r25144 - trunk/languages/ecmascript/src/parser

Subject: [svn:parrot] r25144 - trunk/languages/ecmascript/src/parser
From:
Date: Tue, 22 Jan 2008 04:25:56 -0800 PST
Newsgroups: perl.cvs.parrot

Author: kjs
Date: Tue Jan 22 04:25:53 2008
New Revision: 25144

Modified:
   trunk/languages/ecmascript/src/parser/actions.pm
   trunk/languages/ecmascript/src/parser/grammar.pg

Log:
[ecmascript] 
* add basics for try/catch
* fix action for block
* fix action for TOP

Modified: trunk/languages/ecmascript/src/parser/actions.pm
==============================================================================
--- trunk/languages/ecmascript/src/parser/actions.pm    (original)
+++ trunk/languages/ecmascript/src/parser/actions.pm    Tue Jan 22 04:25:53 2008
@@ -3,7 +3,7 @@
 class JS::Grammar::Actions;
 
 method TOP($/) {
-    my $past := PAST::Stmts.new( :node($/) );
+    my $past := PAST::Block.new( :node($/), :blocktype('declaration') );
     for $<source_element> {
         $past.push( $( $_ ) );
     }
@@ -26,12 +26,10 @@
 }
 
 method block($/) {
-    my $past := PAST::Block.new( :node($/) );
-    my $stmt := PAST::Stmts.new( :node($/) );
+    my $past := PAST::Block.new( :node($/), :blocktype('immediate') );
     for $<statement> {
-        $stmt.push( $( $_ ) );
+        $past.push( $($_) );
     }
-    $past.push($stmt);
     make $past;
 }
 
@@ -51,6 +49,33 @@
     make PAST::Op.new( $cond, $block, :pasttype('while'), :node($/) );
 }
 
+method try_statement($/) {
+    my $past := PAST::Op.new( :pasttype('try'), :node($/) );
+    my $tryblock := $( $<block> );
+    $past.push($tryblock);
+
+    if $<catch> {
+        my $catchblock := $( $<catch> );
+        $past.push($catchblock);
+    }
+    if $<finally> {
+        my $finallyblock := $( $<finally> );
+        # what to do with this?
+    }
+    make $past;
+}
+
+method catch($/) {
+   my $past := $( $<block> );
+   # todo: unshift a statement with .get_results to catch the identifier
+   # onto this block.
+   make $past;
+}
+
+method finally($/) {
+    make $( $<block> );
+}
+
 method empty_statement($/) {
     make PAST::Op.new( :node($/), :inline('    # no-op') );
 }

Modified: trunk/languages/ecmascript/src/parser/grammar.pg
==============================================================================
--- trunk/languages/ecmascript/src/parser/grammar.pg    (original)
+++ trunk/languages/ecmascript/src/parser/grammar.pg    Tue Jan 22 04:25:53 2008
@@ -37,6 +37,7 @@
     | <if_statement> {*}        #= if_statement
     | <while_statement> {*}     #= while_statement
     | <empty_statement> {*}     #= empty_statement
+    | <try_statement> {*}       #= try_statement
     | <call_expression> {*}     #= call_expression
 }
 
@@ -55,6 +56,24 @@
     {*}
 }
 
+rule try_statement {
+    'try' <block>
+    [ <catch>
+    | <finally>
+    | <catch> <finally>
+    ]
+    {*}
+}
+
+rule catch {
+    'catch' '(' <identifier> ')' <block>
+    {*}
+}
+
+rule finally {
+    'finally' <block> {*}
+}
+
 rule empty_statement {
     ';' {*}
 }
@@ -193,40 +212,38 @@
 
 
 #### whitespace
-##token ws {
-##    | <?whitespace>
-##    | <?newline>
-##    | <?comment>
-##}
-##
-##
-##token whitespace {
-##    | <[ \t \f \  ]>
-###?    | \verttab
-###?    | \nbsp
-###?    | \usp #unicode sp
-##}
-##
-##token newline {
-##    | <[ \n \r ]>
-###?    | \LS
-###?    | \PS
-##}
-##
-##token comment {
-##    | <multilinecomment>
-##    | <singlelinecomment>
-##}
+#token ws {
+#    | <.whitespace>
+#    | <.newline>
+#    | <.comment>
+#}
+
+#token whitespace {
+#    | <[\t\v\f\ ]>
+#    | \nbsp
+#    | \usp #unicode sp
+#}
+
+#token newline {
+#    | \r?\n
+#    | \LS
+#    | \PS
+#}
+
+#token comment {
+#    <.singlelinecomment>
+#}
+
 ##
 #### comments
 ##rule multilinecomment {
 ##    <PGE::Text::Bracketed: /* */>
 ##}
 ##
-##rule singlelinecomment {
-##    '//' <!newline>* <newline>
-##}
-##
+token singlelinecomment {
+    '//' \N* <newline>
+}
+
 #### keywords
 
 ##    | <null_literal>

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:parrot] r25144 - trunk/languages/ecmascript/src/parser, kjs <=