Class: RKelly::Parser

Inherits:
GeneratedParser show all
Defined in:
lib/rkelly/parser.rb

Constant Summary collapse

TOKENIZER =
Tokenizer.new

Constants inherited from GeneratedParser

GeneratedParser::Racc_arg, GeneratedParser::Racc_debug_parser, GeneratedParser::Racc_token_to_s_table

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GeneratedParser

#_reduce_none

Constructor Details

#initializeParser

Returns a new instance of Parser.



26
27
28
29
30
31
32
# File 'lib/rkelly/parser.rb', line 26

def initialize
  @tokens = []
  @logger = nil
  @terminator = false
  @prev_token = nil
  @comments = []
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



25
26
27
# File 'lib/rkelly/parser.rb', line 25

def logger
  @logger
end

Instance Method Details

#parse(javascript, filename = nil) ⇒ Object

Parse javascript and return an AST



35
36
37
38
39
40
41
# File 'lib/rkelly/parser.rb', line 35

def parse(javascript, filename = nil)
  @tokens = TOKENIZER.raw_tokens(javascript)
  @position = 0
  @filename = filename
  ast = do_parse
  apply_comments(ast)
end

#yyabortObject



43
44
45
# File 'lib/rkelly/parser.rb', line 43

def yyabort
  raise "something bad happened, please report a bug with sample JavaScript"
end