Add functions

pull/70/head
Max Brunsfeld 2014-07-30 12:57:11 +07:00
parent 43ec1d2949
commit 016c86dd45
2 changed files with 35 additions and 1 deletions

@ -33,7 +33,8 @@ module.exports = compiler.grammar
@null,
@undefined,
@object,
@array)
@array,
@function)
object: -> seq(
"{",
@ -43,6 +44,21 @@ module.exports = compiler.grammar
@expression))
"}")
function: -> seq(
keyword("function"),
@formal_parameters,
@statement_block)
formal_parameters: -> seq(
"(",
commaSep(@identifier),
")")
statement_block: -> seq(
"{",
repeat(@statement),
"}")
array: -> seq(
"[",
commaSep(@expression)

@ -104,3 +104,21 @@ Arrays
(expression_statement (array))
(expression_statement (array (string)))
(expression_statement (array (string) (identifier))))
============================================
Functions
============================================
function() {};
function(arg1, arg2) {
arg2;
};
---
(program
(expression_statement (function (formal_parameters) (statement_block)))
(expression_statement (function
(formal_parameters (identifier) (identifier))
(statement_block
(expression_statement (identifier))))))