halunke 0.5.3 → 0.6.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
  SHA1:
3
- metadata.gz: e392834f93d1e8a31556b550cd9a85f8746fbb1c
4
- data.tar.gz: e9d9a8aed17f7c861bfc987df05d72a5e5dcd4b6
3
+ metadata.gz: 587cfa31e2be95b2b47f3bc8b37f2a749fccdd68
4
+ data.tar.gz: c6365eaadd5898b4eb3be920b0da777bf72e7963
5
5
  SHA512:
6
- metadata.gz: b29f8e9324a0d33a245fd8ce6ee2b7c47d0ee0550bcc86cdd4f22610c596dd112aaf80f4f37b64bd8bf376faf5aaa657afec10c6a7cf89b4415369dcc7af4ced
7
- data.tar.gz: 6ca3d129843dd9d774160f57fa4807677c2c3e84e08669fddc37bd749e99c60240b8ec68aa394071dafadd9e52e17546680e51b8f3c00a7f51d66ecd6530508d
6
+ metadata.gz: c4f24894837424828d9497f1f7051dcd3a821b0fb1000a8f7595910b50f431954459adc86a7aaedf4df8958d82b7eaeda5163fbeff1d604d754e6f0f693b8eb1
7
+ data.tar.gz: 00be7897906fa849398cede10df3b32a5e136857274e465733fbdd276c7750f5ddf63d0d11f4651de2dcc9dcc57e64d86937f63968b0d86bbe4a2c33e00e54e1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- halunke (0.5.3)
4
+ halunke (0.6.0)
5
5
  rack (~> 2.0.4)
6
6
 
7
7
  GEM
@@ -31,6 +31,9 @@
31
31
  <li class="nav-item">
32
32
  <a class="nav-link" href="/dictionary">Dictionary</a>
33
33
  </li>
34
+ <li class="nav-item">
35
+ <a class="nav-link" href="/regexp">Regexp</a>
36
+ </li>
34
37
  <li class="nav-item">
35
38
  <a class="nav-link" href="/true-false">True & False</a>
36
39
  </li>
@@ -52,17 +55,35 @@
52
55
 
53
56
  <header>
54
57
  <div class="alert alert-primary" role="alert">
55
- Halunke is Open Source and on <a href="http://github.com/moonglum/halunke">Github. <a href="http://try.halunke.jetzt">Try out Halunke online!</a>
58
+ Halunke is Open Source and on <a href="http://github.com/moonglum/halunke">Github. <a href="#repl">Try out Halunke online!</a>
56
59
  </div>
57
60
  <h1>{{ page.title }}</h1>
58
61
  </header>
59
62
  <main>
60
63
  {{ content }}
61
64
  </main>
65
+ <footer>
66
+ <h2 id="repl">Try Halunke in your browser</h2>
67
+ <a href="https://try.halunke.jetzt/repl" onclick="javascript:launch_repl(this); return false;">Click here to start an interactive Halunke Shell.</a>
68
+ You can also go to <a target="_blank" href="https://try.halunke.jetzt/repl">try.halunke.jetzt</a> to directly open the REPL.
69
+ <div id="try-frame-target"></div>
70
+ </footer>
62
71
  </div>
63
72
 
64
73
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
65
74
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
66
75
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
76
+ <script>
77
+ var launch_repl = function(element) {
78
+ var iframe = document.createElement('iframe');
79
+ var wrapper = document.querySelectorAll('#try-frame-target');
80
+ iframe.src = element.getAttribute('href');
81
+ iframe.id = 'try-frame';
82
+ iframe.style = 'width: 100%; border: 2px solid #f3f3f3; position: sticky; height: 200px; margin-top: 10px; bottom: 0; left: 0; right: 0; box-shadow: 0 -3px 6px 0px #888888';
83
+ iframe.scrolling = 'no';
84
+ element.remove();
85
+ wrapper[0].replaceWith(iframe);
86
+ };
87
+ </script>
67
88
  </body>
68
89
  </html>
data/docs/array.md CHANGED
@@ -17,6 +17,18 @@ whitespace.
17
17
 
18
18
  It can answer to the following messages:
19
19
 
20
+ ## `@ else`
21
+
22
+ Looks up a value in the Array by index. If the index is out of
23
+ bounds for the array, return the fallback value
24
+
25
+ **Example:**
26
+
27
+ ```
28
+ ([2 3 4] @ 1 else "NOT FOUND") /* => 3 */
29
+ ([2 3 4] @ 3 else "NOT FOUND") /* => "NOT FOUND" */
30
+ ```
31
+
20
32
  ## `=`
21
33
 
22
34
  Compares to arrays. If they have the same length and each item from
data/docs/dictionary.md CHANGED
@@ -13,6 +13,14 @@ written in square brackets, prefixed with an `@`.
13
13
  @["a" 1 "b" 2]
14
14
  ```
15
15
 
16
+ It has an alternative constructor to construct it from an array of
17
+ two element arrays:
18
+
19
+ ```
20
+ (Dictionary from [["a" 1] ["b" 2]])
21
+ /* => @["a" 1 "b" 2] */
22
+ ```
23
+
16
24
  It can answer to the following message:
17
25
 
18
26
  ## `@ else`
@@ -27,6 +35,18 @@ dictionary, the fallback value is used.
27
35
  (@["a" 1 "b" 2] @ "c" else "Not Found") /* => "Not Found" */
28
36
  ```
29
37
 
38
+ ## `merge`
39
+
40
+ Returns a new dictionary that is this dictionary merged with
41
+ another dictionary.
42
+
43
+ **Example:**
44
+
45
+ ```
46
+ (@["a" 1 "b" 2] merge @["c" 3])
47
+ /* => @["a" 1 "b" 2 "c" 3] */
48
+ ```
49
+
30
50
  ## `to_s`
31
51
 
32
52
  This returns a string to represent the dictionary in output.
data/docs/regexp.md ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ title: Regexp
3
+ ---
4
+
5
+ Regexp is a regular expression. It can be created like this:
6
+
7
+ ```
8
+ (Regexp from "a+")
9
+ ```
10
+
11
+ Currently it doesn't answer to any messages except `inspect` and `to_s`. To use
12
+ a Regexp, see the messages you can send to [String](/string).
data/docs/string.md CHANGED
@@ -24,12 +24,47 @@ Return a reversed version of the String.
24
24
 
25
25
  ## `replace with`
26
26
 
27
- Replace all occurrences of the first string with the second string.
27
+ Replace all occurrences of the first string with the second string. You can
28
+ also provide a Regexp as the first argument. You can then use backreferences in
29
+ the `with` String: The entire match can be referenced by `\0`, the first group
30
+ by `\1` etc,
28
31
 
29
- **Example:**
32
+ **Examples:**
30
33
 
31
34
  ```
32
35
  ("ababab" replace "a" with "c") /* => "cbcbcb" */
36
+
37
+ ("ababab" replace (Regexp from "(a)") with "<\1>")
38
+ /* => "<a>b<a>b<a>b" */
39
+ ```
40
+
41
+ ## `scan`
42
+
43
+ Find all occurrences of the given Regex. Returns an Array. If it doesn't
44
+ include any groups, it contains Strings. If it contains groups, then it
45
+ contains arrays of strings.
46
+
47
+ ```
48
+ ('result = ("aaabaac" scan (Regexp from "a+")))
49
+ (result @ 0 else "NOT FOUND") /* => "aaa" */
50
+ ```
51
+
52
+ ## `match`
53
+
54
+ This matches a Regexp over a String an collects the results in a Dictionary.
55
+ The entire match is available under the key 0. Every named match can be
56
+ referenced by its position starting from 1. And all named matches can be
57
+ referenced by their name and their position.
58
+
59
+ ```
60
+ ('regexp = (Regexp from "(?<foo>a+)b(?<bar>c+)"))
61
+ ('match = ("aaaabcc" match regexp))
62
+
63
+ (match @ 0 else "NOT FOUND") /* => "aaaabcc" */
64
+ (match @ 1 else "NOT FOUND") /* => "aaaa" */
65
+ (match @ 2 else "NOT FOUND") /* => "cc" */
66
+ (match @ "foo" else "NOT FOUND") /* => "aaaa" */
67
+ (match @ "bar" else "NOT FOUND") /* => "cc" */
33
68
  ```
34
69
 
35
70
  ## `=`
@@ -13,6 +13,9 @@ module Halunke
13
13
  memo.receive_message(context, "and", [value])
14
14
  end
15
15
  }),
16
+ "@ else" => HFunction.new([:self, :index, :fallback], lambda { |context|
17
+ context["self"].ruby_value[context["index"].ruby_value] || context["fallback"]
18
+ }),
16
19
  "map" => HFunction.new([:self, :fn], lambda { |context|
17
20
  return HArray.create_instance(context["self"].ruby_value.map do |x|
18
21
  context["fn"].receive_message(context, "call", [HArray.create_instance([x])])
@@ -10,6 +10,9 @@ module Halunke
10
10
  end
11
11
  result ? result[1] : context["fallback"]
12
12
  }),
13
+ "merge" => HFunction.new([:self, :other], lambda { |context|
14
+ HDictionary.create_instance(context["self"].ruby_value.merge(context["other"].ruby_value))
15
+ }),
13
16
  "to_s" => HFunction.new([:self], lambda { |context|
14
17
  x = []
15
18
  context["self"].ruby_value.each_pair do |key, value|
@@ -28,7 +31,11 @@ module Halunke
28
31
  HString.create_instance("@[#{x.join(' ')}]")
29
32
  })
30
33
  },
31
- {},
34
+ {
35
+ "from" => HFunction.new([:self, :array], lambda { |context|
36
+ context["self"].create_instance(context["array"].ruby_value.map(&:ruby_value).to_h)
37
+ })
38
+ },
32
39
  true
33
40
  )
34
41
  end
@@ -4,7 +4,10 @@ module Halunke
4
4
  "Regexp",
5
5
  [],
6
6
  {
7
- "inspect" => HFunction.new([:self, :attr], lambda { |context|
7
+ "to_s" => HFunction.new([:self], lambda { |context|
8
+ HString.create_instance(context["self"].ruby_value.inspect)
9
+ }),
10
+ "inspect" => HFunction.new([:self], lambda { |context|
8
11
  HString.create_instance(context["self"].ruby_value.inspect)
9
12
  })
10
13
  },
@@ -27,6 +27,17 @@ module Halunke
27
27
  end
28
28
  HDictionary.create_instance(h)
29
29
  }),
30
+ "scan" => HFunction.new([:self, :regexp], lambda { |context|
31
+ result = context["self"].ruby_value.scan(context["regexp"].ruby_value)
32
+
33
+ HArray.create_instance(result.map do |r|
34
+ if r.class == Array
35
+ HArray.create_instance(r.map { |x| HString.create_instance(x) })
36
+ else
37
+ HString.create_instance(r)
38
+ end
39
+ end)
40
+ }),
30
41
  "=" => HFunction.new([:self, :other], lambda { |context|
31
42
  if context["self"].ruby_value == context["other"].ruby_value
32
43
  context["true"]
@@ -1,3 +1,3 @@
1
1
  module Halunke
2
- VERSION = "0.5.3"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halunke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Dohmen
@@ -112,6 +112,7 @@ files:
112
112
  - docs/function.md
113
113
  - docs/index.md
114
114
  - docs/number.md
115
+ - docs/regexp.md
115
116
  - docs/stdio.md
116
117
  - docs/string.md
117
118
  - docs/true-false.md