Commits

henr...@monster.local  committed 3ebe8f0

bits of function expression

  • Participants
  • Parent commits 7cb0308

Comments (0)

Files changed (1)

File tests/samples/javascript.ometa

 #                | AssignmentExpression(In)
 Expression :In = PrimaryExpression
 
-FunctionExpression :In = "nada"
 ConditionalExpression :In = "nada"
 
+
+# @returns an AST
+IdPattern = name:id -> self.ast("IdPatt", name=id) 
+
+
+## debugger statement
+# DebuggerStatement = k("debugger") sc -> self.ast("DebuggerStmt") 
+
+
+## A.5 Functions and Programs
+
+# FunctionDeclaration = k("function") IdPattern:patt
+#                       "(" (FormalParameterList | (empty -> [])):formals ")"
+#                       "{" FunctionBody:body "}" -> self.ast_list("FunctionDecl",
+#                                  [patt, self.ast("ParamDecl",{},formals)] + body) )
+
+FunctionExpression = k("function") IdPattern:patt
+                     "(" (FormalParameterList | (empty -> [])):formals ")"
+                     "{" FunctionBody:body "}" -> self.ast_list("FunctionExpr", [patt, self.ast_list("ParamDecl",formals)] + body) 
+                   | k("function") "(" (FormalParameterList | empty -> []):formals ")"
+                     "{" FunctionBody:body "}" -> this.ast_list("FunctionExpr", [self.emptyAst(), self.ast_list("ParamDecl",formals)] + body) 
+
+// @returns an array of ASTs
+FormalParameterList = FormalParameterList:formals "," FormalParameter:formal -> formals + [formal]
+                    | FormalParameter:formal -> [formal]
+
+// @returns an AST
+FormalParameter = IdPattern
+
+// @returns an array of ASTs
+FunctionBody = SourceElements | (empty -> [])
+
+// @returns an array of ASTs
+SourceElements = SourceElements:elts SourceElement:e -> elts + [e] 
+               | SourceElement:e -> [e]
+
+SourceElement = Declaration | Statement
+
+Declaration = "decl;"
+Statement = "statement;"
+
+