Class: Nydp::Builtin::StringMatch
- Includes:
- Base, Singleton
- Defined in:
- lib/nydp/builtin/string_match.rb
Instance Method Summary collapse
Methods included from Base
#builtin_invoke_1, #builtin_invoke_2, #builtin_invoke_3, #builtin_invoke_4, #handle_error, #inspect, #invoke, #invoke_1, #invoke_2, #invoke_3, #invoke_4, #name, #nydp_type, #to_s
Methods included from Helper
#cons, #list, #literal?, #pair?, #sig, #sym, #sym?
Methods included from Converter
Instance Method Details
#builtin_invoke(vm, args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nydp/builtin/string_match.rb', line 4 def builtin_invoke vm, args kmatch = Nydp::Symbol.mk :match , vm.ns kcaptures = Nydp::Symbol.mk :captures, vm.ns target = args.car.to_s pattern = Regexp.new(args.cdr.car.to_s) match = pattern.match target if match result = Nydp::Hash.new result[kmatch] = match.to_s result[kcaptures] = Nydp::Pair.from_list match.captures.map { |cap| cap.to_s } else result = Nydp::NIL end vm.push_arg result end |