Class: XMP2Assert::Parser

Inherits:
Ripper
  • Object
show all
Defined in:
lib/xmp2assert/parser.rb

Overview

This is a Ruby parser. Generates ASTs from the given program.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, file = nil, line = nil) ⇒ Parser

Returns a new instance of Parser.

Raises:

  • (SyntaxError)

    failed to parse the program.



38
39
40
41
42
43
44
# File 'lib/xmp2assert/parser.rb', line 38

def initialize obj, file = nil, line = nil
  @qfile = XMP2Assert::Quasifile.new obj, file, line
  super @qfile.read, *locations
  @tokens = []
  @sexp = parse
  @tokens.sort!
end

Instance Attribute Details

#sexpArray (readonly)



34
35
36
# File 'lib/xmp2assert/parser.rb', line 34

def sexp
  @sexp
end

#tokensArray<Token> (readonly)



33
34
35
# File 'lib/xmp2assert/parser.rb', line 33

def tokens
  @tokens
end

Instance Method Details

#linesArray<Array<Token>>

Split tokens into lines.



54
55
56
# File 'lib/xmp2assert/parser.rb', line 54

def lines
  return @lines ||= @tokens.group_by(&:__LINE__)
end

#locationsString, Integer



47
48
49
# File 'lib/xmp2assert/parser.rb', line 47

def locations
  return @qfile.__FILE__, @qfile.__LINE__
end