rpl 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cde98587c0d2ec81f1a6a6d9918b8f7b3ffa40c26959a58d97e7f6e6aef6ef3
4
- data.tar.gz: a8aef5c02a2956265a862b3a2530cd972639c60055387adb2dd74c3785a71dc5
3
+ metadata.gz: c6394da05e2547dd85c3ab87e8ad841d72edc90b99e16bb1abbd43850e4c824d
4
+ data.tar.gz: 87e6d2304b45909e04ccdae776cea33fb26048c98f6488ceb44539c348ad7063
5
5
  SHA512:
6
- metadata.gz: 4fc702e52d8c6d8089bb45cc251964056be1758aea579f3a798afcf404468a7ac754de90f2bb5eacc67c5d1f0489c65b3eb6ca0b3d38c3c0f0f8be54961ad44f
7
- data.tar.gz: 83346cce2d900ca261932ceed751e268abc4cab1c5d37da2b198709a1823647d8fefd375f55adbc67b92ee2b3ed3d7c4e28c4fde30c9b8e1f213f275bfdffb7f
6
+ metadata.gz: 0fbe309e4c373ab91b0f50022c3571d28e387b9476d7deb96fb35fb2db25970a946f254a4819b088a0741b3271fa07d6710165f186365478726ad01e6d3ce788
7
+ data.tar.gz: 5d928b2865843d21275a26e14dce2fc4be75ddb371a7d0dd0cf185037c2766af85186da83fd8acdd56f6500647d4610bd245ae7fe243ef53790871a396d5f4c3
@@ -18,7 +18,7 @@ class Interpreter
18
18
  attr_accessor :precision
19
19
 
20
20
  def initialize( stack = [], dictionary = Rpl::Lang::Dictionary.new )
21
- @version = 0.7
21
+ @version = 0.8
22
22
 
23
23
  @dictionary = dictionary
24
24
  @stack = stack
data/lib/rpl/parser.rb CHANGED
@@ -7,7 +7,7 @@ class Parser
7
7
  unless input.index("\n").nil?
8
8
  input = input.split("\n")
9
9
  .map do |line|
10
- comment_begin_index = line.index('#')
10
+ comment_begin_index = line.index('@')
11
11
 
12
12
  case comment_begin_index
13
13
  when nil
@@ -38,26 +38,27 @@ module Types
38
38
  @value = BigDecimal( value, @@precision )
39
39
  when String
40
40
  begin
41
- @value = BigDecimal( value )
41
+ @value = BigDecimal( value, @@precision )
42
42
  rescue ArgumentError
43
43
  case value
44
44
  when /^0x[0-9a-f]+$/
45
45
  @base = 16
46
- @value = /^0x(?<value>[0-9a-f]+)$/.match( value )['value'].to_i( @base )
46
+ @value = BigDecimal( /^0x(?<value>[0-9a-f]+)$/.match( value )['value'].to_i( @base ), @@precision )
47
47
  when /^0o[0-7]+$/
48
48
  @base = 8
49
- @value = /^0o(?<value>[0-7]+)$/.match( value )['value'].to_i( @base )
49
+ @value = BigDecimal( /^0o(?<value>[0-7]+)$/.match( value )['value'].to_i( @base ), @@precision )
50
50
  when /^0b[0-1]+$/
51
51
  @base = 2
52
- @value = /^0b(?<value>[0-1]+)$/.match( value )['value'].to_i( @base )
52
+ @value = BigDecimal( /^0b(?<value>[0-1]+)$/.match( value )['value'].to_i( @base ), @@precision )
53
53
  when '∞'
54
54
  @value = BigDecimal('+Infinity')
55
55
  when '-∞'
56
56
  @value = BigDecimal('-Infinity')
57
57
  else
58
58
  matches = /(?<base>[0-9]+)b(?<value>[0-9a-z]+)/.match( value )
59
+
59
60
  @base = matches['base'].to_i
60
- @value = matches['value'].to_i( @base )
61
+ @value = BigDecimal( matches['value'].to_i( @base ), @@precision )
61
62
  end
62
63
  end
63
64
  end
@@ -74,21 +75,20 @@ module Types
74
75
  when 16
75
76
  '0x'
76
77
  else
77
- "0#{@base}_"
78
+ "#{@base}b"
78
79
  end
79
80
 
80
- if @value.infinite?
81
- suffix = @value.infinite?.positive? ? '∞' : '-∞'
82
- elsif @value.nan?
83
- suffix = '<NaN>'
84
- else
85
- suffix = if @value.to_i == @value
86
- @value.to_i
87
- else
88
- @value.to_s('F')
89
- end
90
- suffix = @value.to_s( @base ) unless @base == 10
91
- end
81
+ suffix = if @value.infinite?
82
+ @value.infinite?.positive? ? '∞' : '-∞'
83
+ elsif @value.nan?
84
+ '<NaN>'
85
+ elsif @base != 10
86
+ @value.to_i.to_s( @base )
87
+ elsif @value.frac.zero?
88
+ @value.to_i
89
+ else
90
+ @value.to_s( 'F' )
91
+ end
92
92
 
93
93
  "#{prefix}#{suffix}"
94
94
  end
@@ -14,13 +14,13 @@ module RplLang
14
14
  'Time and date',
15
15
  '( -- t ) push current time',
16
16
  proc do
17
- @stack << Types.new_object( RplString, "\"#{Time.now}\"" )
17
+ @stack << Types.new_object( RplString, "\"#{DateTime.now.iso8601.to_s.split('T').last[0..7]}\"" )
18
18
  end )
19
19
  @dictionary.add_word( ['date'],
20
20
  'Time and date',
21
21
  '( -- d ) push current date',
22
22
  proc do
23
- @stack << Types.new_object( RplString, "\"#{Date.today}\"" )
23
+ @stack << Types.new_object( RplString, "\"#{Date.today.iso8601}\"" )
24
24
  end )
25
25
  @dictionary.add_word( ['ticks'],
26
26
  'Time and date',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gwenhael Le Moine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-02 00:00:00.000000000 Z
11
+ date: 2022-03-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A language inspired by HP's RPL and https://github.com/louisrubet/rpn/
14
14
  email: gwenhael@le-moine.org
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  requirements: []
65
- rubygems_version: 3.2.32
65
+ rubygems_version: 3.3.7
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: Functional Stack Language