Class: RubyQt6::RSpec::BandoFileParser
- Inherits:
-
Object
- Object
- RubyQt6::RSpec::BandoFileParser
- Defined in:
- lib/qt6/rspec/bando_file_parser.rb
Defined Under Namespace
Classes: MissingLine
Instance Method Summary collapse
-
#initialize(cppfile, qmod) ⇒ BandoFileParser
constructor
A new instance of BandoFileParser.
- #line ⇒ Object
- #parse ⇒ Object
- #parse_bando_definition(bando) ⇒ Object
- #parse_bando_definitions ⇒ Object
- #parse_bando_variants_declaration ⇒ Object
- #take_next_line ⇒ Object
Constructor Details
#initialize(cppfile, qmod) ⇒ BandoFileParser
Returns a new instance of BandoFileParser.
12 13 14 15 16 |
# File 'lib/qt6/rspec/bando_file_parser.rb', line 12 def initialize(cppfile, qmod) @qmod = qmod @bandoes = [] @lines, @lineno = File.read(cppfile).lines, 0 end |
Instance Method Details
#line ⇒ Object
97 98 99 |
# File 'lib/qt6/rspec/bando_file_parser.rb', line 97 def line @lines[@lineno].strip end |
#parse ⇒ Object
18 19 20 21 22 23 |
# File 'lib/qt6/rspec/bando_file_parser.rb', line 18 def parse parse_bando_variants_declaration parse_bando_definitions raise MissingLine.new("}", line) unless line == "}" @bandoes end |
#parse_bando_definition(bando) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/qt6/rspec/bando_file_parser.rb', line 63 def parse_bando_definition(bando) name = bando.name expected = "rb_mBando_c#{name} =" if line == expected take_next_line else raise MissingLine.new(expected, line) end expected = "define_bando_#{bando.template.downcase}_under<Bando_#{name}, #{name}>(rb_mQt6Bando, \"#{name}\")" if line == expected take_next_line else raise MissingLine.new(expected, line) end expected = ".define_constructor(Constructor<Bando_#{name}, #{bando.constructor_args}>()" if line.start_with?(expected) take_next_line else raise MissingLine.new(expected, line) end while line == "" || line == "}" return if line == "}" take_next_line end end |
#parse_bando_definitions ⇒ Object
57 58 59 60 61 |
# File 'lib/qt6/rspec/bando_file_parser.rb', line 57 def parse_bando_definitions @bandoes.each do |bando| parse_bando_definition(bando) end end |
#parse_bando_variants_declaration ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/qt6/rspec/bando_file_parser.rb', line 25 def parse_bando_variants_declaration while line == "" || line.start_with?("#include") || line.start_with?("using ") matched = line.match(/^using Bando_(\w+) = Bando(\w+)<(\w+), (.*)>/) if matched.nil? take_next_line next end if matched[1] != matched[3] expected = "using Bando_#{matched[1]} = Bando#{matched[2]}<#{matched[1]}, ..." raise MissingLine.new(expected, line) else take_next_line end @bandoes << Struct.new(:name, :template, :constructor_args).new(matched[1], matched[2], matched[4]) end @bandoes.each do |bando| expected = "Rice::Class rb_mBando_c#{bando.name};" if line == expected take_next_line else raise MissingLine.new(expected, line) end end while line == "" || line.start_with?("void Init_bando_q") || line == "{" take_next_line end end |
#take_next_line ⇒ Object
93 94 95 |
# File 'lib/qt6/rspec/bando_file_parser.rb', line 93 def take_next_line @lineno += 1 end |