Class/Module Index [+]

Quicksearch

RKelly::Parser

Constants

TOKENIZER

Attributes

logger[RW]

Public Class Methods

new() click to toggle source
# File lib/rkelly/parser.rb, line 30
def initialize
  @tokens = []
  @logger = nil
  @terminator = false
  @prev_token = nil
  @comments = []
end

Public Instance Methods

parse(javascript, filename = nil) click to toggle source

Parse javascript and return an AST

# File lib/rkelly/parser.rb, line 39
def parse(javascript, filename = nil)
  @tokens = TOKENIZER.raw_tokens(javascript)
  @position = 0
  @filename = filename
  ast = do_parse
  ast.comments = @comments if ast
  ast
end
stopped_at() click to toggle source

When parsing finishes without all tokens being parsed, returns the token at which the parsing stopped. Returns nil when parser reached to the very last token (but possibly still failed as it expeced more tokens).

Useful for pin-pointing the position of a syntax error.

# File lib/rkelly/parser.rb, line 58
def stopped_at
  if @position < @tokens.length
    @tokens[@position-1]
  else
    nil
  end
end
yyabort() click to toggle source
# File lib/rkelly/parser.rb, line 48
def yyabort
  raise "something bad happened, please report a bug with sample JavaScript"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.