language-ruby 0.6.2 → 0.8.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
2
  SHA256:
3
- metadata.gz: f4baad3490a61d7414a3010ae28d7ebe15678cf7155d6fa733d6db38e69a6f15
4
- data.tar.gz: 498e238afd5c1fdee3eb7d43d6416deda5c4af0a7ea3e7be7b16b3c52f35fc08
3
+ metadata.gz: 1fa93a1100450c8e70de898e1de91c49194fe5f140f5a72bcccf63617dba9c31
4
+ data.tar.gz: 2c91243be68269482a432d1d41469019f74e2e6c1b20746c4ea70f83fee90216
5
5
  SHA512:
6
- metadata.gz: b51659b87522dbe212304842b3d8af561e6caf86ce78cef0ed0bfd732123736961736750fe603073398e50150b03d4be328c858754a7d4d2e6bd3926377878da
7
- data.tar.gz: 740130b9f8e3a5c5e6ac8e09b8adbb5c0bd75074fbc0c94b1bac6a58276bed37b818a82d98e4cfe6953bb3e6f318a222790ddfe6089ffe6c01aae97f4ea605d1
6
+ metadata.gz: abd34ca928437348691865067cf26f3735bb4e89b49589dd44e448f8a300b3bdb41f9a0108fa7abc0d81b6c1edb29f7afc46d52c88939528a6932e86c047322c
7
+ data.tar.gz: 281b2d88b13acbab58914bdbb5bacefc00307b8b68f83d27bc7bee83f4408bb3e6ad355f3ac691847fef953560b83628e5206b0a1576e5d3315d0dabf4b12ac7
data/Gemfile.lock CHANGED
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- language-ruby (0.6.2)
4
+ language-ruby (0.7.0)
5
5
  zeitwerk (~> 2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- diff-lcs (1.5.0)
11
- rspec (3.12.0)
12
- rspec-core (~> 3.12.0)
13
- rspec-expectations (~> 3.12.0)
14
- rspec-mocks (~> 3.12.0)
15
- rspec-core (3.12.2)
16
- rspec-support (~> 3.12.0)
17
- rspec-expectations (3.12.3)
10
+ diff-lcs (1.5.1)
11
+ rspec (3.13.0)
12
+ rspec-core (~> 3.13.0)
13
+ rspec-expectations (~> 3.13.0)
14
+ rspec-mocks (~> 3.13.0)
15
+ rspec-core (3.13.0)
16
+ rspec-support (~> 3.13.0)
17
+ rspec-expectations (3.13.0)
18
18
  diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.12.0)
20
- rspec-mocks (3.12.6)
19
+ rspec-support (~> 3.13.0)
20
+ rspec-mocks (3.13.0)
21
21
  diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.12.0)
23
- rspec-support (3.12.1)
24
- zeitwerk (2.6.12)
22
+ rspec-support (~> 3.13.0)
23
+ rspec-support (3.13.1)
24
+ zeitwerk (2.6.13)
25
25
 
26
26
  PLATFORMS
27
27
  arm64-darwin-22
@@ -10,7 +10,12 @@ class Language
10
10
 
11
11
  def parse(parser)
12
12
  @parent.parse(parser)
13
- parser.output = Output.from_raw(@block.call(parser.output.to_raw))
13
+
14
+ if parser.output.nil?
15
+ parser.buffer = @block.call(parser.buffer)
16
+ else
17
+ parser.output = Output.from_raw(@block.call(parser.output.to_raw))
18
+ end
14
19
  end
15
20
 
16
21
  def to_s
@@ -18,6 +18,23 @@ class Language
18
18
  end
19
19
  end
20
20
 
21
+ def nil?
22
+ raw.nil?
23
+ end
24
+
25
+ def empty?
26
+ case @raw
27
+ when NilClass
28
+ true
29
+ when String
30
+ raw.empty?
31
+ when Array
32
+ raw.empty?
33
+ when Hash
34
+ raw.empty?
35
+ end
36
+ end
37
+
21
38
  def to_raw
22
39
  if raw.is_a?(Array)
23
40
  raw.map(&:to_raw)
@@ -33,7 +50,7 @@ class Language
33
50
  end
34
51
 
35
52
  def present?
36
- @raw != nil
53
+ !nil? && !empty?
37
54
  end
38
55
 
39
56
  def ==(other)
@@ -19,7 +19,7 @@ class Language
19
19
  raise NotEndOfInput, self
20
20
  end
21
21
 
22
- @output.present? ? @output : Output.new(@buffer)
22
+ @output.present? ? @output : Output.new(@buffer.empty? ? nil : @buffer)
23
23
  end
24
24
 
25
25
  def consume(n)
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative "../language"
4
4
 
5
- Language::Version = Gem::Version.new("0.6.2")
5
+ Language::Version = Gem::Version.new("0.8.0")
@@ -11,11 +11,43 @@ class Code
11
11
  nothing_keyword.aka(:nothing)
12
12
  end
13
13
  end
14
+
15
+ class ThenWithBuffer < Language
16
+ def root
17
+ any.repeat(1).then { "something-else" }
18
+ end
19
+ end
20
+
21
+ class ThenWithBufferTransformed < Language
22
+ def root
23
+ any.repeat(1).then { |buffer| buffer.upcase }
24
+ end
25
+ end
26
+
27
+ class ThenWithOutput < Language
28
+ def root
29
+ any.repeat(1).aka(:something).then do |output|
30
+ output[:something].upcase
31
+ end
32
+ end
33
+ end
14
34
  end
15
35
  end
16
36
 
17
37
  RSpec.describe Language do
18
- it "works" do
38
+ it "works with nothing" do
19
39
  expect(Code::Parser::Nothing.parse("nothing")).to eq({ nothing: "nothing" })
20
40
  end
41
+
42
+ it "works with then with buffer" do
43
+ expect(Code::Parser::ThenWithBuffer.parse("something")).to eq("something-else")
44
+ end
45
+
46
+ it "works with then with buffer transformed" do
47
+ expect(Code::Parser::ThenWithBufferTransformed.parse("something")).to eq("SOMETHING")
48
+ end
49
+
50
+ it "works with then with output" do
51
+ expect(Code::Parser::ThenWithOutput.parse("value")).to eq("VALUE")
52
+ end
21
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: language-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk