develooper Front page | perl.cvs.parrot | Postings from December 2008

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

From:
tewk
Date:
December 12, 2008 15:38
Subject:
[svn:parrot] r33842 - trunk/languages/ecmascript/src/parser
Message ID:
20081212233823.89ECECB9AF@x12.develooper.com
Author: tewk
Date: Fri Dec 12 15:38:22 2008
New Revision: 33842

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

Log:
[js] added regex parsing, fixed LTM issues with numeric literals, fixed array_literals, fudged nested functions


Modified: trunk/languages/ecmascript/src/parser/actions.pm
==============================================================================
--- trunk/languages/ecmascript/src/parser/actions.pm	(original)
+++ trunk/languages/ecmascript/src/parser/actions.pm	Fri Dec 12 15:38:22 2008
@@ -395,6 +395,10 @@
     make $( $/{$key} );
 }
 
+method regular_expression_literal ($/) {
+    make PAST::Val.new( :value( ~$<regular_expression_literal> ), :node($/) );
+}
+
 method this($/) {
     ## XXX wait for PAST support for 'self'
     ## load 'self' into a register; when this PAST node is used as a child somewhere
@@ -546,7 +550,7 @@
     make $( $/{$key} );
 }
 
-method member_expression($/) {
+method member_expressionX($/) {
     my $member := $( $<member_prefix> );
 
     ## if there are any arguments, $member is invoked with these arguments.

Modified: trunk/languages/ecmascript/src/parser/grammar.pg
==============================================================================
--- trunk/languages/ecmascript/src/parser/grammar.pg	(original)
+++ trunk/languages/ecmascript/src/parser/grammar.pg	Fri Dec 12 15:38:22 2008
@@ -51,6 +51,8 @@
 ##
 
 rule statement {
+##tewk  added function_expression, don't know if it should go here though
+    | <function_expression> {*}   #= function_expression
     | <expression_statement> {*}  #= expression_statement
     | <block> {*}                 #= block
     | <variable_statement> {*}    #= variable_statement
@@ -187,6 +189,8 @@
 
 rule expression_statement {
     ##<!['{'|'function']> ## is this necessary? isn't this fixed automatically by PGE?
+    #<!before \w>
+    <!['{'|'function']>
     <expression> ';'
     {*}
 }
@@ -244,6 +248,57 @@
     | <identifier> {*}          #= identifier
     | <object_literal> {*}      #= object_literal
     | '(' <expression> ')' {*}  #= expression
+    | <regular_expression_literal> {*} #= regular_expression_literal
+}
+
+#RegularExpressionLiteral :: See section 7.8.5
+#/ RegularExpressionBody / RegularExpressionFlags
+token regular_expression_literal {
+  '/' <regular_expression_body> '/' <regular_expression_flags>? {*}
+}
+#RegularExpressionBody :: See section 7.8.5
+#RegularExpressionFirstChar RegularExpressionChars
+token regular_expression_body {
+  <regular_expression_first_char> <regular_expression_char>*
+}
+
+#RegularExpressionChars :: See section 7.8.5
+#[empty]
+#RegularExpressionChars RegularExpressionChar
+
+#RegularExpressionFirstChar :: See section 7.8.5
+#NonTerminator but not * or \ or /
+#BackslashSequence
+token regular_expression_first_char {
+  | <-[\n*\\/]>
+  | '\\' \N
+}
+
+#RegularExpressionChar :: See section 7.8.5
+#NonTerminator but not \ or /
+#BackslashSequence
+token regular_expression_char {
+  | <-[\n\\/]>
+  | '\\' \N
+}
+
+#BackslashSequence :: See section 7.8.5
+#\ NonTerminator
+#token backslash_sequence {
+#  '\\' \N
+#}
+#
+#token NonTerminator :: See section 7.8.5
+#SourceCharacter but not LineTerminator
+#token non_terminator {
+#  \N
+#}
+
+#RegularExpressionFlags :: See section 7.8.5
+#[empty]
+#RegularExpressionFlags IdentifierPart
+token regular_expression_flags {
+  <identifier_part>+
 }
 
 token this { 'this' {*} }
@@ -259,12 +314,12 @@
 }
 
 rule element_list {
-    <elision> <assignment_expression> [',' <elision> <assignment_expression>]*
+    <elision>? <assignment_expression> [',' <elision>? <assignment_expression>]*
     {*}
 }
 
 rule elision {
-    [$<comma>=',']* {*}
+    [$<comma>=',']+ {*}
 }
 
 token identifier {
@@ -273,6 +328,10 @@
     {*}
 }
 
+token <identifier_part> {
+    [<alpha>|<digit>|_]
+}
+
 token literal {
     | <str_literal> {*}            #= str_literal
     | <numeric_literal> {*}        #= numeric_literal
@@ -307,8 +366,8 @@
 }
 
 token numeric_literal {
-    | <decimal_literal> {*}        #= decimal_literal
     | <hex_integer_literal> {*}    #= hex_integer_literal
+    | <decimal_literal> {*}        #= decimal_literal
 }
 
 token hex_integer_literal {
@@ -318,13 +377,13 @@
 token hex_digits { <[0..9 a..f A..F]> }
 
 token decimal_literal {
-    | <integer_number> {*}         #= integer_number
     | <floating_point_number> {*}  #= floating_point_number
+    | <integer_number> {*}         #= integer_number
 }
 
 token floating_point_number {
     [
-    | <decimal_integer_literal> '.' <digit>+? <exponent_part>?
+    | <decimal_integer_literal> '.' <digit>* <exponent_part>?
     | '.' <digit>+ <exponent_part>?
     ]
     {*}



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About