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

122 lines
3.4 KiB
Text
Raw Normal View History

2014-03-24 09:14:29 -07:00
==========================================
parses multiple statements
==========================================
var x = {}
2014-04-04 08:44:35 -07:00
firstFunction(x)
2014-03-26 22:56:58 -07:00
secondFunction(x);
2014-03-24 09:14:29 -07:00
---
(program
2014-03-28 12:59:47 -07:00
(var_declaration (assignment (identifier) (object)))
(expression_statement (function_call (identifier) (identifier)))
(expression_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()) {
2014-04-04 08:44:35 -07:00
console.log(theData)
}
2014-03-24 09:14:29 -07:00
---
(program
(if_statement (function_call (identifier))
2014-03-28 12:59:47 -07:00
(statement_block (expression_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-28 12:59:47 -07:00
(statement_block (expression_statement (function_call (identifier))))
(statement_block (expression_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)
2014-03-28 12:59:47 -07:00
(statement_block (expression_statement (function_call (identifier))))
2014-03-26 22:56:58 -07:00
(if_statement (identifier)
2014-03-28 12:59:47 -07:00
(expression_statement (function_call (identifier)))
(statement_block (expression_statement (function_call (identifier)))))))
==========================================
parses for loops
==========================================
for (var i = 1; someCondition(i); i = next()) {
doSomething();
}
---
(program (for_statement
(var_declaration (assignment (identifier) (number)))
(expression_statement (function_call (identifier) (identifier)))
(assignment (identifier) (function_call (identifier)))
(statement_block (expression_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);
---
2014-03-28 13:51:32 -07:00
(program
2014-03-28 12:59:47 -07:00
(var_declaration (assignment
(identifier)
(object (identifier) (function_expression
(formal_parameters (identifier) (identifier))
2014-03-28 12:59:47 -07:00
(statement_block (var_declaration (assignment (identifier) (identifier))))))))
(expression_statement (function_call
(property_access (identifier) (identifier))
(number) (number))))
===========================================
parses switch statements
===========================================
switch(x) {
case "hello":
print("one");
break;
case z():
print("two");
break;
default:
print("three");
}
---
(program
(switch_statement (identifier)
(switch_case
(string)
(expression_statement (function_call (identifier) (string)))
(break_statement))
(switch_case
(function_call (identifier))
(expression_statement (function_call (identifier) (string)))
(break_statement))
(switch_case
(expression_statement (function_call (identifier) (string))))))