Class: XRay::JS::Parser
- Inherits:
-
BaseParser
- Object
- BaseParser
- XRay::JS::Parser
- Includes:
- Expr::Expr, Stat::Stat
- Defined in:
- lib/js/parser.rb
Direct Known Subclasses
Constant Summary
Constants included from Expr::Primary
Expr::Primary::RESERVED_WORDS, Expr::Primary::R_HEX, Expr::Primary::R_IDENTIFY, Expr::Primary::R_NUMBERIC, Expr::Primary::R_REGEXP, Expr::Primary::R_STRING, Expr::Primary::R_THIS_NULL_BOOLEAN
Instance Attribute Summary collapse
-
#mutiline_comments ⇒ Object
readonly
Returns the value of attribute mutiline_comments.
-
#singleline_comments ⇒ Object
readonly
Returns the value of attribute singleline_comments.
Instance Method Summary collapse
-
#initialize(js, logger) ⇒ Parser
constructor
A new instance of Parser.
- #parse_function_declaration(skip_name = false) ⇒ Object
- #parse_function_name ⇒ Object
- #parse_function_parameters ⇒ Object
- #parse_mutiline_comment ⇒ Object
- #parse_program ⇒ Object (also: #parse)
- #parse_singleline_comment ⇒ Object
- #parse_source_element ⇒ Object
Methods included from Stat::Stat
#after_parse_statement, #parse_stat_block, #parse_stat_break, #parse_stat_continue, #parse_stat_empty, #parse_stat_expression, #parse_stat_label, #parse_stat_return, #parse_stat_throw, #parse_statement
Methods included from Stat::Var
#parse_stat_var, #parse_stat_var_declaration, #parse_stat_var_declarationlist
Methods included from Stat::If
Methods included from Stat::Switch
#parse_stat_caseblock, #parse_stat_caseclause, #parse_stat_caseclauses, #parse_stat_defaultclause, #parse_stat_switch
Methods included from Stat::Iter
#parse_stat_dowhile, #parse_stat_for, #parse_stat_while
Methods included from Stat::Try
Methods included from Expr::Expr
#parse_expr_assignment, #parse_expr_condition, #parse_expression
Methods included from Expr::Primary
#parse_expr_array, #parse_expr_identifier, #parse_expr_literal_hex, #parse_expr_literal_number, #parse_expr_literal_regexp, #parse_expr_literal_string, #parse_expr_literal_this_null_boolean, #parse_expr_object, #parse_expr_object_item, #parse_expr_parentheses, #parse_expr_primary
Methods included from Expr::LeftHand
#parse_expr_lefthand, #parse_expr_member, #parse_expr_new
Methods included from Expr::Operate
#expr_operate_not_in=, #expr_operate_not_in?, #parse_expr_add, #parse_expr_bit_and, #parse_expr_bit_or, #parse_expr_bit_xor, #parse_expr_equal, #parse_expr_logical_and, #parse_expr_logical_or, #parse_expr_mul, #parse_expr_postfix, #parse_expr_relation, #parse_expr_shift, #parse_expr_unary
Methods inherited from BaseParser
#batch, #check, #eos?, #raw_scan, #reset, #scan, #skip, #skip_empty, #to_s
Constructor Details
#initialize(js, logger) ⇒ Parser
Returns a new instance of Parser.
18 19 20 21 |
# File 'lib/js/parser.rb', line 18 def initialize(js, logger) super js, logger @singleline_comments, @mutiline_comments = [], [] end |
Instance Attribute Details
#mutiline_comments ⇒ Object (readonly)
Returns the value of attribute mutiline_comments.
16 17 18 |
# File 'lib/js/parser.rb', line 16 def mutiline_comments @mutiline_comments end |
#singleline_comments ⇒ Object (readonly)
Returns the value of attribute singleline_comments.
16 17 18 |
# File 'lib/js/parser.rb', line 16 def singleline_comments @singleline_comments end |
Instance Method Details
#parse_function_declaration(skip_name = false) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/js/parser.rb', line 37 def parse_function_declaration(skip_name = false) log 'parse function declaration' pos = skip /function/ name = (skip_name && check(/\(/)) ? nil : parse_function_name skip /\(/ params = parse_function_parameters skip /\)\s*\{/ body = parse_source_elements true skip /\}/ FunctionDeclaraion.new name, params, body, pos end |
#parse_function_name ⇒ Object
52 53 54 |
# File 'lib/js/parser.rb', line 52 def parse_function_name parse_expr_identifier end |
#parse_function_parameters ⇒ Object
56 57 58 |
# File 'lib/js/parser.rb', line 56 def parse_function_parameters Elements.new batch(:parse_expr_identifier, /\)/, /,/) end |
#parse_mutiline_comment ⇒ Object
67 68 69 70 71 72 |
# File 'lib/js/parser.rb', line 67 def parse_mutiline_comment log 'parse mutiline comment' comment = raw_scan /\/\*[^*]*\*+([^\/*][^*]*\*+)*\// log " #{comment}" comment end |
#parse_program ⇒ Object Also known as: parse
23 24 25 26 27 |
# File 'lib/js/parser.rb', line 23 def parse_program log 'parse program' parse_comments Program.new parse_source_elements end |
#parse_singleline_comment ⇒ Object
60 61 62 63 64 65 |
# File 'lib/js/parser.rb', line 60 def parse_singleline_comment log 'parse singleline comment' comment = raw_scan /\/\/.*/ log " #{comment}" comment end |
#parse_source_element ⇒ Object
31 32 33 34 35 |
# File 'lib/js/parser.rb', line 31 def parse_source_element log 'parse source_element' check(/function\b/) ? parse_function_declaration : parse_statement end |