gloss 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gloss/writer.rb CHANGED
@@ -1,43 +1,59 @@
1
- # frozen_string_literal: true
2
-
1
+
3
2
  ##### This file was generated by Gloss; any changes made here will be overwritten.
4
- ##### See src/ to make changes
3
+ ##### See / to make changes
5
4
 
6
5
  require "pathname"
7
6
  require "fileutils"
8
7
  module Gloss
9
8
  class Writer
10
- def initialize(content, src_path, output_path = Pathname.new(Utils.src_path_to_output_path(src_path)))
9
+ def initialize(content, src_path, output = nil)
11
10
  @content = content
12
11
  @src_path = src_path
13
- @output_path = output_path
12
+ @output = output
14
13
  end
15
14
  def run()
16
- unless @output_path.parent
17
- .exist?
18
- FileUtils.mkdir_p(@output_path.parent)
19
- end
20
- File.open(@output_path, "wb") { |file|
15
+ write_to_output() { |otpt|
21
16
  sb = shebang
22
17
  (if sb
23
- file.puts(sb)
18
+ otpt.puts(sb)
24
19
  end)
25
- file.puts(@content)
20
+ otpt.puts(@content)
26
21
  }
27
22
  end
28
23
  private def shebang()
29
- (if @output_path.executable?
30
- first_line = File.open(@src_path) { |f|
31
- f.readline
32
- }
33
- (if first_line.start_with?("#!")
34
- first_line
24
+ case @output
25
+ when Pathname
26
+ (if @output.executable?
27
+ first_line = File.open(@src_path) { |f|
28
+ f.readline
29
+ }
30
+ (if first_line.start_with?("#!")
31
+ first_line
32
+ else
33
+ nil
34
+ end)
35
+ end)
35
36
  else
36
37
  nil
37
- end)
38
- else
39
- nil
40
- end)
38
+ end
39
+ end
40
+ private def write_to_output(&blk)
41
+ case @output
42
+ when IO, StringIO
43
+ yield(@output)
44
+ else
45
+ output = @output || Pathname.new(Utils.src_path_to_output_path(@src_path))
46
+ unless output.parent
47
+ .exist?
48
+ FileUtils.mkdir_p(output.parent)
49
+ end
50
+ File.open(output, "wb") { |file|
51
+ yield(file)
52
+ }
53
+ (if Config.prettify_output_executable_path
54
+ system(Config.prettify_output_executable_path, @output.to_s)
55
+ end)
56
+ end
41
57
  end
42
58
  end
43
59
  end
data/logo.svg ADDED
@@ -0,0 +1,6 @@
1
+ <svg width="171px" height="100px" xmlns="http://www.w3.org/2000/svg" viewBox="175 25 150 150" style="background-color: transparent;" preserveAspectRatio="xMidYMid"><defs><filter id="editing-golden" x="-100%" y="-100%" width="300%" height="300%"><feFlood flood-color="#000000" result="flood"></feFlood><feFlood flood-color="#eaa5a5" result="flood-light"></feFlood><feComposite operator="in" in="flood" in2="SourceAlpha" result="flood-comp"></feComposite><feGaussianBlur in="flood-comp" stdDeviation="3" result="blur"></feGaussianBlur><feOffset in="blur" dy="3" result="offset-blur"></feOffset><feComponentTransfer in="offset-blur" result="comp-blur"><feFuncA type="linear" slope="0.7" intercept="-0.1"></feFuncA></feComponentTransfer><feSpecularLighting surfaceScale="200" specularConstant="20" specularExponent="1" lighting-color="#fff" in="blur" result="specular"><fePointLight x="-250" y="-250" z="3500"></fePointLight></feSpecularLighting><feComponentTransfer in="specular" result="inspecular"><feFuncA type="linear" slope="-1" intercept="1"></feFuncA></feComponentTransfer><feComposite operator="in" in="flood-light" in2="inspecular" result="inspecular2"></feComposite><feComposite operator="in" in="inspecular2" in2="SourceAlpha" result="light"></feComposite><feMerge><feMergeNode in="comp-blur"></feMergeNode><feMergeNode in="SourceGraphic"></feMergeNode><feMergeNode in="light"></feMergeNode></feMerge></filter></defs><g filter="url(#editing-golden)"><g transform="translate(119.08499717712402, 130.10500073432922)"><path d="M27.50-50.40L27.50-50.40L27.50-50.40Q23.22-39.91 23.22-30.87L23.22-30.87L23.22-30.87Q23.22-21.83 26.91-17.55L26.91-17.55L26.91-17.55Q30.60-13.27 38.84-13.27L38.84-13.27L38.84-13.27Q43.76-13.27 47.51-16.80L47.51-16.80L47.51-16.80Q48.69-25.57 49.43-28.46L49.43-28.46L49.43-28.46Q51.25-35.52 55.00-35.52L55.00-35.52L55.00-35.52Q57.99-35.52 60.67-31.40L60.67-31.40L60.67-31.40Q63.34-27.29 63.24-24.40L63.24-24.40L63.24-24.40Q63.24-19.58 59.38-6.53L59.38-6.53L59.38-6.53Q66.88-12.20 76.61-23.33L76.61-23.33L76.61-23.33Q78.00-24.93 78.97-24.93L78.97-24.93L78.97-24.93Q80.46-24.93 80.46-21.40L80.46-21.40L80.46-21.40Q80.46-14.55 73.62-6.79L73.62-6.79L73.62-6.79Q66.77 0.96 55.43 5.56L55.43 5.56L55.43 5.56Q54.57 7.60 54.03 9.42L54.03 9.42L54.03 9.42Q53.50 11.23 52.64 13.80L52.64 13.80L52.64 13.80Q51.79 16.37 49.65 19.42L49.65 19.42L49.65 19.42Q47.51 22.47 44.30 24.61L44.30 24.61L44.30 24.61Q37.45 29.32 28.62 29.32L28.62 29.32L28.62 29.32Q19.79 29.32 13.86 25.41L13.86 25.41L13.86 25.41Q7.92 21.51 7.92 14.66L7.92 14.66L7.92 14.66Q7.92 11.34 11.13 9.20L11.13 9.20L11.13 9.20Q14.34 7.06 19.47 5.51L19.47 5.51L19.47 5.51Q24.61 3.96 31.03 2.78L31.03 2.78L31.03 2.78Q37.45 1.60 43.87 0.11L43.87 0.11L43.87 0.11Q44.73-2.35 45.15-4.49L45.15-4.49L45.15-4.49Q40.98-1.28 34.88-1.28L34.88-1.28L34.88-1.28Q22.15-1.28 14.87-6.53L14.87-6.53L14.87-6.53Q6.42-12.63 6.42-25.57L6.42-25.57L6.42-25.57Q6.42-42.48 14.98-57.67L14.98-57.67L14.98-57.67Q12.41-60.67 10.81-63.93L10.81-63.93L10.81-63.93Q9.20-67.20 9.20-68.91L9.20-68.91L9.20-68.91Q9.20-71.90 11.34-71.80L11.34-71.80L11.34-71.80Q12.73-71.80 14.55-70.08L14.55-70.08L14.55-70.08Q16.37-68.37 17.49-67.20L17.49-67.20L17.49-67.20Q18.62-66.02 19.90-65.06L19.90-65.06L19.90-65.06Q25.47-72.12 32.96-76.50L32.96-76.50L32.96-76.50Q40.45-80.89 49.43-80.89L49.43-80.89L49.43-80.89Q58.42-80.89 63.45-77.58L63.45-77.58L63.45-77.58Q68.48-74.26 68.48-66.02L68.48-66.02L68.48-66.02Q68.48-57.78 62.11-52.32L62.11-52.32L62.11-52.32Q55.75-46.87 44.41-46.87L44.41-46.87L44.41-46.87Q36.59-46.87 27.50-50.40ZM31.03-57.67L31.03-57.67L31.03-57.67Q36.91-55.10 45.26-55.10L45.26-55.10L45.26-55.10Q50.40-55.10 53.50-57.89L53.50-57.89L53.50-57.89Q56.60-60.67 56.60-63.93L56.60-63.93L56.60-63.93Q56.60-67.20 54.52-68.75L54.52-68.75L54.52-68.75Q52.43-70.30 49.01-70.30L49.01-70.30L49.01-70.30Q38.73-70.30 31.03-57.67ZM27.39 21.08L27.39 21.08L27.39 21.08Q34.67 21.08 40.13 10.16L40.13 10.16L40.13 10.16Q34.24 11.66 30.17 12.52L30.17 12.52L30.17 12.52Q26.11 13.38 23.59 14.02L23.59 14.02L23.59 14.02Q21.08 14.66 19.96 15.30L19.96 15.30L19.96 15.30Q18.83 15.94 18.83 17.12L18.83 17.12L18.83 17.12Q18.83 19.15 21.56 20.06L21.56 20.06L21.56 20.06Q24.29 20.97 27.39 21.08ZM98.97 0.32L98.97 0.32L98.97 0.32Q83.67 0.43 78.11-11.13L78.11-11.13L78.11-11.13Q76.18-15.19 76.18-21.35L76.18-21.35L76.18-21.35Q76.18-27.50 77.25-34.45L77.25-34.45L77.25-34.45Q79.39-48.36 85.49-60.13L85.49-60.13L85.49-60.13Q88.60-66.13 92.45-70.41L92.45-70.41L92.45-70.41Q100.90-79.82 111.28-79.72L111.28-79.72L111.28-79.72Q115.88-79.72 118.50-77.20L118.50-77.20L118.50-77.20Q121.12-74.69 121.12-69.98L121.12-69.98L121.12-69.98Q121.12-65.27 118.34-60.51L118.34-60.51L118.34-60.51Q115.56-55.75 111.23-50.66L111.23-50.66L111.23-50.66Q106.89-45.58 101.65-40.02L101.65-40.02L101.65-40.02Q96.41-34.45 91.38-27.93L91.38-27.93L91.38-23.65L91.38-23.65Q91.38-17.66 93.95-14.87L93.95-14.87L93.95-14.87Q96.51-12.09 99.94-12.09L99.94-12.09L99.94-12.09Q109.14-12.09 116.20-21.19L116.20-21.19L116.20-21.19Q119.09-24.93 120.59-24.93L120.59-24.93L120.59-24.93Q122.09-24.93 122.09-21.29L122.09-21.29L122.09-21.29Q122.09-17.66 120.11-13.86L120.11-13.86L120.11-13.86Q118.13-10.06 114.92-6.90L114.92-6.90L114.92-6.90Q111.71-3.75 107.53-1.71L107.53-1.71L107.53-1.71Q103.36 0.32 98.97 0.32ZM104.75-57.14L104.75-57.14L104.75-57.14Q107-59.92 108.28-62.17L108.28-62.17L108.28-62.17Q109.57-64.41 109.57-66.82L109.57-66.82L109.57-66.82Q109.57-69.23 107.86-69.23L107.86-69.23L107.86-69.23Q104.11-69.23 99.56-61.52L99.56-61.52L99.56-61.52Q95.02-53.82 92.77-41.30L92.77-41.30L92.77-41.30Q96.41-46.87 99.46-50.61L99.46-50.61L99.46-50.61Q102.51-54.36 104.75-57.14ZM159.00-9.10L159.00-9.10L159.00-9.10Q150.55 0.86 138.73 0.86L138.73 0.86L138.73 0.86Q126.90 0.86 121.02-5.19L121.02-5.19L121.02-5.19Q115.13-11.23 115.24-20.22L115.24-20.22L115.24-20.22Q115.13-32.96 123.26-42.16L123.26-42.16L123.26-42.16Q131.40-51.36 144.56-51.36L144.56-51.36L144.56-51.36Q150.55-51.36 154.19-49.86L154.19-49.86L154.19-49.86Q160.50-47.29 160.50-45.05L160.50-45.05L160.50-45.05Q160.50-43.34 151.67-43.28L151.67-43.28L151.67-43.28Q142.84-43.23 136.91-37.18L136.91-37.18L136.91-37.18Q130.97-31.14 130.97-21.93L130.97-21.93L130.97-21.93Q130.97-17.12 133.80-13.86L133.80-13.86L133.80-13.86Q136.64-10.59 141.83-10.59L141.83-10.59L141.83-10.59Q147.02-10.59 150.44-12.73L150.44-12.73L150.44-12.73Q142.84-17.87 142.84-27.61L142.84-27.61L142.84-27.61Q142.74-32.74 146.54-36.97L146.54-36.97L146.54-36.97Q150.33-41.20 156.27-41.25L156.27-41.25L156.27-41.25Q162.21-41.30 164.78-37.98L164.78-37.98L164.78-37.98Q167.35-34.67 167.35-29.48L167.35-29.48L167.35-29.48Q167.35-24.29 164.89-18.51L164.89-18.51L165.53-18.51L165.53-18.51Q170.24-18.62 173.66-21.83L173.66-21.83L173.66-21.83Q174.94-23.11 175.85-24.07L175.85-24.07L175.85-24.07Q176.76-25.04 177.73-25.04L177.73-25.04L177.73-25.04Q179.22-25.04 179.22-21.51L179.22-21.51L179.22-21.51Q179.22-14.98 175.37-11.72L175.37-11.72L175.37-11.72Q171.52-8.45 166.87-8.45L166.87-8.45L166.87-8.45Q162.21-8.45 159.00-9.10ZM158.04-21.51L158.04-21.51L158.04-21.51Q159.86-25.36 159.86-29.00L159.86-29.00L159.86-29.00Q159.86-32.63 157.50-32.63L157.50-32.63L157.50-32.63Q156.54-32.63 155.90-31.24L155.90-31.24L155.90-31.24Q155.26-29.85 155.26-28.57L155.26-28.57L155.26-28.57Q155.26-24.29 158.04-21.51ZM198.27-51.84L198.27-51.84L198.27-51.84Q205.44-51.89 208.97-49.17L208.97-49.17L208.97-49.17Q212.50-46.44 212.50-41.36L212.50-41.36L212.50-41.36Q212.50-36.27 209.45-32.69L209.45-32.69L209.45-32.69Q206.40-29.10 202.02-27.61L202.02-27.61L202.02-27.61Q205.12-24.40 207.63-21.08L207.63-21.08L207.63-21.08Q210.15-17.76 210.15-14.12L210.15-14.12L210.15-14.12Q210.15-6.96 204.48-3.05L204.48-3.05L204.48-3.05Q198.81 0.86 188.69 0.86L188.69 0.86L188.69 0.86Q178.58 0.86 173.55-3.16L173.55-3.16L173.55-3.16Q168.53-7.17 168.53-12.25L168.53-12.25L168.53-12.25Q168.53-17.33 171.04-21.51L171.04-21.51L171.04-21.51Q173.55-25.68 176.44-25.68L176.44-25.68L176.44-25.68Q178.16-25.68 178.90-24.45L178.90-24.45L178.90-24.45Q179.65-23.22 181.69-17.33L181.69-17.33L181.69-17.33Q182.44-15.19 184.15-13.27L184.15-13.27L184.15-13.27Q188.11-8.88 196.67-8.88L196.67-8.88L196.67-8.88Q195.38-12.95 192.55-15.89L192.55-15.89L192.55-15.89Q189.71-18.83 186.93-21.61L186.93-21.61L186.93-21.61Q184.15-24.40 182.01-27.55L182.01-27.55L182.01-27.55Q179.87-30.71 179.87-34.99L179.87-34.99L179.87-34.99Q179.87-42.69 185.64-47.51L185.64-47.51L185.64-47.51Q191.10-51.79 198.27-51.84ZM197.84-31.99L197.84-31.99L197.84-31.99Q202.12-36.59 202.12-39.38L202.12-39.38L202.12-39.38Q202.12-40.66 201.21-41.68L201.21-41.68L201.21-41.68Q200.30-42.69 198.59-42.69L198.59-42.69L198.59-42.69Q196.88-42.69 195.33-42.27L195.33-42.27L195.33-42.27Q193.78-41.84 192.81-41.62L192.81-41.62L192.81-41.62Q192.81-37.56 197.84-31.99ZM241.18-51.84L241.18-51.84L241.18-51.84Q248.35-51.89 251.88-49.17L251.88-49.17L251.88-49.17Q255.41-46.44 255.41-41.36L255.41-41.36L255.41-41.36Q255.41-36.27 252.36-32.69L252.36-32.69L252.36-32.69Q249.31-29.10 244.92-27.61L244.92-27.61L244.92-27.61Q248.03-24.40 250.54-21.08L250.54-21.08L250.54-21.08Q253.06-17.76 253.06-14.12L253.06-14.12L253.06-14.12Q253.06-6.96 247.38-3.05L247.38-3.05L247.38-3.05Q241.71 0.86 231.60 0.86L231.60 0.86L231.60 0.86Q221.49 0.86 216.46-3.16L216.46-3.16L216.46-3.16Q211.43-7.17 211.43-12.25L211.43-12.25L211.43-12.25Q211.43-17.33 213.95-21.51L213.95-21.51L213.95-21.51Q216.46-25.68 219.35-25.68L219.35-25.68L219.35-25.68Q221.06-25.68 221.81-24.45L221.81-24.45L221.81-24.45Q222.56-23.22 224.59-17.33L224.59-17.33L224.59-17.33Q225.34-15.19 227.05-13.27L227.05-13.27L227.05-13.27Q231.01-8.88 239.57-8.88L239.57-8.88L239.57-8.88Q238.29-12.95 235.45-15.89L235.45-15.89L235.45-15.89Q232.62-18.83 229.84-21.61L229.84-21.61L229.84-21.61Q227.05-24.40 224.91-27.55L224.91-27.55L224.91-27.55Q222.77-30.71 222.77-34.99L222.77-34.99L222.77-34.99Q222.77-42.69 228.55-47.51L228.55-47.51L228.55-47.51Q234.01-51.79 241.18-51.84ZM240.75-31.99L240.75-31.99L240.75-31.99Q245.03-36.59 245.03-39.38L245.03-39.38L245.03-39.38Q245.03-40.66 244.12-41.68L244.12-41.68L244.12-41.68Q243.21-42.69 241.50-42.69L241.50-42.69L241.50-42.69Q239.79-42.69 238.24-42.27L238.24-42.27L238.24-42.27Q236.68-41.84 235.72-41.62L235.72-41.62L235.72-41.62Q235.72-37.56 240.75-31.99Z" fill="#ae0606"></path></g></g><style>text {
2
+ font-size: 64px;
3
+ font-family: Arial Black;
4
+ dominant-baseline: central;
5
+ text-anchor: middle;
6
+ }</style></svg>
data/src/lib/gloss.gl CHANGED
@@ -18,9 +18,9 @@ require "gloss/errors"
18
18
  require "gloss/logger"
19
19
  require "gloss/prog_loader"
20
20
  require "gloss/utils"
21
+ require "gloss/runtime"
21
22
 
22
- is_ci = ENV.fetch("CI") { false }
23
- require "gls" unless is_ci # a bit of a hack for now
23
+ require "gls"
24
24
 
25
25
  EMPTY_ARRAY = Array.new.freeze
26
26
  EMPTY_HASH = {}.freeze
data/src/lib/gloss/cli.gl CHANGED
@@ -21,6 +21,7 @@ module Gloss
21
21
  when "version", "--version", "-v"
22
22
  puts Gloss::VERSION
23
23
  when "watch", "build"
24
+ Gloss.load_config
24
25
  type_checker = ProgLoader.new.run
25
26
  if command == "watch"
26
27
  files = files.map do |f|
@@ -8,14 +8,18 @@ module Gloss
8
8
  frozen_string_literals: true,
9
9
  src_dir: "src",
10
10
  entrypoint: nil,
11
- strict_require: false
11
+ strict_require: false,
12
+ type_checking_strictness: "lenient",
13
+ prettify_output_executable_path: nil
12
14
  }
13
15
  )
14
16
 
15
- user_config = if File.exist?(CONFIG_PATH)
16
- YAML.safe_load(File.read(CONFIG_PATH))
17
- else
18
- Config.default_config
19
- end
20
- Config.default_config.each { |k, v| Config.send(:"#{k}=", user_config[k.to_s] || v) }
17
+ def self.load_config
18
+ user_config = if File.exist?(File.absolute_path(File.join(Dir.pwd, CONFIG_PATH)))
19
+ YAML.safe_load(File.read(CONFIG_PATH))
20
+ else
21
+ Config.default_config
22
+ end
23
+ Config.default_config.each { |k, v| Config.send(:"#{k}=", user_config[k.to_s] || v) }
24
+ end
21
25
  end
@@ -15,7 +15,9 @@ module Gloss
15
15
  nil => nil,
16
16
  "" => nil
17
17
  }.fetch env_log_level
18
- @logger = Logger.new(real_log_level ? STDOUT : IO::NULL)
18
+ @logger = Logger.new(real_log_level ? STDOUT : IO::NULL).tap do |l|
19
+ l.level = real_log_level if real_log_level
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -4,33 +4,41 @@ module Gloss
4
4
  OUTPUT_BY_PATH = Hash.new
5
5
 
6
6
  class ProgLoader
7
- def initialize
8
- entrypoint = Config.entrypoint
9
- if entrypoint == nil || entrypoint == ""
7
+ attr_reader :type_checker
8
+
9
+ def initialize(entrypoint_path = nil, entrypoint_contents = nil)
10
+ entrypoint_path ||= Config.entrypoint
11
+ if entrypoint_path == nil || entrypoint_path == ""
10
12
  throw :error, "Entrypoint is not yet set in .gloss.yml"
11
13
  end
12
- @files_to_process = [
13
- Utils.absolute_path(Config.entrypoint),
14
- # __dir__ is typed as String? - but it shouldn't be nil here
15
- Utils.absolute_path(File.join((__dir__||""), "..", "..", "sig", "core.rbs"))
16
- ]
14
+ entrypoint = if entrypoint_path && entrypoint_contents
15
+ ep = entrypoint_path == Runtime::NON_EXISTENT_FILEPATH ? entrypoint_path : Utils.absolute_path(entrypoint_path)
16
+ [ep, entrypoint_contents]
17
+ else
18
+ Utils.abs_path_with_contents(entrypoint_path)
19
+ end
20
+ # __dir__ is typed as String? - but it shouldn't be nil here
21
+ core_types = Utils.abs_path_with_contents(File.join((__dir__||""), "..", "..", "sig", "core.rbs"))
22
+ @files_to_process = [entrypoint, core_types]
17
23
  @processed_files = Set.new
18
24
  @type_checker = TypeChecker.new
19
25
  end
20
26
 
21
27
  def run
22
- @files_to_process.each do |path_string|
28
+ @files_to_process.each do |(path_string, file_contents)|
23
29
  # currently steep would give an `unexpected jump` if next was used
24
- unless @processed_files.member?(path_string) || OUTPUT_BY_PATH.[](path_string)
30
+ if path_string.end_with? ".rbs"
31
+ @type_checker.load_sig_path path_string
32
+ elsif !@processed_files.member?(path_string) || !OUTPUT_BY_PATH.[](path_string)
25
33
  Gloss.logger.debug "Loading #{path_string}"
26
- path = Utils.absolute_path(path_string)
27
- file_contents = File.open(path).read
28
34
  contents_tree = Parser.new(file_contents).run
29
- on_new_file_referenced = proc do |pa, relative|
30
- if relative
31
- handle_require_relative pa
32
- else
33
- handle_require pa
35
+ on_new_file_referenced = proc do |ps, relative|
36
+ ps.each do |pa|
37
+ if relative
38
+ handle_require_relative pa, path_string
39
+ else
40
+ handle_require pa
41
+ end
34
42
  end
35
43
  end
36
44
  OUTPUT_BY_PATH.[](path_string) = Visitor.new(contents_tree, @type_checker, on_new_file_referenced).run
@@ -52,7 +60,7 @@ module Gloss
52
60
  base = File.join(Dir.pwd, path)
53
61
  fp = base + ".gl"
54
62
  if File.exist? fp
55
- @files_to_process << fp
63
+ @files_to_process << Utils.abs_path_with_contents(fp)
56
64
  end
57
65
  return
58
66
  end
@@ -61,14 +69,14 @@ module Gloss
61
69
  full = File.absolute_path("#{File.join(Config.src_dir, "lib", path)}.gl")
62
70
  pathn = Pathname.new full
63
71
  if pathn.file?
64
- @files_to_process << pathn.to_s
72
+ @files_to_process << Utils.abs_path_with_contents(pathn.to_s)
65
73
  else
66
74
  # no .gl file available - .rbs file available?
67
75
  # TODO: verify file is still actually requireable
68
76
  pathn = Pathname.new("#{File.join(Dir.pwd, "sig", path)}.rbs")
69
77
  gem_path = Utils.gem_path_for(path)
70
78
  if gem_path
71
- sig_files = Dir.glob(File.absolute_path(File.join(gem_path, "..", "..", "sig", "**", "*.rbs")))
79
+ sig_files = Dir.glob(File.absolute_path(File.join(gem_path, "..", "sig", "**", "*.rbs")))
72
80
  if sig_files.length.positive?
73
81
  sig_files.each do |fp|
74
82
  @type_checker.load_sig_path fp
@@ -86,7 +94,7 @@ module Gloss
86
94
  @type_checker.load_sig_path(pathn.to_s)
87
95
  @processed_files.add pathn.to_s
88
96
  else
89
- rbs_stdlib_dir = File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "..", "stdlib", path))
97
+ rbs_stdlib_dir = File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "stdlib", path))
90
98
  if Pathname.new(rbs_stdlib_dir).exist?
91
99
  load_rbs_from_require_path(path)
92
100
  rbs_type_deps = STDLIB_TYPE_DEPENDENCIES.fetch(path) { nil }
@@ -102,25 +110,28 @@ module Gloss
102
110
  end
103
111
  end
104
112
 
105
- private def handle_require_relative(path)
106
- base = File.join(@filepath, "..", path)
113
+ private def handle_require_relative(path, source_file)
114
+ base = File.join(source_file, "..", path)
107
115
  pn : String? = nil
108
- Gem.suffixes.each do |ext|
116
+ exts = %w[.gl].concat(Gem.suffixes)
117
+ exts.each do |ext|
109
118
  full = File.absolute_path(base + ext)
110
119
  pn = full if File.exist?(full)
111
120
  end
112
121
 
113
122
  if pn
114
- @files_to_process << pn unless @files_to_process.include? pn
123
+ unless @files_to_process.any? { |(fp, _)| fp == pn }
124
+ @files_to_process << Utils.abs_path_with_contents(pn)
125
+ end
115
126
  elsif Config.strict_require
116
- throw :error, "Cannot resolve require path for #{pn}"
127
+ throw :error, "Cannot resolve relative path for #{path}"
117
128
  else
118
129
  Gloss.logger.debug "No path found for #{path}"
119
130
  end
120
131
  end
121
132
 
122
133
  private def rbs_stdlib_path_for(libr)
123
- File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "..", "stdlib", libr))
134
+ File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "stdlib", libr))
124
135
  end
125
136
 
126
137
  private def load_rbs_from_require_path(path)
@@ -0,0 +1,20 @@
1
+ require "stringio"
2
+
3
+ module Gloss
4
+ class Runtime
5
+ NON_EXISTENT_FILEPATH = "__string__"
6
+
7
+ def self.process_string(str : String, options = Config.default_config)
8
+ out_io = StringIO.new
9
+ error_msg = catch :error do
10
+ tree = Parser.new(str).run
11
+ tc = ProgLoader.new(NON_EXISTENT_FILEPATH, str).run
12
+ rb_output = Visitor.new(tree, tc).run
13
+ tc.run(NON_EXISTENT_FILEPATH, rb_output)
14
+ Writer.new(rb_output, NON_EXISTENT_FILEPATH, out_io).run
15
+ nil
16
+ end
17
+ return out_io.string, error_msg
18
+ end
19
+ end
20
+ end
@@ -2,16 +2,27 @@ require "set"
2
2
 
3
3
  module Gloss
4
4
  class TypeChecker
5
- Project = Struct.new :targets
6
-
7
5
  attr_reader :steep_target, :top_level_decls, :env, :rbs_gem_dir
8
6
 
7
+ enum Strictness
8
+ Strict = "strict"
9
+ Lenient = "lenient"
10
+ Default = "default"
11
+ end
12
+
9
13
  def initialize
14
+ options = Steep::Project::Options.new
15
+ case Config.type_checking_strictness
16
+ when Strictness::Strict
17
+ options.apply_strict_typing_options!
18
+ when Strictness::Lenient
19
+ options.apply_lenient_typing_options!
20
+ else
21
+ options.apply_default_typing_options!
22
+ end
10
23
  @steep_target = Steep::Project::Target.new(
11
24
  name: "gloss",
12
- options: Steep::Project::Options.new.tap do |o|
13
- o.allow_unknown_constant_assignment = true
14
- end,
25
+ options: options,
15
26
  source_patterns: ["**/*.rb"],
16
27
  ignore_patterns: Array.new,
17
28
  signature_patterns: ["sig"]
@@ -54,7 +65,7 @@ module Gloss
54
65
  when Steep::Diagnostic::Ruby::UnexpectedBlockGiven
55
66
  "Unexpected block given"
56
67
  else
57
- "#{e.header_line}\n#{e.inspect}"
68
+ "#{e.header_line}\n#{e}"
58
69
  end
59
70
  }.join("\n")
60
71
  throw :error, errors
@@ -19,11 +19,8 @@ module Gloss
19
19
  end
20
20
 
21
21
  def gem_path_for(gem_name)
22
- Gem.ui.instance_variable_set :"@outs", StringIO.new
23
- Gem::GemRunner.new.run(["which", gem_name])
24
- Gem.ui.outs.string
25
- rescue SystemExit => e
26
- nil
22
+ spec = Gem::Specification.find_by_path(gem_name)
23
+ spec.full_require_paths.first if spec
27
24
  end
28
25
 
29
26
  def with_file_header(str)
@@ -34,5 +31,10 @@ module Gloss
34
31
  src_path.sub("#{Config.src_dir}/", "")
35
32
  .sub(/\.gl$/, ".rb")
36
33
  end
34
+
35
+ def abs_path_with_contents(path)
36
+ abs_path = absolute_path(path)
37
+ return abs_path, File.open(abs_path).read
38
+ end
37
39
  end
38
40
  end
@@ -1,3 +1,3 @@
1
1
  module Gloss
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -102,7 +102,7 @@ module Gloss
102
102
  members: Array.new, # TODO
103
103
  annotations: Array.new, # TODO
104
104
  location: build_location(node),
105
- comment: node[:comment]
105
+ comment: node[:comment],
106
106
  )
107
107
  old_parent_scope = @current_scope
108
108
  @current_scope = module_type
@@ -151,7 +151,7 @@ module Gloss
151
151
  rest_keywords: args.dig(:types, :rest_keywords),
152
152
  return_type: return_type
153
153
  ),
154
- block: node[:yield_arg_count] ?
154
+ block: node[:yield_arg_count] || args.dig(:types, :block_arg) ?
155
155
  RBS::Types::Block.new(
156
156
  type: RBS::Types::Function.new(
157
157
  required_positionals: Array.new,
@@ -202,6 +202,7 @@ module Gloss
202
202
  else
203
203
  nil
204
204
  end
205
+ name = node[:name]
205
206
  block = node[:block] ? " #{visit_node(node[:block])}" : nil
206
207
  has_parens = !!(node[:has_parentheses] || args || block)
207
208
  opening_delimiter = if has_parens
@@ -209,11 +210,18 @@ module Gloss
209
210
  else
210
211
  nil
211
212
  end
212
- name = node[:name]
213
213
  call = "#{obj}#{name}#{opening_delimiter}#{args}#{")" if has_parens}#{block}"
214
214
  case name
215
215
  when "require_relative"
216
- @on_new_file_referenced.call(name, true) if @on_new_file_referenced
216
+ if @on_new_file_referenced
217
+ paths = arg_arr.map do |a|
218
+ unless a[:type] == "LiteralNode"
219
+ throw :error, "Dynamic file paths are not allowed in require_relative"
220
+ end
221
+ eval(visit_node(a, scope).strip)
222
+ end
223
+ @on_new_file_referenced.call(paths, true)
224
+ end
217
225
  when "module_function"
218
226
  @after_module_function = true
219
227
  end
@@ -264,7 +272,7 @@ module Gloss
264
272
  path = node[:value]
265
273
  src.write_ln %(require "#{path}")
266
274
 
267
- @on_new_file_referenced.call(path, false) if @on_new_file_referenced
275
+ @on_new_file_referenced.call([path], false) if @on_new_file_referenced
268
276
  when "Assign", "OpAssign"
269
277
 
270
278
  src.write_ln "#{visit_node(node[:target])} #{node[:op]}= #{visit_node(node[:value]).strip}"
@@ -515,7 +523,8 @@ module Gloss
515
523
  okw : Hash[Symbol, Any] = node.fetch(:opt_kw_args) { EMPTY_HASH }
516
524
  rest_p : String? = node[:rest_p_args] ? visit_node(node[:rest_p_args]) : nil
517
525
  rest_kw : Hash[Symbol, Any]? = node[:rest_kw_args]
518
- return nil if [rp, op, rkw, okw, rest_p, rest_kw].all? { |a| a && a.empty? }
526
+ block_arg : Hash[Symbol, Any]? = node[:block_arg]
527
+ return nil if [rp, op, rkw, okw, rest_p, rest_kw, block_arg].all? { |a| a && a.empty? }
519
528
 
520
529
  contents = [
521
530
  rp.map { |a| visit_node(a) },
@@ -523,7 +532,8 @@ module Gloss
523
532
  rkw.map { |name, _| "#{name}:" },
524
533
  okw.map { |name, value| "#{name}: #{value}" },
525
534
  rest_p ? "*#{rest_p}" : "",
526
- rest_kw ? "**#{visit_node(rest_kw)}" : ""
535
+ rest_kw ? "**#{visit_node(rest_kw)}" : "",
536
+ block_arg ? "&#{visit_node(block_arg)}" : ""
527
537
  ].reject(&:empty?).flatten.join(", ")
528
538
  representation = "(#{contents})"
529
539
  rp_args = rp.map do |a|
@@ -553,6 +563,7 @@ module Gloss
553
563
  trailing_positionals: EMPTY_ARRAY, # TODO
554
564
  required_keywords: node[:req_kw_args] || EMPTY_HASH,
555
565
  optional_keywords: node[:opt_kw_args] || EMPTY_HASH,
566
+ block_arg: true,
556
567
  rest_keywords: node[:rest_kw_args] ?
557
568
  RBS::Types::Function::Param.new(
558
569
  name: visit_node(node[:rest_kw_args]).to_sym,