tree-sitter/spec/runtime/languages/javascript/main.txt

77 lines
2.1 KiB
Text
Raw Normal View History

2014-03-24 09:14:29 -07:00
==========================================
parses multiple statements
==========================================
var x = {};
2014-03-26 22:56:58 -07:00
firstFunction(x);
secondFunction(x);
2014-03-24 09:14:29 -07:00
---
(program
(statement (assignment (identifier) (object)))
2014-03-26 22:56:58 -07:00
(statement (function_call (identifier) (identifier)))
(statement (function_call (identifier) (identifier))))
2014-03-24 09:14:29 -07:00
==========================================
parses if statements
==========================================
2014-03-26 22:56:58 -07:00
if (isReady()) {
console.log(theData);
}
2014-03-24 09:14:29 -07:00
---
(program
(if_statement (function_call (identifier))
2014-03-26 22:56:58 -07:00
(statement_block (statement (function_call (property_access (identifier) (identifier)) (identifier))))))
2014-03-24 09:14:29 -07:00
2014-03-25 23:40:53 -07:00
==========================================
parses if-else statements
==========================================
if (theCondition) {
2014-03-26 22:56:58 -07:00
firstFunction();
2014-03-25 23:40:53 -07:00
} else {
2014-03-26 22:56:58 -07:00
secondFunction();
2014-03-25 23:40:53 -07:00
}
---
(program (if_statement
(identifier)
2014-03-26 22:56:58 -07:00
(statement_block (statement (function_call (identifier))))
(statement_block (statement (function_call (identifier))))))
2014-03-25 23:40:53 -07:00
2014-03-26 22:56:58 -07:00
==================================================
parses if-else statements with multiple conditions
==================================================
if (firstValue) {
firstFunction();
} else if (secondValue)
secondFunction();
else {
2014-03-26 22:56:58 -07:00
thirdFunction();
}
---
2014-03-26 22:56:58 -07:00
(program
(if_statement (identifier)
(statement_block (statement (function_call (identifier))))
(if_statement (identifier)
(statement (function_call (identifier)))
(statement_block (statement (function_call (identifier)))))))
==========================================
2014-03-26 22:56:58 -07:00
parses function expressions and calls
==========================================
var x = {
theMethod: function(argA, argB) {
var x = argA;
}
};
x.theMethod(5, 6);
---
(program
(statement (assignment
(identifier)
(object (identifier) (function_expression
(formal_parameters (identifier) (identifier))
(statement_block (statement (assignment (identifier) (identifier))))))))
(statement (function_call
(property_access (identifier) (identifier))
(number) (number))))