Class: Fdlint::Parser::JS::JsParser

Inherits:
BaseParser show all
Includes:
Expr::Expr, Stat::Stat, ParserVisitable
Defined in:
lib/fdlint/parser/js/js_parser.rb

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

Constants included from Helper::Logger

Helper::Logger::LEVELS

Instance Attribute Summary collapse

Attributes inherited from BaseParser

#source

Instance Method Summary collapse

Methods included from ParserVisitable

#add_visitor, #add_visitors, included, #parse_no_throw, #results, #visitors, wrap

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

#parse_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

#parse_stat_try

Methods included from Expr::Expr

#parse_expr_assignment, #parse_expr_condition, #parse_expr_with_operate, #parse_expression

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 included from Expr::LeftHand

#parse_expr_lefthand, #parse_expr_member, #parse_expr_new

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 inherited from BaseParser

#batch, #check, #eos?, #raw_scan, #reset, #rest_source, #scan, #scanned_source, #scanner_pos, #skip, #skip_empty, #to_s

Methods included from Helper::Logger

#log, #logger

Constructor Details

#initialize(js) ⇒ JsParser

Returns a new instance of JsParser.



19
20
21
22
# File 'lib/fdlint/parser/js/js_parser.rb', line 19

def initialize(js)
  super
  @singleline_comments, @mutiline_comments = [], []
end

Instance Attribute Details

#mutiline_commentsObject (readonly)

Returns the value of attribute mutiline_comments.



17
18
19
# File 'lib/fdlint/parser/js/js_parser.rb', line 17

def mutiline_comments
  @mutiline_comments
end

#singleline_commentsObject (readonly)

Returns the value of attribute singleline_comments.



17
18
19
# File 'lib/fdlint/parser/js/js_parser.rb', line 17

def singleline_comments
  @singleline_comments
end

Instance Method Details

#parse_function_declaration(skip_name = false) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fdlint/parser/js/js_parser.rb', line 38

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_nameObject



53
54
55
# File 'lib/fdlint/parser/js/js_parser.rb', line 53

def parse_function_name
   parse_expr_identifier
end

#parse_function_parametersObject



57
58
59
# File 'lib/fdlint/parser/js/js_parser.rb', line 57

def parse_function_parameters
  Elements.new batch(:parse_expr_identifier, /\)/, /,/)
end

#parse_mutiline_commentObject



68
69
70
71
72
73
# File 'lib/fdlint/parser/js/js_parser.rb', line 68

def parse_mutiline_comment
  log 'parse mutiline comment'
  comment = raw_scan /\/\*[^*]*\*+([^\/*][^*]*\*+)*\//
  log "  #{comment}"
  comment
end

#parse_programObject Also known as: parse



24
25
26
27
28
# File 'lib/fdlint/parser/js/js_parser.rb', line 24

def parse_program
  log 'parse program'
  parse_comments
  Program.new parse_source_elements
end

#parse_singleline_commentObject



61
62
63
64
65
66
# File 'lib/fdlint/parser/js/js_parser.rb', line 61

def parse_singleline_comment
  log 'parse singleline comment'
  comment = raw_scan /\/\/.*/
  log "  #{comment}"
  comment
end

#parse_source_elementObject



32
33
34
35
36
# File 'lib/fdlint/parser/js/js_parser.rb', line 32

def parse_source_element
  log 'parse source_element'

  check(/function\b/) ? parse_function_declaration : parse_statement
end