This commit is contained in:
josh committed 2023-08-20 16:53:54 -04:00
1 parent c7185edef0
commit dace12310a
2 files changed
+55 -34

No files matched your search

+28 -7
View File
@@ -27,8 +27,9 @@ class Propane
end
extensions.each do |extension|
erb = ERB.new(File.read(File.join(File.dirname(File.expand_path(__FILE__)), "../../assets/parser.#{extension}.erb")), trim_mode: "<>")
output_file = @output_file.sub(%r{\.[a-z]+$}, ".#{extension}")
result = erb.result(binding.clone)
File.open(@output_file.sub(%r{\.[a-z]+$}, ".#{extension}"), "wb") do |fh|
File.open(output_file, "wb") do |fh|
fh.write(result)
end
end
@@ -204,10 +205,10 @@ class Propane
code = code.gsub(/\$(\d+)/) do |match|
index = $1.to_i
case @language
when "d"
"statevalues[$-1-n_states+#{index}].pvalue.v_#{rule.components[index - 1].ptypename}"
when "c"
"state_value_stack_index(statevalues, -1 - (int)n_states + #{index})->pvalue.v_#{rule.components[index - 1].ptypename}"
when "d"
"statevalues[$-1-n_states+#{index}].pvalue.v_#{rule.components[index - 1].ptypename}"
end
end
else
@@ -220,7 +221,12 @@ class Propane
unless mode_id
raise Error.new("Lexer mode '#{mode_name}' not found")
end
"context.mode = #{mode_id}u"
case @language
when "c"
"context->mode = #{mode_id}u"
when "d"
"context.mode = #{mode_id}u"
end
end
end
code
@@ -246,11 +252,26 @@ class Propane
# Type.
def get_type_for(max)
if max <= 0xFF
"ubyte"
case @language
when "c"
"uint8_t"
when "d"
"ubyte"
end
elsif max <= 0xFFFF
"ushort"
case @language
when "c"
"uint16_t"
when "d"
"ushort"
end
else
"uint"
case @language
when "c"
"uint32_t"
else
"uint"
end
end
end