halunke 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d34373e62580207f15e635b87cbbba8187f43aa5
4
+ data.tar.gz: '08eebf0cc515092ff533c44a271d7fc4b3c4a451'
5
+ SHA512:
6
+ metadata.gz: 41960737ac425cc20b7183ab8a506e64e11c55a7dab81d00abfa120d32b9b770e1500f69e595b0d4a73c19d5442e96adb2cfaf06ddace218b71415ec9df66a58
7
+ data.tar.gz: f00d5bae53b39ae1c26b7bcde7ad8c16917b7e04a94c358680fc98850ead5e40284ec72cb3d1a6fb8802306dcbcb4d645236369b76fd9917b29ce26af4dbe1b0
data/.editorconfig ADDED
@@ -0,0 +1,23 @@
1
+ # This is an EditorConfig file
2
+ # http://EditorConfig.org
3
+ # It configures your editor or IDE according to the project standards
4
+
5
+ # top-most EditorConfig file
6
+ root = true
7
+
8
+ # These rules apply to all files
9
+ [*]
10
+ # Unix-style newlines
11
+ end_of_line = lf
12
+ # Newline at the end of the file (See: https://robots.thoughtbot.com/no-newline-at-end-of-file)
13
+ insert_final_newline = true
14
+ # Set default charset
15
+ charset = utf-8
16
+ # 2 space indentation
17
+ indent_style = space
18
+ indent_size = 2
19
+ # Trim trailing whitespace
20
+ trim_trailing_whitespace = true
21
+
22
+ [*{.md,.markdown,.mdown}]
23
+ indent_size = 4
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.3
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at lucas@dohmen.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in halunke.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ halunke (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.11.3)
10
+ racc (1.4.14)
11
+ rake (12.3.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.16.1)
18
+ halunke!
19
+ minitest (~> 5.11.3)
20
+ racc (~> 1.4.14)
21
+ rake (~> 12.3.0)
22
+
23
+ BUNDLED WITH
24
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Lucas Dohmen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Halunke
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/halunke`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'halunke'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install halunke
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/halunke. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Halunke project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/halunke/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ desc 'Compile Lexer with Ragel'
5
+ task :compile do
6
+ sh 'ragel -R -o lib/halunke/lexer.rb lib/halunke/lexer.rl'
7
+ sh 'racc -o lib/halunke/parser.rb lib/halunke/grammar.y'
8
+ end
9
+
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << "test"
12
+ t.libs << "lib"
13
+ t.test_files = FileList["test/**/*_test.rb"]
14
+ t.deps = [:compile]
15
+ end
16
+
17
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "halunke"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/exe/halunke ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "halunke/interpreter"
4
+ require "readline"
5
+
6
+ interpreter = Halunke::Interpreter.new
7
+
8
+ puts "Halunke REPL. Ctrl+d to quit"
9
+ while (line = Readline.readline(">> ", true))
10
+ value = interpreter.eval(line)
11
+ puts "=> #{value}"
12
+ end
data/halunke.gemspec ADDED
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "halunke/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "halunke"
8
+ spec.version = Halunke::VERSION
9
+ spec.authors = ["Lucas Dohmen"]
10
+ spec.email = ["lucas@dohmen.io"]
11
+
12
+ spec.summary = %q{The Halunke programming language}
13
+ spec.description = %q{A prototype for an OO language that embraces ideas like immutability and Lispyness}
14
+ spec.homepage = "https://github.com/moonglum/halunke"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16.1"
25
+ spec.add_development_dependency "rake", "~> 12.3.0"
26
+ spec.add_development_dependency "minitest", "~> 5.11.3"
27
+ spec.add_development_dependency "racc", "~> 1.4.14"
28
+ end
data/lib/halunke.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "halunke/version"
2
+
3
+ module Halunke
4
+ end
@@ -0,0 +1,54 @@
1
+ class Halunke::Parser
2
+
3
+ token NUMBER
4
+ token STRING
5
+ token BAREWORD
6
+ token OPEN_PAREN
7
+ token CLOSE_PAREN
8
+ token OPERATOR
9
+
10
+ rule
11
+ Program:
12
+ /* empty */ { result = Nodes.new }
13
+ | Expressions { result = val[0] }
14
+ ;
15
+
16
+ Expressions:
17
+ Expression { result = Nodes.new(val) }
18
+ ;
19
+
20
+ Expression:
21
+ Literal
22
+ | OPEN_PAREN Literal Literals CLOSE_PAREN { result = Halunke::MessageSendNode.new(val[1], MessageNode.new(val[2].nodes)) }
23
+ ;
24
+
25
+ Literals:
26
+ /* empty */ { result = Nodes.new }
27
+ | Literal Literals { result = Nodes.new([val[0]]).concat(val[1]) }
28
+ ;
29
+
30
+ Literal:
31
+ NUMBER { result = NumberNode.new(val[0]) }
32
+ | STRING { result = StringNode.new(val[0]) }
33
+ /* TODO: Are Operators just Barewords? */
34
+ | BAREWORD { result = BarewordNode.new(val[0]) }
35
+ | OPERATOR { result = BarewordNode.new(val[0]) }
36
+ ;
37
+
38
+ end
39
+
40
+ ---- header
41
+
42
+ require "halunke/lexer"
43
+ require "halunke/nodes"
44
+
45
+ ---- inner
46
+
47
+ def parse(code)
48
+ @tokens = Lexer.new.tokenize(code)
49
+ do_parse
50
+ end
51
+
52
+ def next_token
53
+ @tokens.shift
54
+ end
@@ -0,0 +1,28 @@
1
+ require "halunke/parser"
2
+
3
+ module Halunke
4
+ class Interpreter
5
+ def initialize
6
+ @parser = Parser.new
7
+ @context = {}
8
+ prelude
9
+ end
10
+
11
+ def eval(str)
12
+ nodes = @parser.parse(str)
13
+ nodes.eval(@context)
14
+ end
15
+
16
+ private
17
+
18
+ def prelude
19
+ @context[:Number] = Halunke::NativeClass.new(
20
+ "+" => Halunke::NativeFunction.new(->(receiver, args) { receiver.ruby_value + args.first.ruby_value })
21
+ )
22
+
23
+ @context[:String] = Halunke::NativeClass.new(
24
+ "reverse" => Halunke::NativeFunction.new(->(receiver, _args) { receiver.ruby_value.reverse })
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,380 @@
1
+
2
+ # line 1 "lib/halunke/lexer.rl"
3
+ =begin
4
+
5
+ # line 24 "lib/halunke/lexer.rl"
6
+
7
+ =end
8
+
9
+ module Halunke
10
+ class Lexer
11
+ def initialize
12
+
13
+ # line 14 "lib/halunke/lexer.rb"
14
+ class << self
15
+ attr_accessor :_lexer_actions
16
+ private :_lexer_actions, :_lexer_actions=
17
+ end
18
+ self._lexer_actions = [
19
+ 0, 1, 0, 1, 1, 1, 2, 1,
20
+ 5, 1, 6, 1, 7, 1, 8, 1,
21
+ 9, 1, 10, 1, 11, 1, 12, 1,
22
+ 13, 2, 2, 3, 2, 2, 4
23
+ ]
24
+
25
+ class << self
26
+ attr_accessor :_lexer_key_offsets
27
+ private :_lexer_key_offsets, :_lexer_key_offsets=
28
+ end
29
+ self._lexer_key_offsets = [
30
+ 0, 1, 16, 17, 19
31
+ ]
32
+
33
+ class << self
34
+ attr_accessor :_lexer_trans_keys
35
+ private :_lexer_trans_keys, :_lexer_trans_keys=
36
+ end
37
+ self._lexer_trans_keys = [
38
+ 34, 32, 34, 40, 41, 43, 45, 95,
39
+ 9, 13, 48, 57, 65, 90, 97, 122,
40
+ 34, 48, 57, 95, 65, 90, 97, 122,
41
+ 0
42
+ ]
43
+
44
+ class << self
45
+ attr_accessor :_lexer_single_lengths
46
+ private :_lexer_single_lengths, :_lexer_single_lengths=
47
+ end
48
+ self._lexer_single_lengths = [
49
+ 1, 7, 1, 0, 1
50
+ ]
51
+
52
+ class << self
53
+ attr_accessor :_lexer_range_lengths
54
+ private :_lexer_range_lengths, :_lexer_range_lengths=
55
+ end
56
+ self._lexer_range_lengths = [
57
+ 0, 4, 0, 1, 2
58
+ ]
59
+
60
+ class << self
61
+ attr_accessor :_lexer_index_offsets
62
+ private :_lexer_index_offsets, :_lexer_index_offsets=
63
+ end
64
+ self._lexer_index_offsets = [
65
+ 0, 2, 14, 16, 18
66
+ ]
67
+
68
+ class << self
69
+ attr_accessor :_lexer_trans_targs
70
+ private :_lexer_trans_targs, :_lexer_trans_targs=
71
+ end
72
+ self._lexer_trans_targs = [
73
+ 1, 0, 1, 2, 1, 1, 3, 3,
74
+ 4, 1, 3, 4, 4, 1, 1, 0,
75
+ 3, 1, 4, 4, 4, 1, 1, 1,
76
+ 1, 1, 0
77
+ ]
78
+
79
+ class << self
80
+ attr_accessor :_lexer_trans_actions
81
+ private :_lexer_trans_actions, :_lexer_trans_actions=
82
+ end
83
+ self._lexer_trans_actions = [
84
+ 7, 0, 13, 5, 9, 11, 28, 28,
85
+ 0, 13, 25, 0, 0, 15, 7, 0,
86
+ 25, 23, 0, 0, 0, 17, 21, 19,
87
+ 23, 17, 0
88
+ ]
89
+
90
+ class << self
91
+ attr_accessor :_lexer_to_state_actions
92
+ private :_lexer_to_state_actions, :_lexer_to_state_actions=
93
+ end
94
+ self._lexer_to_state_actions = [
95
+ 0, 1, 0, 0, 0
96
+ ]
97
+
98
+ class << self
99
+ attr_accessor :_lexer_from_state_actions
100
+ private :_lexer_from_state_actions, :_lexer_from_state_actions=
101
+ end
102
+ self._lexer_from_state_actions = [
103
+ 0, 3, 0, 0, 0
104
+ ]
105
+
106
+ class << self
107
+ attr_accessor :_lexer_eof_trans
108
+ private :_lexer_eof_trans, :_lexer_eof_trans=
109
+ end
110
+ self._lexer_eof_trans = [
111
+ 23, 0, 24, 25, 26
112
+ ]
113
+
114
+ class << self
115
+ attr_accessor :lexer_start
116
+ end
117
+ self.lexer_start = 1;
118
+ class << self
119
+ attr_accessor :lexer_first_final
120
+ end
121
+ self.lexer_first_final = 1;
122
+ class << self
123
+ attr_accessor :lexer_error
124
+ end
125
+ self.lexer_error = -1;
126
+
127
+ class << self
128
+ attr_accessor :lexer_en_main
129
+ end
130
+ self.lexer_en_main = 1;
131
+
132
+
133
+ # line 31 "lib/halunke/lexer.rl"
134
+ @tokens = []
135
+ end
136
+
137
+ def tokenize(data)
138
+ data.chomp!
139
+ eof = data.length
140
+
141
+
142
+ # line 143 "lib/halunke/lexer.rb"
143
+ begin
144
+ p ||= 0
145
+ pe ||= data.length
146
+ cs = lexer_start
147
+ ts = nil
148
+ te = nil
149
+ act = 0
150
+ end
151
+
152
+ # line 39 "lib/halunke/lexer.rl"
153
+
154
+ # line 155 "lib/halunke/lexer.rb"
155
+ begin
156
+ _klen, _trans, _keys, _acts, _nacts = nil
157
+ _goto_level = 0
158
+ _resume = 10
159
+ _eof_trans = 15
160
+ _again = 20
161
+ _test_eof = 30
162
+ _out = 40
163
+ while true
164
+ _trigger_goto = false
165
+ if _goto_level <= 0
166
+ if p == pe
167
+ _goto_level = _test_eof
168
+ next
169
+ end
170
+ end
171
+ if _goto_level <= _resume
172
+ _acts = _lexer_from_state_actions[cs]
173
+ _nacts = _lexer_actions[_acts]
174
+ _acts += 1
175
+ while _nacts > 0
176
+ _nacts -= 1
177
+ _acts += 1
178
+ case _lexer_actions[_acts - 1]
179
+ when 1 then
180
+ # line 1 "NONE"
181
+ begin
182
+ ts = p
183
+ end
184
+ # line 185 "lib/halunke/lexer.rb"
185
+ end # from state action switch
186
+ end
187
+ if _trigger_goto
188
+ next
189
+ end
190
+ _keys = _lexer_key_offsets[cs]
191
+ _trans = _lexer_index_offsets[cs]
192
+ _klen = _lexer_single_lengths[cs]
193
+ _break_match = false
194
+
195
+ begin
196
+ if _klen > 0
197
+ _lower = _keys
198
+ _upper = _keys + _klen - 1
199
+
200
+ loop do
201
+ break if _upper < _lower
202
+ _mid = _lower + ( (_upper - _lower) >> 1 )
203
+
204
+ if data[p].ord < _lexer_trans_keys[_mid]
205
+ _upper = _mid - 1
206
+ elsif data[p].ord > _lexer_trans_keys[_mid]
207
+ _lower = _mid + 1
208
+ else
209
+ _trans += (_mid - _keys)
210
+ _break_match = true
211
+ break
212
+ end
213
+ end # loop
214
+ break if _break_match
215
+ _keys += _klen
216
+ _trans += _klen
217
+ end
218
+ _klen = _lexer_range_lengths[cs]
219
+ if _klen > 0
220
+ _lower = _keys
221
+ _upper = _keys + (_klen << 1) - 2
222
+ loop do
223
+ break if _upper < _lower
224
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1)
225
+ if data[p].ord < _lexer_trans_keys[_mid]
226
+ _upper = _mid - 2
227
+ elsif data[p].ord > _lexer_trans_keys[_mid+1]
228
+ _lower = _mid + 2
229
+ else
230
+ _trans += ((_mid - _keys) >> 1)
231
+ _break_match = true
232
+ break
233
+ end
234
+ end # loop
235
+ break if _break_match
236
+ _trans += _klen
237
+ end
238
+ end while false
239
+ end
240
+ if _goto_level <= _eof_trans
241
+ cs = _lexer_trans_targs[_trans]
242
+ if _lexer_trans_actions[_trans] != 0
243
+ _acts = _lexer_trans_actions[_trans]
244
+ _nacts = _lexer_actions[_acts]
245
+ _acts += 1
246
+ while _nacts > 0
247
+ _nacts -= 1
248
+ _acts += 1
249
+ case _lexer_actions[_acts - 1]
250
+ when 2 then
251
+ # line 1 "NONE"
252
+ begin
253
+ te = p+1
254
+ end
255
+ when 3 then
256
+ # line 14 "lib/halunke/lexer.rl"
257
+ begin
258
+ act = 1; end
259
+ when 4 then
260
+ # line 19 "lib/halunke/lexer.rl"
261
+ begin
262
+ act = 6; end
263
+ when 5 then
264
+ # line 15 "lib/halunke/lexer.rl"
265
+ begin
266
+ te = p+1
267
+ begin emit(:STRING, data[ts+1...te-1]) end
268
+ end
269
+ when 6 then
270
+ # line 17 "lib/halunke/lexer.rl"
271
+ begin
272
+ te = p+1
273
+ begin emit(:OPEN_PAREN, data[ts...te]) end
274
+ end
275
+ when 7 then
276
+ # line 18 "lib/halunke/lexer.rl"
277
+ begin
278
+ te = p+1
279
+ begin emit(:CLOSE_PAREN, data[ts...te]) end
280
+ end
281
+ when 8 then
282
+ # line 20 "lib/halunke/lexer.rl"
283
+ begin
284
+ te = p+1
285
+ end
286
+ when 9 then
287
+ # line 21 "lib/halunke/lexer.rl"
288
+ begin
289
+ te = p+1
290
+ begin raise "Could not lex '#{ data[ts...te] }'" end
291
+ end
292
+ when 10 then
293
+ # line 16 "lib/halunke/lexer.rl"
294
+ begin
295
+ te = p
296
+ p = p - 1; begin emit(:BAREWORD, data[ts...te]) end
297
+ end
298
+ when 11 then
299
+ # line 21 "lib/halunke/lexer.rl"
300
+ begin
301
+ te = p
302
+ p = p - 1; begin raise "Could not lex '#{ data[ts...te] }'" end
303
+ end
304
+ when 12 then
305
+ # line 21 "lib/halunke/lexer.rl"
306
+ begin
307
+ begin p = ((te))-1; end
308
+ begin raise "Could not lex '#{ data[ts...te] }'" end
309
+ end
310
+ when 13 then
311
+ # line 1 "NONE"
312
+ begin
313
+ case act
314
+ when 1 then
315
+ begin begin p = ((te))-1; end
316
+ emit(:NUMBER, data[ts...te].to_i) end
317
+ when 6 then
318
+ begin begin p = ((te))-1; end
319
+ emit(:OPERATOR, data[ts ... te]) end
320
+ end
321
+ end
322
+ # line 323 "lib/halunke/lexer.rb"
323
+ end # action switch
324
+ end
325
+ end
326
+ if _trigger_goto
327
+ next
328
+ end
329
+ end
330
+ if _goto_level <= _again
331
+ _acts = _lexer_to_state_actions[cs]
332
+ _nacts = _lexer_actions[_acts]
333
+ _acts += 1
334
+ while _nacts > 0
335
+ _nacts -= 1
336
+ _acts += 1
337
+ case _lexer_actions[_acts - 1]
338
+ when 0 then
339
+ # line 1 "NONE"
340
+ begin
341
+ ts = nil; end
342
+ # line 343 "lib/halunke/lexer.rb"
343
+ end # to state action switch
344
+ end
345
+ if _trigger_goto
346
+ next
347
+ end
348
+ p += 1
349
+ if p != pe
350
+ _goto_level = _resume
351
+ next
352
+ end
353
+ end
354
+ if _goto_level <= _test_eof
355
+ if p == eof
356
+ if _lexer_eof_trans[cs] > 0
357
+ _trans = _lexer_eof_trans[cs] - 1;
358
+ _goto_level = _eof_trans
359
+ next;
360
+ end
361
+ end
362
+ end
363
+ if _goto_level <= _out
364
+ break
365
+ end
366
+ end
367
+ end
368
+
369
+ # line 40 "lib/halunke/lexer.rl"
370
+
371
+ @tokens
372
+ end
373
+
374
+ private
375
+
376
+ def emit(type, value)
377
+ @tokens << [ type, value ]
378
+ end
379
+ end
380
+ end
@@ -0,0 +1,50 @@
1
+ =begin
2
+ %%{
3
+ machine lexer;
4
+
5
+ number = ('+'|'-')?[0-9]+;
6
+ string = '"' [^"]* '"';
7
+ bareword = [a-zA-Z_]+;
8
+ open_paren = '(';
9
+ close_paren = ')';
10
+ operator = '+' | '-';
11
+
12
+ main := |*
13
+
14
+ number => { emit(:NUMBER, data[ts...te].to_i) };
15
+ string => { emit(:STRING, data[ts+1...te-1]) };
16
+ bareword => { emit(:BAREWORD, data[ts...te]) };
17
+ open_paren => { emit(:OPEN_PAREN, data[ts...te]) };
18
+ close_paren => { emit(:CLOSE_PAREN, data[ts...te]) };
19
+ operator => { emit(:OPERATOR, data[ts ... te]) };
20
+ space;
21
+ any => { raise "Could not lex '#{ data[ts...te] }'" };
22
+
23
+ *|;
24
+ }%%
25
+ =end
26
+
27
+ module Halunke
28
+ class Lexer
29
+ def initialize
30
+ %% write data;
31
+ @tokens = []
32
+ end
33
+
34
+ def tokenize(data)
35
+ data.chomp!
36
+ eof = data.length
37
+
38
+ %% write init;
39
+ %% write exec;
40
+
41
+ @tokens
42
+ end
43
+
44
+ private
45
+
46
+ def emit(type, value)
47
+ @tokens << [ type, value ]
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,56 @@
1
+ require "halunke/runtime"
2
+
3
+ module Halunke
4
+ Nodes = Struct.new(:nodes) do
5
+ def initialize(nodes = [])
6
+ super(nodes)
7
+ end
8
+
9
+ def concat(other)
10
+ Nodes.new(nodes.concat(other.nodes))
11
+ end
12
+
13
+ def eval(context)
14
+ val = nil
15
+
16
+ nodes.each do |node|
17
+ val = node.eval(context)
18
+ end
19
+
20
+ val
21
+ end
22
+ end
23
+
24
+ LiteralNode = Struct.new(:value)
25
+
26
+ class NumberNode < LiteralNode
27
+ def eval(context)
28
+ context[:Number].create_instance(value)
29
+ end
30
+ end
31
+
32
+ class StringNode < LiteralNode
33
+ def eval(context)
34
+ context[:String].create_instance(value)
35
+ end
36
+ end
37
+
38
+ class BarewordNode < LiteralNode
39
+ end
40
+
41
+ MessageSendNode = Struct.new(:receiver, :message) do
42
+ def eval(context)
43
+ receiver.eval(context).receive_message(*message.eval(context))
44
+ end
45
+ end
46
+
47
+ MessageNode = Struct.new(:nodes) do
48
+ def eval(context)
49
+ case nodes.length
50
+ when 1 then [nodes[0].value, []]
51
+ when 2 then [nodes[0].value, [nodes[1].eval(context)]]
52
+ else raise "Not implemented"
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,206 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.14
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+
10
+ require "halunke/lexer"
11
+ require "halunke/nodes"
12
+
13
+ module Halunke
14
+ class Parser < Racc::Parser
15
+
16
+ module_eval(<<'...end grammar.y/module_eval...', 'grammar.y', 46)
17
+
18
+ def parse(code)
19
+ @tokens = Lexer.new.tokenize(code)
20
+ do_parse
21
+ end
22
+
23
+ def next_token
24
+ @tokens.shift
25
+ end
26
+ ...end grammar.y/module_eval...
27
+ ##### State transition tables begin ###
28
+
29
+ racc_action_table = [
30
+ 6, 7, 8, 5, 10, 9, 6, 7, 8, 12,
31
+ 15, 9, 6, 7, 8, nil, nil, 9, 6, 7,
32
+ 8, nil, nil, 9 ]
33
+
34
+ racc_action_check = [
35
+ 0, 0, 0, 0, 1, 0, 5, 5, 5, 10,
36
+ 13, 5, 11, 11, 11, nil, nil, 11, 14, 14,
37
+ 14, nil, nil, 14 ]
38
+
39
+ racc_action_pointer = [
40
+ -2, 4, nil, nil, nil, 4, nil, nil, nil, nil,
41
+ 9, 10, nil, 4, 16, nil, nil ]
42
+
43
+ racc_action_default = [
44
+ -1, -12, -2, -3, -4, -12, -8, -9, -10, -11,
45
+ -12, -6, 17, -12, -6, -5, -7 ]
46
+
47
+ racc_goto_table = [
48
+ 4, 13, 1, 2, 16, 11, 3 ]
49
+
50
+ racc_goto_check = [
51
+ 4, 5, 1, 2, 5, 4, 3 ]
52
+
53
+ racc_goto_pointer = [
54
+ nil, 2, 3, 6, 0, -10 ]
55
+
56
+ racc_goto_default = [
57
+ nil, nil, nil, nil, 14, nil ]
58
+
59
+ racc_reduce_table = [
60
+ 0, 0, :racc_error,
61
+ 0, 9, :_reduce_1,
62
+ 1, 9, :_reduce_2,
63
+ 1, 10, :_reduce_3,
64
+ 1, 11, :_reduce_none,
65
+ 4, 11, :_reduce_5,
66
+ 0, 13, :_reduce_6,
67
+ 2, 13, :_reduce_7,
68
+ 1, 12, :_reduce_8,
69
+ 1, 12, :_reduce_9,
70
+ 1, 12, :_reduce_10,
71
+ 1, 12, :_reduce_11 ]
72
+
73
+ racc_reduce_n = 12
74
+
75
+ racc_shift_n = 17
76
+
77
+ racc_token_table = {
78
+ false => 0,
79
+ :error => 1,
80
+ :NUMBER => 2,
81
+ :STRING => 3,
82
+ :BAREWORD => 4,
83
+ :OPEN_PAREN => 5,
84
+ :CLOSE_PAREN => 6,
85
+ :OPERATOR => 7 }
86
+
87
+ racc_nt_base = 8
88
+
89
+ racc_use_result_var = true
90
+
91
+ Racc_arg = [
92
+ racc_action_table,
93
+ racc_action_check,
94
+ racc_action_default,
95
+ racc_action_pointer,
96
+ racc_goto_table,
97
+ racc_goto_check,
98
+ racc_goto_default,
99
+ racc_goto_pointer,
100
+ racc_nt_base,
101
+ racc_reduce_table,
102
+ racc_token_table,
103
+ racc_shift_n,
104
+ racc_reduce_n,
105
+ racc_use_result_var ]
106
+
107
+ Racc_token_to_s_table = [
108
+ "$end",
109
+ "error",
110
+ "NUMBER",
111
+ "STRING",
112
+ "BAREWORD",
113
+ "OPEN_PAREN",
114
+ "CLOSE_PAREN",
115
+ "OPERATOR",
116
+ "$start",
117
+ "Program",
118
+ "Expressions",
119
+ "Expression",
120
+ "Literal",
121
+ "Literals" ]
122
+
123
+ Racc_debug_parser = false
124
+
125
+ ##### State transition tables end #####
126
+
127
+ # reduce 0 omitted
128
+
129
+ module_eval(<<'.,.,', 'grammar.y', 11)
130
+ def _reduce_1(val, _values, result)
131
+ result = Nodes.new
132
+ result
133
+ end
134
+ .,.,
135
+
136
+ module_eval(<<'.,.,', 'grammar.y', 12)
137
+ def _reduce_2(val, _values, result)
138
+ result = val[0]
139
+ result
140
+ end
141
+ .,.,
142
+
143
+ module_eval(<<'.,.,', 'grammar.y', 16)
144
+ def _reduce_3(val, _values, result)
145
+ result = Nodes.new(val)
146
+ result
147
+ end
148
+ .,.,
149
+
150
+ # reduce 4 omitted
151
+
152
+ module_eval(<<'.,.,', 'grammar.y', 21)
153
+ def _reduce_5(val, _values, result)
154
+ result = Halunke::MessageSendNode.new(val[1], MessageNode.new(val[2].nodes))
155
+ result
156
+ end
157
+ .,.,
158
+
159
+ module_eval(<<'.,.,', 'grammar.y', 25)
160
+ def _reduce_6(val, _values, result)
161
+ result = Nodes.new
162
+ result
163
+ end
164
+ .,.,
165
+
166
+ module_eval(<<'.,.,', 'grammar.y', 26)
167
+ def _reduce_7(val, _values, result)
168
+ result = Nodes.new([val[0]]).concat(val[1])
169
+ result
170
+ end
171
+ .,.,
172
+
173
+ module_eval(<<'.,.,', 'grammar.y', 30)
174
+ def _reduce_8(val, _values, result)
175
+ result = NumberNode.new(val[0])
176
+ result
177
+ end
178
+ .,.,
179
+
180
+ module_eval(<<'.,.,', 'grammar.y', 31)
181
+ def _reduce_9(val, _values, result)
182
+ result = StringNode.new(val[0])
183
+ result
184
+ end
185
+ .,.,
186
+
187
+ module_eval(<<'.,.,', 'grammar.y', 33)
188
+ def _reduce_10(val, _values, result)
189
+ result = BarewordNode.new(val[0])
190
+ result
191
+ end
192
+ .,.,
193
+
194
+ module_eval(<<'.,.,', 'grammar.y', 34)
195
+ def _reduce_11(val, _values, result)
196
+ result = BarewordNode.new(val[0])
197
+ result
198
+ end
199
+ .,.,
200
+
201
+ def _reduce_none(val, _values, result)
202
+ val[0]
203
+ end
204
+
205
+ end # class Parser
206
+ end # module Halunke
@@ -0,0 +1,41 @@
1
+ # This file is not tested directly right now,
2
+ # because I'm not sure if this structure is good
3
+ module Halunke
4
+ class NativeClass
5
+ def initialize(methods)
6
+ @runtime_methods = methods
7
+ end
8
+
9
+ def create_instance(ruby_value)
10
+ NativeObject.new(self, ruby_value)
11
+ end
12
+
13
+ def lookup(message)
14
+ @runtime_methods[message]
15
+ end
16
+ end
17
+
18
+ class NativeObject
19
+ attr_reader :ruby_value
20
+
21
+ def initialize(runtime_class, ruby_value)
22
+ @runtime_class = runtime_class
23
+ @ruby_value = ruby_value
24
+ end
25
+
26
+ def receive_message(message_name, message_value)
27
+ m = @runtime_class.lookup(message_name)
28
+ m.call(self, message_value)
29
+ end
30
+ end
31
+
32
+ class NativeFunction
33
+ def initialize(fn)
34
+ @fn = fn
35
+ end
36
+
37
+ def call(receiver, args)
38
+ @fn.call(receiver, args)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Halunke
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: halunke
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Dohmen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.16.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.16.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.11.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.11.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: racc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.14
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.4.14
69
+ description: A prototype for an OO language that embraces ideas like immutability
70
+ and Lispyness
71
+ email:
72
+ - lucas@dohmen.io
73
+ executables:
74
+ - halunke
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".editorconfig"
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - exe/halunke
90
+ - halunke.gemspec
91
+ - lib/halunke.rb
92
+ - lib/halunke/grammar.y
93
+ - lib/halunke/interpreter.rb
94
+ - lib/halunke/lexer.rb
95
+ - lib/halunke/lexer.rl
96
+ - lib/halunke/nodes.rb
97
+ - lib/halunke/parser.rb
98
+ - lib/halunke/runtime.rb
99
+ - lib/halunke/version.rb
100
+ homepage: https://github.com/moonglum/halunke
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.6.14
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: The Halunke programming language
124
+ test_files: []