tree-sitter/spec/runtime/languages/javascript/literals.txt
2014-10-21 08:49:16 -07:00

93 lines
2 KiB
Text

==========================================
regexes
==========================================
theFunction(/regex1/, /regex2/g);
---
(expression_statement (function_call (identifier)
(arguments (regex) (regex))))
==========================================
numbers
==========================================
theFunction(100.0, 200);
---
(expression_statement (function_call (identifier)
(arguments (number) (number))))
==========================================
strings
==========================================
theFunction('', "", 'single-quoted-string', "double-quoted-string");
---
(expression_statement (function_call (identifier)
(arguments (string) (string) (string) (string))))
==========================================
function expressions
==========================================
var x = {
theMethod: function(argA, argB) {
var x = argA;
}
};
---
(var_declaration (var_assignment
(identifier)
(object (pair (identifier) (function_expression
(formal_parameters (identifier) (identifier))
(statement_block
(var_declaration (var_assignment (identifier) (identifier)))))))))
==========================================
comments
==========================================
// this is the beginning of the script.
// here we go.
var thing = {
// this is a property.
// its value is a function.
key: function(x /* this is a parameter */) {
// this is a statement
doStuff();
}
};
---
(comment)
(comment)
(var_declaration (var_assignment
(identifier)
(object
(comment)
(comment)
(pair (identifier) (function_expression
(formal_parameters (identifier) (comment))
(statement_block
(comment)
(expression_statement (function_call (identifier)))))))))
==========================================
comments within expressions
==========================================
y // comment
* z;
---
(expression_statement (math_op (expression (identifier) (comment)) (identifier)))