Class: JsDuck::JsParser
- Inherits:
-
Object
- Object
- JsDuck::JsParser
- Defined in:
- lib/jsduck/js_parser.rb
Overview
JavaScript parser that internally uses Esprima.js
Instance Method Summary collapse
-
#initialize(input, options = {}) ⇒ JsParser
constructor
Initializes the parser with JavaScript source code to be parsed.
-
#parse ⇒ Object
Parses JavaScript source code and returns array of hashes like this:.
Constructor Details
#initialize(input, options = {}) ⇒ JsParser
Initializes the parser with JavaScript source code to be parsed.
10 11 12 13 14 15 16 |
# File 'lib/jsduck/js_parser.rb', line 10 def initialize(input, = {}) @input = input # Initialize line number counting @start_index = 0 @start_linenr = 1 end |
Instance Method Details
#parse ⇒ Object
Parses JavaScript source code and returns array of hashes like this:
{
:comment => "The contents of the comment",
:code => {...AST data structure for code following the comment...},
:linenr => 12, // Beginning with 1
:type => :doc_comment, // or :plain_comment
}
27 28 29 30 31 32 |
# File 'lib/jsduck/js_parser.rb', line 27 def parse @ast = Esprima.parse(@input) @ast["comments"] = merge_comments(@ast["comments"]) locate_comments end |