Module ringo/parser
This module provides an interface to the Rhino parser.
Instance Methods
-
parse(script, [encoding])
-
visit(script, visitorFunction, [encoding])
Create a new Parser object. The constructor must be called with the new keyword.
It takes an options argument which may contain the following properties:
languageVersion (number) the JavaScript language version to use.
Defaults to 180.
parseComments (boolean) whether to attach jsdoc-style comments to parsed nodes.
Defaults to false.
Parameters
| Object |
options |
the parser options |
Parser.prototype.parse
(script, [encoding])
Parse a script resource and return its AST tree.
Parameters
| Resource|String |
script |
a string or org.ringojs.repository.Resource object representing
the script. |
| string |
[encoding] |
optional encoding to use, defaults to UTF-8 |
Returns
| AstNode |
the root node of the AST tree, an instance of org.mozilla.javascript.ast.AstRoot |
Parser.prototype.visit
(script, visitorFunction, [encoding])
Parse a script resource and apply the visitor function to its AST tree.
The function takes one argument which is a org.mozilla.javascript.ast.AstNode.
The function must return true to visit child nodes of the current node.
Parameters
| Resource|String |
script |
a string or org.ringojs.repository.Resource object representing
the script. |
| Function |
visitorFunction |
the visitor function |
| string |
[encoding] |
optional encoding to use, defaults to UTF-8 |
The org.mozilla.javascript.Token class. This can be used to easily check
find out the types of AST nodes:
node.type == Token.NAME
Utility function to get the name value of a node, or the empty
string if it is not a NAME node.
Returns
| String |
the name value of the node |
Get the type name of the token as string such as "CALL" or "NAME".
Returns
| String |
the name of the AST node's type |
Utility function to test whether a node is a NAME node
(a node of type org.mozilla.javascript.ast.Name)
Returns
| Boolean |
true if node is a name node |