Begin using whittle to parse preprocessor output

This commit is contained in:
Josh Holtrop 2018-04-06 09:20:11 -04:00
parent 70e8795b32
commit 571fce2672
2 changed files with 25 additions and 16 deletions

View File

@ -7,8 +7,7 @@ module Cxl
class << self class << self
def compile_to(input_fname, output_fname, cppflags) def compile_to(input_fname, output_fname, cppflags)
parser = Parser.new(input_fname, cppflags) parsed = Parser.load(input_fname, cppflags)
parsed = parser.parse
0 0
end end

View File

@ -1,24 +1,34 @@
require "open3" require "open3"
require "whittle"
module Cxl module Cxl
class Parser class Parser < Whittle::Parser
rule(:tok => /./)
rule(:eol => "\n")
def initialize(fname, cppflags) rule(:translation_unit) do |r|
@fname = fname r[]
@cppflags = cppflags r[:translation_unit, :tok]
r[:translation_unit, :eol]
end end
def parse start(:translation_unit)
c_preprocessor_command = Config.instance.c_preprocessor
command = c_preprocessor_command + @cppflags + [@fname] class << self
pp_out, pp_err, status = Open3.capture3(*command)
if pp_err != "" def load(fname, cppflags)
$stderr.write(pp_err) c_preprocessor_command = Config.instance.c_preprocessor
command = c_preprocessor_command + cppflags + [fname]
pp_out, pp_err, status = Open3.capture3(*command)
if pp_err != ""
$stderr.write(pp_err)
end
if status != 0
return
end
Parser.new.parse(pp_out)
end end
if status != 0
return
end
puts pp_out.lines[0, 2]
end end
end end