Add comments

pull/70/head
Max Brunsfeld 2014-08-04 13:17:05 +07:00
parent be4273cb3b
commit b9c22c7c72
2 changed files with 32 additions and 1 deletions

@ -7,6 +7,8 @@ commaSep = (rule) ->
module.exports = compiler.grammar
name: 'javascript',
ubiquitous: ["comment"]
rules:
program: -> repeat(@statement)
@ -150,8 +152,12 @@ module.exports = compiler.grammar
seq('"', repeat(choice(/[^"]/, '\\"')), '"'),
seq("'", repeat(choice(/[^']/, "\\'")), "'")))
comment: -> token(choice(
seq("//", /.*/),
seq("/*", repeat(choice(/[^\*]/, /\*[^/]/)), "*/")))
regex: -> token(seq(
'/', repeat(choice(/[^/]/, '\\/')), '/',
'/', repeat(choice(/[^/\n]/, '\\/')), '/',
repeat(choice('i', 'g'))))
true: -> keyword("true")

@ -77,3 +77,28 @@ var x, y = {}, z;
(identifier)
(identifier) (object)
(identifier)))
============================================
Comments
============================================
{
// This is a property
aProperty: 1,
/*
* This is a method
*/
aMethod: function() {}
};
---
(program
(expression_statement (object
(comment)
(identifier) (number)
(comment)
(identifier) (function (formal_parameters) (statement_block)))))