Add regex postfix flags to javascript grammar
- Refactor statement terminators in javascript grammar - Reorganize javascript language tests
This commit is contained in:
parent
082560dd6e
commit
bb4d83ce47
9 changed files with 32747 additions and 32747 deletions
83
spec/runtime/languages/javascript/literals.txt
Normal file
83
spec/runtime/languages/javascript/literals.txt
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
==========================================
|
||||
parses regexes
|
||||
==========================================
|
||||
theFunction(/regex1/, /regex2/g);
|
||||
---
|
||||
(program (expression_statement (function_call (identifier)
|
||||
(regex) (regex))))
|
||||
|
||||
==========================================
|
||||
parses numbers
|
||||
==========================================
|
||||
theFunction(100.0, 200);
|
||||
---
|
||||
(program (expression_statement (function_call (identifier)
|
||||
(number) (number))))
|
||||
|
||||
==========================================
|
||||
parses strings
|
||||
==========================================
|
||||
theFunction('', "", 'single-quoted-string', "double-quoted-string");
|
||||
---
|
||||
(program (expression_statement (function_call (identifier)
|
||||
(string) (string) (string) (string))))
|
||||
|
||||
==========================================
|
||||
parses multiple statements
|
||||
==========================================
|
||||
var x = {}, z, i = 0;
|
||||
firstFunction(x)
|
||||
secondFunction(x);
|
||||
---
|
||||
(program
|
||||
(var_declaration
|
||||
(assignment (identifier) (object))
|
||||
(identifier)
|
||||
(assignment (identifier) (number)))
|
||||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(expression_statement (function_call (identifier) (identifier))))
|
||||
|
||||
==========================================
|
||||
parses function expressions
|
||||
==========================================
|
||||
var x = {
|
||||
theMethod: function(argA, argB) {
|
||||
var x = argA;
|
||||
}
|
||||
};
|
||||
---
|
||||
(program
|
||||
(var_declaration (assignment
|
||||
(identifier)
|
||||
(object (identifier) (function_expression
|
||||
(formal_parameters (identifier) (identifier))
|
||||
(statement_block (var_declaration (assignment (identifier) (identifier)))))))))
|
||||
|
||||
==========================================
|
||||
parses 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();
|
||||
}
|
||||
};
|
||||
---
|
||||
(program
|
||||
(comment)
|
||||
(comment)
|
||||
(var_declaration (assignment (identifier) (object
|
||||
(comment)
|
||||
(comment)
|
||||
(identifier) (function_expression
|
||||
(formal_parameters (identifier) (comment))
|
||||
(statement_block
|
||||
(comment)
|
||||
(expression_statement (function_call (identifier)))))))))
|
||||
|
||||
|
|
@ -1,180 +0,0 @@
|
|||
==========================================
|
||||
parses literals
|
||||
==========================================
|
||||
theFunction(
|
||||
100.0,
|
||||
200,
|
||||
/the-regex/,
|
||||
'',
|
||||
"",
|
||||
'the-single-quoted-string',
|
||||
"the-double-quoted-string"
|
||||
);
|
||||
---
|
||||
(program (expression_statement (function_call
|
||||
(identifier)
|
||||
(number)
|
||||
(number)
|
||||
(regex)
|
||||
(string)
|
||||
(string)
|
||||
(string)
|
||||
(string))))
|
||||
|
||||
==========================================
|
||||
parses constructor calls
|
||||
==========================================
|
||||
var x = new Node(5, new Node(3, null));
|
||||
---
|
||||
(program (var_declaration
|
||||
(assignment (identifier)
|
||||
(constructor_call (function_call (identifier)
|
||||
(number)
|
||||
(constructor_call (function_call (identifier)
|
||||
(number)
|
||||
(null))))))))
|
||||
|
||||
==========================================
|
||||
parses multiple statements
|
||||
==========================================
|
||||
var x = {}, z, i = 0;
|
||||
firstFunction(x)
|
||||
secondFunction(x);
|
||||
---
|
||||
(program
|
||||
(var_declaration
|
||||
(assignment (identifier) (object))
|
||||
(identifier)
|
||||
(assignment (identifier) (number)))
|
||||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(expression_statement (function_call (identifier) (identifier))))
|
||||
|
||||
==========================================
|
||||
parses function expressions and calls
|
||||
==========================================
|
||||
var x = {
|
||||
theMethod: function(argA, argB) {
|
||||
var x = argA;
|
||||
}
|
||||
};
|
||||
|
||||
x.theMethod(5, 6);
|
||||
---
|
||||
(program
|
||||
(var_declaration (assignment
|
||||
(identifier)
|
||||
(object (identifier) (function_expression
|
||||
(formal_parameters (identifier) (identifier))
|
||||
(statement_block (var_declaration (assignment (identifier) (identifier))))))))
|
||||
(expression_statement (function_call
|
||||
(property_access (identifier) (identifier))
|
||||
(number) (number))))
|
||||
|
||||
==========================================
|
||||
parses property access with dot notation
|
||||
==========================================
|
||||
object.property = "the-value";
|
||||
print(object.property);
|
||||
---
|
||||
(program
|
||||
(expression_statement (assignment
|
||||
(property_access (identifier) (identifier))
|
||||
(string)))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(property_access (identifier) (identifier)))))
|
||||
|
||||
===========================================
|
||||
parses dynamic property access
|
||||
==========================================
|
||||
object[propertName()] = propertyValue();
|
||||
print(object[propertyName()]);
|
||||
---
|
||||
(program
|
||||
(expression_statement (assignment
|
||||
(property_access (identifier) (function_call (identifier)))
|
||||
(function_call (identifier))))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(property_access (identifier) (function_call (identifier))))))
|
||||
|
||||
==========================================
|
||||
parses 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();
|
||||
}
|
||||
};
|
||||
---
|
||||
(program
|
||||
(comment)
|
||||
(comment)
|
||||
(var_declaration (assignment (identifier) (object
|
||||
(comment)
|
||||
(comment)
|
||||
(identifier) (function_expression
|
||||
(formal_parameters (identifier) (comment))
|
||||
(statement_block
|
||||
(comment)
|
||||
(expression_statement (function_call (identifier)))))))))
|
||||
|
||||
======================================
|
||||
parses real code
|
||||
=====================================
|
||||
_.each = _.forEach = function(obj, iterator, context) {
|
||||
if (obj == null) return obj;
|
||||
if (obj.length === obj.length) {
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (iterator.call(context, obj[i], i, obj) === breaker) return;
|
||||
}
|
||||
} else {
|
||||
var keys = _.keys(obj);
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
---
|
||||
(program (expression_statement
|
||||
(assignment
|
||||
(property_access (identifier) (identifier))
|
||||
(assignment (property_access (identifier) (identifier))
|
||||
(function_expression
|
||||
(formal_parameters (identifier) (identifier) (identifier))
|
||||
(statement_block
|
||||
(if_statement (bool_op (identifier) (null)) (return_statement (identifier)))
|
||||
(if_statement
|
||||
(bool_op (property_access (identifier) (identifier)) (property_access (identifier) (identifier)))
|
||||
(statement_block
|
||||
(for_statement
|
||||
(var_declaration (assignment (identifier) (number)))
|
||||
(expression_statement (bool_op (identifier) (identifier)))
|
||||
(math_op (identifier))
|
||||
(statement_block
|
||||
(if_statement
|
||||
(bool_op (function_call (property_access (identifier) (identifier)) (identifier) (property_access (identifier) (identifier)) (identifier) (identifier)) (identifier))
|
||||
(return_statement)))))
|
||||
(statement_block
|
||||
(var_declaration (assignment (identifier) (function_call (property_access (identifier) (identifier)) (identifier))))
|
||||
(for_statement
|
||||
(var_declaration (assignment (identifier) (number)))
|
||||
(expression_statement (bool_op (identifier) (identifier)))
|
||||
(math_op (identifier))
|
||||
(statement_block
|
||||
(if_statement
|
||||
(bool_op (function_call
|
||||
(property_access (identifier) (identifier))
|
||||
(identifier)
|
||||
(property_access (identifier) (property_access (identifier) (identifier)))
|
||||
(property_access (identifier) (identifier)) (identifier)) (identifier))
|
||||
(return_statement))))))
|
||||
(return_statement (identifier))))))))
|
||||
|
|
@ -1,3 +1,53 @@
|
|||
==========================================
|
||||
parses function calls
|
||||
==========================================
|
||||
x.theMethod(5, 6);
|
||||
---
|
||||
(program (expression_statement (function_call
|
||||
(property_access (identifier) (identifier))
|
||||
(number) (number))))
|
||||
|
||||
==========================================
|
||||
parses constructor calls
|
||||
==========================================
|
||||
var x = new Node(5, new Node(3, null));
|
||||
---
|
||||
(program (var_declaration
|
||||
(assignment (identifier)
|
||||
(constructor_call (function_call (identifier)
|
||||
(number)
|
||||
(constructor_call (function_call (identifier)
|
||||
(number)
|
||||
(null))))))))
|
||||
|
||||
==========================================
|
||||
parses property access with dot notation
|
||||
==========================================
|
||||
object.property = "the-value";
|
||||
print(object.property);
|
||||
---
|
||||
(program
|
||||
(expression_statement (assignment
|
||||
(property_access (identifier) (identifier))
|
||||
(string)))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(property_access (identifier) (identifier)))))
|
||||
|
||||
===========================================
|
||||
parses dynamic property access
|
||||
==========================================
|
||||
object[propertName()] = propertyValue();
|
||||
print(object[propertyName()]);
|
||||
---
|
||||
(program
|
||||
(expression_statement (assignment
|
||||
(property_access (identifier) (function_call (identifier)))
|
||||
(function_call (identifier))))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(property_access (identifier) (function_call (identifier))))))
|
||||
|
||||
==========================================
|
||||
parses ternary expressions
|
||||
==========================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue