yadriggy 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5af1fba63b8de51cbdd01aec66b557292134c43f
4
- data.tar.gz: f797ce20c6a020eac1cd3ecc7de7cdc6567ccd13
2
+ SHA256:
3
+ metadata.gz: 965a6bb4be2daef3f40ee7c19460bc96cc991f0a6e438c5dbf60f4b725ab6950
4
+ data.tar.gz: 10bc72c4deaec889fc53da6f6d0e91acf0c23f77b4dc58af06587d5574720a32
5
5
  SHA512:
6
- metadata.gz: e91097275404a17c9c6e98c1ee0b4ae58c4c21a13562baae2fdad877d0d9905dc53878a99d754ba729465d2e8716d925ef1191ce836419307ea85c2c91f25605
7
- data.tar.gz: 8a6e29162f1f420ec5598ffed5de0a179cc45f3cf9639570d08d281566bff2bf21d176730b5767bb19f0d4a10012825eda4e6044dc86626da47e5f95cef0e857
6
+ metadata.gz: 42d1f8b97ec8384892b667921a09bee0a4abbb1d90c2bacd426a1386bb68e986061b950b3ff151065064fbc9230554b564f9ba7a08afd165a19d790670664118
7
+ data.tar.gz: 6d2aa2b2c56d28da350eaec79535b2c03d843362904d7cdf1da7264d2cd22a411f5f706945414a889eeaed70c1ef8e096364f06b59e9d1c3a845cddd24e09558
data/lib/yadriggy/ast.rb CHANGED
@@ -257,7 +257,7 @@ module Yadriggy
257
257
  attr_reader :column
258
258
 
259
259
  def self.tags()
260
- [:@int, :@float]
260
+ [:@int, :@float, :@rational, :@imaginary]
261
261
  end
262
262
 
263
263
  def initialize(sexp)
@@ -270,8 +270,12 @@ module Yadriggy
270
270
  end
271
271
  when :@float
272
272
  sexp[1].to_f
273
+ when :@rational
274
+ sexp[1].to_r
275
+ when :@imaginary
276
+ Complex(sexp[1])
273
277
  else
274
- raise "unknown symbol " + sexp[0]
278
+ raise "unknown symbol #{sexp[0]}"
275
279
  end
276
280
  @line_no = sexp[2][0].to_i
277
281
  @column = sexp[2][1].to_i
@@ -300,11 +304,11 @@ module Yadriggy
300
304
  end
301
305
 
302
306
  # @param [Array] s an S-expression.
303
- # @param [Symbol] tag
307
+ # @param [Array<Symbol>] tags
304
308
  # @return [Array] the S-expression if it starts with the tag.
305
309
  # Otherwise, raise an error.
306
- def has_tag?(s, tag)
307
- raise "s-exp is not :#{tag.to_s}. #{s}" if !s.nil? && s[0] != tag
310
+ def has_tag?(s, *tags)
311
+ raise "s-exp is not :#{tags.join(", ")}. #{s}" if !s.nil? && !tags.include?(s[0])
308
312
  s
309
313
  end
310
314
  end
@@ -916,7 +920,7 @@ module Yadriggy
916
920
  @name = if sexp[3] == :call
917
921
  nil
918
922
  else
919
- @name = to_node(has_tag?(sexp[3], :@ident))
923
+ @name = to_node(has_tag?(sexp[3], :@ident, :@const))
920
924
  end
921
925
  add_child(@receiver)
922
926
  add_child(@name)
@@ -1596,7 +1600,7 @@ module Yadriggy
1596
1600
  @name = if def_name[0] == :@op
1597
1601
  to_node(def_name)
1598
1602
  else
1599
- to_node(has_tag?(def_name, :@ident))
1603
+ to_node(has_tag?(def_name, :@ident, :@const))
1600
1604
  end
1601
1605
  add_child(@name)
1602
1606
 
@@ -238,8 +238,12 @@ module Yadriggy
238
238
  end
239
239
  when :**, :*, :/, :%, :+, :-
240
240
  if left_t <= RubyClass::Numeric
241
- if left_t <= RubyClass::Float || right_t <= RubyClass::Float
241
+ if left_t <= RubyClass::Complex || right_t <= RubyClass::Complex
242
+ return RubyClass::Complex
243
+ elsif left_t <= RubyClass::Float || right_t <= RubyClass::Float
242
244
  return RubyClass::Float
245
+ elsif left_t <= RubyClass::Rational || right_t <= RubyClass::Rational
246
+ return RubyClass::Rational
243
247
  else
244
248
  return RubyClass::Integer
245
249
  end
@@ -514,7 +514,7 @@ module Yadriggy
514
514
  block_param: (Identifier) }
515
515
  Block <= Parameters + { body: exprs }
516
516
  Lambda <= Block
517
- Call <= { receiver: (expr), op: (Symbol), name: (Identifier),
517
+ Call <= { receiver: (expr), op: (Symbol), name: (Identifier | Const),
518
518
  args: [ expr ], block_arg: (expr), block: (Block) }
519
519
  Command <= Call
520
520
  Exprs <= { expressions: [ expr ] }
@@ -524,7 +524,7 @@ module Yadriggy
524
524
  else: (exprs), ensure: (exprs) }
525
525
  BeginEnd <= { body: exprs, rescue: (Rescue) }
526
526
  Def <= Parameters +
527
- { singular: (expr), name: Identifier, body: exprs,
527
+ { singular: (expr), name: (Identifier | Const), body: exprs,
528
528
  rescue: (Rescue) }
529
529
  ModuleDef <= { name: Const | ConstPathRef, body: exprs,
530
530
  rescue: (Rescue) }
data/lib/yadriggy/type.rb CHANGED
@@ -381,6 +381,8 @@ module Yadriggy
381
381
  RubyClass::String = RubyClass.make(String)
382
382
  RubyClass::Integer = RubyClass.make(Integer)
383
383
  RubyClass::Float = RubyClass.make(Float)
384
+ RubyClass::Rational = RubyClass.make(Rational)
385
+ RubyClass::Complex = RubyClass.make(Complex)
384
386
  RubyClass::Range = RubyClass.make(Range)
385
387
  RubyClass::Hash = RubyClass.make(Hash)
386
388
  RubyClass::Array = RubyClass.make(Array)
@@ -621,10 +623,21 @@ module Yadriggy
621
623
  # Obtains the name of this type.
622
624
  # @return [String] the type name.
623
625
  def name
624
- name = @ruby_class.name
626
+ name = @ruby_class.name.dup
625
627
  name << '<' << @args.map{|e| e.name }.join(',') << '>'
626
628
  name
627
629
  end
630
+
631
+ # @api private
632
+ # Gets a method with the given name declared in this type.
633
+ # `nil` is returned when the method is not exactly determined.
634
+ #
635
+ # @return [Method|nil]
636
+ def get_method_object(method_name)
637
+ exact_type.instance_method(method_name)
638
+ rescue NameError
639
+ Type.error_found!("no such method: #{@ruby_class}\##{method_name}")
640
+ end
628
641
  end
629
642
 
630
643
  # A role that can be attached to a {Type} object.
@@ -1,5 +1,5 @@
1
1
  # Copyright (C) 2017- Shigeru Chiba. All rights reserved.
2
2
 
3
3
  module Yadriggy
4
- VERSION = "1.3.0"
4
+ VERSION = "1.4.0"
5
5
  end
data/yadriggy.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "pry"
29
29
 
30
30
  spec.add_development_dependency "bundler"
31
- spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rake", ">= 12.3.3"
32
32
  spec.add_development_dependency "yard"
33
33
  # spec.add_development_dependency "minitest", "~> 5.0"
34
34
  spec.add_development_dependency "test-unit", "~> 3.2.5"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yadriggy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shigeru Chiba
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-26 00:00:00.000000000 Z
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pycall
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: 12.3.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: 12.3.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: yard
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -176,8 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
178
  requirements: []
179
- rubyforge_project:
180
- rubygems_version: 2.6.14
179
+ rubygems_version: 3.3.11
181
180
  signing_key:
182
181
  specification_version: 4
183
182
  summary: library for building a DSL embedded in Ruby.