/usr/lib/ruby/vendor_ruby/treetop/compiler/node_classes/terminal.rb is in ruby-treetop 1.6.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 | module Treetop
module Compiler
class Terminal < AtomicExpression
def compile(address, builder, parent_expression = nil)
super
# Handle modifiers:
insensitive = modifiers.text_value.include? 'i'
re = modifiers.text_value.include? 'r'
if re
grounded_regexp = "#{('\A'+eval(string)).inspect}"
cache_key = "'__#{modifiers.text_value}__'+(gr = #{grounded_regexp})"
re_modifiers = "#{insensitive ? 'Regexp::IGNORECASE' : 0}"
str = "@regexps[#{cache_key}] ||= Regexp.new(gr, #{re_modifiers})"
mode = ':regexp'
elsif insensitive
str = string.downcase
string_length = eval(str).length
mode = ':insens'
else
str = string
string_length = eval(str).length
mode = 'false'
end
builder.if__ "(match_len = has_terminal?(#{str}, #{mode}, index))" do
if address == 0 || decorated? || mode != 'false' || string_length > 1
assign_result "instantiate_node(#{node_class_name},input, index...(index + match_len))"
# debugger if parent_expression and parent_expression.inline_modules.size > 0
# extend_result_with_inline_module parent_expression
if parent_expression
parent_expression.inline_modules.each do |inline|
extend_result inline.module_name
end
end
else
assign_lazily_instantiated_node
end
builder << "@index += match_len"
end
builder.else_ do
builder << "terminal_parse_failure(#{expected})"
assign_result 'nil'
end
end
def expected
single_quote(string)
end
def inline_module
nil
end
end
end
end
|