Class: XMP2Assert::Parser
- Inherits:
-
Ripper
- Object
- Ripper
- XMP2Assert::Parser
- Defined in:
- lib/xmp2assert/parser.rb
Overview
This is a Ruby parser. Generates ASTs from the given program.
Instance Attribute Summary collapse
-
#sexp ⇒ Array
readonly
Constructed s-expression.
-
#tokens ⇒ Array<Token>
readonly
Program, split into tokens.
Instance Method Summary collapse
-
#initialize(obj, file = nil, line = nil) ⇒ Parser
constructor
A new instance of Parser.
-
#lines ⇒ Array<Array<Token>>
Split tokens into lines.
-
#locations ⇒ String, Integer
The program's file name and line offset.
Constructor Details
#initialize(obj, file = nil, line = nil) ⇒ Parser
Returns a new instance of Parser.
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
#sexp ⇒ Array (readonly)
Returns constructed s-expression.
34 35 36 |
# File 'lib/xmp2assert/parser.rb', line 34 def sexp @sexp end |
#tokens ⇒ Array<Token> (readonly)
Returns program, split into tokens.
33 34 35 |
# File 'lib/xmp2assert/parser.rb', line 33 def tokens @tokens end |
Instance Method Details
#lines ⇒ Array<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 |
#locations ⇒ String, Integer
Returns the program's file name and line offset.
47 48 49 |
# File 'lib/xmp2assert/parser.rb', line 47 def locations return @qfile.__FILE__, @qfile.__LINE__ end |