Begin using whittle to parse preprocessor output
This commit is contained in:
parent
70e8795b32
commit
571fce2672
@ -7,8 +7,7 @@ module Cxl
|
||||
class << self
|
||||
|
||||
def compile_to(input_fname, output_fname, cppflags)
|
||||
parser = Parser.new(input_fname, cppflags)
|
||||
parsed = parser.parse
|
||||
parsed = Parser.load(input_fname, cppflags)
|
||||
|
||||
0
|
||||
end
|
||||
|
@ -1,24 +1,34 @@
|
||||
require "open3"
|
||||
require "whittle"
|
||||
|
||||
module Cxl
|
||||
class Parser
|
||||
class Parser < Whittle::Parser
|
||||
rule(:tok => /./)
|
||||
rule(:eol => "\n")
|
||||
|
||||
def initialize(fname, cppflags)
|
||||
@fname = fname
|
||||
@cppflags = cppflags
|
||||
rule(:translation_unit) do |r|
|
||||
r[]
|
||||
r[:translation_unit, :tok]
|
||||
r[:translation_unit, :eol]
|
||||
end
|
||||
|
||||
def parse
|
||||
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)
|
||||
start(:translation_unit)
|
||||
|
||||
class << self
|
||||
|
||||
def load(fname, cppflags)
|
||||
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
|
||||
if status != 0
|
||||
return
|
||||
end
|
||||
puts pp_out.lines[0, 2]
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user