ascode 0.7.3 → 0.7.4
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 +4 -4
- data/README.md +2 -2
- data/ascode.gemspec +22 -0
- data/docs/functions.md +46 -0
- data/lib/ascode/interpreter/main.rb +4 -4
- data/lib/ascode/parser/function.rb +44 -36
- data/lib/ascode/parser/main.rb +1 -1
- metadata +4 -3
- data/lib/ascode/functions.md +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b9614d0f7afda646d8b000aa8ce1280ec964142644005940a83783534ff2a3
|
4
|
+
data.tar.gz: 590186bd0ea7102961238075d3f7518ee2afd3bdf1eecb0f70c86eb76ccc2792
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e3d1e1482766751d880e650cb8ec65488340e502baf631cde0a6832429ee40b44b50b925d94270a65764cc0caeee2773f0e569d723d32082b374596d150d87c
|
7
|
+
data.tar.gz: 5ab43c64aa85ef777703e3b5b19843d431b65e60707f892137ee1dc6628895cefb35d1ef6bfd31bdaa12ff402acee78c5e59009a98899bbf498fa709f912655b
|
data/README.md
CHANGED
@@ -18,8 +18,8 @@ gem install ascode
|
|
18
18
|
|
19
19
|
###### Run
|
20
20
|
|
21
|
-
> Function reference is available in [`
|
22
|
-
`](https://github.com/sudoio/ascode/blob/master/
|
21
|
+
> Function reference is available in [`docs/functions.md
|
22
|
+
`](https://github.com/sudoio/ascode/blob/master/docs/functions.md).
|
23
23
|
|
24
24
|
```bash
|
25
25
|
ascode 'your code here'
|
data/ascode.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "ascode"
|
3
|
+
s.authors = ["Artem Varaksa"]
|
4
|
+
|
5
|
+
s.version = "0.7.4"
|
6
|
+
s.date = Time.now.strftime("%Y-%m-%d")
|
7
|
+
|
8
|
+
s.summary = "[β] Esoteric golfing language"
|
9
|
+
s.description =
|
10
|
+
"Esoteric golfing language. In active development, so behavior may be changed without prior notice."
|
11
|
+
|
12
|
+
s.bindir = "bin"
|
13
|
+
s.executables << "ascode"
|
14
|
+
s.files = Dir["**/*"]
|
15
|
+
|
16
|
+
s.homepage = "https://github.com/sudoio/ascode"
|
17
|
+
s.license = "MIT"
|
18
|
+
s.metadata = {
|
19
|
+
"bug_tracker_uri" => "https://github.com/sudoio/ascode/issues",
|
20
|
+
"source_code_uri" => "https://github.com/sudoio/ascode"
|
21
|
+
}
|
22
|
+
end
|
data/docs/functions.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Functions
|
2
|
+
|
3
|
+
- [`IO`](#io)
|
4
|
+
- [`Environment`](#environment)
|
5
|
+
- [`Conditions`](#conditions)
|
6
|
+
- [`Math`](#math)
|
7
|
+
|
8
|
+
##### IO
|
9
|
+
|
10
|
+
Function|`pop`s|`push`es|Description
|
11
|
+
---|---|---|---
|
12
|
+
`I`| |`a`|`stdin` -> `a`
|
13
|
+
`O`|`a`| |`a` -> `stdout`
|
14
|
+
`N`| | |`\n` -> `stdout`
|
15
|
+
|
16
|
+
##### Environment
|
17
|
+
|
18
|
+
Function|`pop`s|`push`es|Description
|
19
|
+
---|---|---|---
|
20
|
+
`P`|`a`| |
|
21
|
+
`C`|`a`| |`a` -> `Register`
|
22
|
+
`V`| |`a`|`Register` -> `a`
|
23
|
+
`S`|`a`, `b`|`a`, `b`|Swaps first two elements in the stack
|
24
|
+
`D`|`a`|`a`, `a`|Duplicates first element in the stack
|
25
|
+
|
26
|
+
##### Conditions
|
27
|
+
|
28
|
+
> `a` = `pop`
|
29
|
+
> Condition is false if `a` is `0` or `false`
|
30
|
+
|
31
|
+
Syntax: `[` **ascode for true** `:` **ascode for false** `]`
|
32
|
+
|
33
|
+
##### Math
|
34
|
+
|
35
|
+
Function|`pop`s|`push`es|Description
|
36
|
+
---|---|---|---
|
37
|
+
`+`|`a`, `b`|`c`|`c` = `a` + `b`
|
38
|
+
`-`|`a`, `b`|`c`|`c` = `a` - `b`
|
39
|
+
`/`|`a`, `b`|`c`|`c` = `a` / `b`
|
40
|
+
`*`|`a`, `b`|`c`|`c` = `a` * `b`
|
41
|
+
`>`|`a`, `b`|`c`|`c` = `1` if `a` > `b`, `0` otherwise
|
42
|
+
`<`|`a`, `b`|`c`|`c` = `1` if `a` < `b`, `0` otherwise
|
43
|
+
`=`|`a`, `b`|`c`|`c` = `1` if `a` = `b`, `0` otherwise
|
44
|
+
`e`|`a`|`b`|`b` = `1` if `a` is even, `0` otherwise
|
45
|
+
`!`|`a`|`b`|`b` = `1` if `a` = `0`, otherwise `0`
|
46
|
+
`s`|`a`|`b`|`b` = `-1` * `a`
|
@@ -11,9 +11,9 @@ module Ascode
|
|
11
11
|
@env.ast = ast
|
12
12
|
|
13
13
|
@map = {
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
io: IO,
|
15
|
+
math: Math,
|
16
|
+
condition: Condition
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
@@ -32,7 +32,7 @@ module Ascode
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def call(type, name)
|
35
|
-
if type ==
|
35
|
+
if type == :env
|
36
36
|
@env.send name
|
37
37
|
else
|
38
38
|
@map[type].send name, @env
|
@@ -1,50 +1,58 @@
|
|
1
1
|
module Ascode
|
2
2
|
module Parser
|
3
3
|
class Function
|
4
|
-
attr_reader :csv_data
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@csv_data = []
|
8
|
-
|
9
|
-
filename = File.join(File.dirname(__FILE__), "../functions.md")
|
10
|
-
File.open(filename, "r") do |file|
|
11
|
-
read_csv file
|
12
|
-
end
|
13
|
-
|
14
|
-
@csv_data.delete_if do |e|
|
15
|
-
e[:short].nil? || e[:short].to_s.length > 1
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
4
|
def parse(char)
|
20
|
-
|
21
|
-
|
5
|
+
CODE.find do |type|
|
6
|
+
type[1].find_index do |function|
|
7
|
+
@ast = ast type[0], function[1] if function[0] == char
|
8
|
+
end
|
22
9
|
end
|
23
10
|
|
24
|
-
return unless
|
11
|
+
return unless @ast
|
12
|
+
@ast
|
13
|
+
end
|
25
14
|
|
15
|
+
def ast(type, name)
|
26
16
|
{
|
27
|
-
type:
|
28
|
-
action:
|
17
|
+
type: type,
|
18
|
+
action: name
|
29
19
|
}
|
30
20
|
end
|
31
21
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
22
|
+
CODE = {
|
23
|
+
io: [
|
24
|
+
%w[I input],
|
25
|
+
%w[O output],
|
26
|
+
%w[N new_line]
|
27
|
+
],
|
28
|
+
|
29
|
+
env: [
|
30
|
+
%w[P pop],
|
31
|
+
%w[C reg_copy],
|
32
|
+
%w[V reg_paste],
|
33
|
+
%w[S swap],
|
34
|
+
%w[D duplicate]
|
35
|
+
],
|
36
|
+
|
37
|
+
condition: [
|
38
|
+
%w([ begin),
|
39
|
+
%w[: else],
|
40
|
+
%w(] end)
|
41
|
+
],
|
42
|
+
|
43
|
+
math: [
|
44
|
+
%w[+ plus],
|
45
|
+
%w[- minus],
|
46
|
+
%w[* multiply],
|
47
|
+
%w[/ divide],
|
48
|
+
%w[> bigger_than],
|
49
|
+
%w[< less_than],
|
50
|
+
%w[= equal],
|
51
|
+
%w[e even],
|
52
|
+
%w[! invert],
|
53
|
+
%w[s change_sign]
|
54
|
+
]
|
55
|
+
}.freeze
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
data/lib/ascode/parser/main.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ascode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Varaksa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Esoteric golfing language. In active development, so behavior may be
|
14
14
|
changed without prior notice.
|
@@ -20,10 +20,11 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- LICENSE.md
|
22
22
|
- README.md
|
23
|
+
- ascode.gemspec
|
23
24
|
- bin/ascode
|
25
|
+
- docs/functions.md
|
24
26
|
- lib/ascode.rb
|
25
27
|
- lib/ascode/converter.rb
|
26
|
-
- lib/ascode/functions.md
|
27
28
|
- lib/ascode/interpreter/condition.rb
|
28
29
|
- lib/ascode/interpreter/environment.rb
|
29
30
|
- lib/ascode/interpreter/io.rb
|
data/lib/ascode/functions.md
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
#### IO
|
2
|
-
|
3
|
-
Character|Type|Name|`pop`s|`push`es|Description
|
4
|
-
---|---|---|---|---|---
|
5
|
-
`I`|`io`|`input`||`a`|`stdin` -> `a`
|
6
|
-
`O`|`io`|`output`|`a`||`a` -> `stdout`
|
7
|
-
`N`|`io`|`new_line`|||`\n` -> `stdout`
|
8
|
-
|
9
|
-
#### Environment
|
10
|
-
|
11
|
-
Character|Type|Name|`pop`s|`push`es|Description
|
12
|
-
---|---|---|---|---|---
|
13
|
-
`P`|`env`|`pop`|`a`||
|
14
|
-
`C`|`env`|`reg_copy`|`a`||`a` -> `Register`
|
15
|
-
`V`|`env`|`reg_paste`||`a`|`Register` -> `a`
|
16
|
-
`S`|`env`|`swap`|`a`, `b`|`a`, `b`|Swaps first two elements in the stack
|
17
|
-
`D`|`env`|`duplicate`|`a`|`a`, `a`|Duplicates first element in the stack
|
18
|
-
|
19
|
-
#### Condition
|
20
|
-
|
21
|
-
Character|Type|Name|`pop`s|`push`es|Description
|
22
|
-
---|---|---|---|---|---
|
23
|
-
`[`|`condition`|`begin`|`a`|| Condition is false if `a` = `0` or `false`
|
24
|
-
`:`|`condition`|`else`|||
|
25
|
-
`]`|`condition`|`end`|||
|
26
|
-
|
27
|
-
#### Math
|
28
|
-
|
29
|
-
Character|Type|Name|`pop`s|`push`es|Description
|
30
|
-
---|---|---|---|---|---
|
31
|
-
`+`|`math`|`plus`|`a`, `b`|`c`|`c` = `a` + `b`
|
32
|
-
`-`|`math`|`minus`|`a`, `b`|`c`|`c` = `a` - `b`
|
33
|
-
`/`|`math`|`divide`|`a`, `b`|`c`|`c` = `a` / `b`
|
34
|
-
`*`|`math`|`multiply`|`a`, `b`|`c`|`c` = `a` * `b`
|
35
|
-
`>`|`math`|`bigger_than`|`a`, `b`|`c`|`c` = `1` if `a` > `b`, `0` otherwise
|
36
|
-
`<`|`math`|`less_than`|`a`, `b`|`c`|`c` = `1` if `a` < `b`, `0` otherwise
|
37
|
-
`=`|`math`|`equal`|`a`, `b`|`c`|`c` = `1` if `a` = `b`, `0` otherwise
|
38
|
-
`e`|`math`|`even`|`a`|`b`|`b` = `1` if `a` is even, `0` otherwise
|
39
|
-
`!`|`math`|`invert`|`a`|`b`|`b` = `1` if `a` = `0`, otherwise `0`
|
40
|
-
`s`|`math`|`change_sign`|`a`|`b`|`b` = `-1` * `a`
|