ascode 0.1.1 → 0.2.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: 4e347f2a2e10ef39e70ad4907e8022d9f89c0c350c0f921fc17807b3a3878cfb
4
- data.tar.gz: e5b604191d92aee5d267eb7b355383652f4ff1238fbdde7d94de3f41201a268b
3
+ metadata.gz: ee65159e184599f488bf3465c010bbcefeb1112cf6e3424a0679b391afe267cd
4
+ data.tar.gz: 8f339c4334a31d099617680a15c2892d951b113f77b947e8eee3be57d0144960
5
5
  SHA512:
6
- metadata.gz: 23b136682677c97243be1edda4896c4e97c083750d824892db1e7723a3e71414b72174bf6028e95f769b807860f5ae37d3a59e0ede09bfd510c6fd77b3d3b0fc
7
- data.tar.gz: 74302d958ab766210cb7e58bd82680759f8c4a823d88c9011684c454c68dce3adbee514bceda07703e586190f64f2a4b0ce6435adec331a771bd288890e07b0e
6
+ metadata.gz: 07736e47d143f77e4d2d0bc23810d54d71a1bb6cfaa5cb1b71f344c42e54200fd0c7abb1a4544052d6aa802c93479570ebfa61925ec0bbb3e1f6c2ff94818082
7
+ data.tar.gz: ece6c8d48ecc8c422d9bce25a8d591b5b0ad5ab3ff1aef3660c754b2e33ced609a71b4ab1619c64f8520c72c87232a1453dc2b74e360bbd7e1a6d161d37c3d3a
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # ascode
2
- [![gem](https://img.shields.io/gem/v/ascode.svg?style=flat-square)](https://rubygems.org/gems/ascode) [![Gem](https://img.shields.io/gem/dt/ascode.svg?style=flat-square)](https://rubygems.org/gems/ascode)
2
+ [![RubyGem Version](https://img.shields.io/gem/v/ascode.svg?style=flat-square)](https://rubygems.org/gems/ascode) [![RubyGem Downloads](https://img.shields.io/gem/dt/ascode.svg?style=flat-square)](https://rubygems.org/gems/ascode)
3
3
 
4
4
  > Esoteric golfing language
5
5
 
@@ -0,0 +1,15 @@
1
+ module Ascode
2
+ class Converter
3
+ def self.convert(value)
4
+ return value unless value
5
+
6
+ if value =~ /^[0-9]+$/
7
+ value.to_i
8
+ elsif value =~ /^[0-9.]+$/
9
+ value.to_f
10
+ else
11
+ value
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,7 @@
1
1
  Character|Name|`pop`s|`push`es|Description
2
2
  ---|---|---|---|---
3
- `>`|`output`|`a`||Prints `a` to stdout
3
+ `>`|`output`|`a`||`a` -> `stdout`
4
+ `<`|`input`||`a`|`stdin` -> `a`
4
5
  `^`|`pop`|`a`||
5
6
  `+`|`plus`|`a`, `b`|`c`|`c` = `a` + `b`
6
7
  `-`|`minus`|`a`, `b`|`c`|`c` = `a` - `b`
@@ -1,3 +1,5 @@
1
+ require_relative 'converter'
2
+
1
3
  module Ascode
2
4
  class Interpreter
3
5
  def initialize(ast)
@@ -24,7 +26,17 @@ module Ascode
24
26
  end
25
27
 
26
28
  def pop
27
- @stack.pop
29
+ value = @stack.pop
30
+ if value
31
+ value
32
+ else
33
+ input
34
+ @stack.pop
35
+ end
36
+ end
37
+
38
+ def input
39
+ push Converter.convert gets
28
40
  end
29
41
 
30
42
  def output
data/lib/ascode/parser.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative 'functions'
2
+ require_relative 'converter'
2
3
 
3
4
  module Ascode
4
5
  class Parser
@@ -53,11 +54,7 @@ module Ascode
53
54
  def ast_add_buffer
54
55
  return unless @push_buffer
55
56
 
56
- if @push_buffer =~ /^[0-9]+$/
57
- @push_buffer = @push_buffer.to_i
58
- elsif @push_buffer =~ /^[0-9.]+$/
59
- @push_buffer = @push_buffer.to_f
60
- end
57
+ @push_buffer = Converter.convert @push_buffer
61
58
 
62
59
  ast_add_action 'push', @push_buffer
63
60
  @push_buffer = false
data/lib/ascode.rb CHANGED
@@ -12,4 +12,4 @@ module Ascode
12
12
  end
13
13
 
14
14
  # Test
15
- Ascode.run('5 5*ê↺5*±')
15
+ Ascode.run('*±')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ascode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Varaksa
@@ -20,6 +20,7 @@ files:
20
20
  - LICENSE.md
21
21
  - README.md
22
22
  - lib/ascode.rb
23
+ - lib/ascode/converter.rb
23
24
  - lib/ascode/functions.md
24
25
  - lib/ascode/functions.rb
25
26
  - lib/ascode/interpreter.rb