Begin using whittle to parse preprocessor output
This commit is contained in:
parent
70e8795b32
commit
571fce2672
@ -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
|
||||||
|
@ -1,16 +1,24 @@
|
|||||||
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)
|
||||||
|
|
||||||
|
class << self
|
||||||
|
|
||||||
|
def load(fname, cppflags)
|
||||||
c_preprocessor_command = Config.instance.c_preprocessor
|
c_preprocessor_command = Config.instance.c_preprocessor
|
||||||
command = c_preprocessor_command + @cppflags + [@fname]
|
command = c_preprocessor_command + cppflags + [fname]
|
||||||
pp_out, pp_err, status = Open3.capture3(*command)
|
pp_out, pp_err, status = Open3.capture3(*command)
|
||||||
if pp_err != ""
|
if pp_err != ""
|
||||||
$stderr.write(pp_err)
|
$stderr.write(pp_err)
|
||||||
@ -18,7 +26,9 @@ module Cxl
|
|||||||
if status != 0
|
if status != 0
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
puts pp_out.lines[0, 2]
|
Parser.new.parse(pp_out)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user