Sha256: 212d64149a0c15de9f427c4b83e3ae1b97ab62aa72eb3e01f5f2c17236b89681

Contents?: true

Size: 768 Bytes

Versions: 33

Compression:

Stored size: 768 Bytes

Contents

module Treetop
  module Compiler    
    class CharacterClass < AtomicExpression
      def compile(address, builder, parent_expression = nil)
        super
        
        builder.if__ "has_terminal?(#{grounded_regexp(text_value)}, true, index)" do
          assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))"
          extend_result_with_inline_module
          builder << "@index += 1"
        end
        builder.else_ do
          "terminal_parse_failure(#{single_quote(characters)})"
          assign_result 'nil'
        end
      end

      def grounded_regexp(string)
        # Double any backslashes, then backslash any single-quotes:
        "'\\G#{string.gsub(/\\/) { '\\\\' }.gsub(/'/) { "\\'"}}'"
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
cloudhead-less-1.0.16 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.0 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.1 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.10 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.11 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.12 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.13 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.2 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.3 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.4 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.5 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.6 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.7 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.8 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.1.9 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.2.0 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.2.1 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.2.2 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
cloudhead-less-1.2.3 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
nirvdrum-less-1.1.4 lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb